From 6a9f2161d5fa062bbb7173d63a8808eee1f9da66 Mon Sep 17 00:00:00 2001
From: Lubomir Rintel <lkundrak@v3.sk>
Date: Sun, 21 Feb 2010 00:54:52 +0100
Subject: [PATCH 2/2] Port to use xerces 3
Upgrade from 2.8 to 3.0.1.
---
src/XmlCommon.cpp | 4 +
src/XmlProcessor.cpp | 89 +++++++++++++++++------
src/XmlProcessor.h | 34 ++++++++-
src/probes/independent/XmlFileContentProbe.cpp | 13 ++++
src/probes/independent/XmlFileContentProbe.h | 6 ++
5 files changed, 119 insertions(+), 27 deletions(-)
diff --git a/src/XmlCommon.cpp b/src/XmlCommon.cpp
index d09d4d5..a74a155 100644
--- a/src/XmlCommon.cpp
+++ b/src/XmlCommon.cpp
@@ -546,7 +546,11 @@ void XmlCommon::AddSchemaLocation(XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument *do
string XmlCommon::GetNamespace(DOMElement *element) {
string xmlns = "";
+#if XERCES_VERSION_MAJOR < 3
xmlns = XmlCommon::ToString(element->getTypeInfo()->getNamespace());
+#else
+ xmlns = XmlCommon::ToString(element->getSchemaTypeInfo()->getTypeNamespace());
+#endif
if (xmlns.compare("") == 0) {
xmlns = "";
}
diff --git a/src/XmlProcessor.cpp b/src/XmlProcessor.cpp
index 2bec33e..90d8066 100644
--- a/src/XmlProcessor.cpp
+++ b/src/XmlProcessor.cpp
@@ -33,7 +33,17 @@
// DataDirResolver Class //
//****************************************************************************************//
+#if XERCES_VERSION_MAJOR < 3
DOMInputSource* DataDirResolver::resolveEntity (const XMLCh *const publicId, const XMLCh *const systemId, const XMLCh *const baseURI) {
+#else
+InputSource* DataDirResolver::resolveEntity(const XMLCh* publicId, const XMLCh* systemId)
+{
+ return NULL;
+ //return DataDirResolver::resolveEntity (publicId, systemId, NULL);
+}
+
+DOMLSInput* DataDirResolver::resolveEntity (const XMLCh *const publicId, const XMLCh *const systemId, const XMLCh *const baseURI) {
+#endif
string path = "";
size_t last;
@@ -107,21 +117,36 @@ XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument* XmlProcessor::ParseFile(string fileP
// Instantiate the DOM parser.
static const XMLCh gLS[] = { chLatin_L, chLatin_S, chNull };
DOMImplementation *impl = DOMImplementationRegistry::getDOMImplementation(gLS);
+#if XERCES_VERSION_MAJOR < 3
parser = ((DOMImplementationLS*)impl)->createDOMBuilder(DOMImplementationLS::MODE_SYNCHRONOUS, 0);
+#else
+ parser = ((DOMImplementationLS*)impl)->createLSParser(DOMImplementationLS::MODE_SYNCHRONOUS, 0);
+#endif
///////////////////////////////////////////////////////
// Set fetuares on the builder
///////////////////////////////////////////////////////
-
- parser->setFeature(XMLUni::fgDOMComments, false); // Discard Comment nodes in the document.
- parser->setFeature(XMLUni::fgDOMDatatypeNormalization, true); // Let the validation process do its datatype normalization that is defined in the used schema language.
- parser->setFeature(XMLUni::fgDOMNamespaces, true); // Perform Namespace processing
- parser->setFeature(XMLUni::fgDOMValidation, true); // Report all validation errors.
- parser->setFeature(XMLUni::fgXercesSchema, true); // Enable the parser's schema support.
- parser->setFeature(XMLUni::fgXercesSchemaFullChecking, true); // Enable full schema constraint checking, including checking which may be time-consuming or memory intensive. Currently, particle unique attribution constraint checking and particle derivation restriction checking are controlled by this option.
- parser->setFeature(XMLUni::fgXercesValidationErrorAsFatal, true); // The parser will treat validation error as fatal and will exit
- parser->setFeature(XMLUni::fgXercesDOMHasPSVIInfo, true); // Enable storing of PSVI information in element and attribute nodes.
+#if XERCES_VERSION_MAJOR < 3
+#define SetParameter(parser,n,v) parser->setFeature(n,v)
+#else
+#define SetParameter(parser,n,v) parser->getDomConfig()->setParameter(n,v)
+#endif
+
+ SetParameter(parser, XMLUni::fgDOMComments, false); // Discard Comment nodes in the document.
+ SetParameter(parser, XMLUni::fgDOMDatatypeNormalization, true); // Let the validation process do its datatype normalization that is defined in the used schema language.
+ SetParameter(parser, XMLUni::fgDOMNamespaces, true); // Perform Namespace processing
+#if XERCES_VERSION_MAJOR < 3
+ SetParameter(parser, XMLUni::fgDOMValidation, true); // Report all validation errors.
+#else
+ SetParameter(parser, XMLUni::fgDOMValidate, true); // Report all validation errors.
+#endif
+ SetParameter(parser, XMLUni::fgXercesSchema, true); // Enable the parser's schema support.
+ SetParameter(parser, XMLUni::fgXercesSchemaFullChecking, true); // Enable full schema constraint checking, including checking which may be time-consuming or memory intensive. Currently, particle unique attribution constraint checking and particle derivation restriction checking are controlled by this option.
+ SetParameter(parser, XMLUni::fgXercesValidationErrorAsFatal, true); // The parser will treat validation error as fatal and will exit
+ SetParameter(parser, XMLUni::fgXercesDOMHasPSVIInfo, true); // Enable storing of PSVI information in element and attribute nodes.
+
+#undef SetParameter
///////////////////////////////////////////////////////
//****************************************************************************************//
@@ -129,7 +154,11 @@ XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument* XmlProcessor::ParseFile(string fileP
//****************************************************************************************//
/* Look for XML schemas in local directory instead of Internet */
DataDirResolver resolver;
+#if XERCES_VERSION_MAJOR < 3
parser->setEntityResolver (&resolver);
+#else
+ parser->getDomConfig()->setParameter(XMLUni::fgXercesEntityResolver, &resolver);
+#endif
//****************************************************************************************//
// End of air-gap code //
//****************************************************************************************//
@@ -140,7 +169,11 @@ XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument* XmlProcessor::ParseFile(string fileP
// Create a new DOMErrorHandler
// and set it to the builder
XmlProcessorErrorHandler *errHandler = new XmlProcessorErrorHandler();
+#if XERCES_VERSION_MAJOR < 3
parser->setErrorHandler(errHandler);
+#else
+ parser->getDomConfig()->setParameter(XMLUni::fgDOMErrorHandler, errHandler);
+#endif
try {
// reset document pool
@@ -206,23 +239,27 @@ void XmlProcessor::WriteDOMDocument(XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument*
XMLCh tempStr[100];
XMLString::transcode("LS", tempStr, 99);
DOMImplementation *impl = DOMImplementationRegistry::getDOMImplementation(tempStr);
+#if XERCES_VERSION_MAJOR < 3
DOMWriter *theSerializer = ((DOMImplementationLS*)impl)->createDOMWriter();
-
+#else
+ DOMLSSerializer *theSerializer = ((DOMImplementationLS*)impl)->createLSSerializer();
+#endif
+
+#if XERCES_VERSION_MAJOR < 3
+#define SetParameter(serializer,n,v) if (serializer->canSetFeature(n,v)) \
+ serializer->setFeature(n,v)
+#else
+#define SetParameter(serializer,n,v) if (serializer->getDomConfig()->canSetParameter(n,v)) \
+ serializer->getDomConfig()->setParameter(n,v)
+#endif
// set feature if the serializer supports the feature/mode
- if (theSerializer->canSetFeature(XMLUni::fgDOMWRTSplitCdataSections, true))
- theSerializer->setFeature(XMLUni::fgDOMWRTSplitCdataSections, true);
-
- if (theSerializer->canSetFeature(XMLUni::fgDOMWRTDiscardDefaultContent, true))
- theSerializer->setFeature(XMLUni::fgDOMWRTDiscardDefaultContent, true);
-
- if (theSerializer->canSetFeature(XMLUni::fgDOMWRTFormatPrettyPrint, true))
- theSerializer->setFeature(XMLUni::fgDOMWRTFormatPrettyPrint, true);
-
- if (theSerializer->canSetFeature(XMLUni::fgDOMWRTBOM, false))
- theSerializer->setFeature(XMLUni::fgDOMWRTBOM, false);
+ SetParameter(theSerializer, XMLUni::fgDOMWRTSplitCdataSections, true);
+ SetParameter(theSerializer, XMLUni::fgDOMWRTDiscardDefaultContent, true);
+ SetParameter(theSerializer, XMLUni::fgDOMWRTFormatPrettyPrint, true);
+ SetParameter(theSerializer, XMLUni::fgDOMWRTBOM, false);
+ //SetParameter(theSerializer, XMLUni::fgDOMWRTBOM, true);
- //if (theSerializer->canSetFeature(XMLUni::fgDOMWRTDiscardDefaultContent, true))
- // theSerializer->setFeature(XMLUni::fgDOMWRTBOM, true);
+#undef SetParameter
//
// Plug in a format target to receive the resultant
@@ -240,7 +277,13 @@ void XmlProcessor::WriteDOMDocument(XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument*
//
// do the serialization through DOMWriter::writeNode();
//
+#if XERCES_VERSION_MAJOR < 3
theSerializer->writeNode(myFormTarget, *doc);
+#else
+ DOMLSOutput *output = ((DOMImplementationLS*)impl)->createLSOutput();
+ output->setByteStream(myFormTarget);
+ theSerializer->write(doc, output);
+#endif
delete theSerializer;
delete myFormTarget;
diff --git a/src/XmlProcessor.h b/src/XmlProcessor.h
index faa7e2e..84ec4e3 100644
--- a/src/XmlProcessor.h
+++ b/src/XmlProcessor.h
@@ -39,8 +39,11 @@
#include "Common.h"
// required xerces includes
-#include <xercesc/dom/DOMImplementationRegistry.hpp>
+#if XERCES_VERSION_MAJOR < 3
#include <xercesc/dom/DOMBuilder.hpp>
+#else
+#endif
+#include <xercesc/dom/DOMImplementationRegistry.hpp>
#include <xercesc/dom/DOMException.hpp>
#include <xercesc/dom/DOMErrorHandler.hpp>
#include <xercesc/dom/DOMError.hpp>
@@ -48,17 +51,26 @@
#include <xercesc/dom/DOMNamedNodeMap.hpp>
// for dom Writer
+#if XERCES_VERSION_MAJOR < 3
+#include <xercesc/dom/DOMWriter.hpp>
+#else
+#endif
#include <xercesc/dom/DOMImplementation.hpp>
#include <xercesc/dom/DOMImplementationLS.hpp>
-#include <xercesc/dom/DOMWriter.hpp>
#include <xercesc/framework/StdOutFormatTarget.hpp>
#include <xercesc/framework/LocalFileFormatTarget.hpp>
#include <xercesc/parsers/XercesDOMParser.hpp>
#include <xercesc/util/XMLUni.hpp>
// for entity resolver
+#if XERCES_VERSION_MAJOR < 3
#include <xercesc/dom/DOMEntityResolver.hpp>
#include <xercesc/dom/DOMInputSource.hpp>
+#else
+#include <xercesc/sax/EntityResolver.hpp>
+#include <xercesc/sax/InputSource.hpp>
+#include <xercesc/sax2/SAX2XMLReader.hpp>
+#endif
#include <xercesc/framework/LocalFileInputSource.hpp>
#include <xercesc/framework/Wrapper4InputSource.hpp>
@@ -68,15 +80,24 @@ using namespace std;
/**
- This class extends the default DOMEntityResolver and implments the resolve entity method
+ This class extends the default EntityResolver and implments the resolve entity method
to support
*/
+#if XERCES_VERSION_MAJOR < 3
class DataDirResolver : public DOMEntityResolver {
+#else
+class DataDirResolver : public EntityResolver {
+#endif
public:
/**
*
*/
+#if XERCES_VERSION_MAJOR < 3
DOMInputSource *resolveEntity (const XMLCh *const publicId, const XMLCh *const systemId, const XMLCh *const baseURI);
+#else
+ InputSource *resolveEntity (const XMLCh *const publicId, const XMLCh *const systemId);
+ DOMLSInput *resolveEntity (const XMLCh *const publicId, const XMLCh *const systemId, const XMLCh *const baseURI);
+#endif
};
/**
@@ -115,8 +136,13 @@ private:
XmlProcessor();
static XmlProcessor* instance;
-
+
+#if XERCES_VERSION_MAJOR < 3
DOMBuilder *parser;
+#else
+ //SAX2XMLReader *parser;
+ DOMLSParser *parser;
+#endif
};
/**
diff --git a/src/probes/independent/XmlFileContentProbe.cpp b/src/probes/independent/XmlFileContentProbe.cpp
index b595fcb..74c763f 100644
--- a/src/probes/independent/XmlFileContentProbe.cpp
+++ b/src/probes/independent/XmlFileContentProbe.cpp
@@ -417,12 +417,25 @@ BinInputStream* DummyEntityResolver::NoOpInputSource::makeStream() const
return new DummyEntityResolver::DoNothingBinInputStream();
}
+#if XERCES_VERSION_MAJOR < 3
unsigned int DummyEntityResolver::DoNothingBinInputStream::curPos() const
+#else
+const XMLCh* DummyEntityResolver::DoNothingBinInputStream::getContentType() const
+{
+ return NULL;
+}
+
+XMLFilePos DummyEntityResolver::DoNothingBinInputStream::curPos() const
+#endif
{
return 0;
}
+#if XERCES_VERSION_MAJOR < 3
unsigned int DummyEntityResolver::DoNothingBinInputStream::readBytes(XMLByte *const toFill, const unsigned int maxToRead)
+#else
+XMLSize_t DummyEntityResolver::DoNothingBinInputStream::readBytes(XMLByte *const toFill, XMLSize_t maxToRead)
+#endif
{
return 0;
}
diff --git a/src/probes/independent/XmlFileContentProbe.h b/src/probes/independent/XmlFileContentProbe.h
index d498718..733a1a4 100644
--- a/src/probes/independent/XmlFileContentProbe.h
+++ b/src/probes/independent/XmlFileContentProbe.h
@@ -135,8 +135,14 @@ private:
class DoNothingBinInputStream : public BinInputStream
{
public:
+#if XERCES_VERSION_MAJOR < 3
virtual unsigned int curPos() const;
virtual unsigned int readBytes(XMLByte *const toFill, const unsigned int maxToRead);
+#else
+ virtual XMLFilePos curPos() const;
+ virtual const XMLCh* getContentType() const;
+ virtual XMLSize_t readBytes(XMLByte *const toFill, XMLSize_t maxToRead);
+#endif
};
};
--
1.7.0