From 5678fc1abe4cd5bea090d24b8c49d1a170d7de61 Mon Sep 17 00:00:00 2001 From: berniev Date: Fri, 2 Sep 2022 10:03:27 +1000 Subject: [PATCH] remove xcerces2 --- src/Base/InputSource.cpp | 36 -------- src/Base/InputSource.h | 5 -- src/Base/Parameter.cpp | 183 --------------------------------------- src/Base/PreCompiled.h | 3 - src/Base/Reader.cpp | 8 -- src/Base/Reader.h | 5 -- src/Base/XMLTools.cpp | 14 --- 7 files changed, 254 deletions(-) diff --git a/src/Base/InputSource.cpp b/src/Base/InputSource.cpp index 6fad8cb739..00d32a3f42 100644 --- a/src/Base/InputSource.cpp +++ b/src/Base/InputSource.cpp @@ -50,41 +50,6 @@ StdInputStream::~StdInputStream() = default; // --------------------------------------------------------------------------- // StdInputStream: Implementation of the input stream interface // --------------------------------------------------------------------------- -#if (XERCES_VERSION_MAJOR == 2) -unsigned int StdInputStream::curPos() const -{ - return stream.tellg(); -} - -unsigned int StdInputStream::readBytes( XMLByte* const toFill, const unsigned int maxToRead ) -{ - // - // Read up to the maximum bytes requested. We return the number - // actually read. - // - - stream.read((char *)toFill,maxToRead); - XMLSize_t len = stream.gcount(); - - QTextCodec *codec = QTextCodec::codecForName("UTF-8"); - const QString text = codec->toUnicode((char *)toFill, len, &state); - if (state.invalidChars > 0) { - // In case invalid characters were found decode back to 'utf-8' and replace - // them with '?' - // First, Qt replaces invalid characters with '\0' (see ConvertInvalidToNull) - // but Xerces doesn't like this because it handles this as termination. Thus, - // we have to go through the array and replace '\0' with '?'. - XMLSize_t pos = 0; - QByteArray ba = codec->fromUnicode(text); - for (int i=0; i(stream.tellg()); @@ -118,7 +83,6 @@ XMLSize_t StdInputStream::readBytes(XMLByte* const toFill, const XMLSize_t maxT return static_cast(len); } -#endif // --------------------------------------------------------------------------- diff --git a/src/Base/InputSource.h b/src/Base/InputSource.h index e281c2ff6b..88e07caebb 100644 --- a/src/Base/InputSource.h +++ b/src/Base/InputSource.h @@ -50,14 +50,9 @@ public : // ----------------------------------------------------------------------- // Implementation of the input stream interface // ----------------------------------------------------------------------- -#if (XERCES_VERSION_MAJOR == 2) - virtual unsigned int curPos() const; - virtual unsigned int readBytes( XMLByte* const toFill, const unsigned int maxToRead ); -#else XMLFilePos curPos() const override; XMLSize_t readBytes( XMLByte* const toFill, const XMLSize_t maxToRead ) override; const XMLCh* getContentType() const override {return nullptr;} -#endif private : // ----------------------------------------------------------------------- diff --git a/src/Base/Parameter.cpp b/src/Base/Parameter.cpp index 00a8defdeb..e96793a276 100644 --- a/src/Base/Parameter.cpp +++ b/src/Base/Parameter.cpp @@ -28,9 +28,6 @@ # include # include # include -# if (XERCES_VERSION_MAJOR == 2) -# include -# endif # include # include # include @@ -112,40 +109,6 @@ public: }; -#if (XERCES_VERSION_MAJOR == 2) -class DOMPrintFilter : public DOMWriterFilter -{ -public: - - /** @name Constructors */ - DOMPrintFilter(unsigned long whatToShow = DOMNodeFilter::SHOW_ALL); - //@{ - - /** @name Destructors */ - ~DOMPrintFilter() {}; - //@{ - - /** @ interface from DOMWriterFilter */ - virtual short acceptNode(const XERCES_CPP_NAMESPACE_QUALIFIER DOMNode*) const; - //@{ - - virtual unsigned long getWhatToShow() const { - return fWhatToShow; - }; - - virtual void setWhatToShow(unsigned long toShow) { - fWhatToShow = toShow; - }; - -private: - // unimplemented copy ctor and assignment operator - DOMPrintFilter(const DOMPrintFilter&); - DOMPrintFilter & operator = (const DOMPrintFilter&); - - unsigned long fWhatToShow; - -}; -#else class DOMPrintFilter : public DOMLSSerializerFilter { public: @@ -173,7 +136,6 @@ private: ShowType fWhatToShow; }; -#endif class DOMPrintErrorHandler : public DOMErrorHandler { public: @@ -1370,74 +1332,6 @@ void ParameterManager::SaveDocument(const char* sFileName) const void ParameterManager::SaveDocument(XMLFormatTarget* pFormatTarget) const { -#if (XERCES_VERSION_MAJOR == 2) - DOMPrintFilter *myFilter = 0; - - try { - // get a serializer, an instance of DOMWriter - XMLCh tempStr[100]; - XMLString::transcode("LS", tempStr, 99); - DOMImplementation *impl = DOMImplementationRegistry::getDOMImplementation(tempStr); - DOMWriter *theSerializer = ((DOMImplementationLS*)impl)->createDOMWriter(); - - // set user specified end of line sequence and output encoding - theSerializer->setNewLine(gMyEOLSequence); - theSerializer->setEncoding(gOutputEncoding); - - // plug in user's own filter - if (gUseFilter) { - // even we say to show attribute, but the DOMWriter - // will not show attribute nodes to the filter as - // the specs explicitly says that DOMWriter shall - // NOT show attributes to DOMWriterFilter. - // - // so DOMNodeFilter::SHOW_ATTRIBUTE has no effect. - // same DOMNodeFilter::SHOW_DOCUMENT_TYPE, no effect. - // - myFilter = new DOMPrintFilter(DOMNodeFilter::SHOW_ELEMENT | - DOMNodeFilter::SHOW_ATTRIBUTE | - DOMNodeFilter::SHOW_DOCUMENT_TYPE - ); - theSerializer->setFilter(myFilter); - } - - // plug in user's own error handler - DOMErrorHandler *myErrorHandler = new DOMPrintErrorHandler(); - theSerializer->setErrorHandler(myErrorHandler); - - // set feature if the serializer supports the feature/mode - if (theSerializer->canSetFeature(XMLUni::fgDOMWRTSplitCdataSections, gSplitCdataSections)) - theSerializer->setFeature(XMLUni::fgDOMWRTSplitCdataSections, gSplitCdataSections); - - if (theSerializer->canSetFeature(XMLUni::fgDOMWRTDiscardDefaultContent, gDiscardDefaultContent)) - theSerializer->setFeature(XMLUni::fgDOMWRTDiscardDefaultContent, gDiscardDefaultContent); - - if (theSerializer->canSetFeature(XMLUni::fgDOMWRTFormatPrettyPrint, gFormatPrettyPrint)) - theSerializer->setFeature(XMLUni::fgDOMWRTFormatPrettyPrint, gFormatPrettyPrint); - - // - // do the serialization through DOMWriter::writeNode(); - // - theSerializer->writeNode(pFormatTarget, *_pDocument); - - delete theSerializer; - - // - // Filter and error handler - // are NOT owned by the serializer. - // - delete myErrorHandler; - - if (gUseFilter) - delete myFilter; - - } - catch (XMLException& e) { - std::cerr << "An error occurred during creation of output transcoder. Msg is:" - << std::endl - << StrX(e.getMessage()) << std::endl; - } -#else try { std::unique_ptr myFilter; std::unique_ptr myErrorHandler; @@ -1495,7 +1389,6 @@ void ParameterManager::SaveDocument(XMLFormatTarget* pFormatTarget) const << std::endl << StrX(e.getMessage()) << std::endl; } -#endif } void ParameterManager::CreateDocument() @@ -1613,81 +1506,6 @@ void DOMTreeErrorReporter::resetErrors() //************************************************************************** // DOMPrintFilter //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -#if (XERCES_VERSION_MAJOR == 2) -DOMPrintFilter::DOMPrintFilter(unsigned long whatToShow) - :fWhatToShow(whatToShow) -{ - -} - -short DOMPrintFilter::acceptNode(const DOMNode* node) const -{ - // - // The DOMWriter shall call getWhatToShow() before calling - // acceptNode(), to show nodes which are supposed to be - // shown to this filter. - // TODO: - // REVISIT: In case the DOMWriter does not follow the protocol, - // Shall the filter honor, or NOT, what it claims - // (when it is constructed/setWhatToShow()) - // it is interested in ? - // - // The DOMLS specs does not specify that acceptNode() shall do - // this way, or not, so it is up the implementation, - // to skip the code below for the sake of performance ... - // - if ((getWhatToShow() & (1 << (node->getNodeType() - 1))) == 0) - return DOMNodeFilter::FILTER_ACCEPT; - - switch (node->getNodeType()) { - case DOMNode::ELEMENT_NODE: { - // for element whose name is "person", skip it - //if (XMLString::compareString(node->getNodeName(), element_person)==0) - // return DOMNodeFilter::FILTER_SKIP; - // for element whose name is "line", reject it - //if (XMLString::compareString(node->getNodeName(), element_link)==0) - // return DOMNodeFilter::FILTER_REJECT; - // for rest, accept it - return DOMNodeFilter::FILTER_ACCEPT; - - break; - } - case DOMNode::COMMENT_NODE: { - // the WhatToShow will make this no effect - //return DOMNodeFilter::FILTER_REJECT; - return DOMNodeFilter::FILTER_ACCEPT; - break; - } - case DOMNode::TEXT_NODE: { - // the WhatToShow will make this no effect - //return DOMNodeFilter::FILTER_REJECT; - return DOMNodeFilter::FILTER_ACCEPT; - break; - } - case DOMNode::DOCUMENT_TYPE_NODE: { - // even we say we are going to process document type, - // we are not able be to see this node since - // DOMWriterImpl (a XercesC's default implementation - // of DOMWriter) will not pass DocumentType node to - // this filter. - // - return DOMNodeFilter::FILTER_REJECT; // no effect - break; - } - case DOMNode::DOCUMENT_NODE: { - // same as DOCUMENT_NODE - return DOMNodeFilter::FILTER_REJECT; // no effect - break; - } - default : { - return DOMNodeFilter::FILTER_ACCEPT; - break; - } - } - - return DOMNodeFilter::FILTER_ACCEPT; -} -#else DOMPrintFilter::DOMPrintFilter(ShowType whatToShow) : fWhatToShow(whatToShow) { @@ -1737,7 +1555,6 @@ DOMPrintFilter::FilterAction DOMPrintFilter::acceptNode(const DOMNode* node) con return DOMNodeFilter::FILTER_ACCEPT; } -#endif //************************************************************************** //************************************************************************** diff --git a/src/Base/PreCompiled.h b/src/Base/PreCompiled.h index 1e4bc9ef17..25936cf8ec 100644 --- a/src/Base/PreCompiled.h +++ b/src/Base/PreCompiled.h @@ -85,9 +85,6 @@ #include #include #include -#if (XERCES_VERSION_MAJOR == 2) -#include -#endif #include #include #include diff --git a/src/Base/Reader.cpp b/src/Base/Reader.cpp index cf963b6ce7..507186db52 100644 --- a/src/Base/Reader.cpp +++ b/src/Base/Reader.cpp @@ -451,22 +451,14 @@ void Base::XMLReader::endCDATA () ReadType = EndCDATA; } -#if (XERCES_VERSION_MAJOR == 2) -void Base::XMLReader::characters(const XMLCh* const chars, const unsigned int length) -#else void Base::XMLReader::characters(const XMLCh* const chars, const XMLSize_t length) -#endif { Characters = StrX(chars).c_str(); ReadType = Chars; CharacterCount += length; } -#if (XERCES_VERSION_MAJOR == 2) -void Base::XMLReader::ignorableWhitespace( const XMLCh* const /*chars*/, const unsigned int /*length*/) -#else void Base::XMLReader::ignorableWhitespace( const XMLCh* const /*chars*/, const XMLSize_t /*length*/) -#endif { //fSpaceCount += length; } diff --git a/src/Base/Reader.h b/src/Base/Reader.h index 91dd602264..d06617a95f 100644 --- a/src/Base/Reader.h +++ b/src/Base/Reader.h @@ -227,13 +227,8 @@ protected: void endDocument() override; void startElement(const XMLCh* const uri, const XMLCh* const localname, const XMLCh* const qname, const XERCES_CPP_NAMESPACE_QUALIFIER Attributes& attrs) override; void endElement (const XMLCh* const uri, const XMLCh *const localname, const XMLCh *const qname) override; -#if (XERCES_VERSION_MAJOR == 2) - virtual void characters (const XMLCh* const chars, const unsigned int length); - virtual void ignorableWhitespace(const XMLCh* const chars, const unsigned int length); -#else void characters (const XMLCh* const chars, const XMLSize_t length) override; void ignorableWhitespace(const XMLCh* const chars, const XMLSize_t length) override; -#endif //@} /** @name Lexical handler */ diff --git a/src/Base/XMLTools.cpp b/src/Base/XMLTools.cpp index 9d824c2b1b..84b5a8eaf5 100644 --- a/src/Base/XMLTools.cpp +++ b/src/Base/XMLTools.cpp @@ -49,17 +49,10 @@ std::string XMLTools::toStdString(const XMLCh* const toTranscode) //char outBuff[128]; static XMLByte outBuff[128]; -#if (XERCES_VERSION_MAJOR == 2) - unsigned int outputLength; - unsigned int eaten = 0; - unsigned int offset = 0; - unsigned int inputLength = XMLString::stringLen(toTranscode); -#else XMLSize_t outputLength; XMLSize_t eaten = 0; XMLSize_t offset = 0; XMLSize_t inputLength = XMLString::stringLen(toTranscode); -#endif while (inputLength) { @@ -87,17 +80,10 @@ std::basic_string XMLTools::toXMLString(const char* const fromTranscode) static XMLCh outBuff[128]; const XMLByte* xmlBytes = reinterpret_cast(fromTranscode); -#if (XERCES_VERSION_MAJOR == 2) - unsigned int outputLength; - unsigned int eaten = 0; - unsigned int offset = 0; - unsigned int inputLength = std::string(fromTranscode).size(); -#else XMLSize_t outputLength; XMLSize_t eaten = 0; XMLSize_t offset = 0; XMLSize_t inputLength = std::string(fromTranscode).size(); -#endif unsigned char* charSizes = new unsigned char[inputLength]; while (inputLength)