source: trunk/src/xmlpatterns/utils/qxpathhelper.cpp@ 1036

Last change on this file since 1036 was 846, checked in by Dmitry A. Kuminov, 14 years ago

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

File size: 4.7 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4** All rights reserved.
5** Contact: Nokia Corporation ([email protected])
6**
7** This file is part of the QtXmlPatterns module of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:LGPL$
10** Commercial Usage
11** Licensees holding valid Qt Commercial licenses may use this file in
12** accordance with the Qt Commercial License Agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in
14** a written agreement between you and Nokia.
15**
16** GNU Lesser General Public License Usage
17** Alternatively, this file may be used under the terms of the GNU Lesser
18** General Public License version 2.1 as published by the Free Software
19** Foundation and appearing in the file LICENSE.LGPL included in the
20** packaging of this file. Please review the following information to
21** ensure the GNU Lesser General Public License version 2.1 requirements
22** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23**
24** In addition, as a special exception, Nokia gives you certain additional
25** rights. These rights are described in the Nokia Qt LGPL Exception
26** version 1.1, included in the file LGPL_EXCEPTION.txt in this 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 have questions regarding the use of this file, please contact
37** Nokia at [email protected].
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#include <QStringList>
43
44#include "private/qxmlutils_p.h"
45#include "qbuiltintypes_p.h"
46#include "qcommonvalues_p.h"
47#include "qnamepool_p.h"
48
49#include "qxpathhelper_p.h"
50
51QT_BEGIN_NAMESPACE
52
53using namespace QPatternist;
54
55bool XPathHelper::isReservedNamespace(const QXmlName::NamespaceCode ns)
56{
57 /* The order is because of that XFN and WXS are the most common. */
58 return ns == StandardNamespaces::fn ||
59 ns == StandardNamespaces::xs ||
60 ns == StandardNamespaces::xml ||
61 ns == StandardNamespaces::xsi;
62}
63
64bool XPathHelper::isQName(const QString &qName)
65{
66 const QStringList result(qName.split(QLatin1Char(':')));
67 const int c = result.count();
68
69 if(c == 2)
70 {
71 return QXmlUtils::isNCName(result.first()) &&
72 QXmlUtils::isNCName(result.last());
73 }
74 else if(c == 1)
75 return QXmlUtils::isNCName(result.first());
76 else
77 return false;
78}
79
80void XPathHelper::splitQName(const QString &qName, QString &prefix, QString &ncName)
81{
82 Q_ASSERT_X(isQName(qName), Q_FUNC_INFO,
83 "qName must be a valid QName.");
84
85 const QStringList result(qName.split(QLatin1Char(':')));
86
87 if(result.count() == 1)
88 {
89 Q_ASSERT(QXmlUtils::isNCName(result.first()));
90 ncName = result.first();
91 }
92 else
93 {
94 Q_ASSERT(result.count() == 2);
95 Q_ASSERT(QXmlUtils::isNCName(result.first()));
96 Q_ASSERT(QXmlUtils::isNCName(result.last()));
97
98 prefix = result.first();
99 ncName = result.last();
100 }
101}
102
103ItemType::Ptr XPathHelper::typeFromKind(const QXmlNodeModelIndex::NodeKind nodeKind)
104{
105 switch(nodeKind)
106 {
107 case QXmlNodeModelIndex::Element:
108 return BuiltinTypes::element;
109 case QXmlNodeModelIndex::Attribute:
110 return BuiltinTypes::attribute;
111 case QXmlNodeModelIndex::Text:
112 return BuiltinTypes::text;
113 case QXmlNodeModelIndex::ProcessingInstruction:
114 return BuiltinTypes::pi;
115 case QXmlNodeModelIndex::Comment:
116 return BuiltinTypes::comment;
117 case QXmlNodeModelIndex::Document:
118 return BuiltinTypes::document;
119 default:
120 {
121 Q_ASSERT_X(false, Q_FUNC_INFO,
122 "A node type that doesn't exist in the XPath Data Model was encountered.");
123 return ItemType::Ptr(); /* Dummy, silence compiler warning. */
124 }
125 }
126}
127
128QUrl XPathHelper::normalizeQueryURI(const QUrl &uri)
129{
130 Q_ASSERT_X(uri.isEmpty() || uri.isValid(), Q_FUNC_INFO,
131 "The URI passed to QXmlQuery::setQuery() must be valid or empty.");
132 if(uri.isEmpty())
133 return QUrl::fromLocalFile(QCoreApplication::applicationFilePath());
134 else if(uri.isRelative())
135 return QUrl::fromLocalFile(QCoreApplication::applicationFilePath()).resolved(uri);
136 else
137 return uri;
138}
139
140QT_END_NAMESPACE
Note: See TracBrowser for help on using the repository browser.