Qt 4.8
Public Types | Public Functions | Static Public Functions | Protected Functions | Friends | List of all members
QPatternist::AnyURI Class Reference

A value of type xs:anyURI. More...

#include <qanyuri_p.h>

Inheritance diagram for QPatternist::AnyURI:
QPatternist::AtomicString QPatternist::AtomicValue QSharedData QPatternist::CppCastingHelper< AtomicValue >

Public Types

typedef QExplicitlySharedDataPointer< AnyURIPtr
 
- Public Types inherited from QPatternist::AtomicString
typedef AtomicValue::Ptr Ptr
 
- Public Types inherited from QPatternist::AtomicValue
typedef QList< AtomicValue::PtrList
 
typedef QExplicitlySharedDataPointer< AtomicValuePtr
 

Public Functions

QUrl toQUrl () const
 Returns this xs:anyURI value in a QUrl. More...
 
virtual ItemType::Ptr type () const
 
- Public Functions inherited from QPatternist::AtomicString
virtual bool evaluateEBV (const QExplicitlySharedDataPointer< DynamicContext > &) const
 
virtual QString stringValue () const
 
- Public Functions inherited from QPatternist::AtomicValue
virtual bool hasError () const
 
virtual ~AtomicValue ()
 
- Public Functions inherited from QSharedData
 QSharedData ()
 Constructs a QSharedData object with a reference count of 0. More...
 
 QSharedData (const QSharedData &)
 Constructs a QSharedData object with reference count 0. More...
 
- Public Functions inherited from QPatternist::CppCastingHelper< AtomicValue >
const TCastTarget * as () const
 
TCastTarget * as ()
 

Static Public Functions

template<const ReportContext::ErrorCode code, typename TReportContext >
static AnyURI::Ptr fromLexical (const QString &value, const TReportContext &context, const SourceLocationReflection *const r)
 Constructs a xs:anyURI value from the lexical representation value. More...
 
static AnyURI::Ptr fromLexical (const QString &value)
 
static AnyURI::Ptr fromValue (const QString &value)
 
static AnyURI::Ptr fromValue (const QUrl &uri)
 
static bool isValid (const QString &candidate)
 Return true if candidate is a valid xs:anyURI, otherwise false. More...
 
static AnyURI::Ptr resolveURI (const QString &relative, const QString &base)
 
template<const ReportContext::ErrorCode code, typename TReportContext >
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. More...
 
- Static Public Functions inherited from QPatternist::AtomicString
static AtomicString::Ptr fromValue (const QString &value)
 
static AtomicString::Ptr fromValue (const QUrl &value)
 
- Static Public Functions inherited from QPatternist::AtomicValue
static ItemType::Ptr qtToXDMType (const QXmlItem &item)
 
static QVariant toQt (const AtomicValue *const value)
 
static QVariant toQt (const AtomicValue::Ptr &value)
 
static Item toXDM (const QVariant &value)
 

Protected Functions

 AnyURI (const QString &value)
 
- Protected Functions inherited from QPatternist::AtomicString
 AtomicString (const QString &value)
 
- Protected Functions inherited from QPatternist::AtomicValue
 AtomicValue ()
 
- Protected Functions inherited from QPatternist::CppCastingHelper< AtomicValue >
 CppCastingHelper ()
 

Friends

class CommonValues
 

Additional Inherited Members

- Public Variables inherited from QSharedData
QAtomicInt ref
 
- Protected Variables inherited from QPatternist::AtomicString
const QString m_value
 

Detailed Description

A value of type xs:anyURI.

Due to bugs in QUrl and slight differences in behavior and interpretation, QUrl can never be used directly for dealing with URIs, values of type xs:anyURI. Therefore, it's important to use the functionality this class provides, such as the functions toQUrl(), fromLexical(), isValid(), and resolveURI().

See also
QUrl
Author
Frans Englich frans.nosp@m..eng.nosp@m.lich@.nosp@m.noki.nosp@m.a.com

Definition at line 82 of file qanyuri_p.h.

Typedefs

◆ Ptr

Definition at line 85 of file qanyuri_p.h.

Constructors and Destructors

◆ AnyURI()

AnyURI::AnyURI ( const QString value)
protected

Definition at line 52 of file qanyuri.cpp.

Referenced by fromLexical(), and fromValue().

52  : AtomicString(s)
53 {
54 }
AtomicString(const QString &value)

Functions

◆ fromLexical() [1/2]

template<const ReportContext::ErrorCode code, typename TReportContext >
static AnyURI::Ptr QPatternist::AnyURI::fromLexical ( const QString value,
const TReportContext &  context,
const SourceLocationReflection *const  r 
)
inlinestatic

Constructs a xs:anyURI value from the lexical representation value.

If value is not a valid lexical representation of xs:anyURI, an error is issued via context.

Definition at line 153 of file qanyuri_p.h.

Referenced by QPatternist::ToAnyURICaster::castFrom(), isValidUri(), QPatternist::XsdSchemaParser::parseAppInfo(), QPatternist::XsdSchemaParser::parseDocumentation(), QPatternist::XsdSchemaParser::parseNotation(), and QPatternist::XsdSchemaParser::readXPathExpression().

