2009-11-06 18:06:12 +01:00
|
|
|
#include "xercescatalogresolver.h"
|
|
|
|
#include <xercesc/sax2/SAX2XMLReader.hpp>
|
|
|
|
#include <xercesc/framework/LocalFileInputSource.hpp>
|
|
|
|
|
|
|
|
#ifdef __WXMSW__
|
|
|
|
#include "wx/wx.h"
|
|
|
|
#include "replace.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
InputSource *XercesCatalogResolver::resolveEntity (
|
|
|
|
const XMLCh* const publicID,
|
|
|
|
const XMLCh* const systemId )
|
|
|
|
{
|
|
|
|
/* the following _should_ work but doesn't always, so drop it for now
|
|
|
|
#ifndef __WXMSW__
|
2012-08-30 16:37:01 +02:00
|
|
|
resolved = lookupPublicId ( narrowPublicId );
|
2009-11-06 18:06:12 +01:00
|
|
|
#else
|
|
|
|
return NULL;
|
|
|
|
std::string stdPublicId = narrowPublicId;
|
|
|
|
|
|
|
|
// on Windows, call libxml's own xmlcatalog binary
|
|
|
|
// because calling libxml from xerces causes a protection fault
|
|
|
|
|
|
|
|
std::string narrowCommand = "";
|
|
|
|
narrowCommand += myCatalogUtilityPath;
|
|
|
|
narrowCommand += " \"";
|
|
|
|
narrowCommand += myCatalogPath;
|
|
|
|
narrowCommand += "\" \"";
|
|
|
|
narrowCommand += narrowPublicId;
|
|
|
|
narrowCommand += "\"";
|
|
|
|
|
|
|
|
wxString wideCommand = wxString (
|
|
|
|
narrowCommand.c_str(),
|
|
|
|
wxConvUTF8,
|
|
|
|
narrowCommand.size() );
|
|
|
|
|
|
|
|
wxArrayString stringArray;
|
|
|
|
long ret = wxExecute (
|
|
|
|
wideCommand,
|
|
|
|
stringArray,
|
|
|
|
wxEXEC_SYNC | wxEXEC_NODISABLE );
|
|
|
|
if ( ret == -1 || stringArray.empty() )
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
wxString returnValue = stringArray[0];
|
|
|
|
|
|
|
|
std::string narrowReturnValue = (const char *)returnValue.mb_str ( wxConvLocal );
|
|
|
|
|
|
|
|
Replace::run ( narrowReturnValue, "%20", " ", false );
|
|
|
|
|
|
|
|
char *s, *it;
|
|
|
|
s = (char *) narrowReturnValue.c_str();
|
|
|
|
|
|
|
|
for (char *scan = s; *scan; scan++ )
|
|
|
|
if (*scan == '/')
|
|
|
|
*scan = '\\';
|
|
|
|
|
|
|
|
if ( strstr ( s, "No entry" ) )
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
it = strstr ( s, "\\\\\\" );
|
|
|
|
if ( it )
|
|
|
|
resolved = it + 3;
|
|
|
|
else
|
|
|
|
resolved = (const char *)s;//narrowReturnValue;
|
|
|
|
#endif
|
|
|
|
*/
|
|
|
|
|
2013-10-15 13:19:40 +02:00
|
|
|
if ( publicID == NULL || *publicID == '\0' )
|
|
|
|
return NULL;
|
|
|
|
|
2013-10-16 19:28:39 +02:00
|
|
|
// Since public IDs consist of ANSII characters, it doesn't matter how
|
|
|
|
// publicID is encoded as long as it's a multibyte string
|
2009-11-06 18:06:12 +01:00
|
|
|
char *narrowPublicId = XMLString::transcode ( publicID );
|
2013-10-15 13:19:40 +02:00
|
|
|
if ( narrowPublicId == NULL )
|
|
|
|
return NULL;
|
|
|
|
|
2009-11-06 18:06:12 +01:00
|
|
|
std::string resolved;
|
2012-08-30 16:37:01 +02:00
|
|
|
resolved = lookupPublicId ( narrowPublicId );
|
2009-11-06 18:06:12 +01:00
|
|
|
|
|
|
|
XMLString::release ( &narrowPublicId );
|
2012-08-30 16:37:01 +02:00
|
|
|
|
2009-11-06 18:06:12 +01:00
|
|
|
if ( resolved.empty() )
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
XMLCh *wideResolved = XMLString::transcode ( resolved.c_str() );
|
2013-10-15 13:19:40 +02:00
|
|
|
|
|
|
|
InputSource *source = (InputSource *)new LocalFileInputSource ( wideResolved );
|
2009-11-06 18:06:12 +01:00
|
|
|
XMLString::release ( &wideResolved );
|
|
|
|
|
|
|
|
return source;
|
|
|
|
}
|