1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** Contact: Qt Software Information ([email protected])
|
---|
5 | **
|
---|
6 | ** This file is part of the QtXmlPatterns module of the Qt Toolkit.
|
---|
7 | **
|
---|
8 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
9 | ** Commercial Usage
|
---|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
11 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
12 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
13 | ** a written agreement between you and Nokia.
|
---|
14 | **
|
---|
15 | ** GNU Lesser General Public License Usage
|
---|
16 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
17 | ** General Public License version 2.1 as published by the Free Software
|
---|
18 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
19 | ** packaging of this file. Please review the following information to
|
---|
20 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
21 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
22 | **
|
---|
23 | ** In addition, as a special exception, Nokia gives you certain
|
---|
24 | ** additional rights. These rights are described in the Nokia Qt LGPL
|
---|
25 | ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
|
---|
26 | ** package.
|
---|
27 | **
|
---|
28 | ** GNU General Public License Usage
|
---|
29 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
30 | ** General Public License version 3.0 as published by the Free Software
|
---|
31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
32 | ** packaging of this file. Please review the following information to
|
---|
33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
35 | **
|
---|
36 | ** If you are unsure which license is appropriate for your use, please
|
---|
37 | ** contact the sales department at [email protected].
|
---|
38 | ** $QT_END_LICENSE$
|
---|
39 | **
|
---|
40 | ****************************************************************************/
|
---|
41 |
|
---|
42 | #include "qanyuri_p.h"
|
---|
43 | #include "qbuiltintypes_p.h"
|
---|
44 | #include "qcommonvalues_p.h"
|
---|
45 | #include "qpatternistlocale_p.h"
|
---|
46 | #include "qnodenamespaceresolver_p.h"
|
---|
47 | #include "qqnameconstructor_p.h"
|
---|
48 | #include "qqnamevalue_p.h"
|
---|
49 | #include "qatomicstring_p.h"
|
---|
50 | #include "qxpathhelper_p.h"
|
---|
51 |
|
---|
52 | #include "qqnamefns_p.h"
|
---|
53 |
|
---|
54 | QT_BEGIN_NAMESPACE
|
---|
55 |
|
---|
56 | using namespace QPatternist;
|
---|
57 |
|
---|
58 | Item QNameFN::evaluateSingleton(const DynamicContext::Ptr &context) const
|
---|
59 | {
|
---|
60 | const Item paramURI(m_operands.first()->evaluateSingleton(context));
|
---|
61 | const QString paramQName(m_operands.last()->evaluateSingleton(context).stringValue());
|
---|
62 |
|
---|
63 | QString ns;
|
---|
64 | if(paramURI)
|
---|
65 | ns = paramURI.stringValue();
|
---|
66 |
|
---|
67 | if(!XPathHelper::isQName(paramQName))
|
---|
68 | {
|
---|
69 | context->error(QtXmlPatterns::tr("%1 is an invalid %2").arg(formatData(paramQName),
|
---|
70 | formatType(context->namePool(), BuiltinTypes::xsQName)),
|
---|
71 | ReportContext::FOCA0002, this);
|
---|
72 | return Item();
|
---|
73 | }
|
---|
74 |
|
---|
75 | QString prefix;
|
---|
76 | QString lname;
|
---|
77 | XPathHelper::splitQName(paramQName, prefix, lname);
|
---|
78 | const QXmlName n(context->namePool()->allocateQName(ns, lname, prefix));
|
---|
79 |
|
---|
80 | if(ns.isEmpty())
|
---|
81 | {
|
---|
82 | if(prefix.isEmpty())
|
---|
83 | return toItem(QNameValue::fromValue(context->namePool(), n));
|
---|
84 | else
|
---|
85 | {
|
---|
86 | context->error(QtXmlPatterns::tr(
|
---|
87 | "If the first argument is the empty sequence or "
|
---|
88 | "a zero-length string (no namespace), a prefix "
|
---|
89 | "cannot be specified. Prefix %1 was specified.")
|
---|
90 | .arg(formatKeyword(prefix)),
|
---|
91 | ReportContext::FOCA0002, this);
|
---|
92 | return Item(); /* Silence compiler warning. */
|
---|
93 | }
|
---|
94 | }
|
---|
95 | else
|
---|
96 | return toItem(QNameValue::fromValue(context->namePool(), n));
|
---|
97 | }
|
---|
98 |
|
---|
99 | Item ResolveQNameFN::evaluateSingleton(const DynamicContext::Ptr &context) const
|
---|
100 | {
|
---|
101 | const Item itemName(m_operands.first()->evaluateSingleton(context));
|
---|
102 |
|
---|
103 | if(!itemName)
|
---|
104 | return Item();
|
---|
105 |
|
---|
106 | const NamespaceResolver::Ptr resolver(new NodeNamespaceResolver(m_operands.last()->evaluateSingleton(context)));
|
---|
107 | const QString strName(itemName.stringValue());
|
---|
108 | const QXmlName name = QNameConstructor::expandQName<DynamicContext::Ptr,
|
---|
109 | ReportContext::FOCA0002,
|
---|
110 | ReportContext::FONS0004>(strName,
|
---|
111 | context,
|
---|
112 | resolver,
|
---|
113 | this);
|
---|
114 |
|
---|
115 | return toItem(QNameValue::fromValue(context->namePool(), name));
|
---|
116 | }
|
---|
117 |
|
---|
118 | Item PrefixFromQNameFN::evaluateSingleton(const DynamicContext::Ptr &context) const
|
---|
119 | {
|
---|
120 | const QNameValue::Ptr arg(m_operands.first()->evaluateSingleton(context).as<QNameValue>());
|
---|
121 | if(!arg)
|
---|
122 | return Item();
|
---|
123 |
|
---|
124 | const QString prefix(context->namePool()->stringForPrefix(arg->qName().prefix()));
|
---|
125 |
|
---|
126 | if(prefix.isEmpty())
|
---|
127 | return Item();
|
---|
128 | else
|
---|
129 | return AtomicString::fromValue(context->namePool()->stringForPrefix(arg->qName().prefix()));
|
---|
130 | }
|
---|
131 |
|
---|
132 | Item LocalNameFromQNameFN::evaluateSingleton(const DynamicContext::Ptr &context) const
|
---|
133 | {
|
---|
134 | const QNameValue::Ptr arg(m_operands.first()->evaluateSingleton(context).as<QNameValue>());
|
---|
135 | return arg ? toItem(AtomicString::fromValue(context->namePool()->stringForLocalName(arg->qName().localName()))) : Item();
|
---|
136 | }
|
---|
137 |
|
---|
138 | Item NamespaceURIFromQNameFN::evaluateSingleton(const DynamicContext::Ptr &context) const
|
---|
139 | {
|
---|
140 | const QNameValue::Ptr arg(m_operands.first()->evaluateSingleton(context).as<QNameValue>());
|
---|
141 | return arg ? toItem(AnyURI::fromValue(context->namePool()->stringForNamespace(arg->qName().namespaceURI()))) : Item();
|
---|
142 | }
|
---|
143 |
|
---|
144 | Item NamespaceURIForPrefixFN::evaluateSingleton(const DynamicContext::Ptr &context) const
|
---|
145 | {
|
---|
146 | const Item prefixItem(m_operands.first()->evaluateSingleton(context));
|
---|
147 | QXmlName::PrefixCode prefix;
|
---|
148 |
|
---|
149 | if(prefixItem)
|
---|
150 | prefix = context->namePool()->allocatePrefix(prefixItem.stringValue());
|
---|
151 | else
|
---|
152 | prefix = StandardPrefixes::empty;
|
---|
153 |
|
---|
154 | const Item eleItem(m_operands.last()->evaluateSingleton(context));
|
---|
155 | Q_ASSERT(eleItem);
|
---|
156 |
|
---|
157 | const QXmlName::NamespaceCode ns = eleItem.asNode().namespaceForPrefix(prefix);
|
---|
158 |
|
---|
159 | if(ns == NamespaceResolver::NoBinding)
|
---|
160 | {
|
---|
161 | /* This is a bit tricky. The default namespace is not considered an in-scope binding
|
---|
162 | * on a node, but the specification for this function do consider it a binding and therefore
|
---|
163 | * the empty string. */
|
---|
164 | if(prefix == StandardPrefixes::empty)
|
---|
165 | return CommonValues::EmptyString;
|
---|
166 | else
|
---|
167 | return Item();
|
---|
168 | }
|
---|
169 | else
|
---|
170 | return toItem(AnyURI::fromValue(context->namePool()->stringForNamespace(ns)));
|
---|
171 | }
|
---|
172 |
|
---|
173 | Item::Iterator::Ptr InScopePrefixesFN::evaluateSequence(const DynamicContext::Ptr &context) const
|
---|
174 | {
|
---|
175 | const Item e(m_operands.first()->evaluateSingleton(context));
|
---|
176 |
|
---|
177 | const QVector<QXmlName> nbs(e.asNode().namespaceBindings());
|
---|
178 | const int len = nbs.size();
|
---|
179 | const NamePool::Ptr np(context->namePool());
|
---|
180 |
|
---|
181 | QList<Item> result;
|
---|
182 |
|
---|
183 | for(int i = 0; i < len; ++i)
|
---|
184 | result.append(AtomicString::fromValue(np->stringForPrefix(nbs.at(i).prefix())));
|
---|
185 |
|
---|
186 | return makeListIterator(result);
|
---|
187 | }
|
---|
188 |
|
---|
189 | QT_END_NAMESPACE
|
---|