156  {
157  return AnyURI::Ptr(new AnyURI(toQUrl<code>(value, context, r).toString()));
158  }
QExplicitlySharedDataPointer< AnyURI > Ptr
Definition: qanyuri_p.h:85
static QString toString(Register *reg, int type, bool *ok=0)
AnyURI(const QString &value)
Definition: qanyuri.cpp:52

◆ fromLexical() [2/2]

AnyURI::Ptr AnyURI::fromLexical ( const QString value)
static

If value is not a valid lexical representation for xs:anyURI, a ValidationError is returned.

Definition at line 78 of file qanyuri.cpp.

79 {
80  bool isValid;
81  /* The error code doesn't matter, because we never raise error. */
82  const QUrl retval(toQUrl<ReportContext::FORG0001>(value,
84  0,
85  &isValid,
86  false));
87  if(isValid)
88  return fromValue(retval);
89  else
91 }
static AtomicValue::Ptr createError(const QString &description=QString(), const ReportContext::ErrorCode=ReportContext::FORG0001)
The QUrl class provides a convenient interface for working with URLs.
Definition: qurl.h:61
static bool isValid(const QString &candidate)
Return true if candidate is a valid xs:anyURI, otherwise false.
Definition: qanyuri.cpp:93
static AnyURI::Ptr fromValue(const QString &value)
Definition: qanyuri.cpp:56

◆ fromValue() [1/2]

AnyURI::Ptr AnyURI::fromValue ( const QString value)
static

◆ fromValue() [2/2]

AnyURI::Ptr AnyURI::fromValue ( const QUrl uri)
static

Definition at line 61 of file qanyuri.cpp.

62 {
63  return AnyURI::Ptr(new AnyURI(uri.toString()));
64 }
QExplicitlySharedDataPointer< AnyURI > Ptr
Definition: qanyuri_p.h:85
QString toString(FormattingOptions options=None) const
Returns the human-displayable string representation of the URL.
Definition: qurl.cpp:5896
AnyURI(const QString &value)
Definition: qanyuri.cpp:52

◆ isValid()

bool AnyURI::isValid ( const QString candidate)
static

Return true if candidate is a valid xs:anyURI, otherwise false.

Definition at line 93 of file qanyuri.cpp.

Referenced by fromLexical(), toQUrl(), and QPatternist::yyparse().

94 {
95  bool isOk = false;
96  /* The error code doesn't matter, because we never raise error. */
97  toQUrl<ReportContext::FORG0001>(candidate,
99  0,
100  &isOk,
101  false);
102  return isOk;
103 }
QExplicitlySharedDataPointer< ReportContext > Ptr

◆ resolveURI()

AnyURI::Ptr AnyURI::resolveURI ( const QString relative,
const QString base 
)
static

Creates an AnyURI instance representing an absolute URI which is created from resolving relative against base.

This function must be compatible with the resolution semantics specified for fn:resolve-uri. In fact, the implementation of fn:resolve-uri, ResourceURIFN, relies on this function.

See also
RFC 3986 - Uniform Resource Identifier (URI): Generic Syntax
XQuery 1.0 and XPath 2.0 Functions and Operators, 8.1 fn:resolve-uri

Definition at line 66 of file qanyuri.cpp.

Referenced by fromLexical().

68 {
69  const QUrl urlBase(base);
70  return AnyURI::fromValue(urlBase.resolved(relative).toString());
71 }
The QUrl class provides a convenient interface for working with URLs.
Definition: qurl.h:61
static AnyURI::Ptr fromValue(const QString &value)
Definition: qanyuri.cpp:56

◆ toQUrl() [1/2]

template<const ReportContext::ErrorCode code, typename TReportContext >
static QUrl QPatternist::AnyURI::toQUrl ( const QString value,
const TReportContext &  context,
const SourceLocationReflection *const  r,
bool *const  isValid = 0,
const bool  issueError = true 
)
inlinestatic

Treates value as a lexical representation of xs:anyURI but returns the value instance as a QUrl.

If value is not a valid lexical representation of xs:anyURI, an error is issued via context.

If isValid is passed, no error is raised and it is instead set appropriately.

Definition at line 108 of file qanyuri_p.h.

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  }
QString formatType(const NamePool::Ptr &np, const T &type)
Formats ItemType and SequenceType.
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
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 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
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
static const AtomicType::Ptr xsAnyURI

◆ toQUrl() [2/2]

QUrl QPatternist::AnyURI::toQUrl ( ) const
inline

Returns this xs:anyURI value in a QUrl.

Definition at line 187 of file qanyuri_p.h.

188  {
190  qPrintable(QString::fromLatin1("%1 is apparently not ok for QUrl.").arg(m_value)));
191  return QUrl(m_value);
192  }
The QUrl class provides a convenient interface for working with URLs.
Definition: qurl.h:61
#define Q_ASSERT_X(cond, where, what)
Definition: qglobal.h:1837
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
#define qPrintable(string)
Definition: qglobal.h:1750
#define Q_FUNC_INFO
Definition: qglobal.h:1871

◆ type()

ItemType::Ptr AnyURI::type ( ) const
virtual

Reimplemented from QPatternist::AtomicString.

Definition at line 73 of file qanyuri.cpp.

Referenced by fromLexical().

74 {
76 }
static const AtomicType::Ptr xsAnyURI

Friends and Related Functions

◆ CommonValues

friend class CommonValues
friend

Definition at line 194 of file qanyuri_p.h.


The documentation for this class was generated from the following files: