Resolve DTDs explicitly before loading them
This commit is contained in:
parent
7e7c756c60
commit
fa5e760c82
|
@ -19,6 +19,7 @@
|
||||||
|
|
||||||
#include <wx/wx.h>
|
#include <wx/wx.h>
|
||||||
#include <wx/filename.h>
|
#include <wx/filename.h>
|
||||||
|
#include <wx/filesys.h>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include "xmlpromptgenerator.h"
|
#include "xmlpromptgenerator.h"
|
||||||
#include "xmlencodinghandler.h"
|
#include "xmlencodinghandler.h"
|
||||||
|
@ -306,20 +307,42 @@ int XMLCALL XmlPromptGenerator::externalentityrefhandler (
|
||||||
parser.setDoSchema ( true );
|
parser.setDoSchema ( true );
|
||||||
parser.setValidationSchemaFullChecking ( true );
|
parser.setValidationSchemaFullChecking ( true );
|
||||||
|
|
||||||
|
MySAX2Handler handler;
|
||||||
XercesCatalogResolver catalogResolver;
|
XercesCatalogResolver catalogResolver;
|
||||||
|
parser.setErrorHandler ( &handler );
|
||||||
parser.setEntityResolver ( &catalogResolver );
|
parser.setEntityResolver ( &catalogResolver );
|
||||||
|
|
||||||
wxString wideSystemId ( systemId, wxConvUTF8 ); // TODO: Apply encoding
|
wxString wideSystemId ( systemId, wxConvUTF8 ); // TODO: Apply encoding
|
||||||
wxString widePublicId ( publicId, wxConvUTF8 );
|
wxString widePublicId ( publicId, wxConvUTF8 );
|
||||||
URLInputSource source
|
std::auto_ptr<InputSource> source ( catalogResolver.resolveEntity
|
||||||
( ( const XMLCh * ) WrapXerces::toString ( d->basePath ).GetData()
|
( ( 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 ( wideSystemId ).GetData()
|
||||||
, ( const XMLCh * ) WrapXerces::toString ( widePublicId ).GetData()
|
, ( const XMLCh * ) WrapXerces::toString ( widePublicId ).GetData()
|
||||||
);
|
) );
|
||||||
Grammar *rootGrammar = parser.loadGrammar ( source, Grammar::DTDGrammarType );
|
}
|
||||||
if ( !rootGrammar )
|
|
||||||
|
if ( pThis->TestDestroy() )
|
||||||
return XML_STATUS_ERROR;
|
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;
|
DTDGrammar* grammar = ( DTDGrammar* ) rootGrammar;
|
||||||
NameIdPoolEnumerator<DTDElementDecl> elemEnum = grammar->getElemEnumerator();
|
NameIdPoolEnumerator<DTDElementDecl> elemEnum = grammar->getElemEnumerator();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue