1 /****************************************************************************
3 ** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
6 ** This file is part of the QtXmlPatterns module of the Qt Toolkit.
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 Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
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 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
40 ****************************************************************************/
42 #include "qpatternistlocale_p.h"
44 #include "qoutputvalidator_p.h"
48 using namespace QPatternist;
50 OutputValidator::OutputValidator(QAbstractXmlReceiver *const receiver,
51 const DynamicContext::Ptr &context,
52 const SourceLocationReflection *const r,
53 const bool isXSLT) : DelegatingSourceLocationReflection(r)
54 , m_hasReceivedChildren(false)
55 , m_receiver(receiver)
63 void OutputValidator::namespaceBinding(const QXmlName &nb)
65 m_receiver->namespaceBinding(nb);
68 void OutputValidator::startElement(const QXmlName &name)
70 m_hasReceivedChildren = false;
71 m_receiver->startElement(name);
75 void OutputValidator::endElement()
77 m_hasReceivedChildren = true;
78 m_receiver->endElement();
81 void OutputValidator::attribute(const QXmlName &name,
82 const QStringRef &value)
84 if(m_hasReceivedChildren)
86 m_context->error(QtXmlPatterns::tr("It's not possible to add attributes after any other kind of node."),
87 m_isXSLT ? ReportContext::XTDE0410 : ReportContext::XQTY0024, this);
91 if(!m_isXSLT && m_attributes.contains(name))
93 m_context->error(QtXmlPatterns::tr("An attribute by name %1 has already been created.").arg(formatKeyword(m_context->namePool(), name)),
94 ReportContext::XQDY0025, this);
98 m_attributes.insert(name);
99 m_receiver->attribute(name, value);
104 void OutputValidator::comment(const QString &value)
106 m_hasReceivedChildren = true;
107 m_receiver->comment(value);
110 void OutputValidator::characters(const QStringRef &value)
112 m_hasReceivedChildren = true;
113 m_receiver->characters(value);
116 void OutputValidator::processingInstruction(const QXmlName &name,
117 const QString &value)
119 m_hasReceivedChildren = true;
120 m_receiver->processingInstruction(name, value);
123 void OutputValidator::item(const Item &outputItem)
125 /* We can't send outputItem directly to m_receiver since its item() function
126 * won't dispatch to this OutputValidator, but to itself. We're not sub-classing here,
127 * we're delegating. */
129 if(outputItem.isNode())
130 sendAsNode(outputItem);
133 m_hasReceivedChildren = true;
134 m_receiver->item(outputItem);
138 void OutputValidator::startDocument()
140 m_receiver->startDocument();
143 void OutputValidator::endDocument()
145 m_receiver->endDocument();
148 void OutputValidator::atomicValue(const QVariant &value)
154 void OutputValidator::endOfSequence()
158 void OutputValidator::startOfSequence()