1 /****************************************************************************
2 **
3 ** Copyright (C) 2016 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
40 #ifndef QXML_H
41 #define QXML_H
42
43 #if 0
44 // This is needed because of QTBUG-80347
45 #pragma qt_class(QXmlNamespaceSupport)
46 #pragma qt_class(QXmlAttributes)
47 #pragma qt_class(QXmlInputSource)
48 #pragma qt_class(QXmlParseException)
49 #pragma qt_class(QXmlReader)
50 #pragma qt_class(QXmlSimpleReader)
51 #pragma qt_class(QXmlLocator)
52 #pragma qt_class(QXmlContentHandler)
53 #pragma qt_class(QXmlErrorHandler)
54 #pragma qt_class(QXmlDTDHandler)
55 #pragma qt_class(QXmlEntityResolver)
56 #pragma qt_class(QXmlLexicalHandler)
57 #pragma qt_class(QXmlDeclHandler)
58 #pragma qt_class(QXmlDefaultHandler)
59 #endif
60
61 #include <QtCore/qglobal.h>
62
63 #include <QtXml/qtxmlglobal.h>
64 #include <QtCore/qtextstream.h>
65 #include <QtCore/qfile.h>
66 #include <QtCore/qstring.h>
67 #include <QtCore/qstringlist.h>
68 #include <QtCore/qlist.h>
69 #include <QtCore/qscopedpointer.h>
70
71 #if QT_DEPRECATED_SINCE(5, 15)
72
73 QT_BEGIN_NAMESPACE
74
75 QT_WARNING_PUSH
76 QT_WARNING_DISABLE_DEPRECATED
77
78 class QXmlNamespaceSupport;
79 class QXmlAttributes;
80 class QXmlContentHandler;
81 class QXmlDefaultHandler;
82 class QXmlDTDHandler;
83 class QXmlEntityResolver;
84 class QXmlErrorHandler;
85 class QXmlLexicalHandler;
86 class QXmlDeclHandler;
87 class QXmlInputSource;
88 class QXmlLocator;
89 class QXmlNamespaceSupport;
90 class QXmlParseException;
91
92 class QXmlReader;
93 class QXmlSimpleReader;
94
95 class QXmlSimpleReaderPrivate;
96 class QXmlNamespaceSupportPrivate;
97 class QXmlAttributesPrivate;
98 class QXmlInputSourcePrivate;
99 class QXmlParseExceptionPrivate;
100 class QXmlLocatorPrivate;
101 class QXmlDefaultHandlerPrivate;
102
103 //
104 // SAX Namespace Support
105 //
106
107 class QT_DEPRECATED_VERSION(5, 15) Q_XML_EXPORT QXmlNamespaceSupport
108 {
109 public:
110 QXmlNamespaceSupport();
111 ~QXmlNamespaceSupport();
112
113 void setPrefix(const QString&, const QString&);
114
115 QString prefix(const QString&) const;
116 QString uri(const QString&) const;
117 void splitName(const QString&, QString&, QString&) const;
118 void processName(const QString&, bool, QString&, QString&) const;
119 QStringList prefixes() const;
120 QStringList prefixes(const QString&) const;
121
122 void pushContext();
123 void popContext();
124 void reset();
125
126 private:
127 QXmlNamespaceSupportPrivate *d;
128
129 friend class QXmlSimpleReaderPrivate;
130 Q_DISABLE_COPY(QXmlNamespaceSupport)
131 };
132
133
134 //
135 // SAX Attributes
136 //
137
138 // Although deprecated warnings are disabled, the intel icc 18 compiler
139 // still complains during the instantiation of the templated qSwap() call below
140 // (with the parameter QXmlAttributes::AttributeList) when QXmlAttributes is
141 // deprecated. This makes the build fail when warnings are treated as errors.
142 // To workaround this, deprecated only the constructor.
143 class Q_XML_EXPORT QXmlAttributes
144 {
145 public:
146 QT_DEPRECATED_VERSION(5, 15) QXmlAttributes();
147 QXmlAttributes(const QXmlAttributes &) = default;
148 QXmlAttributes(QXmlAttributes &&) noexcept = default;
149 QXmlAttributes &operator=(const QXmlAttributes &) = default;
150 QXmlAttributes &operator=(QXmlAttributes &&) noexcept = default;
151
152 QT6_NOT_VIRTUAL ~QXmlAttributes();
153
swap(QXmlAttributes & other)154 void swap(QXmlAttributes &other) noexcept
155 {
156 qSwap(attList, other.attList);
157 qSwap(d, other.d);
158 }
159
160 int index(const QString& qName) const;
161 int index(QLatin1String qName) const;
162 int index(const QString& uri, const QString& localPart) const;
163 int length() const;
164 int count() const;
165 QString localName(int index) const;
166 QString qName(int index) const;
167 QString uri(int index) const;
168 QString type(int index) const;
169 QString type(const QString& qName) const;
170 QString type(const QString& uri, const QString& localName) const;
171 QString value(int index) const;
172 QString value(const QString& qName) const;
173 QString value(QLatin1String qName) const;
174 QString value(const QString& uri, const QString& localName) const;
175
176 void clear();
177 void append(const QString &qName, const QString &uri, const QString &localPart, const QString &value);
178
179 private:
180 struct Attribute {
181 QString qname, uri, localname, value;
182 };
183 friend class QTypeInfo<Attribute>;
184 typedef QList<Attribute> AttributeList;
185 AttributeList attList;
186
187 QXmlAttributesPrivate *d;
188 };
189
190 Q_DECLARE_TYPEINFO(QXmlAttributes::Attribute, Q_MOVABLE_TYPE);
Q_DECLARE_SHARED_NOT_MOVABLE_UNTIL_QT6(QXmlAttributes)191 Q_DECLARE_SHARED_NOT_MOVABLE_UNTIL_QT6(QXmlAttributes)
192
193 //
194 // SAX Input Source
195 //
196
197 class QT_DEPRECATED_VERSION(5, 15) Q_XML_EXPORT QXmlInputSource
198 {
199 public:
200 QXmlInputSource();
201 explicit QXmlInputSource(QIODevice *dev);
202 virtual ~QXmlInputSource();
203
204 virtual void setData(const QString& dat);
205 virtual void setData(const QByteArray& dat);
206 virtual void fetchData();
207 virtual QString data() const;
208 virtual QChar next();
209 virtual void reset();
210
211 static const ushort EndOfData;
212 static const ushort EndOfDocument;
213
214 protected:
215 virtual QString fromRawData(const QByteArray &data, bool beginning = false);
216
217 private:
218 void init();
219 QXmlInputSourcePrivate *d;
220 };
221
222 //
223 // SAX Exception Classes
224 //
225
226 class QT_DEPRECATED_VERSION(5, 15) Q_XML_EXPORT QXmlParseException
227 {
228 public:
229 explicit QXmlParseException(const QString &name = QString(), int c = -1, int l = -1,
230 const QString &p = QString(), const QString &s = QString());
231 QXmlParseException(const QXmlParseException &other);
232 ~QXmlParseException();
233
234 int columnNumber() const;
235 int lineNumber() const;
236 QString publicId() const;
237 QString systemId() const;
238 QString message() const;
239
240 private:
241 QScopedPointer<QXmlParseExceptionPrivate> d;
242 };
243
244
245 //
246 // XML Reader
247 //
248
249 class QT_DEPRECATED_VERSION_X(5, 15, "Use QXmlStreamReader") Q_XML_EXPORT QXmlReader
250 {
251 public:
~QXmlReader()252 virtual ~QXmlReader() {}
253 virtual bool feature(const QString& name, bool *ok = nullptr) const = 0;
254 virtual void setFeature(const QString& name, bool value) = 0;
255 virtual bool hasFeature(const QString& name) const = 0;
256 virtual void* property(const QString& name, bool *ok = nullptr) const = 0;
257 virtual void setProperty(const QString& name, void* value) = 0;
258 virtual bool hasProperty(const QString& name) const = 0;
259 virtual void setEntityResolver(QXmlEntityResolver* handler) = 0;
260 virtual QXmlEntityResolver* entityResolver() const = 0;
261 virtual void setDTDHandler(QXmlDTDHandler* handler) = 0;
262 virtual QXmlDTDHandler* DTDHandler() const = 0;
263 virtual void setContentHandler(QXmlContentHandler* handler) = 0;
264 virtual QXmlContentHandler* contentHandler() const = 0;
265 virtual void setErrorHandler(QXmlErrorHandler* handler) = 0;
266 virtual QXmlErrorHandler* errorHandler() const = 0;
267 virtual void setLexicalHandler(QXmlLexicalHandler* handler) = 0;
268 virtual QXmlLexicalHandler* lexicalHandler() const = 0;
269 virtual void setDeclHandler(QXmlDeclHandler* handler) = 0;
270 virtual QXmlDeclHandler* declHandler() const = 0;
271 virtual bool parse(const QXmlInputSource& input) = 0;
272 virtual bool parse(const QXmlInputSource* input) = 0;
273 };
274
275 class QT_DEPRECATED_VERSION_X(5, 15, "Use QXmlStreamReader") Q_XML_EXPORT QXmlSimpleReader
276 : public QXmlReader
277 {
278 public:
279 QXmlSimpleReader();
280 virtual ~QXmlSimpleReader();
281
282 bool feature(const QString& name, bool *ok = nullptr) const override;
283 void setFeature(const QString& name, bool value) override;
284 bool hasFeature(const QString& name) const override;
285
286 void* property(const QString& name, bool *ok = nullptr) const override;
287 void setProperty(const QString& name, void* value) override;
288 bool hasProperty(const QString& name) const override;
289
290 void setEntityResolver(QXmlEntityResolver* handler) override;
291 QXmlEntityResolver* entityResolver() const override;
292 void setDTDHandler(QXmlDTDHandler* handler) override;
293 QXmlDTDHandler* DTDHandler() const override;
294 void setContentHandler(QXmlContentHandler* handler) override;
295 QXmlContentHandler* contentHandler() const override;
296 void setErrorHandler(QXmlErrorHandler* handler) override;
297 QXmlErrorHandler* errorHandler() const override;
298 void setLexicalHandler(QXmlLexicalHandler* handler) override;
299 QXmlLexicalHandler* lexicalHandler() const override;
300 void setDeclHandler(QXmlDeclHandler* handler) override;
301 QXmlDeclHandler* declHandler() const override;
302
303 bool parse(const QXmlInputSource& input) override;
304 bool parse(const QXmlInputSource* input) override;
305 virtual bool parse(const QXmlInputSource* input, bool incremental);
306 virtual bool parseContinue();
307
308 private:
309 Q_DISABLE_COPY(QXmlSimpleReader)
310 Q_DECLARE_PRIVATE(QXmlSimpleReader)
311 QScopedPointer<QXmlSimpleReaderPrivate> d_ptr;
312
313 friend class QXmlSimpleReaderLocator;
314 friend class QDomHandler;
315 };
316
317 //
318 // SAX Locator
319 //
320
321 class QT_DEPRECATED_VERSION(5, 15) Q_XML_EXPORT QXmlLocator
322 {
323 public:
324 QXmlLocator();
325 virtual ~QXmlLocator();
326
327 virtual int columnNumber() const = 0;
328 virtual int lineNumber() const = 0;
329 // QString getPublicId() const
330 // QString getSystemId() const
331 };
332
333 //
334 // SAX handler classes
335 //
336
337 class QT_DEPRECATED_VERSION(5, 15) Q_XML_EXPORT QXmlContentHandler
338 {
339 public:
~QXmlContentHandler()340 virtual ~QXmlContentHandler() {}
341 virtual void setDocumentLocator(QXmlLocator* locator) = 0;
342 virtual bool startDocument() = 0;
343 virtual bool endDocument() = 0;
344 virtual bool startPrefixMapping(const QString& prefix, const QString& uri) = 0;
345 virtual bool endPrefixMapping(const QString& prefix) = 0;
346 virtual bool startElement(const QString& namespaceURI, const QString& localName, const QString& qName, const QXmlAttributes& atts) = 0;
347 virtual bool endElement(const QString& namespaceURI, const QString& localName, const QString& qName) = 0;
348 virtual bool characters(const QString& ch) = 0;
349 virtual bool ignorableWhitespace(const QString& ch) = 0;
350 virtual bool processingInstruction(const QString& target, const QString& data) = 0;
351 virtual bool skippedEntity(const QString& name) = 0;
352 virtual QString errorString() const = 0;
353 };
354
355 class QT_DEPRECATED_VERSION(5, 15) Q_XML_EXPORT QXmlErrorHandler
356 {
357 public:
~QXmlErrorHandler()358 virtual ~QXmlErrorHandler() {}
359 virtual bool warning(const QXmlParseException& exception) = 0;
360 virtual bool error(const QXmlParseException& exception) = 0;
361 virtual bool fatalError(const QXmlParseException& exception) = 0;
362 virtual QString errorString() const = 0;
363 };
364
365 class QT_DEPRECATED_VERSION(5, 15) Q_XML_EXPORT QXmlDTDHandler
366 {
367 public:
~QXmlDTDHandler()368 virtual ~QXmlDTDHandler() {}
369 virtual bool notationDecl(const QString& name, const QString& publicId, const QString& systemId) = 0;
370 virtual bool unparsedEntityDecl(const QString& name, const QString& publicId, const QString& systemId, const QString& notationName) = 0;
371 virtual QString errorString() const = 0;
372 };
373
374 class QT_DEPRECATED_VERSION(5, 15) Q_XML_EXPORT QXmlEntityResolver
375 {
376 public:
~QXmlEntityResolver()377 virtual ~QXmlEntityResolver() {}
378 virtual bool resolveEntity(const QString& publicId, const QString& systemId, QXmlInputSource*& ret) = 0;
379 virtual QString errorString() const = 0;
380 };
381
382 class QT_DEPRECATED_VERSION(5, 15) Q_XML_EXPORT QXmlLexicalHandler
383 {
384 public:
~QXmlLexicalHandler()385 virtual ~QXmlLexicalHandler() {}
386 virtual bool startDTD(const QString& name, const QString& publicId, const QString& systemId) = 0;
387 virtual bool endDTD() = 0;
388 virtual bool startEntity(const QString& name) = 0;
389 virtual bool endEntity(const QString& name) = 0;
390 virtual bool startCDATA() = 0;
391 virtual bool endCDATA() = 0;
392 virtual bool comment(const QString& ch) = 0;
393 virtual QString errorString() const = 0;
394 };
395
396 class QT_DEPRECATED_VERSION(5, 15) Q_XML_EXPORT QXmlDeclHandler
397 {
398 public:
~QXmlDeclHandler()399 virtual ~QXmlDeclHandler() {}
400 virtual bool attributeDecl(const QString& eName, const QString& aName, const QString& type, const QString& valueDefault, const QString& value) = 0;
401 virtual bool internalEntityDecl(const QString& name, const QString& value) = 0;
402 virtual bool externalEntityDecl(const QString& name, const QString& publicId, const QString& systemId) = 0;
403 virtual QString errorString() const = 0;
404 // ### Conform to SAX by adding elementDecl
405 };
406
407 class QT_DEPRECATED_VERSION(5, 15) Q_XML_EXPORT QXmlDefaultHandler : public QXmlContentHandler,
408 public QXmlErrorHandler,
409 public QXmlDTDHandler,
410 public QXmlEntityResolver,
411 public QXmlLexicalHandler,
412 public QXmlDeclHandler
413 {
414 public:
415 QXmlDefaultHandler();
416 virtual ~QXmlDefaultHandler();
417
418 void setDocumentLocator(QXmlLocator* locator) override;
419 bool startDocument() override;
420 bool endDocument() override;
421 bool startPrefixMapping(const QString& prefix, const QString& uri) override;
422 bool endPrefixMapping(const QString& prefix) override;
423 bool startElement(const QString& namespaceURI, const QString& localName, const QString& qName, const QXmlAttributes& atts) override;
424 bool endElement(const QString& namespaceURI, const QString& localName, const QString& qName) override;
425 bool characters(const QString& ch) override;
426 bool ignorableWhitespace(const QString& ch) override;
427 bool processingInstruction(const QString& target, const QString& data) override;
428 bool skippedEntity(const QString& name) override;
429
430 bool warning(const QXmlParseException& exception) override;
431 bool error(const QXmlParseException& exception) override;
432 bool fatalError(const QXmlParseException& exception) override;
433
434 bool notationDecl(const QString& name, const QString& publicId, const QString& systemId) override;
435 bool unparsedEntityDecl(const QString& name, const QString& publicId, const QString& systemId, const QString& notationName) override;
436
437 bool resolveEntity(const QString& publicId, const QString& systemId, QXmlInputSource*& ret) override;
438
439 bool startDTD(const QString& name, const QString& publicId, const QString& systemId) override;
440 bool endDTD() override;
441 bool startEntity(const QString& name) override;
442 bool endEntity(const QString& name) override;
443 bool startCDATA() override;
444 bool endCDATA() override;
445 bool comment(const QString& ch) override;
446
447 bool attributeDecl(const QString& eName, const QString& aName, const QString& type, const QString& valueDefault, const QString& value) override;
448 bool internalEntityDecl(const QString& name, const QString& value) override;
449 bool externalEntityDecl(const QString& name, const QString& publicId, const QString& systemId) override;
450
451 QString errorString() const override;
452
453 private:
454 QXmlDefaultHandlerPrivate *d;
455 Q_DISABLE_COPY(QXmlDefaultHandler)
456 };
457
458 // inlines
459
count()460 inline int QXmlAttributes::count() const
461 { return length(); }
462
463 QT_WARNING_POP
464
465 QT_END_NAMESPACE
466
467 #endif // QT_DEPRECATED_SINCE(5, 15)
468
469 #endif // QXML_H
470