Qt 4.8
qcomputednamespaceconstructor.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 "qanyuri_p.h"
43 #include "qbuiltintypes_p.h"
44 #include "qcommonsequencetypes_p.h"
45 #include "qpatternistlocale_p.h"
46 #include "private/qxmlutils_p.h"
47 
49 
51 
52 using namespace QPatternist;
53 
55  const Expression::Ptr &namespaceURI) : PairContainer(prefix, namespaceURI)
56 {
57 }
58 
60 {
61  const Item prefixItem(m_operand1->evaluateSingleton(context));
62  const QString prefix(prefixItem ? prefixItem.stringValue() : QString());
63 
64  const Item namespaceItem(m_operand2->evaluateSingleton(context));
65  const QString namespaceURI(namespaceItem ? namespaceItem.stringValue() : QString());
66 
67  if(namespaceURI.isEmpty())
68  {
69  context->error(QtXmlPatterns::tr("In a namespace constructor, the value for a namespace cannot be an empty string."),
71  this);
72  }
73 
74  /* One optimization could be to store a pointer to
75  * the name pool as a member in order to avoid the virtual call(s). */
76  const NamePool::Ptr np(context->namePool());
77 
78  if(!prefix.isEmpty() && !QXmlUtils::isNCName(prefix))
79  {
80  context->error(QtXmlPatterns::tr("The prefix must be a valid %1, which %2 is not.")
82  formatKeyword(prefix)),
84  this);
85  }
86  const QXmlName binding(np->allocateBinding(prefix, namespaceURI));
87 
88  AnyURI::toQUrl<ReportContext::XTDE0905, DynamicContext::Ptr>(namespaceURI,
89  context,
90  this);
91 
92  if(binding.prefix() == StandardPrefixes::xmlns)
93  {
94  context->error(QtXmlPatterns::tr("The prefix %1 cannot be bound.")
95  .arg(formatKeyword(prefix)),
97  this);
98  }
99 
100  if((binding.prefix() == StandardPrefixes::xml && binding.namespaceURI() != StandardNamespaces::xml)
101  ||
102  (binding.prefix() != StandardPrefixes::xml && binding.namespaceURI() == StandardNamespaces::xml))
103  {
104  context->error(QtXmlPatterns::tr("Only the prefix %1 can be bound to %2 and vice versa.")
105  .arg(formatKeyword(prefix), formatKeyword(namespaceURI)),
107  this);
108  }
109 
110  context->outputReceiver()->namespaceBinding(binding);
111 }
112 
114 {
116 }
117 
119 {
120  SequenceType::List result;
123  return result;
124 }
125 
127 {
129 }
130 
132 {
133  return visitor->visit(this);
134 }
135 
virtual NamePool::Ptr namePool() const =0
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
QString formatKeyword(const QString &keyword)
QString formatType(const NamePool::Ptr &np, const T &type)
Formats ItemType and SequenceType.
ComputedNamespaceConstructor(const Expression::Ptr &prefix, const Expression::Ptr &namespaceURI)
The QString class provides a Unicode character string.
Definition: qstring.h:83
virtual SequenceType::List expectedOperandTypes() const
static const SequenceType::Ptr ZeroOrOneString
virtual ExpressionVisitorResult::Ptr accept(const ExpressionVisitor::Ptr &visitor) const
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
static const SequenceType::Ptr ExactlyOneAttribute
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
void error(const QString &message, const ReportContext::ErrorCode errorCode, const QSourceLocation &sourceLocation)
The namespace for the internal API of QtXmlPatterns.
virtual void evaluateToSequenceReceiver(const DynamicContext::Ptr &context) const
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...
Represents an item in the XPath 2.0 Data Model.
Definition: qitem_p.h:182
static const AtomicType::Ptr xsNCName
virtual Expression::Properties properties() const
The QFlags class provides a type-safe way of storing OR-combinations of enum values.
Definition: qglobal.h:2313
static bool isNCName(const QStringRef &ncName)
Determines whether c is a valid instance of production [4]NCName in the XML 1.0 Namespaces specificat...
Definition: qxmlutils.cpp:377
virtual Item evaluateSingleton(const DynamicContext::Ptr &context) const
The QList class is a template class that provides lists.
Definition: qdatastream.h:62
Base class for expressions that has exactly two operands.