From 79e0374143ab385cb12a17443e91c8eb9d2f3a4b Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Mon, 7 Sep 2020 14:01:20 +0200 Subject: Remove the SAX parser from QtXml It has been deprecated and will live in qt5compat from now on. Fixes: QTBUG-86480 Change-Id: I3744c7cee058d51d0fce633a174ab1a0f9235d2c Reviewed-by: Karsten Heimrich --- src/xml/dom/qdom.cpp | 111 ------------------------- src/xml/dom/qdom_p.h | 10 --- src/xml/dom/qdomhelpers.cpp | 194 +------------------------------------------- src/xml/dom/qdomhelpers_p.h | 92 --------------------- 4 files changed, 2 insertions(+), 405 deletions(-) (limited to 'src/xml/dom') diff --git a/src/xml/dom/qdom.cpp b/src/xml/dom/qdom.cpp index 0856a83a52..571e7fb0ac 100644 --- a/src/xml/dom/qdom.cpp +++ b/src/xml/dom/qdom.cpp @@ -53,7 +53,6 @@ #include #endif #include -#include #include #include #include @@ -5683,57 +5682,6 @@ void QDomDocumentPrivate::clear() QDomNodePrivate::clear(); } -#if QT_DEPRECATED_SINCE(5, 15) - -QT_WARNING_PUSH -QT_WARNING_DISABLE_DEPRECATED -static void initializeReader(QXmlSimpleReader &reader, bool namespaceProcessing) -{ - reader.setFeature(QLatin1String("http://xml.org/sax/features/namespaces"), namespaceProcessing); - reader.setFeature(QLatin1String("http://xml.org/sax/features/namespace-prefixes"), !namespaceProcessing); - reader.setFeature(QLatin1String("http://trolltech.com/xml/features/report-whitespace-only-CharData"), false); // Shouldn't change in Qt 4 -} - -bool QDomDocumentPrivate::setContent(QXmlInputSource *source, bool namespaceProcessing, QString *errorMsg, int *errorLine, int *errorColumn) -{ - QXmlSimpleReader reader; - initializeReader(reader, namespaceProcessing); - return setContent(source, &reader, &reader, errorMsg, errorLine, errorColumn); -} - -bool QDomDocumentPrivate::setContent(QXmlInputSource *source, QXmlReader *reader, QXmlSimpleReader *simpleReader, QString *errorMsg, int *errorLine, int *errorColumn) -{ - clear(); - impl = new QDomImplementationPrivate; - type = new QDomDocumentTypePrivate(this, this); - type->ref.deref(); - - bool namespaceProcessing = reader->feature(QLatin1String("http://xml.org/sax/features/namespaces")) - && !reader->feature(QLatin1String("http://xml.org/sax/features/namespace-prefixes")); - - QDomHandler hnd(this, simpleReader, namespaceProcessing); - reader->setContentHandler(&hnd); - reader->setErrorHandler(&hnd); - reader->setLexicalHandler(&hnd); - reader->setDeclHandler(&hnd); - reader->setDTDHandler(&hnd); - - if (!reader->parse(source)) { - if (errorMsg) - *errorMsg = std::get<0>(hnd.errorInfo()); - if (errorLine) - *errorLine = std::get<1>(hnd.errorInfo()); - if (errorColumn) - *errorColumn = std::get<2>(hnd.errorInfo()); - return false; - } - - return true; -} -QT_WARNING_POP - -#endif // QT_DEPRECATED_SINCE(5, 15) - bool QDomDocumentPrivate::setContent(QXmlStreamReader *reader, bool namespaceProcessing, QString *errorMsg, int *errorLine, int *errorColumn) { @@ -6273,43 +6221,11 @@ bool QDomDocument::setContent(QIODevice* dev, bool namespaceProcessing, QString if (!impl) impl = new QDomDocumentPrivate(); -#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) && QT_DEPRECATED_SINCE(5, 15) -QT_WARNING_PUSH -QT_WARNING_DISABLE_DEPRECATED - QXmlInputSource source(dev); -QT_WARNING_POP - return IMPL->setContent(&source, namespaceProcessing, errorMsg, errorLine, errorColumn); -#else QXmlStreamReader streamReader(dev); streamReader.setNamespaceProcessing(namespaceProcessing); return IMPL->setContent(&streamReader, namespaceProcessing, errorMsg, errorLine, errorColumn); -#endif } -#if QT_DEPRECATED_SINCE(5, 15) -/*! - \overload - \obsolete - \since 4.5 - - This function reads the XML document from the QXmlInputSource \a source, - returning true if the content was successfully parsed; otherwise returns \c false. - -*/ -QT_WARNING_PUSH -QT_WARNING_DISABLE_DEPRECATED -bool QDomDocument::setContent(QXmlInputSource *source, bool namespaceProcessing, QString *errorMsg, int *errorLine, int *errorColumn ) -{ - if (!impl) - impl = new QDomDocumentPrivate(); - QXmlSimpleReader reader; - initializeReader(reader, namespaceProcessing); - return IMPL->setContent(source, &reader, &reader, errorMsg, errorLine, errorColumn); -} -QT_WARNING_POP - -#endif - /*! \overload @@ -6353,33 +6269,6 @@ bool QDomDocument::setContent(QIODevice* dev, QString *errorMsg, int *errorLine, return setContent(dev, false, errorMsg, errorLine, errorColumn); } -#if QT_DEPRECATED_SINCE(5, 15) -/*! - \overload - \obsolete - - This function reads the XML document from the QXmlInputSource \a source and - parses it with the QXmlReader \a reader, returning true if the content was - successfully parsed; otherwise returns \c false. - - This function doesn't change the features of the \a reader. If you want to - use certain features for parsing you can use this function to set up the - reader appropriately. - - \sa QXmlSimpleReader -*/ -QT_WARNING_PUSH -QT_WARNING_DISABLE_DEPRECATED -bool QDomDocument::setContent(QXmlInputSource *source, QXmlReader *reader, QString *errorMsg, int *errorLine, int *errorColumn ) -{ - if (!impl) - impl = new QDomDocumentPrivate(); - return IMPL->setContent(source, reader, nullptr, errorMsg, errorLine, errorColumn); -} -QT_WARNING_POP - -#endif - /*! \overload \since 5.15 diff --git a/src/xml/dom/qdom_p.h b/src/xml/dom/qdom_p.h index 8ab81aa083..82c533b141 100644 --- a/src/xml/dom/qdom_p.h +++ b/src/xml/dom/qdom_p.h @@ -45,7 +45,6 @@ #include #include #include -#include #include QT_BEGIN_NAMESPACE @@ -462,15 +461,6 @@ public: QDomDocumentPrivate(QDomDocumentPrivate *n, bool deep); ~QDomDocumentPrivate(); -#if QT_DEPRECATED_SINCE(5, 15) -QT_WARNING_PUSH -QT_WARNING_DISABLE_DEPRECATED - bool setContent(QXmlInputSource *source, bool namespaceProcessing, QString *errorMsg, - int *errorLine, int *errorColumn); - bool setContent(QXmlInputSource *source, QXmlReader *reader, QXmlSimpleReader *simpleReader, - QString *errorMsg, int *errorLine, int *errorColumn); -QT_WARNING_POP -#endif bool setContent(QXmlStreamReader *reader, bool namespaceProcessing, QString *errorMsg, int *errorLine, int *errorColumn); diff --git a/src/xml/dom/qdomhelpers.cpp b/src/xml/dom/qdomhelpers.cpp index 69fb99715d..75d4c2c2b7 100644 --- a/src/xml/dom/qdomhelpers.cpp +++ b/src/xml/dom/qdomhelpers.cpp @@ -44,132 +44,10 @@ #include "qdomhelpers_p.h" #include "qdom_p.h" #include "qxmlstream.h" -#include "private/qxml_p.h" -QT_BEGIN_NAMESPACE - -#if QT_DEPRECATED_SINCE(5, 15) - -/************************************************************** - * - * QDomHandler - * - **************************************************************/ -QT_WARNING_PUSH -QT_WARNING_DISABLE_DEPRECATED -QDomHandler::QDomHandler(QDomDocumentPrivate *adoc, QXmlSimpleReader *areader, - bool namespaceProcessing) - : cdata(false), reader(areader), domBuilder(adoc, &locator, namespaceProcessing) -{ -} - -QDomHandler::~QDomHandler() {} - -bool QDomHandler::endDocument() -{ - return domBuilder.endDocument(); -} - -bool QDomHandler::startDTD(const QString &name, const QString &publicId, const QString &systemId) -{ - return domBuilder.startDTD(name, publicId, systemId); -} - -bool QDomHandler::startElement(const QString &nsURI, const QString &, const QString &qName, - const QXmlAttributes &atts) -{ - return domBuilder.startElement(nsURI, qName, atts); -} - -bool QDomHandler::endElement(const QString &, const QString &, const QString &) -{ - return domBuilder.endElement(); -} - -bool QDomHandler::characters(const QString &ch) -{ - return domBuilder.characters(ch, cdata); -} - -bool QDomHandler::processingInstruction(const QString &target, const QString &data) -{ - return domBuilder.processingInstruction(target, data); -} - -bool QDomHandler::skippedEntity(const QString &name) -{ - // we can only handle inserting entity references into content - if (reader && !reader->d_ptr->skipped_entity_in_content) - return true; - - return domBuilder.skippedEntity(name); -} - -bool QDomHandler::fatalError(const QXmlParseException &exception) -{ - domBuilder.errorMsg = exception.message(); - domBuilder.errorLine = exception.lineNumber(); - domBuilder.errorColumn = exception.columnNumber(); - return QXmlDefaultHandler::fatalError(exception); -} - -bool QDomHandler::startCDATA() -{ - cdata = true; - return true; -} - -bool QDomHandler::endCDATA() -{ - cdata = false; - return true; -} - -bool QDomHandler::startEntity(const QString &name) -{ - return domBuilder.startEntity(name); -} - -bool QDomHandler::endEntity(const QString &) -{ - return domBuilder.endEntity(); -} - -bool QDomHandler::comment(const QString &ch) -{ - return domBuilder.comment(ch); -} - -bool QDomHandler::unparsedEntityDecl(const QString &name, const QString &publicId, - const QString &systemId, const QString ¬ationName) -{ - return domBuilder.unparsedEntityDecl(name, publicId, systemId, notationName); -} - -bool QDomHandler::externalEntityDecl(const QString &name, const QString &publicId, - const QString &systemId) -{ - return unparsedEntityDecl(name, publicId, systemId, QString()); -} - -bool QDomHandler::notationDecl(const QString &name, const QString &publicId, - const QString &systemId) -{ - return domBuilder.notationDecl(name, publicId, systemId); -} - -void QDomHandler::setDocumentLocator(QXmlLocator *locator) -{ - this->locator.setLocator(locator); -} - -QDomBuilder::ErrorInfo QDomHandler::errorInfo() const -{ - return domBuilder.error(); -} -QT_WARNING_POP +#include -#endif // QT_DEPRECATED_SINCE(5, 15) +QT_BEGIN_NAMESPACE /************************************************************** * @@ -189,36 +67,6 @@ int QDomDocumentLocator::line() const return static_cast(reader->lineNumber()); } -#if QT_DEPRECATED_SINCE(5, 15) - -QT_WARNING_PUSH -QT_WARNING_DISABLE_DEPRECATED - -void QSAXDocumentLocator::setLocator(QXmlLocator *l) -{ - locator = l; -} - -int QSAXDocumentLocator::column() const -{ - if (!locator) - return 0; - - return static_cast(locator->columnNumber()); -} - -int QSAXDocumentLocator::line() const -{ - if (!locator) - return 0; - - return static_cast(locator->lineNumber()); -} - -QT_WARNING_POP - -#endif // QT_DEPRECATED_SINCE(5, 15) - /************************************************************** * * QDomBuilder @@ -253,44 +101,6 @@ bool QDomBuilder::startDTD(const QString &name, const QString &publicId, const Q return true; } -#if QT_DEPRECATED_SINCE(5, 15) - -QT_WARNING_PUSH -QT_WARNING_DISABLE_DEPRECATED -bool QDomBuilder::startElement(const QString &nsURI, const QString &qName, - const QXmlAttributes &atts) -{ - // tag name - QDomNodePrivate *n; - if (nsProcessing) { - n = doc->createElementNS(nsURI, qName); - } else { - n = doc->createElement(qName); - } - - if (!n) - return false; - - n->setLocation(locator->line(), locator->column()); - - node->appendChild(n); - node = n; - - // attributes - for (int i = 0; i < atts.length(); i++) { - auto domElement = static_cast(node); - if (nsProcessing) - domElement->setAttributeNS(atts.uri(i), atts.qName(i), atts.value(i)); - else - domElement->setAttribute(atts.qName(i), atts.value(i)); - } - - return true; -} -QT_WARNING_POP - -#endif // QT_DEPRECATED_SINCE(5, 15) - bool QDomBuilder::startElement(const QString &nsURI, const QString &qName, const QXmlStreamAttributes &atts) { diff --git a/src/xml/dom/qdomhelpers_p.h b/src/xml/dom/qdomhelpers_p.h index 4de18f7d4d..f7264daf4b 100644 --- a/src/xml/dom/qdomhelpers_p.h +++ b/src/xml/dom/qdomhelpers_p.h @@ -41,7 +41,6 @@ #include #include -#include QT_BEGIN_NAMESPACE @@ -93,29 +92,6 @@ private: QXmlStreamReader *reader; }; -#if QT_DEPRECATED_SINCE(5, 15) - -QT_WARNING_PUSH -QT_WARNING_DISABLE_DEPRECATED - -class QSAXDocumentLocator : public QXmlDocumentLocator -{ -public: - ~QSAXDocumentLocator() override = default; - - int column() const override; - int line() const override; - - void setLocator(QXmlLocator *l); - -private: - QXmlLocator *locator = nullptr; -}; - -QT_WARNING_POP - -#endif - /************************************************************** * * QDomBuilder @@ -129,12 +105,6 @@ public: ~QDomBuilder(); bool endDocument(); -#if QT_DEPRECATED_SINCE(5, 15) -QT_WARNING_PUSH -QT_WARNING_DISABLE_DEPRECATED - bool startElement(const QString &nsURI, const QString &qName, const QXmlAttributes &atts); -QT_WARNING_POP -#endif bool startElement(const QString &nsURI, const QString &qName, const QXmlStreamAttributes &atts); bool endElement(); bool characters(const QString &characters, bool cdata = false); @@ -166,68 +136,6 @@ private: bool nsProcessing; }; -#if QT_DEPRECATED_SINCE(5, 15) - -/************************************************************** - * - * QDomHandler - * - **************************************************************/ - -QT_WARNING_PUSH -QT_WARNING_DISABLE_DEPRECATED - -class QDomHandler : public QXmlDefaultHandler -{ -public: - QDomHandler(QDomDocumentPrivate *d, QXmlSimpleReader *reader, bool namespaceProcessing); - ~QDomHandler() override; - - // content handler - bool endDocument() override; - bool startElement(const QString &nsURI, const QString &localName, const QString &qName, - const QXmlAttributes &atts) override; - bool endElement(const QString &nsURI, const QString &localName, const QString &qName) override; - bool characters(const QString &ch) override; - bool processingInstruction(const QString &target, const QString &data) override; - bool skippedEntity(const QString &name) override; - - // error handler - bool fatalError(const QXmlParseException &exception) override; - - // lexical handler - bool startCDATA() override; - bool endCDATA() override; - bool startEntity(const QString &) override; - bool endEntity(const QString &) override; - bool startDTD(const QString &name, const QString &publicId, const QString &systemId) override; - bool comment(const QString &ch) override; - - // decl handler - bool externalEntityDecl(const QString &name, const QString &publicId, - const QString &systemId) override; - - // DTD handler - bool notationDecl(const QString &name, const QString &publicId, - const QString &systemId) override; - bool unparsedEntityDecl(const QString &name, const QString &publicId, const QString &systemId, - const QString ¬ationName) override; - - void setDocumentLocator(QXmlLocator *locator) override; - - QDomBuilder::ErrorInfo errorInfo() const; - -private: - bool cdata; - QXmlSimpleReader *reader; - QSAXDocumentLocator locator; - QDomBuilder domBuilder; -}; - -QT_WARNING_POP - -#endif // QT_DEPRECATED_SINCE(5, 15) - /************************************************************** * * QDomParser -- cgit v1.2.3