--- parser3/src/classes/xdoc.C 2001/12/29 08:39:04 1.56 +++ parser3/src/classes/xdoc.C 2002/01/14 15:29:41 1.58 @@ -4,7 +4,7 @@ Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com) Author: Alexander Petrosyan (http://paf.design.ru) - $Id: xdoc.C,v 1.56 2001/12/29 08:39:04 paf Exp $ + $Id: xdoc.C,v 1.58 2002/01/14 15:29:41 paf Exp $ */ #include "pa_types.h" #include "classes.h" @@ -12,8 +12,6 @@ #include "pa_request.h" #include "pa_vxdoc.h" -//#include "pa_stylesheet_manager.h" -//#include "pa_stylesheet_connection.h" #include "pa_charset.h" #include "pa_vfile.h" #include "xnode.h" @@ -68,7 +66,7 @@ static void _createElement(Request& r, c GdomeException exc; GdomeNode *node= (GdomeNode *)gdome_doc_createElement(vdoc.get_document(&method_name), - pool.transcode(tagName), + pool.transcode(tagName).get(), &exc); writeNode(r, method_name, node, exc); } @@ -96,7 +94,7 @@ static void _createTextNode(Request& r, GdomeException exc; GdomeNode *node=(GdomeNode *)gdome_doc_createTextNode( vdoc.get_document(&method_name), - pool.transcode(data), + pool.transcode(data).get(), &exc); writeNode(r, method_name, node, exc); } @@ -111,7 +109,7 @@ static void _createComment(Request& r, c GdomeException exc; GdomeNode *node=(GdomeNode *)gdome_doc_createComment( vdoc.get_document(&method_name), - pool.transcode(data), + pool.transcode(data).get(), &exc); writeNode(r, method_name, node, exc); } @@ -126,7 +124,7 @@ static void _createCDATASection(Request& GdomeException exc; GdomeNode *node=(GdomeNode *)gdome_doc_createCDATASection( vdoc.get_document(&method_name), - pool.transcode(data), + pool.transcode(data).get(), &exc); writeNode(r, method_name, node, exc); } @@ -142,8 +140,8 @@ static void _createProcessingInstruction GdomeException exc; GdomeNode *node=(GdomeNode *)gdome_doc_createProcessingInstruction( vdoc.get_document(&method_name), - pool.transcode(target), - pool.transcode(data), + pool.transcode(target).get(), + pool.transcode(data).get(), &exc); writeNode(r, method_name, node, exc); } @@ -158,7 +156,7 @@ static void _createAttribute(Request& r, GdomeException exc; GdomeNode *node=(GdomeNode *)gdome_doc_createAttribute( vdoc.get_document(&method_name), - pool.transcode(name), + pool.transcode(name).get(), &exc); writeNode(r, method_name, node, exc); } @@ -172,7 +170,7 @@ static void _createEntityReference(Reque GdomeException exc; GdomeNode *node=(GdomeNode *)gdome_doc_createEntityReference( vdoc.get_document(&method_name), - pool.transcode(name), + pool.transcode(name).get(), &exc); writeNode(r, method_name, node, exc); } @@ -188,7 +186,7 @@ static void _getElementsByTagName(Reques if(GdomeNodeList *nodes= gdome_doc_getElementsByTagName( vdoc.get_document(&method_name), - pool.transcode(name), + pool.transcode(name).get(), &exc)) { gulong length=gdome_nl_length(nodes, &exc); for(gulong i=0; i(r.self); - VXnode& vnode=*static_cast(r.self); - // node - GdomeNode *node=vnode.get_node(pool, &method_name); + char *mem; + GdomeException exc; + if(!gdome_di_saveDocToMemory(domimpl, + vdoc.get_document(&method_name), + &mem, + GDOME_SAVE_LIBXML_INDENT /*GDOME_SAVE_STANDARD */, + &exc)) + throw Exception(0, 0, + &method_name, + exc); - try { - VXdoc::Output_options oo(vdoc.output_options); - String& parserString=*new(pool) String(pool); - ParserStringXalanOutputStream stream(parserString); - XalanOutputStreamPrintWriter writer(stream); - std::auto_ptr formatterListener= - create_optioned_listener(pool, method_name, params, 0, - oo, writer); - FormatterTreeWalker treeWalker(*formatterListener); - treeWalker.traverse(&node); // Walk that node and produce the XML... + // move to pool memory + size_t buf_size=strlen(mem); + char *buf=(char *)pool.malloc(buf_size); + memcpy(buf, mem, buf_size); + g_free(mem); - // write out result - VFile& vfile=*new(pool) VFile(pool); - const char *cstr=parserString.cstr(); - const String& scontent_type=pool.transcode(oo.mediaType); - Value *vcontent_type; - if(oo.encoding.empty()) - vcontent_type=new(pool) VString(scontent_type); - else { - VHash *vhcontent_type=new(pool) VHash(pool); - vhcontent_type->hash(&method_name).put(*value_name, new(pool) VString(scontent_type)); - const String& scharset=pool.transcode(oo.encoding); - vhcontent_type->hash(&method_name).put(*new(pool) String(pool, "charset"), new(pool) VString(scharset)); - vcontent_type=vhcontent_type; - } - - vfile.set(false/*tainted* /, cstr, strlen(cstr), 0/*file_name* /, vcontent_type); - r.write_no_lang(vfile); - } catch(const XSLException& e) { - Exception::provide_source(pool, &method_name, e); - } + // write out result + VFile& vfile=*new(pool) VFile(pool); + const String& scontent_type=*new(pool) String(pool, "text/xml"); + Value *vcontent_type=new(pool) VString(scontent_type); + VHash *vhcontent_type=new(pool) VHash(pool); + vhcontent_type->hash(&method_name).put(*value_name, new(pool) VString(scontent_type)); + const String& scharset=pool.get_source_charset().name(); + vhcontent_type->hash(&method_name).put(*new(pool) String(pool, "charset"), new(pool) VString(scharset)); + vcontent_type=vhcontent_type; + + vfile.set(false/*tainted*/, buf, buf_size, 0/*file_name*/, vcontent_type); + r.write_no_lang(vfile); } -*/ + /* /// @test lang=String::UL_UNSPECIFIED? static void add_xslt_param(const Hash::Key& aattribute, Hash::Val *ameaning, @@ -770,7 +760,7 @@ MXdoc::MXdoc(Pool& apool) : MXnode(apool // ^xdoc.file[] file with "" // ^xdoc.file[options hash] file with "" -// add_native_method("file", Method::CT_DYNAMIC, _file, 0, 1); + add_native_method("file", Method::CT_DYNAMIC, _file, 0, 1); // ^xdoc.transform[stylesheet file_name] // ^xdoc.transform[stylesheet file_name;params hash]