--- parser3/src/classes/xdoc.C 2012/03/16 09:24:08 1.173
+++ parser3/src/classes/xdoc.C 2015/04/06 22:27:25 1.181
@@ -28,7 +28,7 @@
#include "xnode.h"
#include "pa_charsets.h"
-volatile const char * IDENT_XDOC_C="$Id: xdoc.C,v 1.173 2012/03/16 09:24:08 moko Exp $";
+volatile const char * IDENT_XDOC_C="$Id: xdoc.C,v 1.181 2015/04/06 22:27:25 moko Exp $";
// defines
@@ -381,12 +381,12 @@ static void _create(Request& r, MethodPa
Temp_lang temp_lang(r, String::L_XML);
const String& xml=r.process_to_string(param);
- String::Body sbody=xml.cstr_to_string_body_untaint(r.flang, 0, &r.charsets);
+ String::Body sbody=xml.cstr_to_string_body_untaint(r.flang, r.connection(false), &r.charsets);
xmldoc=xmlParseMemory(sbody.cstr(), sbody.length());
//printf("document=0x%p\n", document);
if(!xmldoc || xmlHaveGenericErrors())
- throw XmlException(0);
+ throw XmlException(0, r);
// must be last action in if, see after if}
} else { // [localName]
@@ -410,11 +410,11 @@ static void _create(Request& r, MethodPa
#endif
xmldoc=xmlNewDoc(0);
if(!xmldoc || xmlHaveGenericErrors())
- throw XmlException(0);
+ throw XmlException(0, r);
xmlNode* node=xmlNewChild((xmlNode*)xmldoc, NULL, localName, NULL);
if(!node || xmlHaveGenericErrors())
- throw XmlException(0);
+ throw XmlException(0, r);
set_encoding=true;
// must be last action in if, see after if}
@@ -422,7 +422,7 @@ static void _create(Request& r, MethodPa
VFile* vfile=param.as_vfile(String::L_AS_IS);
xmldoc=xmlParseMemory(vfile->value_ptr(), vfile->value_size());
if(!xmldoc || xmlHaveGenericErrors())
- throw XmlException(0);
+ throw XmlException(0, r);
}
}
// must be first action after if}
@@ -459,7 +459,7 @@ static void _load(Request& r, MethodPara
/// @todo!! add SAFE MODE!!
xmlDoc* xmldoc=xmlParseFile(uri_cstr);
if(!xmldoc || xmlHaveGenericErrors())
- throw XmlException(uri);
+ throw XmlException(uri, r);
// must be first action after if}
// replace any previous parsed source
@@ -517,11 +517,20 @@ String::C xdoc2buf(Request& r, VXdoc& vd
stylesheet->encoding=BAD_CAST xmlMemStrdup(header_encoding);
if(xsltSaveResultTo(outputBuffer.get(), &xmldoc, stylesheet.get())<0
|| xmlHaveGenericErrors())
- throw XmlException(0);
+ throw XmlException(0, r);
// write out result
char *gnome_str;
size_t gnome_length;
+#ifdef LIBXML2_NEW_BUFFER
+ if(outputBuffer->conv) {
+ gnome_length=xmlBufUse(outputBuffer->conv);
+ gnome_str=(char *)xmlBufContent(outputBuffer->conv);
+ } else {
+ gnome_length=xmlOutputBufferGetSize(&(*outputBuffer));
+ gnome_str=(char *)xmlOutputBufferGetContent(&(*outputBuffer));
+ }
+#else
if(outputBuffer->conv) {
gnome_length=outputBuffer->conv->use;
gnome_str=(char *)outputBuffer->conv->content;
@@ -529,6 +538,7 @@ String::C xdoc2buf(Request& r, VXdoc& vd
gnome_length=outputBuffer->buffer->use;
gnome_str=(char *)outputBuffer->buffer->content;
}
+#endif
if(file_spec){
file_write(r.charsets,
@@ -548,7 +558,8 @@ 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), true/* $.name[filename] could be specified by user */);
+ XDocOutputOptions oo(vdoc.output_options);
+ oo.append(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;
@@ -560,9 +571,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, oo.filename, &vhcontent_type);
-
- vfile.set_mode(true/*text*/);
+ vfile.set_binary(false/*not tainted*/, buf.str?buf.str:""/*to distinguish from stat-ed file*/, buf.length, oo.filename, &vhcontent_type);
// write out result
r.write_no_lang(vfile);
@@ -573,14 +582,16 @@ static void _save(Request& r, MethodPara
const String& file_spec=r.absolute(params.as_string(0, FILE_NAME_MUST_BE_STRING));
- XDocOutputOptions oo(r, get_options(params, 1));
+ XDocOutputOptions oo(vdoc.output_options);
+ oo.append(r, get_options(params, 1));
xdoc2buf(r, vdoc, oo, &file_spec);
}
static void _string(Request& r, MethodParams& params) {
VXdoc& vdoc=GET_SELF(r, VXdoc);
- XDocOutputOptions oo(r, get_options(params, 0));
+ XDocOutputOptions oo(vdoc.output_options);
+ oo.append(r, get_options(params, 0));
String::C buf=xdoc2buf(r, vdoc, oo,
0/*file_name. not to file, to memory*/,
true/*use source charset to render, client charset to put to header*/);
@@ -625,13 +636,39 @@ static VXdoc& _transform(Request& r, con
0/*FILE *profile*/,
transformContext.get());
if(!transformed || xmlHaveGenericErrors())
- throw XmlException(stylesheet_source);
+ throw XmlException(stylesheet_source, r);
//gdome_xml_doc_mkref dislikes XML_HTML_DOCUMENT_NODE type, fixing
transformed->type=XML_DOCUMENT_NODE;
-
// constructing result
- return *new VXdoc(r.charsets, *transformed);
+ VXdoc& result=*new VXdoc(r.charsets, *transformed);
+ /* grabbing options
+
+
+ */
+ XDocOutputOptions& oo=result.output_options;
+
+ oo.method=stylesheet->method?&r.transcode(stylesheet->method):0;
+ oo.encoding=stylesheet->encoding?&r.transcode(stylesheet->encoding):0;
+ oo.mediaType=stylesheet->mediaType?&r.transcode(stylesheet->mediaType):0;
+ oo.indent=stylesheet->indent;
+ oo.version=stylesheet->version?&r.transcode(stylesheet->version):0;
+ oo.standalone=stylesheet->standalone;
+ oo.omitXmlDeclaration=stylesheet->omitXmlDeclaration;
+
+ // return
+ return result;
}
static void _transform(Request& r, MethodParams& params) {
VXdoc& vdoc=GET_SELF(r, VXdoc);
@@ -640,8 +677,8 @@ static void _transform(Request& r, Metho
Array transform_strings;
const xmlChar** transform_params=0;
if(params.count()>1)
- if(HashStringValue* hash=params.as_hash(1)) {
- transform_params=new(UseGC) const xmlChar*[hash->count()*2+1];
+ if(HashStringValue* hash=params.as_hash(1, "transform options")) {
+ transform_params=new const xmlChar*[hash->count()*2+1];
Add_xslt_param_info info={
&r,
&transform_strings,
@@ -657,7 +694,7 @@ static void _transform(Request& r, Metho
// compile xdoc stylesheet
xsltStylesheet_auto_ptr stylesheet_ptr(xsltParseStylesheetDoc(&stylesheetdoc));
if(xmlHaveGenericErrors())
- throw XmlException(0);
+ throw XmlException(0, r);
if(!stylesheet_ptr.get())
throw Exception("xml",
0,