Qt 4.8
qoutputvalidator.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
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 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.
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 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.
24 **
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.
28 **
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.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #include "qpatternistlocale_p.h"
43 
44 #include "qoutputvalidator_p.h"
45 
47 
48 using namespace QPatternist;
49 
51  const DynamicContext::Ptr &context,
52  const SourceLocationReflection *const r,
53  const bool isXSLT) : DelegatingSourceLocationReflection(r)
54  , m_hasReceivedChildren(false)
55  , m_receiver(receiver)
56  , m_context(context)
57  , m_isXSLT(isXSLT)
58 {
59  Q_ASSERT(receiver);
60  Q_ASSERT(context);
61 }
62 
64 {
66 }
67 
69 {
70  m_hasReceivedChildren = false;
71  m_receiver->startElement(name);
73 }
74 
76 {
77  m_hasReceivedChildren = true;
79 }
80 
82  const QStringRef &value)
83 {
85  {
86  m_context->error(QtXmlPatterns::tr("It's not possible to add attributes after any other kind of node."),
88  }
89  else
90  {
91  if(!m_isXSLT && m_attributes.contains(name))
92  {
93  m_context->error(QtXmlPatterns::tr("An attribute by name %1 has already been created.").arg(formatKeyword(m_context->namePool(), name)),
95  }
96  else
97  {
98  m_attributes.insert(name);
99  m_receiver->attribute(name, value);
100  }
101  }
102 }
103 
105 {
106  m_hasReceivedChildren = true;
107  m_receiver->comment(value);
108 }
109 
111 {
112  m_hasReceivedChildren = true;
113  m_receiver->characters(value);
114 }
115 
117  const QString &value)
118 {
119  m_hasReceivedChildren = true;
120  m_receiver->processingInstruction(name, value);
121 }
122 
123 void OutputValidator::item(const Item &outputItem)
124 {
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. */
128 
129  if(outputItem.isNode())
130  sendAsNode(outputItem);
131  else
132  {
133  m_hasReceivedChildren = true;
134  m_receiver->item(outputItem);
135  }
136 }
137 
139 {
141 }
142 
144 {
146 }
147 
149 {
150  Q_UNUSED(value);
151  // TODO
152 }
153 
155 {
156 }
157 
159 {
160 }
161 
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
const DynamicContext::Ptr m_context
virtual NamePool::Ptr namePool() const =0
virtual void characters(const QStringRef &value)
A push interface for the XPath Data Model. Similar to SAX's ContentHandler.
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
virtual void namespaceBinding(const QXmlName &nb)=0
Signals the presence of the namespace declaration nb.
QString formatKeyword(const QString &keyword)
virtual void attribute(const QXmlName &name, const QStringRef &value)
virtual void startElement(const QXmlName name)=0
Signals the start of an element by name name.
The QString class provides a Unicode character string.
Definition: qstring.h:83
bool isNode() const
Determines whether this item is an atomic value, or a node.
Definition: qitem_p.h:349
void sendAsNode(const Item &outputItem)
virtual void endElement()=0
Signals the end of the current element.
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
void error(const QString &message, const ReportContext::ErrorCode errorCode, const QSourceLocation &sourceLocation)
virtual void processingInstruction(const QXmlName &name, const QString &value)
bool contains(const T &value) const
Definition: qset.h:91
OutputValidator(QAbstractXmlReceiver *const receiver, const DynamicContext::Ptr &context, const SourceLocationReflection *const r, const bool isXSLT)
const char * name
The namespace for the internal API of QtXmlPatterns.
QAbstractXmlReceiver *const m_receiver
const_iterator insert(const T &value)
Definition: qset.h:179
virtual void item(const Item &item)=0
Sends an Item to this QAbstractXmlReceiver that may be a QXmlNodeModelIndex or an AtomicValue...
void clear()
Definition: qset.h:87
virtual void comment(const QString &value)=0
virtual void processingInstruction(const QXmlName name, const QString &value)=0
virtual void atomicValue(const QVariant &value)
virtual void item(const Item &item)
Sends an Item to this QAbstractXmlReceiver that may be a QXmlNodeModelIndex or an AtomicValue...
The QStringRef class provides a thin wrapper around QString substrings.
Definition: qstring.h:1099
virtual void characters(const QString &value)=0
The QXmlName class represents the name of an XML node, in an efficient, namespace-aware way...
Definition: qxmlname.h:58
Contains functions used for formatting arguments, such as keywords and paths, in translated strings...
virtual void comment(const QString &value)
Represents an item in the XPath 2.0 Data Model.
Definition: qitem_p.h:182
virtual void endElement()
Signals the end of the current element.
virtual void attribute(const QXmlName name, const QString &value)=0
Signals the presence of an attribute node.
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
virtual void startElement(const QXmlName &name)
Base class for all instances that represents something at a certain location.
virtual void namespaceBinding(const QXmlName &nb)
Signals the presence of the namespace declaration nb.