Made XercesCatalogResolver work. Don't load catalog over and over again. It isn't thread-safe according to the document.

Fixed a compiling problem with wxWidgets 2.9
This commit is contained in:
Zane U. Ji 2012-08-30 22:37:01 +08:00
parent e455fd0da3
commit b4aa69c2ca
26 changed files with 201 additions and 244 deletions

View File

@ -72,7 +72,15 @@ nobase_xmlcopyeditor_DATA = png/*.png \
po/zh_TW/messages.mo \ po/zh_TW/messages.mo \
po/uk_UA/messages.mo \ po/uk_UA/messages.mo \
po/ca/messages.mo \ po/ca/messages.mo \
po/en_us/messages.po po/en_us/messages.po \
catalog/catalog \
dtd/*.* dtd/dita/* \
dtd/docbook/4.4/*.* \
dtd/docbook/4.4/ent/* \
dtd/docbook/5.0b/* \
dtd/tei/p4/* \
dtd/tei/p5/* \
xsl/openlearn2daisyhtml/*
pixmap_DATA = xmlcopyeditor.png pixmap_DATA = xmlcopyeditor.png

View File

@ -314,7 +314,15 @@ nobase_xmlcopyeditor_DATA = png/*.png \
po/zh_TW/messages.mo \ po/zh_TW/messages.mo \
po/uk_UA/messages.mo \ po/uk_UA/messages.mo \
po/ca/messages.mo \ po/ca/messages.mo \
po/en_us/messages.po po/en_us/messages.po \
catalog/catalog \
dtd/*.* dtd/dita/* \
dtd/docbook/4.4/*.* \
dtd/docbook/4.4/ent/* \
dtd/docbook/5.0b/* \
dtd/tei/p4/* \
dtd/tei/p5/* \
xsl/openlearn2daisyhtml/*
pixmap_DATA = xmlcopyeditor.png pixmap_DATA = xmlcopyeditor.png
applications_DATA = xmlcopyeditor.desktop applications_DATA = xmlcopyeditor.desktop

View File

@ -1,21 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog"> <catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog">
<public publicId="-//W3C//DTD XHTML 1.0 Transitional//EN" uri="file:///C:/Program%20Files/XML%20Copy%20Editor/dtd/xhtml1-transitional.dtd"/> <public publicId="-//W3C//DTD XHTML 1.0 Transitional//EN" uri="../dtd/xhtml1-transitional.dtd"/>
<public publicId="-//W3C//DTD XHTML 1.0 Strict//EN" uri="file:///C:/Program%20Files/XML%20Copy%20Editor/dtd/xhtml1-strict.dtd"/> <public publicId="-//W3C//DTD XHTML 1.0 Strict//EN" uri="../dtd/xhtml1-strict.dtd"/>
<public publicId="-//W3C//DTD XHTML 1.0 Frameset//EN" uri="file:///C:/Program%20Files/XML%20Copy%20Editor/dtd/xhtml1-frameset.dtd"/> <public publicId="-//W3C//DTD XHTML 1.0 Frameset//EN" uri="../dtd/xhtml1-frameset.dtd"/>
<public publicId="-//OASIS//DTD DocBook XML 5.0b3//EN" uri="file:///C:/Program%20Files/XML%20Copy%20Editor/dtd/docbook/5.0b/docbook.dtd"/> <public publicId="-//W3C//ENTITIES Latin 1 for XHTML//EN" uri="../dtd/xhtml-lat1.ent"/>
<public publicId="-//OASIS//DTD DocBook XML 4.4//EN" uri="file:///C:/Program%20Files/XML%20Copy%20Editor/dtd/docbook/4.4/docbookx.dtd"/> <public publicId="-//W3C//ENTITIES Symbols for XHTML//EN" uri="../dtd/xhtml-symbol.ent"/>
<public publicId="-//TEI P4//DTD Main Document Type//EN" uri="file:///C:/Program%20Files/XML%20Copy%20Editor/dtd/tei/p4/tei2.dtd"/> <public publicId="-//W3C//ENTITIES Special for XHTML//EN" uri="../dtd/xhtml-special.ent"/>
<public publicId="-//TEI P5//DTD Main Document Type//EN" uri="file:///C:/Program%20Files/XML%20Copy%20Editor/dtd/tei/p5/tei_all.dtd"/> <public publicId="-//OASIS//DTD DocBook XML 5.0b3//EN" uri="../dtd/docbook/5.0b/docbook.dtd"/>
<public publicId="-//OASIS//DTD DITA Map//EN" uri="file:///C:/Program%20Files/XML%20Copy%20Editor/dtd/dita/map.dtd"/> <public publicId="-//OASIS//DTD DocBook XML 4.4//EN" uri="../dtd/docbook/4.4/docbookx.dtd"/>
<public publicId="-//OASIS//DTD DITA Task//EN" uri="file:///C:/Program%20Files/XML%20Copy%20Editor/dtd/dita/task.dtd"/> <public publicId="-//TEI P4//DTD Main Document Type//EN" uri="../dtd/tei/p4/tei2.dtd"/>
<public publicId="-//OASIS//DTD DITA Topic//EN" uri="file:///C:/Program%20Files/XML%20Copy%20Editor/dtd/dita/topic.dtd"/> <public publicId="-//TEI P5//DTD Main Document Type//EN" uri="../dtd/tei/p5/tei_all.dtd"/>
<public publicId="-//OASIS//DTD DITA Concept//EN" uri="file:///C:/Program%20Files/XML%20Copy%20Editor/dtd/dita/concept.dtd"/> <public publicId="-//OASIS//DTD DITA Map//EN" uri="../dtd/dita/map.dtd"/>
<public publicId="-//OpenLaszlo//DTD Main Document Type//EN" uri="file:///C:/Program%20Files/XML%20Copy%20Editor/dtd/lzx.dtd"/> <public publicId="-//OASIS//DTD DITA Task//EN" uri="../dtd/dita/task.dtd"/>
<public publicId="urn:newsml:iptc.org:20021018:NewsMLv1.2:1" uri="file:///C:/Program%20Files/XML%20Copy%20Editor/dtd/NewsML_1.2.dtd"/> <public publicId="-//OASIS//DTD DITA Topic//EN" uri="../dtd/dita/topic.dtd"/>
<public publicId="-//TopicMaps.Org//DTD XML Topic Map (XTM) 1.0//EN" uri="file:///C:/Program%20Files/XML%20Copy%20Editor/dtd/xtm1.dtd"/> <public publicId="-//OASIS//DTD DITA Concept//EN" uri="../dtd/dita/concept.dtd"/>
<public publicId="ISO/IEC 13250-3:2005//DTD XML Topic Maps (XTM) 2.0//EN" uri="file:///C:/Program%20Files/XML%20Copy%20Editor/dtd/xtm2.dtd"/> <public publicId="-//OpenLaszlo//DTD Main Document Type//EN" uri="../dtd/lzx.dtd"/>
<public publicId="-//OpenLearn//DTD" uri="file:///C:/Program%20Files/XML%20Copy%20Editor/dtd/OUGenericFull.dtd"/> <public publicId="urn:newsml:iptc.org:20021018:NewsMLv1.2:1" uri="../dtd/NewsML_1.2.dtd"/>
<public publicId="-//Moodle Glossary//DTD" uri="file:///C:/Program%20Files/XML%20Copy%20Editor/dtd/moodle_glossary.dtd"/> <public publicId="-//TopicMaps.Org//DTD XML Topic Map (XTM) 1.0//EN" uri="../dtd/xtm1.dtd"/>
<public publicId="-//Moodle XML//DTD" uri="file:///C:/Program%20Files/XML%20Copy%20Editor/dtd/moodle_xml.dtd"/> <public publicId="ISO/IEC 13250-3:2005//DTD XML Topic Maps (XTM) 2.0//EN" uri="../dtd/xtm2.dtd"/>
<public publicId="-//OpenLearn//DTD" uri="../dtd/OUGenericFull.dtd"/>
<public publicId="-//Moodle Glossary//DTD" uri="../dtd/moodle_glossary.dtd"/>
<public publicId="-//Moodle XML//DTD" uri="../dtd/moodle_xml.dtd"/>
</catalog> </catalog>

View File

@ -20,19 +20,16 @@
#include <memory> #include <memory>
#include "catalogresolver.h" #include "catalogresolver.h"
CatalogResolver::CatalogResolver( const std::string& catalogPath ) CatalogResolver::CatalogResolver()
{ {
wl = new WrapLibxml ( false, catalogPath );
} }
CatalogResolver::~CatalogResolver() CatalogResolver::~CatalogResolver()
{ {
delete wl;
} }
std::string CatalogResolver::lookupPublicId ( std::string CatalogResolver::lookupPublicId ( const std::string &publicId )
const std::string& publicId)
{ {
//std::auto_ptr<WrapLibxml> libxml ( new WrapLibxml ( false, catalogPath ) ); //std::auto_ptr<WrapLibxml> libxml ( new WrapLibxml ( false, catalogPath ) );
return wl->lookupPublicId ( publicId ); return WrapLibxml::lookupPublicId ( publicId );
} }

View File

@ -23,15 +23,13 @@
#include <string> #include <string>
#include "wraplibxml.h" #include "wraplibxml.h"
class CatalogResolver class CatalogResolver : protected WrapLibxml
{ {
public: public:
CatalogResolver( const std::string& catalogPath ); CatalogResolver();
~CatalogResolver(); ~CatalogResolver();
std::string lookupPublicId ( std::string lookupPublicId (
const std::string& publicId); const std::string& publicId);
private:
WrapLibxml *wl;
}; };
#endif #endif

View File

@ -24,7 +24,7 @@ void *CatalogResolverThread::Entry()
{ {
wxCriticalSectionLocker locker ( catalogResolverCriticalSection ); wxCriticalSectionLocker locker ( catalogResolverCriticalSection );
std::auto_ptr<WrapLibxml> libxml ( new WrapLibxml ( false, myCatalogPath ) ); std::auto_ptr<WrapLibxml> libxml ( new WrapLibxml ( false ) );
*mySystemIdPtr = libxml->lookupPublicId ( *myPublicIdPtr ); *mySystemIdPtr = libxml->lookupPublicId ( *myPublicIdPtr );
} }
Exit(); Exit();

View File

@ -19,25 +19,25 @@
#include <wx/filename.h> #include <wx/filename.h>
#include "pathresolver.h" #include "pathresolver.h"
#include <wx/stdpaths.h>
wxString PathResolver::run ( const wxString& path, const wxString& anchor ) wxString PathResolver::run ( const wxString& path, const wxString& anchor )
{ {
if ( path.empty() ) // no hope for empty paths if ( path.empty() ) // no hope for empty paths
return wxEmptyString; return wxEmptyString;
wxString myPath, myAnchor; wxFileName pathObject ( path );
myPath = path; if ( pathObject.IsAbsolute() || path.Contains ( _T ( "http://" ) ) )
myAnchor = anchor; return path;
wxFileName pathObject ( myPath );
if ( pathObject.IsAbsolute() ||
myPath.Contains ( _T ( "http://" ) ) )
return myPath;
// check anchor // check anchor
wxString myAnchor;
myAnchor = anchor;
wxFileName anchorObject ( myAnchor ); wxFileName anchorObject ( myAnchor );
if ( myAnchor.empty() ) if ( myAnchor.empty() )
{ {
myAnchor = wxFileName::GetCwd(); //myAnchor = wxFileName::GetCwd();
myAnchor = wxStandardPaths::Get().GetDataDir();
} }
else if ( !anchorObject.IsDir() ) else if ( !anchorObject.IsDir() )
{ {

View File

@ -27,13 +27,7 @@ ThreadReaper::ThreadReaper ()
ThreadReaper::~ThreadReaper () ThreadReaper::~ThreadReaper ()
{ {
//wxCriticalSectionLocker lock ( xmlcopyeditorCriticalSection ); clear();
std::vector<boost::shared_ptr<wxThread> >::iterator itr;
for ( itr = mList.begin(); itr != mList.end(); itr++)
{
(**itr).Kill();
}
} }
ThreadReaper &ThreadReaper::get() ThreadReaper &ThreadReaper::get()
@ -59,3 +53,25 @@ void ThreadReaper::add ( wxThread *thread )
itr = mList.erase ( itr ); itr = mList.erase ( itr );
} }
} }
void ThreadReaper::clear()
{
xmlcopyeditorCriticalSection.Enter();
std::vector<boost::shared_ptr<wxThread> > threads = mList;
mList.clear();
xmlcopyeditorCriticalSection.Leave();
// It's safe to call wxThread::Wait() now
std::vector<boost::shared_ptr<wxThread> >::iterator itr;
for ( itr = threads.begin(); itr != threads.end(); itr++)
{
// This will cause the whole program to abort in linux with early
// versions of wxWidgets. A easy way to fix this is to rethrow
// abi::__forced_unwind& exceptions and avoid calling pthread_exit
// in such a condition.
(**itr).Kill();
(**itr).Wait();
}
}

View File

@ -34,6 +34,8 @@ public:
static ThreadReaper &get(); static ThreadReaper &get();
void add ( wxThread *thread ); void add ( wxThread *thread );
// Kills all threads in the list.
void clear();
protected: protected:
std::vector<boost::shared_ptr<wxThread> > mList; std::vector<boost::shared_ptr<wxThread> > mList;

View File

@ -13,9 +13,7 @@ DEFINE_EVENT_TYPE(wxEVT_COMMAND_VALIDATION_COMPLETED);
ValidationThread::ValidationThread ( ValidationThread::ValidationThread (
wxEvtHandler *handler, wxEvtHandler *handler,
const char *buffer, const char *buffer,
const char *system, const char *system )
const char *catalogPath,
const char *catalogUtilityPath )
: wxThread ( wxTHREAD_JOINABLE ) : wxThread ( wxTHREAD_JOINABLE )
, mStopping ( false ) , mStopping ( false )
{ {
@ -27,16 +25,12 @@ ValidationThread::ValidationThread (
myEventHandler = handler; myEventHandler = handler;
myBuffer = buffer; myBuffer = buffer;
mySystem = system; mySystem = system;
myCatalogPath = catalogPath;
myCatalogUtilityPath = catalogUtilityPath;
myIsSucceeded = false; myIsSucceeded = false;
} }
void *ValidationThread::Entry() void *ValidationThread::Entry()
{ {
std::auto_ptr<WrapXerces> validator ( new WrapXerces( std::auto_ptr<WrapXerces> validator ( new WrapXerces() );
myCatalogPath,
myCatalogUtilityPath ) );
if ( TestDestroy() ) if ( TestDestroy() )
{ {

View File

@ -14,9 +14,7 @@ public:
ValidationThread ( ValidationThread (
wxEvtHandler *handler, wxEvtHandler *handler,
const char *buffer, const char *buffer,
const char *system, const char *system );
const char *catalogPath,
const char *catalogUtilityPath );
virtual void *Entry(); virtual void *Entry();
void setBuffer ( const char *buffer, const char *system ); void setBuffer ( const char *buffer, const char *system );
bool isSucceeded () { return myIsSucceeded; } bool isSucceeded () { return myIsSucceeded; }
@ -31,7 +29,7 @@ public:
protected: protected:
wxEvtHandler *myEventHandler; wxEvtHandler *myEventHandler;
std::string myBuffer, mySystem, myCatalogPath, myCatalogUtilityPath; std::string myBuffer, mySystem;
bool myIsSucceeded; bool myIsSucceeded;
std::pair<int, int> myPosition; std::pair<int, int> myPosition;
wxString myMessage; wxString myMessage;

View File

@ -26,21 +26,25 @@
#endif #endif
#include <wx/wx.h> #include <wx/wx.h>
#include <wx/filesys.h>
#include <wx/uri.h>
void WrapLibxml::Init() throw() class Initializer
{ {
static class Initializer public:
Initializer ( const std::string &catalogPath ) throw ()
{ {
public: xmlSetGenericErrorFunc ( xmlGenericErrorContext,
Initializer () throw () &Initializer::OnXmlGenericError );
{
xmlSetGenericErrorFunc ( xmlGenericErrorContext, &Initializer::OnXmlGenericError );
LIBXML_TEST_VERSION LIBXML_TEST_VERSION
xmlInitializeCatalog(); xmlInitializeCatalog();
xmlLoadCatalog ( catalogPath.c_str() );
initGenericErrorDefaultFunc ( NULL ); initGenericErrorDefaultFunc ( NULL );
} }
~Initializer () ~Initializer ()
{ {
xsltCleanupGlobals(); xsltCleanupGlobals();
@ -77,11 +81,15 @@ void WrapLibxml::Init() throw()
std::string ( "Can't format message: " ) + msg ); std::string ( "Can't format message: " ) + msg );
} }
} }
} dummy; };
void WrapLibxml::Init ( const std::string &catalogPath ) throw()
{
static Initializer dummy ( catalogPath );
} }
WrapLibxml::WrapLibxml ( bool netAccessParameter, const std::string& catalogPathParameter ) WrapLibxml::WrapLibxml ( bool netAccessParameter )
: netAccess ( netAccessParameter ), catalogPath ( catalogPathParameter ) : netAccess ( netAccessParameter )
{ {
WrapLibxml::Init(); WrapLibxml::Init();
} }
@ -106,7 +114,6 @@ bool WrapLibxml::validate ( const std::string& fileName )
bool returnValue = false; bool returnValue = false;
loadCatalog();
docPtr = xmlCtxtReadFile ( docPtr = xmlCtxtReadFile (
ctxt, ctxt,
fileName.c_str(), fileName.c_str(),
@ -239,8 +246,6 @@ bool WrapLibxml::parse (
return false; return false;
} }
loadCatalog();
int flags = XML_PARSE_DTDLOAD; int flags = XML_PARSE_DTDLOAD;
if ( resolveEntities ) if ( resolveEntities )
flags |= XML_PARSE_NOENT; flags |= XML_PARSE_NOENT;
@ -301,7 +306,6 @@ bool WrapLibxml::xpath ( const std::string& path, const std::string& fileName )
return false; return false;
} }
loadCatalog();
docPtr = xmlCtxtReadFile ( docPtr = xmlCtxtReadFile (
ctxt, ctxt,
fileName.c_str(), fileName.c_str(),
@ -384,7 +388,6 @@ bool WrapLibxml::xslt (
return false; return false;
} }
loadCatalog();
doc = xmlParseFile ( fileName.c_str() ); doc = xmlParseFile ( fileName.c_str() );
if ( !doc ) if ( !doc )
{ {
@ -432,7 +435,6 @@ bool WrapLibxml::bufferWellFormed ( const std::string& buffer )
if ( !ctxt ) if ( !ctxt )
return false; return false;
loadCatalog();
xmlDocPtr docPtr = xmlCtxtReadMemory ( xmlDocPtr docPtr = xmlCtxtReadMemory (
ctxt, ctxt,
buffer.c_str(), buffer.c_str(),
@ -459,8 +461,6 @@ int WrapLibxml::saveEncoding (
xmlSubstituteEntitiesDefault ( 0 ); xmlSubstituteEntitiesDefault ( 0 );
loadCatalog();
xmlKeepBlanksDefault ( 1 ); // prevents single-line output xmlKeepBlanksDefault ( 1 ); // prevents single-line output
xmlDocPtr docPtr = xmlCtxtReadMemory ( xmlDocPtr docPtr = xmlCtxtReadMemory (
@ -496,9 +496,6 @@ int WrapLibxml::saveEncodingFromFile (
return -1; return -1;
xmlSubstituteEntitiesDefault ( 0 ); xmlSubstituteEntitiesDefault ( 0 );
loadCatalog();
xmlKeepBlanksDefault ( 1 ); // prevents single-line output xmlKeepBlanksDefault ( 1 ); // prevents single-line output
xmlDocPtr docPtr = xmlCtxtReadFile ( xmlDocPtr docPtr = xmlCtxtReadFile (
@ -564,32 +561,21 @@ std::string WrapLibxml::getOutput()
return output; return output;
} }
void WrapLibxml::loadCatalog()
{
#ifdef __WXMSW__
xmlLoadCatalog ( catalogPath.c_str() );
#endif
}
std::string WrapLibxml::lookupPublicId ( const std::string& id ) std::string WrapLibxml::lookupPublicId ( const std::string& id )
{ {
loadCatalog();
std::string ret; std::string ret;
char *s = ( char * ) xmlCatalogResolvePublic ( ( const xmlChar * ) id.c_str() ); char *s = ( char * ) xmlCatalogResolvePublic ( ( const xmlChar * ) id.c_str() );
if ( !s ) if ( s == NULL )
return ret; return ret;
char *original, *it; wxString url ( s, wxConvUTF8 );
original = s; wxFileName file = wxFileSystem::URLToFileName ( url );
if ( file.IsFileReadable() )
it = strstr ( s, "file://" ); ret = file.GetFullPath().mb_str ( wxConvLocal );
if ( it ) else
{
s = it + 6;
}
ret = s; ret = s;
xmlFree ( original ); xmlFree ( s );
return ret; return ret;
} }

View File

@ -38,10 +38,9 @@
class WrapLibxml class WrapLibxml
{ {
public: public:
static void Init() throw(); static void Init ( const std::string &catalogPath = "catalog" ) throw();
WrapLibxml (
bool netAccessParameter = false, WrapLibxml ( bool netAccessParameter = false );
const std::string& catalogPathParameter = "catalog" );
virtual ~WrapLibxml(); virtual ~WrapLibxml();
bool validate ( const std::string& fileName ); bool validate ( const std::string& fileName );
bool validateRelaxNG ( bool validateRelaxNG (
@ -71,9 +70,8 @@ class WrapLibxml
std::string lookupPublicId ( const std::string& id ); std::string lookupPublicId ( const std::string& id );
private: private:
bool netAccess; bool netAccess;
std::string catalogPath, output, nonParserError; std::string output, nonParserError;
int errorLine; int errorLine;
void loadCatalog();
}; };
#endif #endif

View File

@ -46,12 +46,12 @@ void WrapXerces::Init() throw()
} dummy; } dummy;
} }
WrapXerces::WrapXerces( std::string catalogPath, std::string catalogUtilityPath ) WrapXerces::WrapXerces()
{ {
WrapXerces::Init(); WrapXerces::Init();
errorPosition = std::make_pair ( 1, 1 ); errorPosition = std::make_pair ( 1, 1 );
catalogResolver = new XercesCatalogResolver( catalogPath, catalogUtilityPath ); catalogResolver = new XercesCatalogResolver();
} }
WrapXerces::~WrapXerces() WrapXerces::~WrapXerces()
@ -165,6 +165,8 @@ bool WrapXerces::validateMemory (
} }
catch ( ... ) catch ( ... )
{ {
if ( thread != NULL && thread->TestDestroy() )
throw;
lastError = wxEmptyString; lastError = wxEmptyString;
return false; return false;
} }

View File

@ -37,9 +37,8 @@ class WrapXerces
{ {
public: public:
static void Init() throw (); static void Init() throw ();
WrapXerces( std::string catalogPath = "", WrapXerces();
std::string catalogUtilityPath = "" ); virtual ~WrapXerces();
~WrapXerces();
bool validate ( const std::string& fileName ); bool validate ( const std::string& fileName );
bool validateMemory ( const char *buffer, size_t len, bool validateMemory ( const char *buffer, size_t len,
const char *system, wxThread *thread = NULL ); const char *system, wxThread *thread = NULL );

View File

@ -13,7 +13,7 @@ InputSource *XercesCatalogResolver::resolveEntity (
{ {
/* the following _should_ work but doesn't always, so drop it for now /* the following _should_ work but doesn't always, so drop it for now
#ifndef __WXMSW__ #ifndef __WXMSW__
resolved = cr->lookupPublicId ( narrowPublicId ); resolved = lookupPublicId ( narrowPublicId );
#else #else
return NULL; return NULL;
std::string stdPublicId = narrowPublicId; std::string stdPublicId = narrowPublicId;
@ -69,12 +69,9 @@ InputSource *XercesCatalogResolver::resolveEntity (
#endif #endif
*/ */
#ifdef __WXMSW__
return NULL;
#else
char *narrowPublicId = XMLString::transcode ( publicID ); char *narrowPublicId = XMLString::transcode ( publicID );
std::string resolved; std::string resolved;
resolved = cr->lookupPublicId ( narrowPublicId ); resolved = lookupPublicId ( narrowPublicId );
XMLString::release ( &narrowPublicId ); XMLString::release ( &narrowPublicId );
@ -87,5 +84,4 @@ InputSource *XercesCatalogResolver::resolveEntity (
XMLString::release ( &wideResolved ); XMLString::release ( &wideResolved );
return source; return source;
#endif
} }

