--- parser3/src/classes/xdoc.C 2001/10/05 16:12:40 1.9 +++ 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.9 2001/10/05 16:12:40 parser Exp $ + $Id: xdoc.C,v 1.13 2001/10/09 14:25:30 parser Exp $ */ #include "classes.h" #ifdef XML @@ -20,10 +20,12 @@ #include #include #include -#include +#include "XalanTransformer2.hpp" #include # include # include +# include +# include #include #include #include @@ -88,11 +90,27 @@ class XalanSourceTreeParserLiaison2: pub public: XalanSourceTreeParserLiaison2(XalanSourceTreeDOMSupport& theSupport) : XalanSourceTreeParserLiaison(theSupport), ferror_handler(new HandlerBase) { - setErrorHandler(ferror_handler); // disable stderr output } -// virtual fatal?error!! + 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; @@ -104,9 +122,6 @@ public: XalanDefaultParsedSource2(const XSLTInputSource& theInputSource); - virtual - ~XalanDefaultParsedSource2(); - virtual XalanDocument* getDocument() const; @@ -117,7 +132,7 @@ private: XalanSourceTreeDOMSupport m_domSupport; - XalanSourceTreeParserLiaison2 m_parserLiaison; + XalanSourceTreeParserLiaison2 m_parserLiaison2; XalanSourceTreeDocument* const m_parsedSource; }; @@ -125,18 +140,12 @@ private: XalanDefaultParsedSource2::XalanDefaultParsedSource2(const XSLTInputSource& theInputSource): XalanParsedSource(), m_domSupport(), - m_parserLiaison(m_domSupport), - m_parsedSource(m_parserLiaison.mapDocument(m_parserLiaison.parseXMLStream(theInputSource))) + m_parserLiaison2(m_domSupport), + m_parsedSource(m_parserLiaison2.mapDocument(m_parserLiaison2.parseXMLStream2(theInputSource))) { assert(m_parsedSource != 0); - m_domSupport.setParserLiaison(&m_parserLiaison); -} - - - -XalanDefaultParsedSource2::~XalanDefaultParsedSource2() -{ + m_domSupport.setParserLiaison(&m_parserLiaison2); } @@ -322,59 +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()); -*/ - int error; - CharVectorType m_errorMessage; - m_errorMessage.push_back(0); - try - { - parsedSource = new XalanDefaultParsedSource2(&stream); - error=0; - - //todo free parsedSource + try { + parsedSource = new XalanDefaultParsedSource2(&stream); } - catch (XSLException& e) - { - TranscodeToLocalCodePage(e.getMessage(), m_errorMessage, true); - - error = -1; + catch (XSLException& e) { + r._throw(&method_name, e); } - catch (SAXException& e) - { - TranscodeToLocalCodePage(e.getMessage(), m_errorMessage, true); - - error = -2; + catch (SAXParseException& e) { + r._throw(&method_name, e); } - catch (XMLException& e) - { - TranscodeToLocalCodePage(e.getMessage(), m_errorMessage, true); - - error = -3; + catch (SAXException& e) { + r._throw(&method_name, e); } - catch(const XalanDOMException& e) - { - XalanDOMString theMessage("XalanDOMException caught. The code is "); - - append(theMessage, LongToDOMString(long(e.getExceptionCode()))); - - append(theMessage, XalanDOMString(".")); - - TranscodeToLocalCodePage(theMessage, m_errorMessage, true); - - error = -3; + catch (XMLException& e) { + r._throw(&method_name, e); + } + catch(const XalanDOMException& e) { + r._throw(&method_name, e); } - - if(error) - PTHROW(0, 0, - &method_name, - &m_errorMessage[0]); // replace any previous parsed source vdoc.set_parsed_source(*parsedSource); @@ -389,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); @@ -402,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(); @@ -437,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);