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 QtXmlPatterns 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 | // |
41 | // W A R N I N G |
42 | // ------------- |
43 | // |
44 | // This file is not part of the Qt API. It exists purely as an |
45 | // implementation detail. This header file may change from version to |
46 | // version without notice, or even be removed. |
47 | // |
48 | // We mean it. |
49 | |
50 | #ifndef Patternist_XsdInstanceReader_H |
51 | #define Patternist_XsdInstanceReader_H |
52 | |
53 | #include "qabstractxmlnodemodel.h" |
54 | #include <private/qpullbridge_p.h> |
55 | #include <private/qxsdschemacontext_p.h> |
56 | |
57 | QT_BEGIN_NAMESPACE |
58 | |
59 | namespace QPatternist |
60 | { |
61 | /** |
62 | * @short The schema instance reader. |
63 | * |
64 | * This class reads in a xml instance document from a QAbstractXmlNodeModel |
65 | * and provides a QXmlStreamReader like interface with some additional context |
66 | * information. |
67 | * |
68 | * @ingroup Patternist_schema |
69 | * @author Tobias Koenig <tobias.koenig@nokia.com> |
70 | */ |
71 | class XsdInstanceReader |
72 | { |
73 | public: |
74 | typedef QExplicitlySharedDataPointer<XsdInstanceReader> Ptr; |
75 | |
76 | /** |
77 | * Creates a new instance reader that will read the data from |
78 | * the given @p model. |
79 | * |
80 | * @param model The model the data are read from. |
81 | * @param context The context that is used for error reporting etc. |
82 | */ |
83 | XsdInstanceReader(const QAbstractXmlNodeModel *model, const XsdSchemaContext::Ptr &context); |
84 | |
85 | protected: |
86 | /** |
87 | * Returns @c true if the end of the document is reached, @c false otherwise. |
88 | */ |
89 | bool atEnd() const; |
90 | |
91 | /** |
92 | * Reads the next node from the document. |
93 | */ |
94 | void readNext(); |
95 | |
96 | /** |
97 | * Returns whether the current node is a start element. |
98 | */ |
99 | bool isStartElement() const; |
100 | |
101 | /** |
102 | * Returns whether the current node is an end element. |
103 | */ |
104 | bool isEndElement() const; |
105 | |
106 | /** |
107 | * Returns whether the current node has a text node among its children. |
108 | */ |
109 | bool hasChildText() const; |
110 | |
111 | /** |
112 | * Returns whether the current node has an element node among its children. |
113 | */ |
114 | bool hasChildElement() const; |
115 | |
116 | /** |
117 | * Returns the name of the current node. |
118 | */ |
119 | QXmlName name() const; |
120 | |
121 | /** |
122 | * Returns whether the current node has an attribute with the given @p name. |
123 | */ |
124 | bool hasAttribute(const QXmlName &name) const; |
125 | |
126 | /** |
127 | * Returns the attribute with the given @p name of the current node. |
128 | */ |
129 | QString attribute(const QXmlName &name) const; |
130 | |
131 | /** |
132 | * Returns the list of attribute names of the current node. |
133 | */ |
134 | QSet<QXmlName> attributeNames() const; |
135 | |
136 | /** |
137 | * Returns the concatenated text of all direct child text nodes. |
138 | */ |
139 | QString text() const; |
140 | |
141 | /** |
142 | * Converts a qualified name into a QXmlName according to the namespace |
143 | * mappings of the current node. |
144 | */ |
145 | QXmlName convertToQName(const QString &name) const; |
146 | |
147 | /** |
148 | * Returns a source location object for the current position. |
149 | */ |
150 | QSourceLocation sourceLocation() const; |
151 | |
152 | /** |
153 | * Returns the QXmlItem for the current position. |
154 | */ |
155 | QXmlItem item() const; |
156 | |
157 | /** |
158 | * Returns the QXmlItem for the attribute with the given @p name at the current position. |
159 | */ |
160 | QXmlItem attributeItem(const QXmlName &name) const; |
161 | |
162 | /** |
163 | * Returns the namespace bindings for the given node model @p index. |
164 | */ |
165 | QVector<QXmlName> namespaceBindings(const QXmlNodeModelIndex &index) const; |
166 | |
167 | /** |
168 | * The shared schema context. |
169 | */ |
170 | XsdSchemaContext::Ptr m_context; |
171 | |
172 | private: |
173 | PullBridge m_model; |
174 | QHash<QXmlName, QString> m_cachedAttributes; |
175 | QHash<QXmlName, QXmlItem> m_cachedAttributeItems; |
176 | QSourceLocation m_cachedSourceLocation; |
177 | QXmlItem m_cachedItem; |
178 | }; |
179 | } |
180 | |
181 | QT_END_NAMESPACE |
182 | |
183 | #endif |
184 | |