Improved catalog resolving
This commit is contained in:
parent
51cd9699c3
commit
c0db1726e9
|
@ -6,8 +6,8 @@
|
|||
<public publicId="-//W3C//ENTITIES Latin 1 for XHTML//EN" uri="../dtd/xhtml-lat1.ent"/>
|
||||
<public publicId="-//W3C//ENTITIES Symbols for XHTML//EN" uri="../dtd/xhtml-symbol.ent"/>
|
||||
<public publicId="-//W3C//ENTITIES Special for XHTML//EN" uri="../dtd/xhtml-special.ent"/>
|
||||
<public publicId="-//OASIS//DTD DocBook XML 5.0b3//EN" uri="../dtd/docbook/5.0b/docbook.dtd"/>
|
||||
<public publicId="-//OASIS//DTD DocBook XML 4.4//EN" uri="../dtd/docbook/4.4/docbookx.dtd"/>
|
||||
<public publicId="-//OASIS//DTD DocBook XML V5.0b3//EN" uri="../dtd/docbook/5.0b/docbook.dtd"/>
|
||||
<public publicId="-//OASIS//DTD DocBook XML V4.4//EN" uri="../dtd/docbook/4.4/docbookx.dtd"/>
|
||||
<public publicId="-//TEI P4//DTD Main Document Type//EN" uri="../dtd/tei/p4/tei2.dtd"/>
|
||||
<public publicId="-//TEI P5//DTD Main Document Type//EN" uri="../dtd/tei/p5/tei_all.dtd"/>
|
||||
<public publicId="-//OASIS//DTD DITA Map//EN" uri="../dtd/dita/map.dtd"/>
|
||||
|
@ -21,4 +21,5 @@
|
|||
<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"/>
|
||||
<rewriteSystem systemIdStartString="http://www.w3.org/TR/xhtml1/DTD/" rewritePrefix="../dtd/"/>
|
||||
</catalog>
|
||||
|
|
|
@ -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<WrapLibxml> libxml ( new WrapLibxml ( false, catalogPath ) );
|
||||
return WrapLibxml::lookupPublicId ( publicId );
|
||||
return WrapLibxml::catalogResolve ( publicId, systemId );
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook XML 4.4//EN" "http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd">
|
||||
<!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN" "http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd">
|
||||
<article>
|
||||
<title>Title</title>
|
||||
<para>First paragraph</para>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML 4.4//EN" "http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd">
|
||||
<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN" "http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd">
|
||||
<book>
|
||||
<title>Book title</title>
|
||||
<chapter>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook XML 5.0b3//EN" "http://www.oasis-open.org/docbook/xml/5.0b3/dtd/docbook.dtd">
|
||||
<!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook XML V5.0b3//EN" "http://www.oasis-open.org/docbook/xml/5.0b3/dtd/docbook.dtd">
|
||||
<article xmlns="http://docbook.org/ns/docbook" version="5.0" xml:lang="en">
|
||||
<title>Title</title>
|
||||
<para>First paragraph</para>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML 5.0b3//EN" "http://www.oasis-open.org/docbook/xml/5.0b3/dtd/docbook.dtd">
|
||||
<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V5.0b3//EN" "http://www.oasis-open.org/docbook/xml/5.0b3/dtd/docbook.dtd">
|
||||
<book>
|
||||
<title>Book title</title>
|
||||
<titleabbrev>Abbreviated book title</titleabbrev>
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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 );
|
||||
|
|
Loading…
Reference in New Issue