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/* Patternist */
41#include "qbasictypesfactory_p.h"
42#include "qcommonnamespaces_p.h"
43#include "qgenericdynamiccontext_p.h"
44#include "qfunctionfactorycollection_p.h"
45#include "qgenericnamespaceresolver_p.h"
46
47#include "qgenericstaticcontext_p.h"
48
49QT_BEGIN_NAMESPACE
50
51using namespace QPatternist;
52
53GenericStaticContext::GenericStaticContext(const NamePool::Ptr &np,
54 QAbstractMessageHandler *const handler,
55 const QUrl &aBaseURI,
56 const FunctionFactory::Ptr &factory,
57 const QXmlQuery::QueryLanguage lang) : m_boundarySpacePolicy(BSPStrip)
58 , m_constructionMode(CMPreserve)
59 , m_functionFactory(factory)
60 , m_defaultFunctionNamespace(CommonNamespaces::XFN)
61 , m_orderingEmptySequence(Greatest)
62 , m_orderingMode(Ordered)
63 , m_defaultCollation(QUrl(QLatin1String(CommonNamespaces::UNICODE_COLLATION)))
64 , m_baseURI(aBaseURI)
65 , m_messageHandler(handler)
66 , m_preserveMode(Preserve)
67 , m_inheritMode(Inherit)
68 , m_namespaceResolver(lang == QXmlQuery::XQuery10
69 ? GenericNamespaceResolver::defaultXQueryBindings()
70 : GenericNamespaceResolver::defaultXSLTBindings())
71 , m_namePool(np)
72 , m_uriResolver(0)
73 , m_queryLanguage(lang)
74 , m_rangeSlot(-1)
75 , m_compatModeEnabled(false)
76{
77 /* We'll easily have at least this many AST nodes, that we need
78 * to track locations for. */
79 m_locations.reserve(asize: 30);
80
81 Q_ASSERT(np);
82 Q_ASSERT(!m_baseURI.isRelative());
83}
84
85NamespaceResolver::Ptr GenericStaticContext::namespaceBindings() const
86{
87 return m_namespaceResolver;
88}
89
90FunctionFactory::Ptr GenericStaticContext::functionSignatures() const
91{
92 return m_functionFactory;
93}
94
95DynamicContext::Ptr GenericStaticContext::dynamicContext() const
96{
97 GenericDynamicContext::Ptr context(new GenericDynamicContext(m_namePool, m_messageHandler, sourceLocations()));
98 // TODO we have many bugs here..
99 context->setResourceLoader(m_resourceLoader);
100 return context;
101}
102
103SchemaTypeFactory::Ptr GenericStaticContext::schemaDefinitions() const
104{
105 return BasicTypesFactory::self(np: m_namePool);
106}
107
108QUrl GenericStaticContext::baseURI() const
109{
110 Q_ASSERT_X(!m_baseURI.isRelative(), Q_FUNC_INFO,
111 "The static base-uri must be absolute. This error is most likely caused by misuing the API.");
112 return m_baseURI;
113}
114
115void GenericStaticContext::setBaseURI(const QUrl &uri)
116{
117 Q_ASSERT(!uri.isRelative());
118 m_baseURI = uri;
119}
120
121bool GenericStaticContext::compatModeEnabled() const
122{
123 return m_compatModeEnabled;
124}
125
126void GenericStaticContext::setCompatModeEnabled(const bool newVal)
127{
128 m_compatModeEnabled = newVal;
129}
130
131QUrl GenericStaticContext::defaultCollation() const
132{
133 return m_defaultCollation;
134}
135
136QAbstractMessageHandler * GenericStaticContext::messageHandler() const
137{
138 return m_messageHandler;
139}
140
141void GenericStaticContext::setDefaultCollation(const QUrl &uri)
142{
143 m_defaultCollation = uri;
144}
145
146void GenericStaticContext::setNamespaceBindings(const NamespaceResolver::Ptr &resolver)
147{
148 Q_ASSERT(resolver);
149 m_namespaceResolver = resolver;
150}
151
152StaticContext::BoundarySpacePolicy GenericStaticContext::boundarySpacePolicy() const
153{
154 return m_boundarySpacePolicy;
155}
156
157void GenericStaticContext::setBoundarySpacePolicy(const BoundarySpacePolicy policy)
158{
159 Q_ASSERT(policy == BSPPreserve || policy == BSPStrip);
160 m_boundarySpacePolicy = policy;
161}
162
163StaticContext::ConstructionMode GenericStaticContext::constructionMode() const
164{
165 return m_constructionMode;
166}
167
168void GenericStaticContext::setConstructionMode(const ConstructionMode mode)
169{
170 Q_ASSERT(mode == CMPreserve || mode == CMStrip);
171 m_constructionMode = mode;
172}
173
174StaticContext::OrderingMode GenericStaticContext::orderingMode() const
175{
176 return m_orderingMode;
177}
178
179void GenericStaticContext::setOrderingMode(const OrderingMode mode)
180{
181 Q_ASSERT(mode == Ordered || mode == Unordered);
182 m_orderingMode = mode;
183}
184
185StaticContext::OrderingEmptySequence GenericStaticContext::orderingEmptySequence() const
186{
187 return m_orderingEmptySequence;
188}
189
190void GenericStaticContext::setOrderingEmptySequence(const OrderingEmptySequence ordering)
191{
192 Q_ASSERT(ordering == Greatest || ordering == Least);
193 m_orderingEmptySequence = ordering;
194}
195
196QString GenericStaticContext::defaultFunctionNamespace() const
197{
198 return m_defaultFunctionNamespace;
199}
200
201void GenericStaticContext::setDefaultFunctionNamespace(const QString &ns)
202{
203 m_defaultFunctionNamespace = ns;
204}
205
206
207QString GenericStaticContext::defaultElementNamespace() const
208{
209 return m_defaultElementNamespace;
210}
211
212void GenericStaticContext::setDefaultElementNamespace(const QString &ns)
213{
214 m_defaultElementNamespace = ns;
215}
216
217StaticContext::InheritMode GenericStaticContext::inheritMode() const
218{
219 return m_inheritMode;
220}
221
222void GenericStaticContext::setInheritMode(const InheritMode mode)
223{
224 Q_ASSERT(mode == Inherit || mode == NoInherit);
225 m_inheritMode = mode;
226}
227
228StaticContext::PreserveMode GenericStaticContext::preserveMode() const
229{
230 return m_preserveMode;
231}
232
233void GenericStaticContext::setPreserveMode(const PreserveMode mode)
234{
235 Q_ASSERT(mode == Preserve || mode == NoPreserve);
236 m_preserveMode = mode;
237}
238
239ItemType::Ptr GenericStaticContext::contextItemType() const
240{
241 return m_contextItemType;
242}
243
244ItemType::Ptr GenericStaticContext::currentItemType() const
245{
246 return contextItemType();
247}
248
249void GenericStaticContext::setContextItemType(const ItemType::Ptr &type)
250{
251 m_contextItemType = type;
252}
253
254StaticContext::Ptr GenericStaticContext::copy() const
255{
256 GenericStaticContext *const retval = new GenericStaticContext(m_namePool, m_messageHandler, m_baseURI, m_functionFactory, m_queryLanguage);
257 const NamespaceResolver::Ptr newSolver(new GenericNamespaceResolver(m_namespaceResolver->bindings()));
258
259 retval->setNamespaceBindings(newSolver);
260 retval->setDefaultCollation(m_defaultCollation);
261 retval->setBoundarySpacePolicy(m_boundarySpacePolicy);
262 retval->setConstructionMode(m_constructionMode);
263 retval->setOrderingMode(m_orderingMode);
264 retval->setOrderingEmptySequence(m_orderingEmptySequence);
265 retval->setDefaultFunctionNamespace(m_defaultFunctionNamespace);
266 retval->setInheritMode(m_inheritMode);
267 retval->setPreserveMode(m_preserveMode);
268 retval->setExternalVariableLoader(m_externalVariableLoader);
269 retval->setResourceLoader(m_resourceLoader);
270 retval->setContextItemType(m_contextItemType);
271 retval->m_locations = m_locations;
272
273 return StaticContext::Ptr(retval);
274}
275
276ResourceLoader::Ptr GenericStaticContext::resourceLoader() const
277{
278 return m_resourceLoader;
279}
280
281void GenericStaticContext::setResourceLoader(const ResourceLoader::Ptr &loader)
282{
283 m_resourceLoader = loader;
284}
285
286ExternalVariableLoader::Ptr GenericStaticContext::externalVariableLoader() const
287{
288 return m_externalVariableLoader;
289}
290
291void GenericStaticContext::setExternalVariableLoader(const ExternalVariableLoader::Ptr &loader)
292{
293 m_externalVariableLoader = loader;
294}
295
296NamePool::Ptr GenericStaticContext::namePool() const
297{
298 return m_namePool;
299}
300
301void GenericStaticContext::addLocation(const SourceLocationReflection *const reflection,
302 const QSourceLocation &location)
303{
304 Q_ASSERT(!location.isNull());
305 Q_ASSERT_X(reflection, Q_FUNC_INFO,
306 "The reflection cannot be zero.");
307 m_locations.insert(akey: reflection, avalue: location);
308}
309
310StaticContext::LocationHash GenericStaticContext::sourceLocations() const
311{
312 return m_locations;
313}
314
315QSourceLocation GenericStaticContext::locationFor(const SourceLocationReflection *const reflection) const
316{
317 return m_locations.value(akey: reflection->actualReflection());
318}
319
320QAbstractUriResolver *GenericStaticContext::uriResolver() const
321{
322 return m_uriResolver;
323}
324
325VariableSlotID GenericStaticContext::currentRangeSlot() const
326{
327 return m_rangeSlot;
328}
329
330VariableSlotID GenericStaticContext::allocateRangeSlot()
331{
332 ++m_rangeSlot;
333 return m_rangeSlot;
334}
335
336QT_END_NAMESPACE
337

source code of qtxmlpatterns/src/xmlpatterns/environment/qgenericstaticcontext.cpp