diff --git a/src/xmlpromptgenerator.cpp b/src/xmlpromptgenerator.cpp index 3096291..fd9f65b 100644 --- a/src/xmlpromptgenerator.cpp +++ b/src/xmlpromptgenerator.cpp @@ -19,6 +19,7 @@ #include #include +#include #include #include "xmlpromptgenerator.h" #include "xmlencodinghandler.h" @@ -306,20 +307,42 @@ int XMLCALL XmlPromptGenerator::externalentityrefhandler ( parser.setDoSchema ( true ); parser.setValidationSchemaFullChecking ( true ); + MySAX2Handler handler; XercesCatalogResolver catalogResolver; + parser.setErrorHandler ( &handler ); parser.setEntityResolver ( &catalogResolver ); wxString wideSystemId ( systemId, wxConvUTF8 ); // TODO: Apply encoding wxString widePublicId ( publicId, wxConvUTF8 ); - URLInputSource source - ( ( const XMLCh * ) WrapXerces::toString ( d->basePath ).GetData() + std::auto_ptr source ( catalogResolver.resolveEntity + ( ( const XMLCh * ) WrapXerces::toString ( widePublicId ).GetData() + , ( const XMLCh * ) WrapXerces::toString ( wideSystemId ).GetData() + ) ); + if ( !source.get() ) + { + wxString fileURL = wxFileSystem::FileNameToURL ( d->basePath ); + source.reset ( new URLInputSource + ( ( const XMLCh * ) WrapXerces::toString ( fileURL ).GetData() , ( const XMLCh * ) WrapXerces::toString ( wideSystemId ).GetData() , ( const XMLCh * ) WrapXerces::toString ( widePublicId ).GetData() - ); - Grammar *rootGrammar = parser.loadGrammar ( source, Grammar::DTDGrammarType ); - if ( !rootGrammar ) + ) ); + } + + if ( pThis->TestDestroy() ) return XML_STATUS_ERROR; + Grammar *rootGrammar; + try { + rootGrammar = parser.loadGrammar ( *source, Grammar::DTDGrammarType ); + if ( !rootGrammar ) + return XML_STATUS_ERROR; + } + catch ( SAXParseException& e ) + { + wxLogError ( _T ( "%s" ), handler.getErrors().c_str() ); + return XML_STATUS_ERROR; + } + DTDGrammar* grammar = ( DTDGrammar* ) rootGrammar; NameIdPoolEnumerator elemEnum = grammar->getElemEnumerator();