|
|
| version 1.55, 2001/12/28 18:12:30 | version 1.78, 2002/01/28 08:20:33 |
|---|---|
| Line 7 | Line 7 |
| $Id$ | $Id$ |
| */ | */ |
| #include "pa_types.h" | #include "pa_types.h" |
| #include "classes.h" | |
| #ifdef XML | #ifdef XML |
| #include "gdome.h" | |
| #include "libxml/tree.h" | |
| extern "C" { | |
| #include "gdomecore/gdome-xml-node.h" | |
| #include "gdomecore/gdome-xml-document.h" | |
| }; | |
| #include "libxslt/xsltInternals.h" | |
| #include "libxslt/transform.h" | |
| #include "libxslt/xsltutils.h" | |
| #include "pa_stylesheet_connection.h" | |
| #include "classes.h" | |
| #include "pa_request.h" | #include "pa_request.h" |
| #include "pa_vxdoc.h" | #include "pa_vxdoc.h" |
| //#include "pa_stylesheet_manager.h" | |
| //#include "pa_stylesheet_connection.h" | |
| #include "pa_charset.h" | #include "pa_charset.h" |
| #include "pa_vfile.h" | #include "pa_vfile.h" |
| #include "xnode.h" | #include "xnode.h" |
| // defines | // defines |
| #define XDOC_CLASS_NAME "xdoc" | #define XDOC_CLASS_NAME "xdoc" |
| Line 26 | Line 36 |
| #define XDOC_OUTPUT_METHOD_OPTION_VALUE_XML "xml" | #define XDOC_OUTPUT_METHOD_OPTION_VALUE_XML "xml" |
| #define XDOC_OUTPUT_METHOD_OPTION_VALUE_HTML "html" | #define XDOC_OUTPUT_METHOD_OPTION_VALUE_HTML "html" |
| #define XDOC_OUTPUT_METHOD_OPTION_VALUE_TEXT "text" | #define XDOC_OUTPUT_METHOD_OPTION_VALUE_TEXT "text" |
| #define XDOC_OUTPUT_DEFAULT_INDENT 4 | |
| // class | // class |
| Line 42 public: // Methoded | Line 51 public: // Methoded |
| void configure_admin(Request& r); | void configure_admin(Request& r); |
| }; | }; |
| // helper classes | |
| class xmlOutputBuffer_auto_ptr { | |
| public: | |
| explicit xmlOutputBuffer_auto_ptr(xmlOutputBuffer *_APtr = 0) | |
| : _Owns(_APtr != 0), _Ptr(_APtr) {} | |
| xmlOutputBuffer_auto_ptr(const xmlOutputBuffer_auto_ptr& _Y) | |
| : _Owns(_Y._Owns), _Ptr(_Y.release()) {} | |
| xmlOutputBuffer_auto_ptr& operator=(const xmlOutputBuffer_auto_ptr& _Y) | |
| {if (this != &_Y) | |
| {if (_Ptr != _Y.get()) | |
| {if (_Owns && _Ptr) | |
| xmlOutputBufferClose(_Ptr); | |
| _Owns = _Y._Owns; } | |
| else if (_Y._Owns) | |
| _Owns = true; | |
| _Ptr = _Y.release(); } | |
| return (*this); } | |
| ~xmlOutputBuffer_auto_ptr() | |
| {if (_Owns && _Ptr) | |
| xmlOutputBufferClose(_Ptr); } | |
| xmlOutputBuffer& operator*() const | |
| {return (*get()); } | |
| xmlOutputBuffer *operator->() const | |
| {return (get()); } | |
| xmlOutputBuffer *get() const | |
| {return (_Ptr); } | |
| xmlOutputBuffer *release() const | |
| {((xmlOutputBuffer_auto_ptr *)this)->_Owns = false; | |
| return (_Ptr); } | |
| private: | |
| bool _Owns; | |
| xmlOutputBuffer *_Ptr; | |
| }; | |
| class xsltTransformContext_auto_ptr { | |
| public: | |
| explicit xsltTransformContext_auto_ptr(xsltTransformContext *_APtr = 0) | |
| : _Owns(_APtr != 0), _Ptr(_APtr) {} | |
| xsltTransformContext_auto_ptr(const xsltTransformContext_auto_ptr& _Y) | |
| : _Owns(_Y._Owns), _Ptr(_Y.release()) {} | |
| xsltTransformContext_auto_ptr& operator=(const xsltTransformContext_auto_ptr& _Y) | |
| {if (this != &_Y) | |
| {if (_Ptr != _Y.get()) | |
| {if (_Owns && _Ptr) | |
| xsltFreeTransformContext(_Ptr); | |
| _Owns = _Y._Owns; } | |
| else if (_Y._Owns) | |
| _Owns = true; | |
| _Ptr = _Y.release(); } | |
| return (*this); } | |
| ~xsltTransformContext_auto_ptr() | |
| {if (_Owns && _Ptr) | |
| xsltFreeTransformContext(_Ptr); } | |
| xsltTransformContext& operator*() const | |
| {return (*get()); } | |
| xsltTransformContext *operator->() const | |
| {return (get()); } | |
| xsltTransformContext *get() const | |
| {return (_Ptr); } | |
| xsltTransformContext *release() const | |
| {((xsltTransformContext_auto_ptr *)this)->_Owns = false; | |
| return (_Ptr); } | |
| private: | |
| bool _Owns; | |
| xsltTransformContext *_Ptr; | |
| }; | |
| class xsltStylesheet_auto_ptr { | |
| public: | |
| explicit xsltStylesheet_auto_ptr(xsltStylesheet *_APtr = 0) | |
| : _Owns(_APtr != 0), _Ptr(_APtr) {} | |
| xsltStylesheet_auto_ptr(const xsltStylesheet_auto_ptr& _Y) | |
| : _Owns(_Y._Owns), _Ptr(_Y.release()) {} | |
| xsltStylesheet_auto_ptr& operator=(const xsltStylesheet_auto_ptr& _Y) | |
| {if (this != &_Y) | |
| {if (_Ptr != _Y.get()) | |
| {if (_Owns && _Ptr) | |
| xsltFreeStylesheet(_Ptr); | |
| _Owns = _Y._Owns; } | |
| else if (_Y._Owns) | |
| _Owns = true; | |
| _Ptr = _Y.release(); } | |
| return (*this); } | |
| ~xsltStylesheet_auto_ptr() | |
| {if (_Owns && _Ptr) | |
| xsltFreeStylesheet(_Ptr); } | |
| xsltStylesheet& operator*() const | |
| {return (*get()); } | |
| xsltStylesheet *operator->() const | |
| {return (get()); } | |
| xsltStylesheet *get() const | |
| {return (_Ptr); } | |
| xsltStylesheet *release() const | |
| {((xsltStylesheet_auto_ptr *)this)->_Owns = false; | |
| return (_Ptr); } | |
| private: | |
| bool _Owns; | |
| xsltStylesheet *_Ptr; | |
| }; | |
| // methods | // methods |
| static void writeNode(Request& r, const String& method_name, GdomeNode *node, | static void writeNode(Request& r, const String& method_name, GdomeNode *node, |
| Line 68 static void _createElement(Request& r, c | Line 178 static void _createElement(Request& r, c |
| GdomeException exc; | GdomeException exc; |
| GdomeNode *node= | GdomeNode *node= |
| (GdomeNode *)gdome_doc_createElement(vdoc.get_document(&method_name), | (GdomeNode *)gdome_doc_createElement(vdoc.get_document(&method_name), |
| pool.transcode(tagName), | pool.transcode(tagName).get(), |
| &exc); | &exc); |
| writeNode(r, method_name, node, exc); | writeNode(r, method_name, node, exc); |
| } | } |
| Line 96 static void _createTextNode(Request& r, | Line 206 static void _createTextNode(Request& r, |
| GdomeException exc; | GdomeException exc; |
| GdomeNode *node=(GdomeNode *)gdome_doc_createTextNode( | GdomeNode *node=(GdomeNode *)gdome_doc_createTextNode( |
| vdoc.get_document(&method_name), | vdoc.get_document(&method_name), |
| pool.transcode(data), | pool.transcode(data).get(), |
| &exc); | &exc); |
| writeNode(r, method_name, node, exc); | writeNode(r, method_name, node, exc); |
| } | } |
| Line 111 static void _createComment(Request& r, c | Line 221 static void _createComment(Request& r, c |
| GdomeException exc; | GdomeException exc; |
| GdomeNode *node=(GdomeNode *)gdome_doc_createComment( | GdomeNode *node=(GdomeNode *)gdome_doc_createComment( |
| vdoc.get_document(&method_name), | vdoc.get_document(&method_name), |
| pool.transcode(data), | pool.transcode(data).get(), |
| &exc); | &exc); |
| writeNode(r, method_name, node, exc); | writeNode(r, method_name, node, exc); |
| } | } |
| Line 126 static void _createCDATASection(Request& | Line 236 static void _createCDATASection(Request& |
| GdomeException exc; | GdomeException exc; |
| GdomeNode *node=(GdomeNode *)gdome_doc_createCDATASection( | GdomeNode *node=(GdomeNode *)gdome_doc_createCDATASection( |
| vdoc.get_document(&method_name), | vdoc.get_document(&method_name), |
| pool.transcode(data), | pool.transcode(data).get(), |
| &exc); | &exc); |
| writeNode(r, method_name, node, exc); | writeNode(r, method_name, node, exc); |
| } | } |
| Line 142 static void _createProcessingInstruction | Line 252 static void _createProcessingInstruction |
| GdomeException exc; | GdomeException exc; |
| GdomeNode *node=(GdomeNode *)gdome_doc_createProcessingInstruction( | GdomeNode *node=(GdomeNode *)gdome_doc_createProcessingInstruction( |
| vdoc.get_document(&method_name), | vdoc.get_document(&method_name), |
| pool.transcode(target), | pool.transcode(target).get(), |
| pool.transcode(data), | pool.transcode(data).get(), |
| &exc); | &exc); |
| writeNode(r, method_name, node, exc); | writeNode(r, method_name, node, exc); |
| } | } |
| Line 158 static void _createAttribute(Request& r, | Line 268 static void _createAttribute(Request& r, |
| GdomeException exc; | GdomeException exc; |
| GdomeNode *node=(GdomeNode *)gdome_doc_createAttribute( | GdomeNode *node=(GdomeNode *)gdome_doc_createAttribute( |
| vdoc.get_document(&method_name), | vdoc.get_document(&method_name), |
| pool.transcode(name), | pool.transcode(name).get(), |
| &exc); | &exc); |
| writeNode(r, method_name, node, exc); | writeNode(r, method_name, node, exc); |
| } | } |
| Line 172 static void _createEntityReference(Reque | Line 282 static void _createEntityReference(Reque |
| GdomeException exc; | GdomeException exc; |
| GdomeNode *node=(GdomeNode *)gdome_doc_createEntityReference( | GdomeNode *node=(GdomeNode *)gdome_doc_createEntityReference( |
| vdoc.get_document(&method_name), | vdoc.get_document(&method_name), |
| pool.transcode(name), | pool.transcode(name).get(), |
| &exc); | &exc); |
| writeNode(r, method_name, node, exc); | writeNode(r, method_name, node, exc); |
| } | } |
| Line 188 static void _getElementsByTagName(Reques | Line 298 static void _getElementsByTagName(Reques |
| if(GdomeNodeList *nodes= | if(GdomeNodeList *nodes= |
| gdome_doc_getElementsByTagName( | gdome_doc_getElementsByTagName( |
| vdoc.get_document(&method_name), | vdoc.get_document(&method_name), |
| pool.transcode(name), | pool.transcode(name).get(), |
| &exc)) { | &exc)) { |
| gulong length=gdome_nl_length(nodes, &exc); | gulong length=gdome_nl_length(nodes, &exc); |
| for(gulong i=0; i<length; i++) { | for(gulong i=0; i<length; i++) { |
| Line 220 static void _getElementsByTagNameNS(Requ | Line 330 static void _getElementsByTagNameNS(Requ |
| if(GdomeNodeList *nodes= | if(GdomeNodeList *nodes= |
| gdome_doc_getElementsByTagNameNS( | gdome_doc_getElementsByTagNameNS( |
| vdoc.get_document(&method_name), | vdoc.get_document(&method_name), |
| pool.transcode(namespaceURI), | pool.transcode(namespaceURI).get(), |
| pool.transcode(localName), | pool.transcode(localName).get(), |
| &exc)) { | &exc)) { |
| gulong length=gdome_nl_length(nodes, &exc); | gulong length=gdome_nl_length(nodes, &exc); |
| for(gulong i=0; i<length; i++) { | for(gulong i=0; i<length; i++) { |
| Line 251 static void _getElementById(Request& r, | Line 361 static void _getElementById(Request& r, |
| GdomeException exc; | GdomeException exc; |
| if(GdomeNode *node=(GdomeNode *)gdome_doc_getElementById( | if(GdomeNode *node=(GdomeNode *)gdome_doc_getElementById( |
| vdoc.get_document(&method_name), | vdoc.get_document(&method_name), |
| pool.transcode(elementId), | pool.transcode(elementId).get(), |
| &exc)) { | &exc)) { |
| // write out result | // write out result |
| VXnode& result=*new(pool) VXnode(pool, node); | VXnode& result=*new(pool) VXnode(pool, node); |
| r.write_no_lang(result); | r.write_no_lang(result); |
| } else if(exc) | } else if(exc || xmlHaveGenericErrors()) |
| throw Exception(0, 0, | throw Exception(0, 0, |
| &method_name, | &method_name, |
| exc); | exc); |
| Line 265 static void _getElementById(Request& r, | Line 375 static void _getElementById(Request& r, |
| GdomeNode *gdome_doc_importNode (GdomeDocument *self, GdomeNode *importedNode, GdomeBoolean deep, GdomeException *exc); | GdomeNode *gdome_doc_importNode (GdomeDocument *self, GdomeNode *importedNode, GdomeBoolean deep, GdomeException *exc); |
| GdomeElement *gdome_doc_createElementNS (GdomeDocument *self, GdomeDOMString *namespaceURI, GdomeDOMString *qualifiedName, GdomeException *exc); | GdomeElement *gdome_doc_createElementNS (GdomeDocument *self, GdomeDOMString *namespaceURI, GdomeDOMString *qualifiedName, GdomeException *exc); |
| GdomeAttr *gdome_doc_createAttributeNS (GdomeDocument *self, GdomeDOMString *namespaceURI, GdomeDOMString *qualifiedName, GdomeException *exc); | GdomeAttr *gdome_doc_createAttributeNS (GdomeDocument *self, GdomeDOMString *namespaceURI, GdomeDOMString *qualifiedName, GdomeException *exc); |
| GdomeNodeList *gdome_doc_getElementsByTagNameNS (GdomeDocument *self, GdomeDOMString *namespaceURI, GdomeDOMString *localName, GdomeException *exc); | |
| */ | */ |
| Line 284 static void _create(Request& r, const St | Line 393 static void _create(Request& r, const St |
| 0/*publicId* /, | 0/*publicId* /, |
| 0/*systemId* /, | 0/*systemId* /, |
| &exc); | &exc); |
| if(!documentType || exc) | if(!documentType || exc || xmlHaveGenericErrors()) |
| throw Exception(0, 0, | throw Exception(0, 0, |
| &method_name, | &method_name, |
| exc); | exc); |
| */ | */ |
| GdomeDocument *document=gdome_di_createDocument (domimpl, | GdomeDocument *document=gdome_di_createDocument (domimpl, |
| 0/*namespaceURI*/, | 0/*namespaceURI*/, |
| pool.transcode(qualifiedName), | pool.transcode(qualifiedName).get(), |
| 0/*doctype*/, | 0/*doctype*/, |
| &exc); | &exc); |
| if(!document || exc) | if(!document || exc || xmlHaveGenericErrors()) |
| throw Exception(0, 0, | throw Exception(0, 0, |
| &method_name, | &method_name, |
| exc); | exc); |
| /// +createXMLDecl ? | /// +xalan createXMLDecl ? |
| //document.appendChild(document.createElement(*pool.transcode(qualifiedName))); | |
| // replace any previous parsed source | // replace any previous parsed source |
| vdoc.set_document(document); | vdoc.set_document(document); |
| Line 315 static void _set(Request& r, const Strin | Line 423 static void _set(Request& r, const Strin |
| Temp_lang temp_lang(r, String::UL_XML); | Temp_lang temp_lang(r, String::UL_XML); |
| const String& xml=r.process(vxml).as_string(); | const String& xml=r.process(vxml).as_string(); |
| GdomeException exc; | const char *cstr=xml.cstr(String::UL_UNSPECIFIED); |
| GdomeDocument *document=gdome_di_createDocFromMemory(domimpl, | GdomeDocument *document=(GdomeDocument *) |
| xml.cstr(String::UL_UNSPECIFIED, r.connection), | gdome_xml_n_mkref((xmlNode *)xmlParseMemory( |
| GDOME_LOAD_PARSING | cstr, strlen(cstr) |
| /* GDOME_LOAD_VALIDATING */ | )); |
| /*|GDOME_LOAD_SUBSTITUTE_ENTITIES */, | if(!document || xmlHaveGenericErrors()) { |
| &exc); | GdomeException exc=0; |
| if(!document || exc) | |
| throw Exception(0, 0, | throw Exception(0, 0, |
| &method_name, | &method_name, |
| exc); | exc); |
| } | |
| // replace any previous parsed source | // replace any previous parsed source |
| vdoc.set_document(document); | vdoc.set_document(document); |
| Line 339 static void _load(Request& r, const Stri | Line 447 static void _load(Request& r, const Stri |
| const String& file_name=params->as_string(0, "uri must be string"); | const String& file_name=params->as_string(0, "uri must be string"); |
| const String& uri=r.absolute(file_name); | const String& uri=r.absolute(file_name); |
| GdomeException exc; | GdomeDocument *document=(GdomeDocument *) |
| GdomeDocument *document=gdome_di_createDocFromURI(domimpl, | gdome_xml_n_mkref((xmlNode *)xmlParseFile(uri.cstr())); |
| uri.cstr(), | if(!document || xmlHaveGenericErrors()) { |
| GDOME_LOAD_PARSING | GdomeException exc=0; |
| /*GDOME_LOAD_VALIDATING */ | |
| /*|GDOME_LOAD_SUBSTITUTE_ENTITIES */, | |
| &exc); | |
| if(!document || exc) | |
| throw Exception(0, 0, | throw Exception(0, 0, |
| &method_name, | &uri, |
| exc); | exc); |
| } | |
| // replace any previous parsed source | // replace any previous parsed source |
| vdoc.set_document(document); | vdoc.set_document(document); |
| } | } |
| /* | |
| static void param_option_over_output_option(Pool& pool, | static void param_option_over_output_option(Pool& pool, |
| Hash *param_options, const char *option_name, | Hash *param_options, const char *option_name, |
| XalanDOMString& output_option) { | const String *& output_option) { |
| if(Value *value=static_cast<Value *>(param_options->get(*new(pool) | if(Value *value=static_cast<Value *>(param_options->get(*new(pool) String(pool, |
| String(pool, option_name)))) { | option_name)))) |
| output_option.clear(); | output_option=&value->as_string(); |
| output_option.append(value->as_string().cstr()); | |
| } | |
| } | } |
| static void param_option_over_output_option(Pool& pool, | static void param_option_over_output_option(Pool& pool, |
| Hash *param_options, const char *option_name, | Hash *param_options, const char *option_name, |
| Line 382 static void param_option_over_output_opt | Line 484 static void param_option_over_output_opt |
| } | } |
| } | } |
| static std::auto_ptr<FormatterListener> create_optioned_listener( | static void prepare_output_options( |
| Pool& pool, const String& method_name, MethodParams *params, int index, | Pool& pool, const String& method_name, MethodParams *params, int index, |
| VXdoc::Output_options& oo, Writer& writer) { | VXdoc::Output_options& oo) { |
| /* | |
| XalanDOMString encoding; | |
| XalanDOMString mediaType; | |
| XalanDOMString doctypeSystem; | |
| XalanDOMString doctypePublic; | |
| bool doIndent; | |
| XalanDOMString version; | |
| XalanDOMString standalone; | |
| bool xmlDecl; | |
| * / | |
| /* | /* |
| <xsl:output | <xsl:output |
| !method = "xml" | "html" | "text" | qname-but-not-ncname | !method = "xml" | "html" | "text" | qname-but-not-ncname |
| Line 408 static void param_option_over_output_opt | Line 499 static void param_option_over_output_opt |
| cdata-section-elements = qnames | cdata-section-elements = qnames |
| !indent = "yes" | "no" | !indent = "yes" | "no" |
| !media-type = string /> | !media-type = string /> |
| * / | */ |
| /* | |
| fToXML->setStripCData(stripCData); | |
| fToXML->setEscapeCData(escapeCData); | |
| * / | |
| // configuring with options from parameter... | // configuring with options from parameter... |
| if(params->size()>index) { | if(params->size()>index) { |
| Line 423 static void param_option_over_output_opt | Line 509 static void param_option_over_output_opt |
| // $.method[xml|html|text] | // $.method[xml|html|text] |
| if(Value *vmethod=static_cast<Value *>(options->get(*new(pool) | if(Value *vmethod=static_cast<Value *>(options->get(*new(pool) |
| String(pool, XDOC_OUTPUT_METHOD_OPTION_NAME)))) | String(pool, XDOC_OUTPUT_METHOD_OPTION_NAME)))) |
| oo.method=vmethod->as_string().cstr(); | oo.method=&vmethod->as_string(); |
| // $.version[1.0] | // $.version[1.0] |
| param_option_over_output_option(pool, options, "version", oo.version); | param_option_over_output_option(pool, options, "version", oo.version); |
| // $.encoding[windows-1251|...] | // $.encoding[windows-1251|...] |
| param_option_over_output_option(pool, options, "encoding", oo.encoding); | param_option_over_output_option(pool, options, "encoding", oo.encoding); |
| // $.omit-xml-declaration[yes|no] | // $.omit-xml-declaration[yes|no] |
| bool omit_xml_declaration=!oo.xmlDecl; | param_option_over_output_option(pool, options, "omit-xml-declaration", oo.omitXmlDeclaration); |
| param_option_over_output_option(pool, options, "omit-xml-declaration", omit_xml_declaration); | |
| oo.xmlDecl=!omit_xml_declaration; | |
| // $.standalone[yes|no] | // $.standalone[yes|no] |
| param_option_over_output_option(pool, options, "standalone", oo.standalone); | param_option_over_output_option(pool, options, "standalone", oo.standalone); |
| // $.doctype-public[?] | // $.doctype-public[?] |
| Line 440 static void param_option_over_output_opt | Line 524 static void param_option_over_output_opt |
| // $.doctype-system[?] | // $.doctype-system[?] |
| param_option_over_output_option(pool, options, "doctype-system", oo.doctypeSystem); | param_option_over_output_option(pool, options, "doctype-system", oo.doctypeSystem); |
| // $.indent[yes|no] | // $.indent[yes|no] |
| param_option_over_output_option(pool, options, "indent", oo.doIndent); | param_option_over_output_option(pool, options, "indent", oo.indent); |
| // $.media-type[text/{html|xml|plain}] | // $.media-type[text/{html|xml|plain}] |
| param_option_over_output_option(pool, options, "media-type", oo.mediaType); | param_option_over_output_option(pool, options, "media-type", oo.mediaType); |
| } | } |
| Line 448 static void param_option_over_output_opt | Line 532 static void param_option_over_output_opt |
| } | } |
| // default encoding from pool | // default encoding from pool |
| if(oo.encoding.empty()) | if(!oo.encoding) |
| oo.encoding.append(pool.get_source_charset().name().cstr()); | oo.encoding=&pool.get_source_charset().name(); |
| // default method=xml | // default method=xml |
| if(!oo.method) | if(!oo.method) |
| oo.method=XDOC_OUTPUT_METHOD_OPTION_VALUE_XML; | oo.method=new(pool) String(pool, XDOC_OUTPUT_METHOD_OPTION_VALUE_XML); |
| // default mediaType = depending on method | |
| if(!oo.mediaType) { | |
| if(*oo.method==XDOC_OUTPUT_METHOD_OPTION_VALUE_XML) | |
| oo.mediaType=new(pool) String(pool, "text/xml"); | |
| else if(*oo.method==XDOC_OUTPUT_METHOD_OPTION_VALUE_HTML) | |
| oo.mediaType=new(pool) String(pool, "text/html"); | |
| else // XDOC_OUTPUT_METHOD_OPTION_VALUE_TEXT & all others | |
| oo.mediaType=new(pool) String(pool, "text/plain"); | |
| } | |
| } | |
| if(strcmp(oo.method, XDOC_OUTPUT_METHOD_OPTION_VALUE_XML)==0) { | static void xdoc2buf(Pool& pool, VXdoc& vdoc, |
| if(oo.mediaType.empty()) | const String& method_name, MethodParams *params, int index, |
| oo.mediaType.append("text/xml"); | VXdoc::Output_options& oo, |
| return std::auto_ptr<FormatterListener>(new FormatterToXML(writer, | const String *file_spec, |
| oo.version, | char **parser_buf, size_t *parser_size) { |
| oo.doIndent, | prepare_output_options(pool, method_name, params, index, |
| XDOC_OUTPUT_DEFAULT_INDENT, // indent | oo); |
| oo.encoding, | |
| oo.mediaType, | const char *encoding_cstr=oo.encoding->cstr(); |
| oo.doctypeSystem, | xmlCharEncodingHandler *encoder=xmlFindCharEncodingHandler(encoding_cstr); |
| oo.doctypePublic, | if(!encoder) |
| oo.xmlDecl, | |
| oo.standalone | |
| )); | |
| } else if(strcmp(oo.method, XDOC_OUTPUT_METHOD_OPTION_VALUE_HTML)==0) { | |
| if(oo.mediaType.empty()) | |
| oo.mediaType.append("text/html"); | |
| return std::auto_ptr<FormatterListener>(new FormatterToHTML(writer, | |
| oo.encoding, | |
| oo.mediaType, | |
| oo.doctypeSystem, | |
| oo.doctypePublic, | |
| oo.doIndent, | |
| XDOC_OUTPUT_DEFAULT_INDENT, // indent | |
| oo.version, | |
| oo.standalone, | |
| oo.xmlDecl | |
| )); | |
| } else if(strcmp(oo.method, XDOC_OUTPUT_METHOD_OPTION_VALUE_TEXT)==0) { | |
| if(oo.mediaType.empty()) | |
| oo.mediaType.append("text/plain"); | |
| return std::auto_ptr<FormatterListener>(new FormatterToText(writer, | |
| oo.encoding | |
| )); | |
| } else | |
| throw Exception(0, 0, | throw Exception(0, 0, |
| &method_name, | &method_name, |
| XDOC_OUTPUT_METHOD_OPTION_NAME " option is invalid; valid methods are: " | "encoding '%s' not supported", encoding_cstr); |
| "'" XDOC_OUTPUT_METHOD_OPTION_VALUE_XML "', " | // UTF-8 encoder contains empty input/output converters, |
| "'" XDOC_OUTPUT_METHOD_OPTION_VALUE_HTML "', " | // which is wrong for xmlOutputBufferCreateIO |
| "'" XDOC_OUTPUT_METHOD_OPTION_VALUE_TEXT "'"); | // while zero encoder goes perfectly |
| if(encoder && strcmp(encoder->name, "UTF-8")==0) | |
| encoder=0; | |
| // never reached | xmlOutputBuffer_auto_ptr outputBuffer(xmlAllocOutputBuffer(encoder)); |
| } | |
| */ | |
| static void _save(Request& r, const String& method_name, MethodParams *params) { | xsltStylesheet_auto_ptr stylesheet(xsltNewStylesheet()); |
| Pool& pool=r.pool(); | if(!stylesheet.get()) |
| VXdoc& vdoc=*static_cast<VXdoc *>(r.self); | throw Exception(0, 0, |
| &method_name, | |
| "xsltNewStylesheet failed"); | |
| const String& file_name=params->as_string(0, "file name must be string"); | #define OOS2STYLE(name) \ |
| const String& filespec=r.absolute(file_name); | stylesheet->name=oo.name?BAD_CAST g_strdup(pool.transcode(*oo.name)->str):0 |
| #define OOE2STYLE(name) \ | |
| GdomeException exc; | stylesheet->name=oo.name |
| if(!gdome_di_saveDocToFile(domimpl, | |
| vdoc.get_document(&method_name), | OOS2STYLE(method); |
| filespec.cstr(String::UL_FILE_SPEC), | OOS2STYLE(encoding); |
| GDOME_SAVE_LIBXML_INDENT /*GDOME_SAVE_STANDARD */, | OOS2STYLE(mediaType); |
| &exc)) | OOS2STYLE(doctypeSystem); |
| OOS2STYLE(doctypePublic); | |
| OOE2STYLE(indent); | |
| OOS2STYLE(version); | |
| OOE2STYLE(standalone); | |
| OOE2STYLE(omitXmlDeclaration); | |
| xmlDoc *document=gdome_xml_doc_get_xmlDoc(vdoc.get_document(&method_name)); | |
| if(xsltSaveResultTo(outputBuffer.get(), document, stylesheet.get())<0) { | |
| GdomeException exc=0; | |
| throw Exception(0, 0, | throw Exception(0, 0, |
| &method_name, | &method_name, |
| exc); | exc); |
| } | |
| // write out result | |
| char *gnome_buf; size_t gnome_size; | |
| if(outputBuffer->conv) { | |
| gnome_size=outputBuffer->conv->use; | |
| gnome_buf=(char *)outputBuffer->conv->content; | |
| } else { | |
| gnome_size=outputBuffer->buffer->use; | |
| gnome_buf=(char *)outputBuffer->buffer->content; | |
| } | |
| if(file_spec) | |
| file_write( | |
| *file_spec, | |
| gnome_buf, gnome_size, | |
| true/*as_text*/); | |
| else if(*parser_size=gnome_size) { | |
| *parser_buf=(char *)pool.malloc(gnome_size); | |
| memcpy(*parser_buf, gnome_buf, gnome_size); | |
| } else | |
| *parser_buf=0; | |
| } | } |
| static void _string(Request& r, const String& method_name, MethodParams *params) { | static void _file(Request& r, const String& method_name, MethodParams *params) { |
| Pool& pool=r.pool(); | Pool& pool=r.pool(); |
| VXdoc& vdoc=*static_cast<VXdoc *>(r.self); | VXdoc& vdoc=*static_cast<VXdoc *>(r.self); |
| VXdoc::Output_options oo(vdoc.output_options); | |
| char *buf; size_t buf_size; | |
| xdoc2buf(pool, vdoc, method_name, params, 0, | |
| oo, | |
| 0/*not to file, to memory*/, | |
| &buf, &buf_size); | |
| // write out result | |
| r.write_no_lang(*new(pool) String(pool, buf, buf_size)); | |
| 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); | |
| // move to pool memory | |
| size_t size=strlen(mem); | |
| char *buf=(char *)pool.malloc(size); | |
| memcpy(buf, mem, size); | |
| g_free(mem); | |
| // write out result | // write out result |
| r.write_no_lang(*new(pool) String(pool, buf, size)); | VFile& vfile=*new(pool) VFile(pool); |
| Value *vcontent_type; | |
| VHash *vhcontent_type=new(pool) VHash(pool); | |
| vhcontent_type->hash(&method_name).put( | |
| *value_name, | |
| new(pool) VString(*oo.mediaType)); | |
| vhcontent_type->hash(&method_name).put( | |
| *new(pool) String(pool, "charset"), | |
| new(pool) VString(*oo.encoding)); | |
| vcontent_type=vhcontent_type; | |
| vfile.set(false/*tainted*/, buf, buf_size, 0/*file_name*/, vcontent_type); | |
| r.write_no_lang(vfile); | |
| } | } |
| /* | static void _save(Request& r, const String& method_name, MethodParams *params) { |
| static void _file(Request& r, const String& method_name, MethodParams *params) { | |
| Pool& pool=r.pool(); | Pool& pool=r.pool(); |
| VXdoc& vdoc=*static_cast<VXdoc *>(r.self); | VXdoc& vdoc=*static_cast<VXdoc *>(r.self); |
| VXnode& vnode=*static_cast<VXnode *>(r.self); | |
| // node | |
| GdomeNode *node=vnode.get_node(pool, &method_name); | |
| try { | const String& file_spec=r.absolute(params->as_string(0, "file name must be string")); |
| VXdoc::Output_options oo(vdoc.output_options); | |
| String& parserString=*new(pool) String(pool); | VXdoc::Output_options oo(vdoc.output_options); |
| ParserStringXalanOutputStream stream(parserString); | xdoc2buf(pool, vdoc, method_name, params, 1, |
| XalanOutputStreamPrintWriter writer(stream); | oo, |
| std::auto_ptr<FormatterListener> formatterListener= | &file_spec, |
| create_optioned_listener(pool, method_name, params, 0, | 0, 0); |
| oo, writer); | } |
| FormatterTreeWalker treeWalker(*formatterListener); | |
| treeWalker.traverse(&node); // Walk that node and produce the XML... | |
| // write out result | static void _string(Request& r, const String& method_name, MethodParams *params) { |
| VFile& vfile=*new(pool) VFile(pool); | Pool& pool=r.pool(); |
| const char *cstr=parserString.cstr(); | VXdoc& vdoc=*static_cast<VXdoc *>(r.self); |
| const String& scontent_type=pool.transcode(oo.mediaType); | VXdoc::Output_options oo(vdoc.output_options); |
| Value *vcontent_type; | char *buf; size_t buf_size; |
| if(oo.encoding.empty()) | xdoc2buf(pool, vdoc, method_name, params, 0, |
| vcontent_type=new(pool) VString(scontent_type); | oo, |
| else { | 0/*not to file, to memory*/, |
| VHash *vhcontent_type=new(pool) VHash(pool); | &buf, &buf_size); |
| vhcontent_type->hash(&method_name).put(*value_name, new(pool) VString(scontent_type)); | // write out result |
| const String& scharset=pool.transcode(oo.encoding); | r.write_no_lang(*new(pool) String(pool, buf, buf_size)); |
| 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); | |
| } | |
| } | } |
| */ | |
| /* | |
| /// @test lang=String::UL_UNSPECIFIED? | |
| static void add_xslt_param(const Hash::Key& aattribute, Hash::Val *ameaning, | static void add_xslt_param(const Hash::Key& aattribute, Hash::Val *ameaning, |
| void *info) { | void *info) { |
| XalanTransformer2& transformer=*static_cast<XalanTransformer2 *>(info); | Value *meaning=static_cast<Value *>(ameaning); |
| const char *attribute_cstr=aattribute.cstr(String::UL_UNSPECIFIED); | Pool& pool=meaning->pool(); |
| const char *meaning_cstr=static_cast<Value *>(ameaning)->as_string().cstr(String::UL_UNSPECIFIED); | const char **transform_params=(const char **)info; |
| *transform_params++=pool.transcode(aattribute)->str; | |
| transformer.setStylesheetParam( | *transform_params++=pool.transcode(meaning->as_string())->str; |
| XalanDOMString(attribute_cstr), | |
| XalanDOMString(meaning_cstr)); | |
| } | } |
| static void _transform(Request& r, const String& method_name, MethodParams *params) { | static void _transform(Request& r, const String& method_name, MethodParams *params) { |
| //_asm int 3; | |
| Pool& pool=r.pool(); | Pool& pool=r.pool(); |
| VXdoc& vdoc=*static_cast<VXdoc *>(r.self); | VXdoc& vdoc=*static_cast<VXdoc *>(r.self); |
| // params | // params |
| const char **transform_params=0; | |
| if(params->size()>1) { | if(params->size()>1) { |
| Value& vparams=params->as_no_junction(1, "transform parameters parameter must be string"); | Value& vparams=params->as_no_junction(1, "transform parameters must be hash"); |
| if(vparams.is_defined()) | if(vparams.is_defined()) |
| if(Hash *params=vparams.get_hash(&method_name)) | if(Hash *params=vparams.get_hash(&method_name)) { |
| params->for_each(add_xslt_param, &vdoc.transformer()); | transform_params= |
| else | (const char **)pool.malloc(sizeof(const char *)*params->size()*2+1); |
| params->for_each(add_xslt_param, transform_params); | |
| transform_params[params->size()*2]=0; | |
| } else | |
| throw Exception(0, 0, | throw Exception(0, 0, |
| &method_name, | &method_name, |
| "transform parameters parameter must be hash"); | "transform parameters parameter must be hash"); |
| } | } |
| // stylesheet | // stylesheet |
| const String& stylesheet_file_name=params->as_string(0, "file name must be string"); | const String& stylesheet_filespec=r.absolute(params->as_string(0, "file name must be string")); |
| const String& stylesheet_filespec=r.absolute(stylesheet_file_name); | Stylesheet_connection_ptr connection=stylesheet_manager->get_connection(stylesheet_filespec); |
| //_asm int 3; | |
| Stylesheet_connection& connection=stylesheet_manager->get_connection(stylesheet_filespec); | |
| // target | |
| XalanDocument* target=vdoc.parser_xerces_liaison().createDocument(); | |
| // transform | // transform |
| try { | xsltStylesheet *stylesheet=connection->stylesheet(false/*nocache*/); |
| // note: | xmlDoc *document=gdome_xml_doc_get_xmlDoc(vdoc.get_document(&method_name)); |
| // actually, never found any difference between the two | xsltTransformContext_auto_ptr transformContext( |
| // but still there some extra "xerces" words at start of transform body | xsltNewTransformContext(stylesheet, document)); |
| // wich were originally "xalan" | xmlDoc *transformed=xsltApplyStylesheetUser( |
| // not daring to change that | stylesheet, |
| document, | |
| const XalanCompiledStylesheet& stylesheet=connection.stylesheet(false/*nocache* /); | transform_params, |
| if(vdoc.has_parsed_source()) { // set|load, not create? | 0/*const char *output*/, |
| vdoc.transformer().transform2( | 0/*FILE *profile*/, |
| vdoc.get_parsed_source(pool, &method_name), | transformContext.get()); |
| &stylesheet, | if(!transformed || xmlHaveGenericErrors()) { |
| target); | GdomeException exc=0; |
| } else { | throw Exception(0, 0, |
| target=vdoc.parser_xerces_liaison().createDocument(); | &stylesheet_filespec, |
| vdoc.transformer().transform2( | exc); |
| vdoc.get_document(&method_name), | |
| &stylesheet, | |
| target); | |
| } | |
| VXdoc& result=*new(pool) VXdoc(pool, target, false/*owns not* /); | |
| // write out result | |
| r.write_no_lang(result); | |
| // | |
| if(const StylesheetRoot *stylesheetRoot=stylesheet.getStylesheetRoot()) { | |
| /* | |
| <xsl:output | |
| !method = "xml" | "html" | "text" | |
| X| qname-but-not-ncname | |
| !version = nmtoken | |
| !encoding = string | |
| !omit-xml-declaration = "yes" | "no" | |
| !standalone = "yes" | "no" | |
| !doctype-public = string | |
| !doctype-system = string | |
| cdata-section-elements = qnames | |
| !indent = "yes" | "no" | |
| !media-type = string /> | |
| * / | |
| VXdoc::Output_options& oo=result.output_options; | |
| oo.encoding=stylesheetRoot->m_encoding; | |
| oo.mediaType=stylesheetRoot->m_mediatype; | |
| oo.doctypeSystem=stylesheetRoot->m_doctypeSystem; | |
| oo.doctypePublic=stylesheetRoot->m_doctypePublic; | |
| oo.doIndent=stylesheetRoot->m_indentResult; | |
| oo.version=stylesheetRoot->m_version; | |
| oo.standalone=stylesheetRoot->m_standalone; | |
| oo.xmlDecl=!stylesheetRoot->m_omitxmlDecl; | |
| switch(stylesheetRoot->getOutputMethod()) { | |
| case FormatterListener::OUTPUT_METHOD_HTML: | |
| oo.method=XDOC_OUTPUT_METHOD_OPTION_VALUE_HTML; break; | |
| case FormatterListener::OUTPUT_METHOD_TEXT: | |
| oo.method=XDOC_OUTPUT_METHOD_OPTION_VALUE_TEXT; break; | |
| case FormatterListener::OUTPUT_METHOD_NONE: | |
| case FormatterListener::OUTPUT_METHOD_XML: | |
| oo.method=XDOC_OUTPUT_METHOD_OPTION_VALUE_XML; break; | |
| default: | |
| throw Exception(0, 0, | |
| &method_name, | |
| "unsupported output method specified"); | |
| break; // never | |
| } | |
| } | |
| } | |
| catch (XSLException& e) { | |
| connection.close(); | |
| Exception::provide_source(pool, &stylesheet_file_name, e); | |
| } | |
| catch (SAXParseException& e) { | |
| connection.close(); | |
| Exception::provide_source(pool, &stylesheet_file_name, e); | |
| } | |
| catch (SAXException& e) { | |
| connection.close(); | |
| Exception::provide_source(pool, &stylesheet_file_name, e); | |
| } | |
| catch (XMLException& e) { | |
| connection.close(); | |
| Exception::provide_source(pool, &stylesheet_file_name, e); | |
| } | |
| catch(const XalanDOMException& e) { | |
| connection.close(); | |
| Exception::provide_source(pool, &stylesheet_file_name, e); | |
| } | } |
| // close | //gdome_xml_doc_mkref dislikes XML_HTML_DOCUMENT_NODE type, fixing |
| connection.close(); | transformed->type=XML_DOCUMENT_NODE; |
| // constructing result | |
| GdomeDocument *gdomeDocument=gdome_xml_doc_mkref(transformed); | |
| if(!gdomeDocument) | |
| throw Exception(0, 0, | |
| &method_name, | |
| "gdome_xml_doc_mkref failed"); | |
| VXdoc& result=*new(pool) VXdoc(pool, gdomeDocument); | |
| /* grabbing options | |
| <xsl:output | |
| !method = "xml" | "html" | "text" | |
| X| qname-but-not-ncname | |
| !version = nmtoken | |
| !encoding = string | |
| !omit-xml-declaration = "yes" | "no" | |
| !standalone = "yes" | "no" | |
| !doctype-public = string | |
| !doctype-system = string | |
| Xcdata-section-elements = qnames | |
| !indent = "yes" | "no" | |
| !media-type = string /> | |
| */ | |
| memset(&result.output_options, 0, sizeof(result.output_options)); | |
| VXdoc::Output_options& oo=result.output_options; | |
| oo.method=stylesheet->method?&pool.transcode(stylesheet->method):0; | |
| oo.encoding=stylesheet->encoding?&pool.transcode(stylesheet->encoding):0; | |
| oo.mediaType=stylesheet->mediaType?&pool.transcode(stylesheet->mediaType):0; | |
| oo.doctypeSystem=stylesheet->doctypeSystem?&pool.transcode(stylesheet->doctypeSystem):0; | |
| oo.doctypePublic=stylesheet->doctypePublic?&pool.transcode(stylesheet->doctypePublic):0; | |
| oo.indent=stylesheet->indent!=0; | |
| oo.version=stylesheet->version?&pool.transcode(stylesheet->version):0; | |
| oo.standalone=stylesheet->standalone!=0; | |
| oo.omitXmlDeclaration=stylesheet->omitXmlDeclaration!=0; | |
| // write out result | |
| r.write_no_lang(result); | |
| } | } |
| */ | |
| // constructor | // constructor |
| Line 769 MXdoc::MXdoc(Pool& apool) : MXnode(apool | Line 822 MXdoc::MXdoc(Pool& apool) : MXnode(apool |
| // ^xdoc.file[] file with "<doc/>" | // ^xdoc.file[] file with "<doc/>" |
| // ^xdoc.file[options hash] file with "<doc/>" | // ^xdoc.file[options hash] file with "<doc/>" |
| // 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] |
| // ^xdoc.transform[stylesheet file_name;params hash] | // ^xdoc.transform[stylesheet file_name;params hash] |
| // add_native_method("transform", Method::CT_DYNAMIC, _transform, 1, 2); | add_native_method("transform", Method::CT_DYNAMIC, _transform, 1, 2); |
| } | } |