Qt 4.8
qanyuri_p.h
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 //
43 // W A R N I N G
44 // -------------
45 //
46 // This file is not part of the Qt API. It exists purely as an
47 // implementation detail. This header file may change from version to
48 // version without notice, or even be removed.
49 //
50 // We mean it.
51 
52 #ifndef Patternist_AnyURI_H
53 #define Patternist_AnyURI_H
54 
55 #include <QUrl>
56 #include <QtDebug>
57 
58 #include "qatomicstring_p.h"
59 #include "qbuiltintypes_p.h"
60 #include "qpatternistlocale_p.h"
61 #include "qreportcontext_p.h"
62 
64 
66 
67 namespace QPatternist
68 {
82  class AnyURI : public AtomicString
83  {
84  public:
86 
93  static AnyURI::Ptr fromValue(const QString &value);
94 
95  static AnyURI::Ptr fromValue(const QUrl &uri);
96 
107  template<const ReportContext::ErrorCode code, typename TReportContext>
108  static inline QUrl toQUrl(const QString &value,
109  const TReportContext &context,
110  const SourceLocationReflection *const r,
111  bool *const isValid = 0,
112  const bool issueError = true)
113  {
114  /* QUrl doesn't flag ":/..." so we workaround it. */
115  const QString simplified(value.simplified());
116  const QUrl uri(simplified, QUrl::StrictMode);
117 
118  if(uri.isEmpty() || (uri.isValid() && (!simplified.startsWith(QLatin1Char(':')) || !uri.isRelative())))
119  {
120  if(isValid)
121  *isValid = true;
122 
123  return uri;
124  }
125  else
126  {
127  if(isValid)
128  *isValid = false;
129 
130  if(issueError)
131  {
132  context->error(QtXmlPatterns::tr("%1 is not a valid value of type %2.").arg(formatURI(value), formatType(context->namePool(), BuiltinTypes::xsAnyURI)),
133  code, r);
134  }
135 
136  return QUrl();
137  }
138  }
139 
144  static bool isValid(const QString &candidate);
145 
152  template<const ReportContext::ErrorCode code, typename TReportContext>
153  static inline AnyURI::Ptr fromLexical(const QString &value,
154  const TReportContext &context,
155  const SourceLocationReflection *const r)
156  {
157  return AnyURI::Ptr(new AnyURI(toQUrl<code>(value, context, r).toString()));
158  }
159 
164  static AnyURI::Ptr fromLexical(const QString &value);
165 
179  static AnyURI::Ptr resolveURI(const QString &relative,
180  const QString &base);
181 
182  virtual ItemType::Ptr type() const;
183 
187  inline QUrl toQUrl() const
188  {
190  qPrintable(QString::fromLatin1("%1 is apparently not ok for QUrl.").arg(m_value)));
191  return QUrl(m_value);
192  }
193  protected:
194  friend class CommonValues;
195 
196  AnyURI(const QString &value);
197  };
198 
202  static inline QString formatURI(const NamePool::Ptr &np, const QXmlName::NamespaceCode &uri)
203  {
204  return formatURI(np->stringForNamespace(uri));
205  }
206 }
207 
209 
211 
212 #endif
QExplicitlySharedDataPointer< AnyURI > Ptr
Definition: qanyuri_p.h:85
QUrl toQUrl() const
Returns this xs:anyURI value in a QUrl.
Definition: qanyuri_p.h:187
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
#define QT_BEGIN_HEADER
Definition: qglobal.h:136
qint16 NamespaceCode
Definition: qxmlname.h:82
QString formatType(const NamePool::Ptr &np, const T &type)
Formats ItemType and SequenceType.
virtual ItemType::Ptr type() const
Definition: qanyuri.cpp:73
Implements the value instance of the xs:string type.
static AnyURI::Ptr resolveURI(const QString &relative, const QString &base)
Definition: qanyuri.cpp:66
The QUrl class provides a convenient interface for working with URLs.
Definition: qurl.h:61
The QString class provides a Unicode character string.
Definition: qstring.h:83
A value of type xs:anyURI.
Definition: qanyuri_p.h:82
static const uint base
Definition: qurl.cpp:268
static QString toString(Register *reg, int type, bool *ok=0)
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
The namespace for the internal API of QtXmlPatterns.
static QUrl toQUrl(const QString &value, const TReportContext &context, const SourceLocationReflection *const r, bool *const isValid=0, const bool issueError=true)
Treates value as a lexical representation of xs:anyURI but returns the value instance as a QUrl...
Definition: qanyuri_p.h:108
static AnyURI::Ptr fromLexical(const QString &value, const TReportContext &context, const SourceLocationReflection *const r)
Constructs a xs:anyURI value from the lexical representation value.
Definition: qanyuri_p.h:153
#define Q_ASSERT_X(cond, where, what)
Definition: qglobal.h:1837
Contains functions used for formatting arguments, such as keywords and paths, in translated strings...
QString simplified() const Q_REQUIRED_RESULT
Returns a string that has whitespace removed from the start and the end, and that has each sequence o...
Definition: qstring.cpp:4415
static bool isValid(const QString &candidate)
Return true if candidate is a valid xs:anyURI, otherwise false.
Definition: qanyuri.cpp:93
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
AnyURI(const QString &value)
Definition: qanyuri.cpp:52
A collection of common values.
static QString formatURI(const NamePool::Ptr &np, const QXmlName::NamespaceCode &uri)
Formats uri, that&#39;s considered to be a URI, for display.
Definition: qanyuri_p.h:202
#define qPrintable(string)
Definition: qglobal.h:1750
#define QT_END_HEADER
Definition: qglobal.h:137
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
static const AtomicType::Ptr xsAnyURI
static AnyURI::Ptr fromValue(const QString &value)
Definition: qanyuri.cpp:56
Base class for all instances that represents something at a certain location.
#define Q_FUNC_INFO
Definition: qglobal.h:1871