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 "qdocumentcontentvalidator_p.h" |
43 | |
44 | QT_BEGIN_NAMESPACE |
45 | |
46 | using namespace QPatternist; |
47 | |
48 | DocumentContentValidator:: |
49 | DocumentContentValidator(QAbstractXmlReceiver *const receiver, |
50 | const DynamicContext::Ptr &context, |
51 | const Expression::ConstPtr &expr) : m_receiver(receiver) |
52 | , m_context(context) |
53 | , m_expr(expr) |
54 | , m_elementDepth(0) |
55 | { |
56 | Q_ASSERT(receiver); |
57 | Q_ASSERT(m_expr); |
58 | Q_ASSERT(context); |
59 | } |
60 | |
61 | void DocumentContentValidator::namespaceBinding(const QXmlName &nb) |
62 | { |
63 | m_receiver->namespaceBinding(name: nb); |
64 | } |
65 | |
66 | void DocumentContentValidator::startElement(const QXmlName &name) |
67 | { |
68 | ++m_elementDepth; |
69 | m_receiver->startElement(name); |
70 | } |
71 | |
72 | void DocumentContentValidator::endElement() |
73 | { |
74 | Q_ASSERT(m_elementDepth > 0); |
75 | --m_elementDepth; |
76 | m_receiver->endElement(); |
77 | } |
78 | |
79 | void DocumentContentValidator::attribute(const QXmlName &name, |
80 | const QStringRef &value) |
81 | { |
82 | if(m_elementDepth == 0) |
83 | { |
84 | m_context->error(message: QtXmlPatterns::tr(sourceText: "An attribute node cannot be a " |
85 | "child of a document node. " |
86 | "Therefore, the attribute %1 " |
87 | "is out of place." ) |
88 | .arg(a: formatKeyword(np: m_context->namePool(), name)), |
89 | errorCode: ReportContext::XPTY0004, reflection: m_expr.data()); |
90 | } |
91 | else |
92 | m_receiver->attribute(name, value); |
93 | } |
94 | |
95 | void DocumentContentValidator::(const QString &value) |
96 | { |
97 | m_receiver->comment(value); |
98 | } |
99 | |
100 | void DocumentContentValidator::characters(const QStringRef &value) |
101 | { |
102 | m_receiver->characters(value); |
103 | } |
104 | |
105 | void DocumentContentValidator::processingInstruction(const QXmlName &name, |
106 | const QString &value) |
107 | { |
108 | m_receiver->processingInstruction(target: name, value); |
109 | } |
110 | |
111 | void DocumentContentValidator::item(const Item &outputItem) |
112 | { |
113 | /* We can't send outputItem directly to m_receiver since its item() function |
114 | * won't dispatch to this DocumentContentValidator, but to itself. We're not sub-classing here, |
115 | * we're delegating. */ |
116 | |
117 | if(outputItem.isNode()) |
118 | sendAsNode(outputItem); |
119 | else |
120 | m_receiver->item(item: outputItem); |
121 | } |
122 | |
123 | void DocumentContentValidator::startDocument() |
124 | { |
125 | m_receiver->startDocument(); |
126 | } |
127 | |
128 | void DocumentContentValidator::endDocument() |
129 | { |
130 | m_receiver->endDocument(); |
131 | } |
132 | |
133 | void DocumentContentValidator::atomicValue(const QVariant &value) |
134 | { |
135 | Q_UNUSED(value); |
136 | } |
137 | |
138 | void DocumentContentValidator::startOfSequence() |
139 | { |
140 | } |
141 | |
142 | void DocumentContentValidator::endOfSequence() |
143 | { |
144 | } |
145 | |
146 | QT_END_NAMESPACE |
147 | |