xml-copy-editor-code/src/xercescatalogresolver.cpp

53 lines
1.7 KiB
C++
Raw Normal View History

2014-05-05 13:44:31 +02:00
/*
* Copyright 2005-2009 Gerald Schmidt.
*
* This file is part of Xml Copy Editor.
*
* Xml Copy Editor is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* Xml Copy Editor is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Xml Copy Editor; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
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
2013-10-26 15:15:42 +02:00
#include "wrapxerces.h"
2009-11-06 18:06:12 +01:00
InputSource *XercesCatalogResolver::resolveEntity (
2013-10-26 15:15:42 +02:00
const XMLCh* const publicId,
2009-11-06 18:06:12 +01:00
const XMLCh* const systemId )
{
2013-10-26 15:15:42 +02:00
wxString pubId, sysId, resolved;
pubId = WrapXerces::toString ( publicId );
sysId = WrapXerces::toString ( systemId );
resolved = catalogResolve ( pubId, sysId );
if ( !resolved.empty() )
return new LocalFileInputSource (
2013-10-26 15:15:42 +02:00
( const XMLCh * ) WrapXerces::toString ( resolved ).GetData() );
2009-11-06 18:06:12 +01:00
// Xerces-C++ can't open a file URL when there are multi-byte characters.
// Parse the file URL here instead.
2014-05-04 02:40:05 +02:00
wxFileName file = WrapLibxml::URLToFileName ( sysId );
if ( file.IsFileReadable() )
return new LocalFileInputSource (
( const XMLCh * ) WrapXerces::toString ( file.GetFullPath() ).GetData() );
return NULL;
2009-11-06 18:06:12 +01:00
}