From c0db1726e9a8e026daa3c4896537db7b1a544ffb Mon Sep 17 00:00:00 2001 From: "Zane U. Ji" Date: Sat, 26 Oct 2013 21:15:42 +0800 Subject: [PATCH] Improved catalog resolving --- src/catalog/catalog | 5 +++-- src/catalogresolver.cpp | 6 ++++-- src/catalogresolver.h | 6 ++++-- src/templates/DocBook_4.4_article.xml | 2 +- src/templates/DocBook_4.4_book.xml | 2 +- src/templates/DocBook_5.0b_article.xml | 2 +- src/templates/DocBook_5.0b_book.xml | 2 +- src/wraplibxml.cpp | 24 +++++++++++---------- src/wraplibxml.h | 4 +++- src/xercescatalogresolver.cpp | 28 ++++++++----------------- src/xmlpromptgenerator.cpp | 29 ++++++++++++-------------- 11 files changed, 53 insertions(+), 57 deletions(-) diff --git a/src/catalog/catalog b/src/catalog/catalog index 2974552..df8e330 100644 --- a/src/catalog/catalog +++ b/src/catalog/catalog @@ -6,8 +6,8 @@ - - + + @@ -21,4 +21,5 @@ + diff --git a/src/catalogresolver.cpp b/src/catalogresolver.cpp index a88c2dd..849235c 100644 --- a/src/catalogresolver.cpp +++ b/src/catalogresolver.cpp @@ -28,8 +28,10 @@ CatalogResolver::~CatalogResolver() { } -std::string CatalogResolver::lookupPublicId ( const std::string &publicId ) +wxString CatalogResolver::catalogResolve ( + const wxString &publicId, + const wxString &systemId ) { //std::auto_ptr libxml ( new WrapLibxml ( false, catalogPath ) ); - return WrapLibxml::lookupPublicId ( publicId ); + return WrapLibxml::catalogResolve ( publicId, systemId ); } diff --git a/src/catalogresolver.h b/src/catalogresolver.h index 3a0c3b2..ec3d053 100644 --- a/src/catalogresolver.h +++ b/src/catalogresolver.h @@ -28,8 +28,10 @@ class CatalogResolver : protected WrapLibxml public: CatalogResolver(); ~CatalogResolver(); - std::string lookupPublicId ( - const std::string& publicId); + wxString catalogResolve + ( const wxString &pubIdUtf8 + , const wxString &sysIdUtf8 + ); }; #endif diff --git a/src/templates/DocBook_4.4_article.xml b/src/templates/DocBook_4.4_article.xml index c36e0c5..3d25ef6 100644 --- a/src/templates/DocBook_4.4_article.xml +++ b/src/templates/DocBook_4.4_article.xml @@ -1,5 +1,5 @@ - +
Title First paragraph diff --git a/src/templates/DocBook_4.4_book.xml b/src/templates/DocBook_4.4_book.xml index 8722416..82f4f9a 100644 --- a/src/templates/DocBook_4.4_book.xml +++ b/src/templates/DocBook_4.4_book.xml @@ -1,5 +1,5 @@ - + Book title diff --git a/src/templates/DocBook_5.0b_article.xml b/src/templates/DocBook_5.0b_article.xml index 057bbbd..cc6905a 100644 --- a/src/templates/DocBook_5.0b_article.xml +++ b/src/templates/DocBook_5.0b_article.xml @@ -1,5 +1,5 @@ - +
Title First paragraph diff --git a/src/templates/DocBook_5.0b_book.xml b/src/templates/DocBook_5.0b_book.xml index 8826564..0ef61c7 100644 --- a/src/templates/DocBook_5.0b_book.xml +++ b/src/templates/DocBook_5.0b_book.xml @@ -1,5 +1,5 @@ - + Book title Abbreviated book title diff --git a/src/wraplibxml.cpp b/src/wraplibxml.cpp index 67a91cd..17e64d0 100644 --- a/src/wraplibxml.cpp +++ b/src/wraplibxml.cpp @@ -561,21 +561,23 @@ std::string WrapLibxml::getOutput() return output; } -std::string WrapLibxml::lookupPublicId ( const std::string& id ) +wxString WrapLibxml::catalogResolve + ( const wxString &publicId + , const wxString &systemId + ) { - std::string ret; - char *s = ( char * ) xmlCatalogResolvePublic ( ( const xmlChar * ) id.c_str() ); + char *s = ( char * ) xmlCatalogResolve ( + ( const xmlChar * ) ( const char *) publicId.mb_str ( wxConvUTF8 ), + ( const xmlChar * ) ( const char *) systemId.mb_str ( wxConvUTF8 ) ); if ( s == NULL ) - return ret; + return wxEmptyString; wxString url ( s, wxConvUTF8 ); - wxFileName file = wxFileSystem::URLToFileName ( url ); - if ( file.IsFileReadable() ) - ret = file.GetFullPath().mb_str ( wxConvLocal ); - else - ret = s; - xmlFree ( s ); - return ret; + wxFileName file = wxFileSystem::URLToFileName ( url ); + if ( file.IsFileReadable() ) + return file.GetFullPath(); + + return url; } diff --git a/src/wraplibxml.h b/src/wraplibxml.h index 1d1a73c..030fdef 100644 --- a/src/wraplibxml.h +++ b/src/wraplibxml.h @@ -68,7 +68,9 @@ class WrapLibxml const std::string& fileNameSource, const std::string& fileNameDestination, const std::string& encoding ); - std::string lookupPublicId ( const std::string& id ); + wxString catalogResolve ( + const wxString &publicId, + const wxString &systemId ); private: bool netAccess; std::string output, nonParserError; diff --git a/src/xercescatalogresolver.cpp b/src/xercescatalogresolver.cpp index 28057a3..c8783f6 100644 --- a/src/xercescatalogresolver.cpp +++ b/src/xercescatalogresolver.cpp @@ -7,8 +7,10 @@ #include "replace.h" #endif +#include "wrapxerces.h" + InputSource *XercesCatalogResolver::resolveEntity ( - const XMLCh* const publicID, + const XMLCh* const publicId, const XMLCh* const systemId ) { /* the following _should_ work but doesn't always, so drop it for now @@ -69,27 +71,15 @@ InputSource *XercesCatalogResolver::resolveEntity ( #endif */ - if ( publicID == NULL || *publicID == '\0' ) - return NULL; - - // Since public IDs consist of ANSII characters, it doesn't matter how - // publicID is encoded as long as it's a multibyte string - char *narrowPublicId = XMLString::transcode ( publicID ); - if ( narrowPublicId == NULL ) - return NULL; - - std::string resolved; - resolved = lookupPublicId ( narrowPublicId ); - - XMLString::release ( &narrowPublicId ); - + wxString pubId, sysId, resolved; + pubId = WrapXerces::toString ( publicId ); + sysId = WrapXerces::toString ( systemId ); + resolved = catalogResolve ( pubId, sysId ); if ( resolved.empty() ) return NULL; - XMLCh *wideResolved = XMLString::transcode ( resolved.c_str() ); - - InputSource *source = (InputSource *)new LocalFileInputSource ( wideResolved ); - XMLString::release ( &wideResolved ); + InputSource *source = new LocalFileInputSource ( + ( const XMLCh * ) WrapXerces::toString ( resolved ).GetData() ); return source; } diff --git a/src/xmlpromptgenerator.cpp b/src/xmlpromptgenerator.cpp index 3fe8981..1fab3d1 100644 --- a/src/xmlpromptgenerator.cpp +++ b/src/xmlpromptgenerator.cpp @@ -319,30 +319,31 @@ int XMLCALL XmlPromptGenerator::externalentityrefhandler ( return ret; } - std::string stdPublicId; - if ( publicId ) - stdPublicId = publicId; - + wxString widePublicId ( publicId, wxConvUTF8 ); + wxString wideSystemId ( systemId, wxConvUTF8 ); CatalogResolver cr; - std::string stdSystemId = cr.lookupPublicId ( stdPublicId ); + wideSystemId = cr.catalogResolve ( widePublicId, wideSystemId ); - if ( stdSystemId.empty() ) + if ( wideSystemId.empty() ) { if ( systemId ) - stdSystemId = systemId; + wideSystemId = wxString ( systemId, wxConvUTF8 ); if ( base ) { - std::string test = PathResolver::run ( stdSystemId, base ); + wxString test = PathResolver::run ( wideSystemId, + wxString ( base, wxConvUTF8 ) ); if ( !test.empty() ) { - stdSystemId = test; + wideSystemId = test; } } } - if ( !stdSystemId.empty() ) + std::string localName; + localName = wideSystemId.mb_str ( wxConvLocal ); + if ( !localName.empty() ) { - ReadFile::run ( stdSystemId, buffer ); + ReadFile::run ( localName, buffer ); } std::string encoding = XmlEncodingHandler::get ( buffer ); @@ -350,11 +351,7 @@ int XMLCALL XmlPromptGenerator::externalentityrefhandler ( if ( !dtdParser ) return XML_STATUS_ERROR; - wxString wideName, wideDir; - wideName = wxString ( stdSystemId.c_str(), wxConvUTF8, stdSystemId.size() ); - wxFileName fn ( wideName ); - wideDir = fn.GetPath(); - XML_SetBase ( dtdParser, wideName.mb_str ( wxConvUTF8 ) ); + XML_SetBase ( dtdParser, wideSystemId.utf8_str() ); ret = XML_Parse ( dtdParser, buffer.c_str(), buffer.size(), true ); XML_ParserFree ( dtdParser );