|
|
| version 1.2, 2001/09/26 15:43:59 | version 1.12, 2001/10/08 08:35:56 |
|---|---|
| Line 19 | Line 19 |
| #include <strstream> | #include <strstream> |
| #include <Include/PlatformDefinitions.hpp> | #include <Include/PlatformDefinitions.hpp> |
| #include <util/PlatformUtils.hpp> | #include <util/PlatformUtils.hpp> |
| #include <util/TransENameMap.hpp> | |
| #include <XalanTransformer/XalanTransformer.hpp> | #include <XalanTransformer/XalanTransformer.hpp> |
| #include <XalanTransformer/XalanParsedSource.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/FormatterToXML.hpp> |
| #include <XMLSupport/FormatterToHTML.hpp> | #include <XMLSupport/FormatterToHTML.hpp> |
| #include <XMLSupport/FormatterToText.hpp> | #include <XMLSupport/FormatterToText.hpp> |
| Line 55 public: | Line 60 public: |
| public: // Methoded | public: // Methoded |
| bool used_directly() { return true; } | bool used_directly() { return true; } |
| void configure_admin(Request& r); | |
| }; | }; |
| // methods | // methods |
| Line 80 private: | Line 86 private: |
| }; | }; |
| 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 | |
| { | |
| public: | |
| XalanDefaultParsedSource2(const XSLTInputSource& theInputSource); | |
| virtual XalanDocument* | |
| getDocument() const; | |
| virtual XalanParsedSourceHelper* | |
| createHelper() const; | |
| private: | |
| XalanSourceTreeDOMSupport m_domSupport; | |
| XalanSourceTreeParserLiaison2 m_parserLiaison2; | |
| XalanSourceTreeDocument* const m_parsedSource; | |
| }; | |
| XalanDefaultParsedSource2::XalanDefaultParsedSource2(const XSLTInputSource& theInputSource): | |
| XalanParsedSource(), | |
| m_domSupport(), | |
| m_parserLiaison2(m_domSupport), | |
| m_parsedSource(m_parserLiaison2.mapDocument(m_parserLiaison2.parseXMLStream2(theInputSource))) | |
| { | |
| assert(m_parsedSource != 0); | |
| m_domSupport.setParserLiaison(&m_parserLiaison2); | |
| } | |
| XalanDocument* | |
| XalanDefaultParsedSource2::getDocument() const | |
| { | |
| return m_parsedSource; | |
| } | |
| XalanParsedSourceHelper* | |
| XalanDefaultParsedSource2::createHelper() const | |
| { | |
| return new XalanDefaultParsedSourceHelper(m_domSupport); | |
| } | |
| static void create_optioned_listener( | static void create_optioned_listener( |
| const char *& content_type, const char *& charset, FormatterListener *& listener, | const char *& content_type, const char *& charset, FormatterListener *& listener, |
| Pool& pool, | Pool& pool, |
| Line 236 static void _file(Request& r, const Stri | Line 323 static void _file(Request& r, const Stri |
| static void _set(Request& r, const String& method_name, MethodParams *params) { | static void _set(Request& r, const String& method_name, MethodParams *params) { |
| Pool& pool=r.pool(); | Pool& pool=r.pool(); |
| VXdoc& vdom=*static_cast<VXdoc *>(r.self); | VXdoc& vdoc=*static_cast<VXdoc *>(r.self); |
| Value& vxml=params->as_junction(0, "xml must be code"); | Value& vxml=params->as_junction(0, "xml must be code"); |
| Temp_lang temp_lang(r, String::UL_XML); | Temp_lang temp_lang(r, String::UL_XML); |
| Line 244 static void _set(Request& r, const Strin | Line 331 static void _set(Request& r, const Strin |
| std::istrstream stream(xml.cstr()); | std::istrstream stream(xml.cstr()); |
| const XalanParsedSource* parsedSource; | const XalanParsedSource* parsedSource; |
| int error=vdom.transformer().parseSource(&stream, parsedSource); | |
| if(error) | try { |
| PTHROW(0, 0, | parsedSource = new XalanDefaultParsedSource2(&stream); |
| &method_name, | } |
| vdom.transformer().getLastError()); | catch (XSLException& e) { |
| r._throw(&method_name, e); | |
| } | |
| catch (SAXParseException& e) { | |
| r._throw(&method_name, e); | |
| } | |
| catch (SAXException& e) { | |
| r._throw(&method_name, e); | |
| } | |
| catch (XMLException& e) { | |
| r._throw(&method_name, e); | |
| } | |
| catch(const XalanDOMException& e) { | |
| r._throw(&method_name, e); | |
| } | |
| // replace any previous parsed source | // replace any previous parsed source |
| vdom.set_parsed_source(*parsedSource); | vdoc.set_parsed_source(*parsedSource); |
| } | } |
| static void _load(Request& r, const String& method_name, MethodParams *params) { | static void _load(Request& r, const String& method_name, MethodParams *params) { |
| Pool& pool=r.pool(); | Pool& pool=r.pool(); |
| VXdoc& vdom=*static_cast<VXdoc *>(r.self); | VXdoc& vdoc=*static_cast<VXdoc *>(r.self); |
| // filespec | // filespec |
| const String& file_name=params->as_string(0, "file name must not be code"); | const String& file_name=params->as_string(0, "file name must not be code"); |
| const char *filespec=r.absolute(file_name).cstr(String::UL_FILE_SPEC); | const char *filespec=r.absolute(file_name).cstr(String::UL_FILE_SPEC); |
| const XalanParsedSource* parsedSource; | const XalanParsedSource* parsedSource; |
| int error=vdom.transformer().parseSource(filespec, parsedSource); | try { |
| parsedSource = new XalanDefaultParsedSource2(filespec); | |
| if(error) | } |
| PTHROW(0, 0, | catch (XSLException& e) { |
| &file_name, | r._throw(&method_name, e); |
| vdom.transformer().getLastError()); | } |
| catch (SAXParseException& e) { | |
| r._throw(&method_name, e); | |
| } | |
| catch (SAXException& e) { | |
| r._throw(&method_name, e); | |
| } | |
| catch (XMLException& e) { | |
| r._throw(&method_name, e); | |
| } | |
| catch(const XalanDOMException& e) { | |
| r._throw(&method_name, e); | |
| } | |
| // replace any previous parsed source | // replace any previous parsed source |
| vdom.set_parsed_source(*parsedSource); | vdoc.set_parsed_source(*parsedSource); |
| } | } |
| static void add_xslt_param(const Hash::Key& aattribute, Hash::Val *ameaning, | static void add_xslt_param(const Hash::Key& aattribute, Hash::Val *ameaning, |
| Line 285 static void add_xslt_param(const Hash::K | Line 397 static void add_xslt_param(const Hash::K |
| XalanDOMString(attribute_cstr), | XalanDOMString(attribute_cstr), |
| XalanDOMString(meaning_cstr)); | XalanDOMString(meaning_cstr)); |
| } | } |
| static void _xslt(Request& r, const String& method_name, MethodParams *params) { | static void _transform(Request& r, const String& method_name, MethodParams *params) { |
| Pool& pool=r.pool(); | Pool& pool=r.pool(); |
| VXdoc& vdom=*static_cast<VXdoc *>(r.self); | VXdoc& vdoc=*static_cast<VXdoc *>(r.self); |
| // params | // params |
| if(params->size()>1) { | if(params->size()>1) { |
| Value& vparams=params->as_no_junction(1, "transform parameters parameter must not be code"); | Value& vparams=params->as_no_junction(1, "transform parameters parameter must not be code"); |
| if(vparams.is_defined()) | if(vparams.is_defined()) |
| if(Hash *params=vparams.get_hash()) | if(Hash *params=vparams.get_hash()) |
| params->for_each(add_xslt_param, &vdom.transformer()); | params->for_each(add_xslt_param, &vdoc.transformer()); |
| else | else |
| PTHROW(0, 0, | PTHROW(0, 0, |
| &method_name, | &method_name, |
| Line 302 static void _xslt(Request& r, const Stri | Line 414 static void _xslt(Request& r, const Stri |
| } | } |
| // source | // source |
| const XalanParsedSource &parsed_source=vdom.get_parsed_source(pool, &method_name); | const XalanParsedSource &parsed_source=vdoc.get_parsed_source(pool, &method_name); |
| // stylesheet | // stylesheet |
| const String& stylesheet_file_name=params->as_string(0, "file name must not be code"); | const String& stylesheet_file_name=params->as_string(0, "file name must not be code"); |
| Line 311 static void _xslt(Request& r, const Stri | Line 423 static void _xslt(Request& r, const Stri |
| Stylesheet_connection& connection=XSLT_stylesheet_manager->get_connection(stylesheet_filespec); | Stylesheet_connection& connection=XSLT_stylesheet_manager->get_connection(stylesheet_filespec); |
| // target | // target |
| XalanDocument* target=vdom.parser_liaison().createDocument(); | XalanDocument* target=vdoc.parser_liaison().createDocument(); |
| XSLTResultTarget domResultTarget(target); | XSLTResultTarget domResultTarget(target); |
| // transform | // transform |
| int error=vdom.transformer().transform( | int error=vdoc.transformer().transform( |
| parsed_source, | parsed_source, |
| &connection.stylesheet(), | &connection.stylesheet(true/*nocache*/), |
| domResultTarget); | domResultTarget); |
| connection.close(); | connection.close(); |
| if(error) | if(error) |
| PTHROW(0, 0, | PTHROW(0, 0, |
| &stylesheet_file_name, | &stylesheet_file_name, |
| vdom.transformer().getLastError()); | vdoc.transformer().getLastError()); |
| // write out result | // write out result |
| VXdoc& result=*new(pool) VXdoc(pool); | VXdoc& result=*new(pool) VXdoc(pool); |
| Line 345 static void _getElementById(Request& r, | Line 457 static void _getElementById(Request& r, |
| r.write_no_lang(result); | r.write_no_lang(result); |
| } | } |
| } | } |
| /* | |
| 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); |
| Line 399 static void _getElementsByTagNameNS(Requ | Line 511 static void _getElementsByTagNameNS(Requ |
| // write out result | // write out result |
| r.write_no_lang(result); | r.write_no_lang(result); |
| } | } |
| */ | |
| // constructor | // constructor |
| MXdoc::MXdoc(Pool& apool) : MXnode(apool) { | MXdoc::MXdoc(Pool& apool) : MXnode(apool) { |
| Line 423 MXdoc::MXdoc(Pool& apool) : MXnode(apool | Line 535 MXdoc::MXdoc(Pool& apool) : MXnode(apool |
| // ^xdoc::load[some.xml] | // ^xdoc::load[some.xml] |
| add_native_method("load", Method::CT_DYNAMIC, _load, 1, 1); | add_native_method("load", Method::CT_DYNAMIC, _load, 1, 1); |
| // ^xdoc.xslt[stylesheet file_name] | // ^xdoc.transform[stylesheet file_name] |
| // ^xdoc.xslt[stylesheet file_name;params hash] | // ^xdoc.transform[stylesheet file_name;params hash] |
| add_native_method("xslt", Method::CT_DYNAMIC, _xslt, 1, 2); | add_native_method("transform", Method::CT_DYNAMIC, _transform, 1, 2); |
| // ^xdoc.getElementById[elementId] | // ^xdoc.getElementById[elementId] |
| add_native_method("getElementById", Method::CT_DYNAMIC, _getElementById, 1, 1); | add_native_method("getElementById", Method::CT_DYNAMIC, _getElementById, 1, 1); |
| /* | |
| // ^xdoc.getElementById[tagname] | // ^xdoc.getElementsByTagName[tagname] |
| add_native_method("getElementsByTagName", Method::CT_DYNAMIC, _getElementsByTagName, 1, 1); | add_native_method("getElementsByTagName", Method::CT_DYNAMIC, _getElementsByTagName, 1, 1); |
| // ^xdoc.getElementsByTagNameNS[namespaceURI;localName] = array of nodes | // ^xdoc.getElementsByTagNameNS[namespaceURI;localName] = array of nodes |
| add_native_method("getElementsByTagNameNS", Method::CT_DYNAMIC, _getElementsByTagNameNS, 2, 2); | add_native_method("getElementsByTagNameNS", Method::CT_DYNAMIC, _getElementsByTagNameNS, 2, 2); |
| */ | |
| } | |
| void MXdoc::configure_admin(Request& r) { | |
| } | } |
| // global variable | // global variable |
| Methoded *Xdoc_class; | Methoded *Xdoc_class; |