View File

@ -5,42 +5,23 @@
#include <string> #include <string>
#include <xercesc/sax/EntityResolver.hpp> #include <xercesc/sax/EntityResolver.hpp>
#include <xercesc/sax/InputSource.hpp> #include <xercesc/sax/InputSource.hpp>
#include <xercesc/sax/Locator.hpp>
#ifndef __WXMSW__
#include "catalogresolver.h" #include "catalogresolver.h"
#endif
using namespace xercesc; using namespace xercesc;
class XercesCatalogResolver : public EntityResolver class XercesCatalogResolver : public EntityResolver, public CatalogResolver
{ {
public: public:
XercesCatalogResolver( std::string catalogPath = "", XercesCatalogResolver()
std::string catalogUtilityPath = "" )
{ {
#ifndef __WXMSW__
cr = new CatalogResolver ( catalogPath );
#else
myCatalogPath = catalogPath;
myCatalogUtilityPath = catalogUtilityPath;
#endif
} }
~XercesCatalogResolver() ~XercesCatalogResolver()
{ {
#ifndef __WXMSW__
delete cr;
#endif
} }
InputSource *resolveEntity ( virtual InputSource *resolveEntity (
const XMLCh * const publicID, const XMLCh * const publicID,
const XMLCh* const systemId ); const XMLCh* const systemId );
private:
#ifndef __WXMSW__
CatalogResolver *cr;
#else
std::string myCatalogPath;
std::string myCatalogUtilityPath;
#endif
}; };
#endif #endif

