--- parser3/src/classes/xdoc.C 2011/05/27 06:55:47 1.169 +++ parser3/src/classes/xdoc.C 2011/11/23 12:17:23 1.172 @@ -9,7 +9,7 @@ #ifdef XML -static const char * const IDENT_XDOC_C="$Date: 2011/05/27 06:55:47 $"; +static const char * const IDENT_XDOC_C="$Date: 2011/11/23 12:17:23 $"; #include "libxml/tree.h" #include "libxml/HTMLtree.h" @@ -28,6 +28,7 @@ static const char * const IDENT_XDOC_C=" #include "pa_vfile.h" #include "pa_xml_exception.h" #include "xnode.h" +#include "pa_charsets.h" // defines @@ -469,24 +470,22 @@ String::C xdoc2buf(Request& r, VXdoc& vd XDocOutputOptions& oo, const String* file_spec, bool use_source_charset_to_render_and_client_charset_to_write_to_header=false) { - const char* render_encoding; - const char* header_encoding; + Charset* render=0; + Charset* header=0; if(use_source_charset_to_render_and_client_charset_to_write_to_header) { - render_encoding=r.charsets.source().NAME_CSTR(); - header_encoding=r.charsets.client().NAME_CSTR(); + render=&r.charsets.source(); + header=&r.charsets.client(); } else { - header_encoding=render_encoding=oo.encoding->cstr(); + header=render=&charsets.get(oo.encoding->change_case(r.charsets.source(), String::CC_UPPER)); } + const char* render_encoding=render->NAME_CSTR(); + const char* header_encoding=header->NAME_CSTR(); xmlCharEncodingHandler *renderer=xmlFindCharEncodingHandler(render_encoding); - if(!renderer) - throw Exception(PARSER_RUNTIME, - 0, - "encoding '%s' not supported", render_encoding); // UTF-8 renderer contains empty input/output converters, // which is wrong for xmlOutputBufferCreateIO // while zero renderer goes perfectly - if(strcmp(render_encoding, "UTF-8")==0) + if(render->isUTF8()) renderer=0; xmlOutputBuffer_auto_ptr outputBuffer(xmlAllocOutputBuffer(renderer)); @@ -549,7 +548,7 @@ inline HashStringValue* get_options(Meth static void _file(Request& r, MethodParams& params) { VXdoc& vdoc=GET_SELF(r, VXdoc); - XDocOutputOptions oo(r, get_options(params, 0)); + XDocOutputOptions oo(r, get_options(params, 0), true/* $.name[filename] could be specified by user */); String::C buf=xdoc2buf(r, vdoc, oo, 0/*file_name. not to file, to memory*/); VFile& vfile=*new VFile; @@ -561,8 +560,7 @@ static void _file(Request& r, MethodPara String::Body("charset"), new VString(*oo.encoding)); - vfile.set(false/*tainted*/, buf.str?buf.str:""/*to distinguish from stat-ed file*/, buf.length, - 0/*file_name*/, &vhcontent_type); + vfile.set(false/*tainted*/, buf.str?buf.str:""/*to distinguish from stat-ed file*/, buf.length, oo.filename, &vhcontent_type); vfile.set_mode(true/*text*/);