1/****************************************************************************
2**
3** Copyright (C) 2019 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the QtXml module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39#ifndef QDOMHELPERS_P_H
40#define QDOMHELPERS_P_H
41
42#include <qcoreapplication.h>
43#include <qglobal.h>
44
45QT_BEGIN_NAMESPACE
46
47//
48// W A R N I N G
49// -------------
50//
51// This file is not part of the Qt API. It exists for the convenience of
52// qxml.cpp and qdom.cpp. This header file may change from version to version without
53// notice, or even be removed.
54//
55// We mean it.
56//
57
58class QDomDocumentPrivate;
59class QDomNodePrivate;
60class QXmlStreamReader;
61class QXmlStreamAttributes;
62
63/**************************************************************
64 *
65 * QXmlDocumentLocators
66 *
67 **************************************************************/
68
69/* TODO: QXmlDocumentLocator can be removed when the SAX-based
70 * implementation is removed. Right now it is needed for QDomBuilder
71 * to work with both QXmlStreamReader and QXmlInputSource (SAX)
72 * based implementations.
73 */
74class QXmlDocumentLocator
75{
76public:
77 virtual ~QXmlDocumentLocator() = default;
78 virtual int column() const = 0;
79 virtual int line() const = 0;
80};
81
82class QDomDocumentLocator : public QXmlDocumentLocator
83{
84public:
85 QDomDocumentLocator(QXmlStreamReader *r) : reader(r) {}
86 ~QDomDocumentLocator() override = default;
87
88 int column() const override;
89 int line() const override;
90
91private:
92 QXmlStreamReader *reader;
93};
94
95/**************************************************************
96 *
97 * QDomBuilder
98 *
99 **************************************************************/
100
101class QDomBuilder
102{
103public:
104 QDomBuilder(QDomDocumentPrivate *d, QXmlDocumentLocator *l, bool namespaceProcessing);
105 ~QDomBuilder();
106
107 bool endDocument();
108 bool startElement(const QString &nsURI, const QString &qName, const QXmlStreamAttributes &atts);
109 bool endElement();
110 bool characters(const QString &characters, bool cdata = false);
111 bool processingInstruction(const QString &target, const QString &data);
112 bool skippedEntity(const QString &name);
113 bool startEntity(const QString &name);
114 bool endEntity();
115 bool startDTD(const QString &name, const QString &publicId, const QString &systemId);
116 bool comment(const QString &characters);
117 bool externalEntityDecl(const QString &name, const QString &publicId, const QString &systemId);
118 bool notationDecl(const QString &name, const QString &publicId, const QString &systemId);
119 bool unparsedEntityDecl(const QString &name, const QString &publicId, const QString &systemId,
120 const QString &notationName);
121
122 void fatalError(const QString &message);
123
124 using ErrorInfo = std::tuple<QString, int, int>;
125 ErrorInfo error() const;
126
127 QString errorMsg;
128 int errorLine;
129 int errorColumn;
130
131private:
132 QDomDocumentPrivate *doc;
133 QDomNodePrivate *node;
134 QXmlDocumentLocator *locator;
135 QString entityName;
136 bool nsProcessing;
137};
138
139/**************************************************************
140 *
141 * QDomParser
142 *
143 **************************************************************/
144
145class QDomParser
146{
147 Q_DECLARE_TR_FUNCTIONS(QDomParser)
148public:
149 QDomParser(QDomDocumentPrivate *d, QXmlStreamReader *r, bool namespaceProcessing);
150
151 bool parse();
152 QDomBuilder::ErrorInfo errorInfo() const;
153
154private:
155 bool parseProlog();
156 bool parseBody();
157 bool parseMarkupDecl();
158
159 QXmlStreamReader *reader;
160 QDomDocumentLocator locator;
161 QDomBuilder domBuilder;
162};
163
164QT_END_NAMESPACE
165
166#endif // QDOMHELPERS_P_H
167