View File

@ -61,6 +61,7 @@
#include <wx/tokenzr.h> #include <wx/tokenzr.h>
#include <wx/dir.h> #include <wx/dir.h>
#include "xmlschemagenerator.h" #include "xmlschemagenerator.h"
#include "threadreaper.h"
#define ngettext wxGetTranslation #define ngettext wxGetTranslation
@ -218,6 +219,8 @@ MyApp::MyApp() : checker ( NULL ), server ( NULL ), connection ( NULL ),
MyApp::~MyApp() MyApp::~MyApp()
{ {
ThreadReaper::get().clear();
delete checker; delete checker;
delete server; delete server;
delete connection; delete connection;
@ -395,9 +398,6 @@ bool MyApp::OnInit()
wxImage::AddHandler ( new wxPNGHandler ); wxImage::AddHandler ( new wxPNGHandler );
wxSystemOptions::SetOption ( _T ( "msw.remap" ), 0 ); wxSystemOptions::SetOption ( _T ( "msw.remap" ), 0 );
// Initialize libxml
WrapLibxml::Init();
// Initialize Xerces-C++ // Initialize Xerces-C++
WrapXerces::Init(); WrapXerces::Init();
@ -599,9 +599,9 @@ const std::set<const wxLanguageInfo *> &MyApp::getAvailableTranslations (
wxTranslations *t = wxTranslations::Get(); wxTranslations *t = wxTranslations::Get();
if ( t != NULL ) if ( t != NULL )
{ {
translations = t->GetAvailableTranslations ( *catalog ); wxArrayString all = t->GetAvailableTranslations ( *catalog );
wxArrayString::const_iterator trans = translations.begin(); wxArrayString::const_iterator trans = all.begin();
for ( ; trans != translations.end(); trans++ ) for ( ; trans != all.end(); trans++ )
{ {
info = wxLocale::FindLanguageInfo ( *trans ); info = wxLocale::FindLanguageInfo ( *trans );
if ( info != NULL ) if ( info != NULL )
@ -908,6 +908,9 @@ MyFrame::MyFrame (
updatePaths(); updatePaths();
loadBitmaps(); loadBitmaps();
// Initialize libxml
WrapLibxml::Init ( catalogPath );
size_t findFlags = 0; size_t findFlags = 0;
findFlags |= wxFR_DOWN; findFlags |= wxFR_DOWN;
@ -2960,8 +2963,6 @@ void MyFrame::newDocument ( const std::string& s, const std::string& path, bool
wxID_ANY, wxID_ANY,
s.c_str(), // modified s.c_str(), // modified
s.size(), // new s.size(), // new
catalogPath,
catalogUtilityPath,
path, path,
auxPath ); auxPath );
mainBook->AddPage ( ( wxWindow * ) doc, documentLabel ); mainBook->AddPage ( ( wxWindow * ) doc, documentLabel );
@ -3272,8 +3273,6 @@ bool MyFrame::openFile ( wxString& fileName, bool largeFile )
wxID_ANY, wxID_ANY,
finalBuffer, finalBuffer,
finalBufferLen, finalBufferLen,
catalogPath,
catalogUtilityPath,
( const char * ) fileName.mb_str ( wxConvLocal ), ( const char * ) fileName.mb_str ( wxConvLocal ),
auxPath ); auxPath );
#ifdef __WXMSW__ #ifdef __WXMSW__
@ -3829,8 +3828,6 @@ void MyFrame::OnValidateDTD ( wxCommandEvent& event )
if ( ( doc = getActiveDocument() ) == NULL ) if ( ( doc = getActiveDocument() ) == NULL )
return; return;
updatePaths(); // needed to ensure catalog is available
wxString fname = doc->getFullFileName(); wxString fname = doc->getFullFileName();
WrapTempFileName wtfn ( fname ); WrapTempFileName wtfn ( fname );
@ -3856,7 +3853,7 @@ void MyFrame::OnValidateDTD ( wxCommandEvent& event )
doc->clearErrorIndicators(); doc->clearErrorIndicators();
statusProgress ( _ ( "DTD Validation in progress..." ) ); statusProgress ( _ ( "DTD Validation in progress..." ) );
auto_ptr<WrapLibxml> wl ( new WrapLibxml ( libxmlNetAccess, catalogPath ) ); auto_ptr<WrapLibxml> wl ( new WrapLibxml ( libxmlNetAccess ) );
if ( !wl->validate ( fnameLocal ) ) if ( !wl->validate ( fnameLocal ) )
{ {
@ -3950,7 +3947,7 @@ void MyFrame::validateRelaxNG (
doc->clearErrorIndicators(); doc->clearErrorIndicators();
statusProgress ( _ ( "RELAX NG validation in progress..." ) ); statusProgress ( _ ( "RELAX NG validation in progress..." ) );
auto_ptr<WrapLibxml> wl ( new WrapLibxml ( libxmlNetAccess, catalogPath ) ); auto_ptr<WrapLibxml> wl ( new WrapLibxml ( libxmlNetAccess ) );
std::string schemaFileNameLocal = ( const char * ) schemaName.mb_str ( wxConvLocal ); std::string schemaFileNameLocal = ( const char * ) schemaName.mb_str ( wxConvLocal );
std::string fileNameLocal = ( const char * ) fileName.mb_str ( wxConvLocal ); std::string fileNameLocal = ( const char * ) fileName.mb_str ( wxConvLocal );
@ -4042,9 +4039,7 @@ void MyFrame::OnValidateSchema ( wxCommandEvent& event )
statusProgress ( _ ( "Validation in progress..." ) ); statusProgress ( _ ( "Validation in progress..." ) );
doc->clearErrorIndicators(); doc->clearErrorIndicators();
std::auto_ptr<WrapXerces> validator ( std::auto_ptr<WrapXerces> validator ( new WrapXerces() );
new WrapXerces( catalogPath, catalogUtilityPath )
);
std::string fileNameLocal = ( const char * ) fileName.mb_str ( wxConvLocal ); std::string fileNameLocal = ( const char * ) fileName.mb_str ( wxConvLocal );
if ( !validator->validate ( fileNameLocal ) ) if ( !validator->validate ( fileNameLocal ) )
{ {
@ -4131,7 +4126,7 @@ void MyFrame::OnXPath ( wxCommandEvent& event )
rawBufferStream << rawBufferUtf8; rawBufferStream << rawBufferUtf8;
rawBufferStream.close(); rawBufferStream.close();
auto_ptr<WrapLibxml> wl ( new WrapLibxml ( libxmlNetAccess, catalogPath ) ); auto_ptr<WrapLibxml> wl ( new WrapLibxml ( libxmlNetAccess ) );
bool success = wl->xpath ( valUtf8, tempFileName.name() ); bool success = wl->xpath ( valUtf8, tempFileName.name() );
@ -4276,7 +4271,7 @@ void MyFrame::OnXslt ( wxCommandEvent& event )
std::string stylefnameLocal = ( const char * ) path.mb_str ( wxConvLocal ); std::string stylefnameLocal = ( const char * ) path.mb_str ( wxConvLocal );
auto_ptr<WrapLibxml> wl ( new WrapLibxml ( libxmlNetAccess, catalogPath ) ); auto_ptr<WrapLibxml> wl ( new WrapLibxml ( libxmlNetAccess ) );
if ( !wl->xslt ( stylefnameLocal, tempFileName.name() ) ) if ( !wl->xslt ( stylefnameLocal, tempFileName.name() ) )
{ {
std::string error = wl->getLastError(); std::string error = wl->getLastError();
@ -4331,7 +4326,7 @@ void MyFrame::OnPrettyPrint ( wxCommandEvent& event )
rawBufferStream << rawBufferUtf8; rawBufferStream << rawBufferUtf8;
rawBufferStream.close(); rawBufferStream.close();
auto_ptr<WrapLibxml> wl ( new WrapLibxml ( libxmlNetAccess, catalogPath ) ); auto_ptr<WrapLibxml> wl ( new WrapLibxml ( libxmlNetAccess ) );
bool success = wl->parse ( tempFileName.name(), true ); bool success = wl->parse ( tempFileName.name(), true );
if ( !success ) if ( !success )
@ -5872,8 +5867,6 @@ void MyFrame::updatePaths()
applicationDir + wxFileName::GetPathSeparator() + _T ( "catalog" ) + applicationDir + wxFileName::GetPathSeparator() + _T ( "catalog" ) +
wxFileName::GetPathSeparator() + _T ( "catalog" ); wxFileName::GetPathSeparator() + _T ( "catalog" );
catalogPath = wideCatalogPath.mb_str ( wxConvLocal ); catalogPath = wideCatalogPath.mb_str ( wxConvLocal );
wxString wideCatalogUtilityPath = applicationDir + wxFileName::GetPathSeparator() + _T ( "xmlcatalog" );
catalogUtilityPath = wideCatalogUtilityPath.mb_str ( wxConvLocal );
wxString wideXslDtdPath = wxString wideXslDtdPath =
applicationDir + wxFileName::GetPathSeparator() + _T ( "dtd" ) + applicationDir + wxFileName::GetPathSeparator() + _T ( "dtd" ) +
wxFileName::GetPathSeparator() + _T ( "xslt10.dtd" ); wxFileName::GetPathSeparator() + _T ( "xslt10.dtd" );

View File

@ -376,7 +376,7 @@ class MyFrame : public wxFrame
MyNotebook *mainBook; MyNotebook *mainBook;
MyHtmlPane *htmlReport; MyHtmlPane *htmlReport;
std::string catalogPath, catalogUtilityPath, xslDtdPath, rssDtdPath, lzxDtdPath, xtmDtdPath, std::string catalogPath, xslDtdPath, rssDtdPath, lzxDtdPath, xtmDtdPath,
xliffDtdPath, aspellDataPath, aspellDictPath; xliffDtdPath, aspellDataPath, aspellDictPath;
std::pair<int, int> controlCoordinates; std::pair<int, int> controlCoordinates;
std::map<std::string, std::map<std::string, std::set<std::string> > > std::map<std::string, std::map<std::string, std::set<std::string> > >

View File

@ -55,20 +55,18 @@ XmlCtrl::XmlCtrl (
wxWindowID id, wxWindowID id,
const char *buffer, // could be NULL const char *buffer, // could be NULL
size_t bufferLen, size_t bufferLen,
const std::string& catalogPathParameter,
const std::string& catalogUtilityPathParameter,
const std::string& basePathParameter, const std::string& basePathParameter,
const std::string& auxPathParameter, const std::string& auxPathParameter,
const wxPoint& position, const wxPoint& position,
const wxSize& size, const wxSize& size,
long style ) : wxStyledTextCtrl ( parent, id, position, size, style ), long style
type ( typeParameter ), )
protectTags ( protectTagsParameter ), : wxStyledTextCtrl ( parent, id, position, size, style )
visibilityState ( visibilityStateParameter ), , type ( typeParameter )
catalogPath ( catalogPathParameter ), , protectTags ( protectTagsParameter )
catalogUtilityPath ( catalogUtilityPathParameter ), , visibilityState ( visibilityStateParameter )
basePath ( basePathParameter ), , basePath ( basePathParameter )
auxPath ( auxPathParameter ) , auxPath ( auxPathParameter )
{ {
validationThread = NULL; validationThread = NULL;
@ -139,6 +137,8 @@ XmlCtrl::~XmlCtrl()
if ( validationThread != NULL ) if ( validationThread != NULL )
{ {
validationThread->PendingDelete(); validationThread->PendingDelete();
//validationThread->Delete();
//delete validationThread;
} }
} }
@ -1040,7 +1040,6 @@ void XmlCtrl::updatePromptMaps ( const char *buffer, size_t bufferLen )
elementMap.clear(); elementMap.clear();
elementStructureMap.clear(); elementStructureMap.clear();
std::auto_ptr<XmlPromptGenerator> xpg ( new XmlPromptGenerator ( std::auto_ptr<XmlPromptGenerator> xpg ( new XmlPromptGenerator (
catalogPath,
basePath, basePath,
auxPath ) ); auxPath ) );
xpg->parse ( buffer, bufferLen ); xpg->parse ( buffer, bufferLen );
@ -1979,9 +1978,7 @@ bool XmlCtrl::backgroundValidate (
validationThread = new ValidationThread( validationThread = new ValidationThread(
GetEventHandler(), GetEventHandler(),
buffer, buffer,
system, system
catalogPath.c_str(),
catalogUtilityPath.c_str()
); );
if ( validationThread->Create() != wxTHREAD_NO_ERROR if ( validationThread->Create() != wxTHREAD_NO_ERROR

View File

@ -102,8 +102,6 @@ class XmlCtrl: public wxStyledTextCtrl
wxWindowID id = wxID_ANY, wxWindowID id = wxID_ANY,
const char *buffer = NULL, const char *buffer = NULL,
size_t bufferLen = 0, size_t bufferLen = 0,
const std::string& catalogPath = "",
const std::string& catalogUtilityPath = "",
const std::string& basePath = "", const std::string& basePath = "",
const std::string& auxPath = "", const std::string& auxPath = "",
const wxPoint &position = wxDefaultPosition, const wxPoint &position = wxDefaultPosition,
@ -163,7 +161,7 @@ class XmlCtrl: public wxStyledTextCtrl
std::map<wxString, std::set<wxString> > elementMap; std::map<wxString, std::set<wxString> > elementMap;
std::set<wxString> entitySet; std::set<wxString> entitySet;
std::map<wxString, wxString> elementStructureMap; std::map<wxString, wxString> elementStructureMap;
std::string catalogPath, catalogUtilityPath, basePath, auxPath; std::string basePath, auxPath;
XmlCtrlProperties properties; XmlCtrlProperties properties;
wxString getLastAttributeName ( int pos ); wxString getLastAttributeName ( int pos );
int getAttributeStartPos ( int pos ); int getAttributeStartPos ( int pos );

View File

@ -30,8 +30,6 @@ XmlDoc::XmlDoc (
//const std::string& buffer, //const std::string& buffer,
const char *buffer, const char *buffer,
size_t bufferLen, size_t bufferLen,
const std::string& catalogPath,
const std::string& catalogUtilityPath,
const std::string& basePath, const std::string& basePath,
const std::string& auxPath, const std::string& auxPath,
const wxPoint &position, const wxPoint &position,
@ -46,8 +44,6 @@ XmlDoc::XmlDoc (
id, id,
buffer, buffer,
bufferLen, // new bufferLen, // new
catalogPath,
catalogUtilityPath,
basePath, basePath,
auxPath, auxPath,
position, position,

View File

@ -38,8 +38,6 @@ class XmlDoc : public XmlCtrl
//const std::string& buffer = DEFAULT_XML_DECLARATION_UTF8, //const std::string& buffer = DEFAULT_XML_DECLARATION_UTF8,
const char *buffer = NULL, const char *buffer = NULL,
size_t bufferLen = 0, size_t bufferLen = 0,
const std::string& catalogPath = "",
const std::string& catalogUtilityPath = "",
const std::string& basePath = "", const std::string& basePath = "",
const std::string& auxPath = "", const std::string& auxPath = "",
const wxPoint& position = wxDefaultPosition, const wxPoint& position = wxDefaultPosition,

View File

@ -44,13 +44,11 @@
using namespace xercesc; using namespace xercesc;
XmlPromptGenerator::XmlPromptGenerator ( XmlPromptGenerator::XmlPromptGenerator (
const std::string& catalogPath,
const std::string& basePath, const std::string& basePath,
const std::string& auxPath ) : d ( new PromptGeneratorData() ) const std::string& auxPath ) : d ( new PromptGeneratorData() )
{ {
XML_SetUserData ( p, d.get() ); XML_SetUserData ( p, d.get() );
d->p = p; d->p = p;
d->catalogPath = catalogPath;
d->basePath = basePath; d->basePath = basePath;
d->auxPath = auxPath; d->auxPath = auxPath;
d->isRootElement = true; d->isRootElement = true;
@ -325,21 +323,10 @@ int XMLCALL XmlPromptGenerator::externalentityrefhandler (
if ( publicId ) if ( publicId )
stdPublicId = publicId; stdPublicId = publicId;
CatalogResolver cr ( d->catalogPath ); CatalogResolver cr;
std::string stdSystemId = cr.lookupPublicId ( stdPublicId ); std::string stdSystemId = cr.lookupPublicId ( stdPublicId );
if ( !stdSystemId.empty() ) if ( stdSystemId.empty() )
{
Replace::run ( stdSystemId, "file://", "", false );
Replace::run ( stdSystemId, "%20", " ", false );
#ifdef __WXMSW__
Replace::run ( stdSystemId, "//C:/", "C:\\", false );
Replace::run ( stdSystemId, "/C:/", "C:\\", false );
Replace::run ( stdSystemId, "/", "\\", false );
#endif
}
else
{ {
if ( systemId ) if ( systemId )
stdSystemId = systemId; stdSystemId = systemId;

View File

@ -38,7 +38,7 @@ struct PromptGeneratorData : public ParserData
std::map<wxString, std::set<wxString> > requiredAttributeMap; std::map<wxString, std::set<wxString> > requiredAttributeMap;
std::map<wxString, wxString> elementStructureMap; std::map<wxString, wxString> elementStructureMap;
std::set<wxString> entitySet; std::set<wxString> entitySet;
std::string catalogPath, basePath, auxPath, rootElement; std::string basePath, auxPath, rootElement;
bool isRootElement, grammarFound; bool isRootElement, grammarFound;
unsigned attributeValueCutoff; unsigned attributeValueCutoff;
XML_Parser p; XML_Parser p;
@ -51,7 +51,6 @@ class XmlPromptGenerator : public WrapExpat
{ {
public: public:
XmlPromptGenerator ( XmlPromptGenerator (
const std::string& catalogPath = "",
const std::string& basePath = "", const std::string& basePath = "",
const std::string& auxPath = "" ); const std::string& auxPath = "" );
virtual ~XmlPromptGenerator(); virtual ~XmlPromptGenerator();

View File

@ -25,6 +25,7 @@
#include <xercesc/parsers/XercesDOMParser.hpp> #include <xercesc/parsers/XercesDOMParser.hpp>
#include <xercesc/dom/DOMNamedNodeMap.hpp> #include <xercesc/dom/DOMNamedNodeMap.hpp>
#include <xercesc/dom/DOMAttr.hpp> #include <xercesc/dom/DOMAttr.hpp>
#include "xercescatalogresolver.h"
const static size_t maxReservedSchemaBuffer = 1024 * 1024; const static size_t maxReservedSchemaBuffer = 1024 * 1024;
const static size_t maxElementSchemaBuffer = 1024; const static size_t maxElementSchemaBuffer = 1024;
@ -47,10 +48,12 @@ const wxString &XmlSchemaGenerator::generate ( Grammar::GrammarType grammarType,
mElements.clear(); mElements.clear();
mSchema.Clear(); mSchema.Clear();
XercesCatalogResolver catalogResolver;
std::auto_ptr<XercesDOMParser> parser ( new XercesDOMParser() ); std::auto_ptr<XercesDOMParser> parser ( new XercesDOMParser() );
parser->setDoNamespaces ( true ); parser->setDoNamespaces ( true );
parser->setDoSchema ( true ); parser->setDoSchema ( true );
parser->setValidationSchemaFullChecking ( false ); parser->setValidationSchemaFullChecking ( false );
parser->setEntityResolver ( &catalogResolver );
MemBufInputSource source ( ( const XMLByte * ) buffer, len, MemBufInputSource source ( ( const XMLByte * ) buffer, len,
filepath.mb_str( wxConvLocal ) ); filepath.mb_str( wxConvLocal ) );