--- parser3/src/classes/xdoc.C 2001/10/05 11:21:10 1.8 +++ parser3/src/classes/xdoc.C 2001/10/09 14:25:30 1.13 @@ -4,7 +4,7 @@ Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com) Author: Alexander Petrosyan (http://design.ru/paf) - $Id: xdoc.C,v 1.8 2001/10/05 11:21:10 parser Exp $ + $Id: xdoc.C,v 1.13 2001/10/09 14:25:30 parser Exp $ */ #include "classes.h" #ifdef XML @@ -20,8 +20,12 @@ #include #include #include -#include +#include "XalanTransformer2.hpp" #include +# include +# include +# include +# include #include #include #include @@ -82,6 +86,87 @@ private: }; +class XalanSourceTreeParserLiaison2: public XalanSourceTreeParserLiaison { +public: + XalanSourceTreeParserLiaison2(XalanSourceTreeDOMSupport& theSupport) : XalanSourceTreeParserLiaison(theSupport), + ferror_handler(new HandlerBase) { + } + + XalanDocument* + parseXMLStream2( + const InputSource& inputSource) { + XalanSourceTreeContentHandler theContentHandler(createXalanSourceTreeDocument()); + XalanAutoPtr 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( const char *& content_type, const char *& charset, FormatterListener *& listener, Pool& pool, @@ -246,12 +331,25 @@ static void _set(Request& r, const Strin std::istrstream stream(xml.cstr()); const XalanParsedSource* parsedSource; - int error=vdoc.transformer().parseSource(&stream, parsedSource); - if(error) - PTHROW(0, 0, - &method_name, - vdoc.transformer().getLastError()); + try { + parsedSource = new XalanDefaultParsedSource2(&stream); + } + 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 vdoc.set_parsed_source(*parsedSource); @@ -266,12 +364,24 @@ static void _load(Request& r, const Stri const char *filespec=r.absolute(file_name).cstr(String::UL_FILE_SPEC); const XalanParsedSource* parsedSource; - int error=vdoc.transformer().parseSource(filespec, parsedSource); - - if(error) - PTHROW(0, 0, - &file_name, - vdoc.transformer().getLastError()); + try { + parsedSource = new XalanDefaultParsedSource2(filespec); + } + 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 vdoc.set_parsed_source(*parsedSource); @@ -279,7 +389,7 @@ static void _load(Request& r, const Stri static void add_xslt_param(const Hash::Key& aattribute, Hash::Val *ameaning, void *info) { - XalanTransformer& transformer=*static_cast(info); + XalanTransformer2& transformer=*static_cast(info); const char *attribute_cstr=aattribute.cstr(); const char *meaning_cstr=static_cast(ameaning)->as_string().cstr(); @@ -314,18 +424,34 @@ static void _transform(Request& r, const // target XalanDocument* target=vdoc.parser_liaison().createDocument(); - XSLTResultTarget domResultTarget(target); // transform - int error=vdoc.transformer().transform( - parsed_source, - &connection.stylesheet(true/*nocache*/), - domResultTarget); - connection.close(); - if(error) - PTHROW(0, 0, - &stylesheet_file_name, - vdoc.transformer().getLastError()); + try { + vdoc.transformer().transform2( + parsed_source, + &connection.stylesheet(true/*nocache*/), + target); + } + catch (XSLException& e) { + connection.close(); + r._throw(&stylesheet_file_name, e); + } + catch (SAXParseException& e) { + connection.close(); + r._throw(&stylesheet_file_name, e); + } + catch (SAXException& e) { + connection.close(); + r._throw(&stylesheet_file_name, e); + } + catch (XMLException& e) { + connection.close(); + r._throw(&stylesheet_file_name, e); + } + catch(const XalanDOMException& e) { + connection.close(); + r._throw(&stylesheet_file_name, e); + } // write out result VXdoc& result=*new(pool) VXdoc(pool);