|
|
| version 1.46, 2001/11/21 14:00:27 | version 1.55, 2001/12/28 18:12:30 |
|---|---|
| Line 12 | Line 12 |
| #include "pa_request.h" | #include "pa_request.h" |
| #include "pa_vxdoc.h" | #include "pa_vxdoc.h" |
| #include "pa_stylesheet_manager.h" | //#include "pa_stylesheet_manager.h" |
| #include "pa_stylesheet_connection.h" | //#include "pa_stylesheet_connection.h" |
| #include "pa_charset.h" | |
| #include "pa_vfile.h" | #include "pa_vfile.h" |
| #include "xnode.h" | #include "xnode.h" |
| #include <strstream> | |
| #include <Include/PlatformDefinitions.hpp> | |
| #include <util/PlatformUtils.hpp> | |
| #include <util/TransENameMap.hpp> | |
| #include "XalanTransformer2.hpp" | |
| #include <XalanTransformer/XalanParsedSource.hpp> | |
| # include <XalanTransformer/XalanDefaultParsedSource.hpp> | |
| # include <XalanSourceTree/XalanSourceTreeDocument.hpp> | |
| # include <XalanSourceTree/XalanSourceTreeContentHandler.hpp> | |
| # include <sax2/XMLReaderFactory.hpp> | |
| #include <XMLSupport/FormatterToXML.hpp> | |
| #include <XMLSupport/FormatterToHTML.hpp> | |
| #include <XMLSupport/FormatterToText.hpp> | |
| #include <XMLSupport/FormatterTreeWalker.hpp> | |
| #include <PlatformSupport/XalanFileOutputStream.hpp> | |
| #include <PlatformSupport/XalanOutputStreamPrintWriter.hpp> | |
| #include <PlatformSupport/DOMStringPrintWriter.hpp> | |
| #include <XalanDOM/XalanElement.hpp> | |
| #include <XalanDOM/XalanNodeList.hpp> | |
| #include <XalanDOM/XalanDocumentFragment.hpp> | |
| #include <XalanDOM/XalanCDATASection.hpp> | |
| #include <XalanDOM/XalanEntityReference.hpp> | |
| #include <dom/DOM_Document.hpp> | |
| #include <XercesParserLiaison/XercesDocumentBridge.hpp> | |
| #include <XalanTransformer/XercesDOMParsedSource.hpp> | |
| #include <XSLT/StylesheetRoot.hpp> | |
| #include <XalanTransformer/XalanCompiledStylesheet.hpp> | |
| // defines | // defines |
| #define XDOC_CLASS_NAME "xdoc" | #define XDOC_CLASS_NAME "xdoc" |
| Line 59 | Line 32 |
| class MXdoc : public MXnode { | class MXdoc : public MXnode { |
| public: // VStateless_class | public: // VStateless_class |
| Value *create_new_value(Pool& pool) { return new(pool) VXdoc(pool, 0, false); } | Value *create_new_value(Pool& pool) { return new(pool) VXdoc(pool, 0); } |
| public: | public: |
| MXdoc(Pool& pool); | MXdoc(Pool& pool); |
| Line 71 public: // Methoded | Line 44 public: // Methoded |
| // methods | // methods |
| static void writeNode(Request& r, const String& method_name, GdomeNode *node, | |
| GdomeException exc) { | |
| if(!node || exc) | |
| throw Exception(0, 0, | |
| &method_name, | |
| exc); | |
| Pool& pool=r.pool(); | |
| // write out result | |
| VXnode& result=*new(pool) VXnode(pool, node); | |
| r.write_no_lang(result); | |
| } | |
| // Element createElement(in DOMString tagName) raises(DOMException); | // Element createElement(in DOMString tagName) raises(DOMException); |
| static void _createElement(Request& r, const String& method_name, MethodParams *params) { | static void _createElement(Request& r, const String& method_name, MethodParams *params) { |
| Pool& pool=r.pool(); | Pool& pool=r.pool(); |
| Line 78 static void _createElement(Request& r, c | Line 65 static void _createElement(Request& r, c |
| const String& tagName=params->as_string(0, "tagName must be string"); | const String& tagName=params->as_string(0, "tagName must be string"); |
| try { | GdomeException exc; |
| XalanNode *node= | GdomeNode *node= |
| vdoc.get_document(pool, &method_name). | (GdomeNode *)gdome_doc_createElement(vdoc.get_document(&method_name), |
| createElement(*pool.transcode(tagName)); | pool.transcode(tagName), |
| // write out result | &exc); |
| VXnode& result=*new(pool) VXnode(pool, node, false); | writeNode(r, method_name, node, exc); |
| r.write_no_lang(result); | |
| } catch(const XalanDOMException& e) { | |
| Exception::provide_source(pool, &method_name, e); | |
| } | |
| } | } |
| // DocumentFragment createDocumentFragment() | // DocumentFragment createDocumentFragment() |
| Line 95 static void _createDocumentFragment(Requ | Line 78 static void _createDocumentFragment(Requ |
| Pool& pool=r.pool(); | Pool& pool=r.pool(); |
| VXdoc& vdoc=*static_cast<VXdoc *>(r.self); | VXdoc& vdoc=*static_cast<VXdoc *>(r.self); |
| XalanNode *node= | GdomeException exc; |
| vdoc.get_document(pool, &method_name). | GdomeNode *node= |
| createDocumentFragment(); | (GdomeNode *)gdome_doc_createDocumentFragment( |
| // write out result | vdoc.get_document(&method_name), |
| VXnode& result=*new(pool) VXnode(pool, node, false); | &exc); |
| r.write_no_lang(result); | writeNode(r, method_name, node, exc); |
| } | } |
| // Text createTextNode(in DOMString data); | // Text createTextNode(in DOMString data); |
| Line 110 static void _createTextNode(Request& r, | Line 93 static void _createTextNode(Request& r, |
| const String& data=params->as_string(0, "data must be string"); | const String& data=params->as_string(0, "data must be string"); |
| XalanNode *node= | GdomeException exc; |
| vdoc.get_document(pool, &method_name). | GdomeNode *node=(GdomeNode *)gdome_doc_createTextNode( |
| createTextNode(*pool.transcode(data)); | vdoc.get_document(&method_name), |
| // write out result | pool.transcode(data), |
| VXnode& result=*new(pool) VXnode(pool, node, false); | &exc); |
| r.write_no_lang(result); | writeNode(r, method_name, node, exc); |
| } | } |
| // Comment createComment(in DOMString data) | // Comment createComment(in DOMString data) |
| Line 125 static void _createComment(Request& r, c | Line 108 static void _createComment(Request& r, c |
| const String& data=params->as_string(0, "data must be string"); | const String& data=params->as_string(0, "data must be string"); |
| XalanNode *node= | GdomeException exc; |
| vdoc.get_document(pool, &method_name). | GdomeNode *node=(GdomeNode *)gdome_doc_createComment( |
| createComment(*pool.transcode(data)); | vdoc.get_document(&method_name), |
| // write out result | pool.transcode(data), |
| VXnode& result=*new(pool) VXnode(pool, node, false); | &exc); |
| r.write_no_lang(result); | writeNode(r, method_name, node, exc); |
| } | } |
| // CDATASection createCDATASection(in DOMString data) raises(DOMException); | // CDATASection createCDATASection(in DOMString data) raises(DOMException); |
| Line 140 static void _createCDATASection(Request& | Line 123 static void _createCDATASection(Request& |
| const String& data=params->as_string(0, "data must be string"); | const String& data=params->as_string(0, "data must be string"); |
| try { | GdomeException exc; |
| XalanNode *node= | GdomeNode *node=(GdomeNode *)gdome_doc_createCDATASection( |
| vdoc.get_document(pool, &method_name). | vdoc.get_document(&method_name), |
| createCDATASection(*pool.transcode(data)); | pool.transcode(data), |
| // write out result | &exc); |
| VXnode& result=*new(pool) VXnode(pool, node, false); | writeNode(r, method_name, node, exc); |
| r.write_no_lang(result); | |
| } catch(const XalanDOMException& e) { | |
| Exception::provide_source(pool, &method_name, e); | |
| } | |
| } | } |
| // ProcessingInstruction createProcessingInstruction(in DOMString target,in DOMString data) raises(DOMException); | // ProcessingInstruction createProcessingInstruction(in DOMString target,in DOMString data) raises(DOMException); |
| Line 160 static void _createProcessingInstruction | Line 139 static void _createProcessingInstruction |
| const String& target=params->as_string(0, "data must be string"); | const String& target=params->as_string(0, "data must be string"); |
| const String& data=params->as_string(1, "data must be string"); | const String& data=params->as_string(1, "data must be string"); |
| try { | GdomeException exc; |
| XalanNode *node= | GdomeNode *node=(GdomeNode *)gdome_doc_createProcessingInstruction( |
| vdoc.get_document(pool, &method_name). | vdoc.get_document(&method_name), |
| createProcessingInstruction(*pool.transcode(target), *pool.transcode(data)); | pool.transcode(target), |
| // write out result | pool.transcode(data), |
| VXnode& result=*new(pool) VXnode(pool, node, false); | &exc); |
| r.write_no_lang(result); | writeNode(r, method_name, node, exc); |
| } catch(const XalanDOMException& e) { | |
| Exception::provide_source(pool, &method_name, e); | |
| } | |
| } | } |
| // Attr createAttribute(in DOMString name) raises(DOMException); | // Attr createAttribute(in DOMString name) raises(DOMException); |
| Line 179 static void _createAttribute(Request& r, | Line 155 static void _createAttribute(Request& r, |
| const String& name=params->as_string(0, "name must be string"); | const String& name=params->as_string(0, "name must be string"); |
| try { | GdomeException exc; |
| XalanNode *node= | GdomeNode *node=(GdomeNode *)gdome_doc_createAttribute( |
| vdoc.get_document(pool, &method_name). | vdoc.get_document(&method_name), |
| createAttribute(*pool.transcode(name)); | pool.transcode(name), |
| // write out result | &exc); |
| VXnode& result=*new(pool) VXnode(pool, node, false); | writeNode(r, method_name, node, exc); |
| r.write_no_lang(result); | |
| } catch(const XalanDOMException& e) { | |
| Exception::provide_source(pool, &method_name, e); | |
| } | |
| } | } |
| // EntityReference createEntityReference(in DOMString name) raises(DOMException); | // EntityReference createEntityReference(in DOMString name) raises(DOMException); |
| static void _createEntityReference(Request& r, const String& method_name, MethodParams *params) { | static void _createEntityReference(Request& r, const String& method_name, MethodParams *params) { |
| Line 197 static void _createEntityReference(Reque | Line 169 static void _createEntityReference(Reque |
| const String& name=params->as_string(0, "name must be string"); | const String& name=params->as_string(0, "name must be string"); |
| try { | GdomeException exc; |
| XalanNode *node= | GdomeNode *node=(GdomeNode *)gdome_doc_createEntityReference( |
| vdoc.get_document(pool, &method_name). | vdoc.get_document(&method_name), |
| createEntityReference(*pool.transcode(name)); | pool.transcode(name), |
| // write out result | &exc); |
| VXnode& result=*new(pool) VXnode(pool, node, false); | writeNode(r, method_name, node, exc); |
| r.write_no_lang(result); | |
| } catch(const XalanDOMException& e) { | |
| Exception::provide_source(pool, &method_name, e); | |
| } | |
| } | } |
| /* | |
| static void _getElementsByTagName(Request& r, const String& method_name, MethodParams *params) { | static void _getElementsByTagName(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); |
| // tagname | const String& name=params->as_string(0, "name must be string"); |
| const char *name=params->as_string(0, "name must be string").cstr(String::UL_XML); | |
| GdomeException exc; | |
| VHash& result=*new(pool) VHash(pool); | VHash& result=*new(pool) VHash(pool); |
| if(const XalanNodeList *nodes= | if(GdomeNodeList *nodes= |
| vdoc.get_document(pool, &method_name).getElementsByTagName(XalanDOMString(name))) { | gdome_doc_getElementsByTagName( |
| for(int i=0; i<nodes->getLength(); i++) { | vdoc.get_document(&method_name), |
| pool.transcode(name), | |
| &exc)) { | |
| gulong length=gdome_nl_length(nodes, &exc); | |
| for(gulong i=0; i<length; i++) { | |
| String& skey=*new(pool) String(pool); | String& skey=*new(pool) String(pool); |
| { | { |
| char *buf=(char *)pool.malloc(MAX_NUMBER); | char *buf=(char *)pool.malloc(MAX_NUMBER); |
| Line 228 static void _getElementsByTagName(Reques | Line 199 static void _getElementsByTagName(Reques |
| skey << buf; | skey << buf; |
| } | } |
| result.hash().put(skey, new(pool) VXnode(pool, nodes->item(i))); | result.hash(0).put(skey, new(pool) VXnode(pool, gdome_nl_item(nodes, i, &exc))); |
| } | } |
| } | } |
| Line 241 static void _getElementsByTagNameNS(Requ | Line 212 static void _getElementsByTagNameNS(Requ |
| VXdoc& vdoc=*static_cast<VXdoc *>(r.self); | VXdoc& vdoc=*static_cast<VXdoc *>(r.self); |
| // namespaceURI;localName | // namespaceURI;localName |
| const char *namespaceURI=params->as_string(0, "namespaceURI must be string").cstr(String::UL_XML); | const String& namespaceURI=params->as_string(0, "namespaceURI must be string"); |
| const char *localName=params->as_string(0, "localName must be string").cstr(String::UL_XML); | const String& localName=params->as_string(0, "localName must be string"); |
| GdomeException exc; | |
| VHash& result=*new(pool) VHash(pool); | VHash& result=*new(pool) VHash(pool); |
| if(const XalanNodeList *nodes= | if(GdomeNodeList *nodes= |
| vdoc.get_document(pool, &method_name).getElementsByTagNameNS( | gdome_doc_getElementsByTagNameNS( |
| XalanDOMString(namespaceURI), XalanDOMString(localName))) { | vdoc.get_document(&method_name), |
| for(int i=0; i<nodes->getLength(); i++) { | pool.transcode(namespaceURI), |
| pool.transcode(localName), | |
| &exc)) { | |
| gulong length=gdome_nl_length(nodes, &exc); | |
| for(gulong i=0; i<length; i++) { | |
| String& skey=*new(pool) String(pool); | String& skey=*new(pool) String(pool); |
| { | { |
| char *buf=(char *)pool.malloc(MAX_NUMBER); | char *buf=(char *)pool.malloc(MAX_NUMBER); |
| Line 256 static void _getElementsByTagNameNS(Requ | Line 232 static void _getElementsByTagNameNS(Requ |
| skey << buf; | skey << buf; |
| } | } |
| result.hash().put(skey, new(pool) VXnode(pool, nodes->item(i))); | result.hash(0).put(skey, new(pool) VXnode(pool, gdome_nl_item(nodes, i, &exc))); |
| } | } |
| } | } |
| // write out result | // write out result |
| r.write_no_lang(result); | r.write_no_lang(result); |
| } | } |
| */ | |
| class ParserStringXalanOutputStream: public XalanOutputStream { | |
| public: | |
| explicit ParserStringXalanOutputStream(String& astring) : fstring(astring) {} | |
| protected: // XalanOutputStream | |
| virtual void writeData(const char *theBuffer, unsigned long theBufferLength) { | |
| char *copy=(char *)fstring.malloc((size_t)theBufferLength); | |
| memcpy(copy, theBuffer, (size_t)theBufferLength); | |
| fstring.APPEND_CLEAN(copy, (size_t)theBufferLength, "xdoc", 0); | |
| } | |
| virtual void doFlush() {} | |
| private: | |
| String& fstring; | |
| }; | |
| class XalanSourceTreeParserLiaison2: public XalanSourceTreeParserLiaison { | |
| public: | |
| XalanSourceTreeParserLiaison2(XalanSourceTreeDOMSupport& theSupport) : XalanSourceTreeParserLiaison(theSupport), | |
| ferror_handler(new HandlerBase) { | |
| } | |
| XalanDocument* | |
| parseXMLStream2( | |
| const InputSource& inputSource) { | |
| XalanSourceTreeContentHandler theContentHandler(createXalanSourceTreeDocument()); | |
| XalanAutoPtr<SAX2XMLReader> theReader(XMLReaderFactory::createXMLReader()); | |
| theReader->setContentHandler(&theContentHandler); | |
| theReader->setDTDHandler(&theContentHandler); | |
| theReader->setErrorHandler(ferror_handler); // disable stderr output | |
| theReader->setLexicalHandler(&theContentHandler); | |
| EntityResolver* const theResolver = getEntityResolver(); | |
| if (theResolver != 0) { | |
| theReader->setEntityResolver(theResolver); | |
| } | |
| theReader->parse(inputSource); | |
| return theContentHandler.getDocument(); | |
| } | |
| ~XalanSourceTreeParserLiaison2() { | |
| delete ferror_handler; | |
| } | |
| private: | |
| ErrorHandler *ferror_handler; | |
| }; | |
| class XalanDefaultParsedSource2 : public XalanParsedSource | static void _getElementById(Request& r, const String& method_name, MethodParams *params) { |
| { | Pool& pool=r.pool(); |
| public: | VXdoc& vdoc=*static_cast<VXdoc *>(r.self); |
| XalanDefaultParsedSource2(const XSLTInputSource& theInputSource); | |
| virtual XalanDocument* | // elementId |
| getDocument() const; | const String& elementId=params->as_string(0, "elementID must be string"); |
| virtual XalanParsedSourceHelper* | GdomeException exc; |
| createHelper() const; | if(GdomeNode *node=(GdomeNode *)gdome_doc_getElementById( |
| vdoc.get_document(&method_name), | |
| pool.transcode(elementId), | |
| &exc)) { | |
| // write out result | |
| VXnode& result=*new(pool) VXnode(pool, node); | |
| r.write_no_lang(result); | |
| } else if(exc) | |
| throw Exception(0, 0, | |
| &method_name, | |
| 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); | |
| GdomeAttr *gdome_doc_createAttributeNS (GdomeDocument *self, GdomeDOMString *namespaceURI, GdomeDOMString *qualifiedName, GdomeException *exc); | |
| GdomeNodeList *gdome_doc_getElementsByTagNameNS (GdomeDocument *self, GdomeDOMString *namespaceURI, GdomeDOMString *localName, GdomeException *exc); | |
| */ | |
| private: | |
| XalanSourceTreeDOMSupport m_domSupport; | static void _create(Request& r, const String& method_name, MethodParams *params) { |
| //_asm int 3; | |
| Pool& pool=r.pool(); | |
| VXdoc& vdoc=*static_cast<VXdoc *>(r.self); | |
| XalanSourceTreeParserLiaison2 m_parserLiaison2; | const String& qualifiedName=params->as_string(0, "qualifiedName must be string"); |
| XalanSourceTreeDocument* const m_parsedSource; | GdomeException exc; |
| }; | /* |
| GdomeDocumentType *documentType=gdome_di_createDocumentType ( | |
| docimpl, | |
| pool.transcode(qualifiedName), | |
| 0/*publicId* /, | |
| 0/*systemId* /, | |
| &exc); | |
| if(!documentType || exc) | |
| throw Exception(0, 0, | |
| &method_name, | |
| exc); | |
| */ | |
| GdomeDocument *document=gdome_di_createDocument (domimpl, | |
| 0/*namespaceURI*/, | |
| pool.transcode(qualifiedName), | |
| 0/*doctype*/, | |
| &exc); | |
| if(!document || exc) | |
| throw Exception(0, 0, | |
| &method_name, | |
| exc); | |
| XalanDefaultParsedSource2::XalanDefaultParsedSource2(const XSLTInputSource& theInputSource): | /// +createXMLDecl ? |
| XalanParsedSource(), | //document.appendChild(document.createElement(*pool.transcode(qualifiedName))); |
| m_domSupport(), | |
| m_parserLiaison2(m_domSupport), | |
| m_parsedSource(m_parserLiaison2.mapDocument(m_parserLiaison2.parseXMLStream2(theInputSource))) | |
| { | |
| assert(m_parsedSource != 0); | |
| m_domSupport.setParserLiaison(&m_parserLiaison2); | // replace any previous parsed source |
| vdoc.set_document(document); | |
| } | } |
| static void _set(Request& r, const String& method_name, MethodParams *params) { | |
| // _asm int 3; | |
| Pool& pool=r.pool(); | |
| VXdoc& vdoc=*static_cast<VXdoc *>(r.self); | |
| Value& vxml=params->as_junction(0, "xml must be code"); | |
| Temp_lang temp_lang(r, String::UL_XML); | |
| const String& xml=r.process(vxml).as_string(); | |
| GdomeException exc; | |
| GdomeDocument *document=gdome_di_createDocFromMemory(domimpl, | |
| xml.cstr(String::UL_UNSPECIFIED, r.connection), | |
| GDOME_LOAD_PARSING | |
| /* GDOME_LOAD_VALIDATING */ | |
| /*|GDOME_LOAD_SUBSTITUTE_ENTITIES */, | |
| &exc); | |
| if(!document || exc) | |
| throw Exception(0, 0, | |
| &method_name, | |
| exc); | |
| XalanDocument* | // replace any previous parsed source |
| XalanDefaultParsedSource2::getDocument() const | vdoc.set_document(document); |
| { | |
| return m_parsedSource; | |
| } | } |
| static void _load(Request& r, const String& method_name, MethodParams *params) { | |
| Pool& pool=r.pool(); | |
| VXdoc& vdoc=*static_cast<VXdoc *>(r.self); | |
| // filespec | |
| const String& file_name=params->as_string(0, "uri must be string"); | |
| const String& uri=r.absolute(file_name); | |
| GdomeException exc; | |
| GdomeDocument *document=gdome_di_createDocFromURI(domimpl, | |
| uri.cstr(), | |
| GDOME_LOAD_PARSING | |
| /*GDOME_LOAD_VALIDATING */ | |
| /*|GDOME_LOAD_SUBSTITUTE_ENTITIES */, | |
| &exc); | |
| if(!document || exc) | |
| throw Exception(0, 0, | |
| &method_name, | |
| exc); | |
| XalanParsedSourceHelper* | // replace any previous parsed source |
| XalanDefaultParsedSource2::createHelper() const | vdoc.set_document(document); |
| { | |
| return new XalanDefaultParsedSourceHelper(m_domSupport); | |
| } | } |
| /* | |
| 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) { | XalanDOMString& output_option) { |
| Line 392 static void param_option_over_output_opt | Line 382 static void param_option_over_output_opt |
| } | } |
| } | } |
| static void create_optioned_listener( | static std::auto_ptr<FormatterListener> create_optioned_listener( |
| 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, Writer& writer) { |
| FormatterListener *& listener) { | |
| /* | /* |
| XalanDOMString encoding; | XalanDOMString encoding; |
| XalanDOMString mediaType; | XalanDOMString mediaType; |
| Line 405 static void create_optioned_listener( | Line 394 static void create_optioned_listener( |
| XalanDOMString version; | XalanDOMString version; |
| XalanDOMString standalone; | XalanDOMString standalone; |
| bool xmlDecl; | bool xmlDecl; |
| */ | * / |
| /* | /* |
| <xsl:output | <xsl:output |
| Line 419 static void create_optioned_listener( | Line 408 static void create_optioned_listener( |
| cdata-section-elements = qnames | cdata-section-elements = qnames |
| !indent = "yes" | "no" | !indent = "yes" | "no" |
| !media-type = string /> | !media-type = string /> |
| */ | * / |
| /* | /* |
| fToXML->setStripCData(stripCData); | fToXML->setStripCData(stripCData); |
| fToXML->setEscapeCData(escapeCData); | fToXML->setEscapeCData(escapeCData); |
| */ | * / |
| // configuring with options from parameter... | // configuring with options from parameter... |
| if(params->size()>index) { | if(params->size()>index) { |
| Line 460 static void create_optioned_listener( | Line 449 static void create_optioned_listener( |
| // default encoding from pool | // default encoding from pool |
| if(oo.encoding.empty()) | if(oo.encoding.empty()) |
| oo.encoding.append(pool.get_charset().cstr()); | oo.encoding.append(pool.get_source_charset().name().cstr()); |
| // default method=xml | // default method=xml |
| if(!oo.method) | if(!oo.method) |
| oo.method=XDOC_OUTPUT_METHOD_OPTION_VALUE_XML; | oo.method=XDOC_OUTPUT_METHOD_OPTION_VALUE_XML; |
| Line 468 static void create_optioned_listener( | Line 457 static void create_optioned_listener( |
| if(strcmp(oo.method, XDOC_OUTPUT_METHOD_OPTION_VALUE_XML)==0) { | if(strcmp(oo.method, XDOC_OUTPUT_METHOD_OPTION_VALUE_XML)==0) { |
| if(oo.mediaType.empty()) | if(oo.mediaType.empty()) |
| oo.mediaType.append("text/xml"); | oo.mediaType.append("text/xml"); |
| listener=new FormatterToXML(writer, | return std::auto_ptr<FormatterListener>(new FormatterToXML(writer, |
| oo.version, | oo.version, |
| oo.doIndent, | oo.doIndent, |
| XDOC_OUTPUT_DEFAULT_INDENT, // indent | XDOC_OUTPUT_DEFAULT_INDENT, // indent |
| Line 478 static void create_optioned_listener( | Line 467 static void create_optioned_listener( |
| oo.doctypePublic, | oo.doctypePublic, |
| oo.xmlDecl, | oo.xmlDecl, |
| oo.standalone | oo.standalone |
| ); | )); |
| } else if(strcmp(oo.method, XDOC_OUTPUT_METHOD_OPTION_VALUE_HTML)==0) { | } else if(strcmp(oo.method, XDOC_OUTPUT_METHOD_OPTION_VALUE_HTML)==0) { |
| if(oo.mediaType.empty()) | if(oo.mediaType.empty()) |
| oo.mediaType.append("text/html"); | oo.mediaType.append("text/html"); |
| listener=new FormatterToHTML(writer, | return std::auto_ptr<FormatterListener>(new FormatterToHTML(writer, |
| oo.encoding, | oo.encoding, |
| oo.mediaType, | oo.mediaType, |
| oo.doctypeSystem, | oo.doctypeSystem, |
| Line 492 static void create_optioned_listener( | Line 481 static void create_optioned_listener( |
| oo.version, | oo.version, |
| oo.standalone, | oo.standalone, |
| oo.xmlDecl | oo.xmlDecl |
| ); | )); |
| } else if(strcmp(oo.method, XDOC_OUTPUT_METHOD_OPTION_VALUE_TEXT)==0) { | } else if(strcmp(oo.method, XDOC_OUTPUT_METHOD_OPTION_VALUE_TEXT)==0) { |
| if(oo.mediaType.empty()) | if(oo.mediaType.empty()) |
| oo.mediaType.append("text/plain"); | oo.mediaType.append("text/plain"); |
| listener=new FormatterToText(writer, | return std::auto_ptr<FormatterListener>(new FormatterToText(writer, |
| oo.encoding | oo.encoding |
| ); | )); |
| } else | } else |
| throw Exception(0, 0, | throw Exception(0, 0, |
| &method_name, | &method_name, |
| Line 509 static void create_optioned_listener( | Line 498 static void create_optioned_listener( |
| // never reached | // never reached |
| } | } |
| */ | |
| static void _save(Request& r, const String& method_name, MethodParams *params) { | static void _save(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); | |
| // filespec | |
| const String& file_name=params->as_string(0, "file name must be string"); | const String& file_name=params->as_string(0, "file name must be string"); |
| const char *filespec=r.absolute(file_name).cstr(String::UL_FILE_SPEC); | const String& filespec=r.absolute(file_name); |
| // node | GdomeException exc; |
| XalanNode& node=vnode.get_node(pool, &method_name); | if(!gdome_di_saveDocToFile(domimpl, |
| vdoc.get_document(&method_name), | |
| try { | filespec.cstr(String::UL_FILE_SPEC), |
| VXdoc::Output_options oo(vdoc.output_options); | GDOME_SAVE_LIBXML_INDENT /*GDOME_SAVE_STANDARD */, |
| XalanFileOutputStream stream(XalanDOMString(filespec, strlen(filespec))); | &exc)) |
| XalanOutputStreamPrintWriter writer(stream); | throw Exception(0, 0, |
| FormatterListener *formatterListener; | &method_name, |
| create_optioned_listener(pool, method_name, params, 1, | exc); |
| oo, writer, formatterListener); | |
| FormatterTreeWalker treeWalker(*formatterListener); | |
| treeWalker.traverse(&node); // Walk that node and produce the XML... | |
| } catch(const XSLException& e) { | |
| Exception::provide_source(pool, &method_name, e); | |
| } | |
| } | } |
| static void _string(Request& r, const String& method_name, MethodParams *params) { | static void _string(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); |
| // node | char *mem; |
| XalanNode *node=&vdoc.get_document(pool, &method_name);//.getDocumentElement(); | GdomeException exc; |
| if(!node) | if(!gdome_di_saveDocToMemory(domimpl, |
| throw Exception(0, 0, | vdoc.get_document(&method_name), |
| &method_name, | &mem, |
| "no documentElement"); | GDOME_SAVE_LIBXML_INDENT /*GDOME_SAVE_STANDARD */, |
| &exc)) | |
| try { | throw Exception(0, 0, |
| VXdoc::Output_options oo(vdoc.output_options); | &method_name, |
| String parserString=*new(pool) String(pool); | exc); |
| ParserStringXalanOutputStream stream(parserString); | |
| XalanOutputStreamPrintWriter writer(stream); | // move to pool memory |
| FormatterListener *formatterListener; | size_t size=strlen(mem); |
| create_optioned_listener(pool, method_name, params, 0, | char *buf=(char *)pool.malloc(size); |
| oo, writer, formatterListener); | memcpy(buf, mem, size); |
| FormatterTreeWalker treeWalker(*formatterListener); | g_free(mem); |
| treeWalker.traverse(node); // Walk that node and produce the XML... | // write out result |
| r.write_no_lang(*new(pool) String(pool, buf, size)); | |
| // write out result | |
| r.write_no_lang(parserString); | |
| } catch(const XSLException& e) { | |
| Exception::provide_source(pool, &method_name, e); | |
| } | |
| } | } |
| /* | |
| static void _file(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); | VXnode& vnode=*static_cast<VXnode *>(r.self); |
| // node | // node |
| XalanNode& node=vnode.get_node(pool, &method_name); | GdomeNode *node=vnode.get_node(pool, &method_name); |
| try { | try { |
| VXdoc::Output_options oo(vdoc.output_options); | VXdoc::Output_options oo(vdoc.output_options); |
| String& parserString=*new(pool) String(pool); | String& parserString=*new(pool) String(pool); |
| ParserStringXalanOutputStream stream(parserString); | ParserStringXalanOutputStream stream(parserString); |
| XalanOutputStreamPrintWriter writer(stream); | XalanOutputStreamPrintWriter writer(stream); |
| FormatterListener *formatterListener; | std::auto_ptr<FormatterListener> formatterListener= |
| create_optioned_listener(pool, method_name, params, 0, | create_optioned_listener(pool, method_name, params, 0, |
| oo, writer, formatterListener); | oo, writer); |
| FormatterTreeWalker treeWalker(*formatterListener); | FormatterTreeWalker treeWalker(*formatterListener); |
| treeWalker.traverse(&node); // Walk that node and produce the XML... | treeWalker.traverse(&node); // Walk that node and produce the XML... |
| Line 600 static void _file(Request& r, const Stri | Line 577 static void _file(Request& r, const Stri |
| vcontent_type=vhcontent_type; | vcontent_type=vhcontent_type; |
| } | } |
| vfile.set(false/*tainted*/, cstr, strlen(cstr), 0/*file_name*/, vcontent_type); | vfile.set(false/*tainted* /, cstr, strlen(cstr), 0/*file_name* /, vcontent_type); |
| r.write_no_lang(vfile); | r.write_no_lang(vfile); |
| } catch(const XSLException& e) { | } catch(const XSLException& e) { |
| Exception::provide_source(pool, &method_name, e); | Exception::provide_source(pool, &method_name, e); |
| } | } |
| } | } |
| */ | |
| static void _set(Request& r, const String& method_name, MethodParams *params) { | /* |
| //_asm int 3; | |
| Pool& pool=r.pool(); | |
| VXdoc& vdoc=*static_cast<VXdoc *>(r.self); | |
| Value& vxml=params->as_junction(0, "xml must be code"); | |
| Temp_lang temp_lang(r, String::UL_XML); | |
| const String& xml=r.process(vxml).as_string(); | |
| std::istrstream stream( | |
| xml.cstr(String::UL_UNSPECIFIED, r.connection)); | |
| const XalanParsedSource* parsedSource; | |
| try { | |
| parsedSource = new XalanDefaultParsedSource2(&stream); | |
| } | |
| catch (XSLException& e) { | |
| Exception::provide_source(pool, &method_name, e); | |
| } | |
| catch (SAXParseException& e) { | |
| Exception::provide_source(pool, &method_name, e); | |
| } | |
| catch (SAXException& e) { | |
| Exception::provide_source(pool, &method_name, e); | |
| } | |
| catch (XMLException& e) { | |
| Exception::provide_source(pool, &method_name, e); | |
| } | |
| catch(const XalanDOMException& e) { | |
| Exception::provide_source(pool, &method_name, e); | |
| } | |
| // replace any previous parsed source | |
| vdoc.set_parsed_source(*parsedSource); | |
| } | |
| static void _create(Request& r, const String& method_name, MethodParams *params) { | |
| //_asm int 3; | |
| Pool& pool=r.pool(); | |
| VXdoc& vdoc=*static_cast<VXdoc *>(r.self); | |
| const String& qualifiedName=params->as_string(0, "qualifiedName must be string"); | |
| XalanDocument& document=*new XercesDocumentBridge( | |
| DOM_Document::createDocument(), | |
| 0, | |
| false /*threadSafe*/, | |
| false /*don' buildBridge -- too early, empty document*/); | |
| /// +createXMLDecl ? | |
| document.appendChild(document.createElement(*pool.transcode(qualifiedName))); | |
| // replace any previous document | |
| vdoc.set_document(document, true/*owns*/); | |
| } | |
| static void _load(Request& r, const String& method_name, MethodParams *params) { | |
| Pool& pool=r.pool(); | |
| VXdoc& vdoc=*static_cast<VXdoc *>(r.self); | |
| // filespec | |
| const String& file_name=params->as_string(0, "file name must be string"); | |
| const char *filespec=r.absolute(file_name).cstr(String::UL_FILE_SPEC); | |
| const XalanParsedSource* parsedSource; | |
| try { | |
| parsedSource = new XalanDefaultParsedSource2(filespec); | |
| } | |
| catch (XSLException& e) { | |
| Exception::provide_source(pool, &method_name, e); | |
| } | |
| catch (SAXParseException& e) { | |
| Exception::provide_source(pool, &method_name, e); | |
| } | |
| catch (SAXException& e) { | |
| Exception::provide_source(pool, &method_name, e); | |
| } | |
| catch (XMLException& e) { | |
| Exception::provide_source(pool, &method_name, e); | |
| } | |
| catch(const XalanDOMException& e) { | |
| Exception::provide_source(pool, &method_name, e); | |
| } | |
| // replace any previous parsed source | |
| vdoc.set_parsed_source(*parsedSource); | |
| } | |
| /// @test lang=String::UL_UNSPECIFIED? | /// @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) { |
| Line 739 static void _transform(Request& r, const | Line 629 static void _transform(Request& r, const |
| // wich were originally "xalan" | // wich were originally "xalan" |
| // not daring to change that | // not daring to change that |
| const XalanCompiledStylesheet& stylesheet=connection.stylesheet(true/*nocache*/); | const XalanCompiledStylesheet& stylesheet=connection.stylesheet(false/*nocache* /); |
| if(vdoc.has_parsed_source()) { // set|load, not create? | if(vdoc.has_parsed_source()) { // set|load, not create? |
| vdoc.transformer().transform2( | vdoc.transformer().transform2( |
| vdoc.get_parsed_source(pool, &method_name), | vdoc.get_parsed_source(pool, &method_name), |
| Line 748 static void _transform(Request& r, const | Line 638 static void _transform(Request& r, const |
| } else { | } else { |
| target=vdoc.parser_xerces_liaison().createDocument(); | target=vdoc.parser_xerces_liaison().createDocument(); |
| vdoc.transformer().transform2( | vdoc.transformer().transform2( |
| vdoc.get_document(pool, &method_name), | vdoc.get_document(&method_name), |
| &stylesheet, | &stylesheet, |
| target); | target); |
| } | } |
| VXdoc& result=*new(pool) VXdoc(pool, target, false/*owns not*/); | VXdoc& result=*new(pool) VXdoc(pool, target, false/*owns not* /); |
| // write out result | // write out result |
| r.write_no_lang(result); | r.write_no_lang(result); |
| // | // |
| Line 770 static void _transform(Request& r, const | Line 660 static void _transform(Request& r, const |
| cdata-section-elements = qnames | cdata-section-elements = qnames |
| !indent = "yes" | "no" | !indent = "yes" | "no" |
| !media-type = string /> | !media-type = string /> |
| */ | * / |
| VXdoc::Output_options& oo=result.output_options; | VXdoc::Output_options& oo=result.output_options; |
| oo.encoding=stylesheetRoot->m_encoding; | oo.encoding=stylesheetRoot->m_encoding; |
| Line 822 static void _transform(Request& r, const | Line 712 static void _transform(Request& r, const |
| // close | // close |
| connection.close(); | connection.close(); |
| } | } |
| */ | |
| static void _getElementById(Request& r, const String& method_name, MethodParams *params) { | |
| Pool& pool=r.pool(); | |
| VXdoc& vdoc=*static_cast<VXdoc *>(r.self); | |
| // elementId | |
| const String& elementId=params->as_string(0, "elementID must be string"); | |
| if(XalanNode *node= | |
| vdoc.get_document(pool, &method_name).getElementById(*pool.transcode(elementId))) { | |
| // write out result | |
| VXnode& result=*new(pool) VXnode(pool, node, false); | |
| r.write_no_lang(result); | |
| } | |
| } | |
| // constructor | // constructor |
| MXdoc::MXdoc(Pool& apool) : MXnode(apool) { | MXdoc::MXdoc(Pool& apool) : MXnode(apool) { |
| Line 863 MXdoc::MXdoc(Pool& apool) : MXnode(apool | Line 740 MXdoc::MXdoc(Pool& apool) : MXnode(apool |
| // EntityReference createEntityReference(in DOMString name) raises(DOMException); | // EntityReference createEntityReference(in DOMString name) raises(DOMException); |
| add_native_method("createEntityReference", Method::CT_DYNAMIC, _createEntityReference, 1, 1); | add_native_method("createEntityReference", Method::CT_DYNAMIC, _createEntityReference, 1, 1); |
| // NodeList getElementsByTagName(in DOMString tagname); | // NodeList getElementsByTagName(in DOMString tagname); |
| /* | add_native_method("getElementsByTagName", Method::CT_DYNAMIC, _getElementsByTagName, 1, 1); |
| // ^xdoc.getElementsByTagName[tagname] | // ^xdoc.getElementsByTagNameNS[namespaceURI;localName] = array of nodes |
| add_native_method("getElementsByTagName", Method::CT_DYNAMIC, _getElementsByTagName, 1, 1); | add_native_method("getElementsByTagNameNS", Method::CT_DYNAMIC, _getElementsByTagNameNS, 2, 2); |
| // ^xdoc.getElementsByTagNameNS[namespaceURI;localName] = array of nodes | |
| add_native_method("getElementsByTagNameNS", Method::CT_DYNAMIC, _getElementsByTagNameNS, 2, 2); | |
| */ | |
| /// DOM2(?) | /// DOM2(?) |
| Line 878 MXdoc::MXdoc(Pool& apool) : MXnode(apool | Line 751 MXdoc::MXdoc(Pool& apool) : MXnode(apool |
| /// parser | /// parser |
| // ^xdoc::create{qualifiedName} | |
| add_native_method("create", Method::CT_DYNAMIC, _create, 1, 1); | |
| // ^xdoc::set[<some>xml</some>] | |
| add_native_method("set", Method::CT_DYNAMIC, _set, 1, 1); | |
| // ^xdoc::load[some.xml] | |
| add_native_method("load", Method::CT_DYNAMIC, _load, 1, 1); | |
| // ^xdoc.save[some.xml] | // ^xdoc.save[some.xml] |
| // ^xdoc.save[some.xml;options hash] | // ^xdoc.save[some.xml;options hash] |
| add_native_method("save", Method::CT_DYNAMIC, _save, 1, 2); | add_native_method("save", Method::CT_DYNAMIC, _save, 1, 2); |
| Line 888 MXdoc::MXdoc(Pool& apool) : MXnode(apool | Line 769 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::set[<some>xml</some>] | |
| add_native_method("set", Method::CT_DYNAMIC, _set, 1, 1); | |
| // ^xdoc::create{qualifiedName} | |
| add_native_method("create", Method::CT_DYNAMIC, _create, 1, 1); | |
| // ^xdoc::load[some.xml] | |
| add_native_method("load", Method::CT_DYNAMIC, _load, 1, 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); |
| } | } |