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#include "qpatternistlocale_p.h"
41
42#include "qoutputvalidator_p.h"
43
44QT_BEGIN_NAMESPACE
45
46using namespace QPatternist;
47
48OutputValidator::OutputValidator(QAbstractXmlReceiver *const receiver,
49 const DynamicContext::Ptr &context,
50 const SourceLocationReflection *const r,
51 const bool isXSLT) : DelegatingSourceLocationReflection(r)
52 , m_hasReceivedChildren(false)
53 , m_receiver(receiver)
54 , m_context(context)
55 , m_isXSLT(isXSLT)
56{
57 Q_ASSERT(receiver);
58 Q_ASSERT(context);
59}
60
61void OutputValidator::namespaceBinding(const QXmlName &nb)
62{
63 m_receiver->namespaceBinding(name: nb);
64}
65
66void OutputValidator::startElement(const QXmlName &name)
67{
68 m_hasReceivedChildren = false;
69 m_receiver->startElement(name);
70 m_attributes.clear();
71}
72
73void OutputValidator::endElement()
74{
75 m_hasReceivedChildren = true;
76 m_receiver->endElement();
77}
78
79void OutputValidator::attribute(const QXmlName &name,
80 const QStringRef &value)
81{
82 if(m_hasReceivedChildren)
83 {
84 m_context->error(message: QtXmlPatterns::tr(sourceText: "It's not possible to add attributes after any other kind of node."),
85 errorCode: m_isXSLT ? ReportContext::XTDE0410 : ReportContext::XQTY0024, reflection: this);
86 }
87 else
88 {
89 if(!m_isXSLT && m_attributes.contains(value: name))
90 {
91 m_context->error(message: QtXmlPatterns::tr(sourceText: "An attribute by name %1 has already been created.").arg(a: formatKeyword(np: m_context->namePool(), name)),
92 errorCode: ReportContext::XQDY0025, reflection: this);
93 }
94 else
95 {
96 m_attributes.insert(value: name);
97 m_receiver->attribute(name, value);
98 }
99 }
100}
101
102void OutputValidator::comment(const QString &value)
103{
104 m_hasReceivedChildren = true;
105 m_receiver->comment(value);
106}
107
108void OutputValidator::characters(const QStringRef &value)
109{
110 m_hasReceivedChildren = true;
111 m_receiver->characters(value);
112}
113
114void OutputValidator::processingInstruction(const QXmlName &name,
115 const QString &value)
116{
117 m_hasReceivedChildren = true;
118 m_receiver->processingInstruction(target: name, value);
119}
120
121void OutputValidator::item(const Item &outputItem)
122{
123 /* We can't send outputItem directly to m_receiver since its item() function
124 * won't dispatch to this OutputValidator, but to itself. We're not sub-classing here,
125 * we're delegating. */
126
127 if(outputItem.isNode())
128 sendAsNode(outputItem);
129 else
130 {
131 m_hasReceivedChildren = true;
132 m_receiver->item(item: outputItem);
133 }
134}
135
136void OutputValidator::startDocument()
137{
138 m_receiver->startDocument();
139}
140
141void OutputValidator::endDocument()
142{
143 m_receiver->endDocument();
144}
145
146void OutputValidator::atomicValue(const QVariant &value)
147{
148 Q_UNUSED(value);
149 // TODO
150}
151
152void OutputValidator::endOfSequence()
153{
154}
155
156void OutputValidator::startOfSequence()
157{
158}
159
160QT_END_NAMESPACE
161

source code of qtxmlpatterns/src/xmlpatterns/utils/qoutputvalidator.cpp