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_NamespaceSupport_H
51#define Patternist_NamespaceSupport_H
52
53#include <private/qnamepool_p.h>
54
55#include <QtCore/QExplicitlySharedDataPointer>
56#include <QtCore/QHash>
57#include <QtCore/QSet>
58#include <QtCore/QStack>
59#include <QtCore/QXmlStreamNamespaceDeclarations>
60
61QT_BEGIN_NAMESPACE
62
63namespace QPatternist
64{
65 /**
66 * @short A helper class for handling nested namespace declarations.
67 *
68 * This class is mostly an adaption of QXmlNamespaceSupport to the NamePool
69 * mechanism used in XmlPatterns.
70 *
71 * @ingroup Patternist_schema
72 * @author Tobias Koenig <tobias.koenig@nokia.com>
73 */
74 class NamespaceSupport
75 {
76 public:
77 /**
78 * Describes whether the name to process is an attribute or element.
79 */
80 enum NameType
81 {
82 AttributeName, ///< An attribute name to process.
83 ElementName ///< An element name to process.
84 };
85
86 /**
87 * Creates an empty namespace support object.
88 */
89 NamespaceSupport();
90
91 /**
92 * Creates a new namespace support object.
93 *
94 * @param namePool The name pool where all processed names are stored in.
95 */
96 NamespaceSupport(const NamePool::Ptr &namePool);
97
98 /**
99 * Adds a new prefix-to-namespace binding.
100 *
101 * @param prefixCode The name pool code for the prefix.
102 * @param namespaceCode The name pool code for the namespace.
103 */
104 void setPrefix(const QXmlName::PrefixCode prefixCode, const QXmlName::NamespaceCode namespaceCode);
105
106 /**
107 * Adds the prefix-to-namespace bindings from @p declarations to
108 * the namespace support.
109 */
110 void setPrefixes(const QXmlStreamNamespaceDeclarations &declarations);
111
112 /**
113 * Sets the name pool code of the target namespace of the schema the
114 * namespace support works on.
115 */
116 void setTargetNamespace(const QXmlName::NamespaceCode code);
117
118 /**
119 * Returns the prefix code for the given namespace @p code.
120 */
121 QXmlName::PrefixCode prefix(const QXmlName::NamespaceCode code) const;
122
123 /**
124 * Returns the namespace code for the given prefix @p code.
125 */
126 QXmlName::NamespaceCode uri(const QXmlName::PrefixCode code) const;
127
128 /**
129 * Converts the given @p qualifiedName to a resolved QXmlName @p name according
130 * to the current namespace mapping.
131 *
132 * @param qualifiedName The full qualified name.
133 * @param type The type of name processing.
134 * @param name The resolved QXmlName.
135 *
136 * @returns @c true if the name could be processed correctly or @c false if the
137 * namespace prefix is unknown.
138 */
139 bool processName(const QString &qualifiedName, NameType type, QXmlName &name) const;
140
141 /**
142 * Pushes the current namespace mapping onto the stack.
143 */
144 void pushContext();
145
146 /**
147 * Pops the current namespace mapping from the stack.
148 */
149 void popContext();
150
151 /**
152 * Returns the list of namespace bindings.
153 */
154 QList<QXmlName> namespaceBindings() const;
155
156 private:
157 typedef QHash<QXmlName::PrefixCode, QXmlName::NamespaceCode> NamespaceHash;
158
159 NamePool::Ptr m_namePool;
160 QStack<NamespaceHash> m_nsStack;
161 NamespaceHash m_ns;
162 };
163}
164
165QT_END_NAMESPACE
166
167#endif
168

source code of qtxmlpatterns/src/xmlpatterns/schema/qnamespacesupport_p.h