Qt 4.8
Public Types | Public Functions | Static Public Functions | Private Functions | Static Private Functions | Properties | List of all members
QPatternist::AccelTreeResourceLoader Class Reference

Handles requests for documents, and instantiates them as AccelTree instances. More...

#include <qacceltreeresourceloader_p.h>

Inheritance diagram for QPatternist::AccelTreeResourceLoader:
QPatternist::DeviceResourceLoader QPatternist::ResourceLoader QSharedData

Public Types

enum  ErrorHandling { FailOnError, ContinueOnError }
 
- Public Types inherited from QPatternist::DeviceResourceLoader
typedef QExplicitlySharedDataPointer< DeviceResourceLoaderPtr
 
- Public Types inherited from QPatternist::ResourceLoader
typedef QExplicitlySharedDataPointer< ResourceLoaderPtr
 
enum  Usage { MayUse, WillUse }
 

Public Functions

 AccelTreeResourceLoader (const NamePool::Ptr &np, const NetworkAccessDelegator::Ptr &networkDelegator, AccelTreeBuilder< true >::Features=AccelTreeBuilder< true >::NoneFeature)
 
virtual SequenceType::Ptr announceDocument (const QUrl &uri, const Usage usageHint)
 May be called by the compilation framework at compile time to report that an XML document referenced by uri will be loaded at runtime. More...
 
virtual void clear (const QUrl &uri)
 Asks to unload uri from its document pool, such that a subsequent request will require a new read. More...
 
virtual QSet< QUrldeviceURIs () const
 Returns the URIs this AccelTreeResourceLoader has loaded which are for devices through variable bindings. More...
 
virtual bool isDocumentAvailable (const QUrl &uri)
 Calls to this function are generated by calls to the fn:doc-available() function. More...
 
virtual bool isUnparsedTextAvailable (const QUrl &uri, const QString &encoding)
 Calls to this function are generated by calls to the fn:unparsed-text-available() function. More...
 
virtual Item openDocument (const QUrl &uri, const ReportContext::Ptr &context)
 Calls to this function are generated by calls to the fn:document() or fn:doc() function. More...
 
virtual Item openDocument (QIODevice *source, const QUrl &documentUri, const ReportContext::Ptr &context)
 
virtual Item openUnparsedText (const QUrl &uri, const QString &encoding, const ReportContext::Ptr &context, const SourceLocationReflection *const where)
 Calls to this function are generated by calls to the fn:unparsed-text() function. More...
 
- Public Functions inherited from QPatternist::ResourceLoader
virtual SequenceType::Ptr announceCollection (const QUrl &uri)
 May be called by the compilation framework at compile time to report that an node collection referenced by uri will be loaded at runtime. More...
 
virtual ItemType::Ptr announceUnparsedText (const QUrl &uri)
 May be called by the compilation framework at compile time to report that an unparsed text(plain text) file referenced by uri will be loaded at runtime. More...
 
virtual Item::Iterator::Ptr openCollection (const QUrl &uri)
 Calls to this function are generated by calls to the fn:collection() function. More...
 
 ResourceLoader ()
 
virtual ~ResourceLoader ()
 
- 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...
 

Static Public Functions

static QNetworkReplyload (const QUrl &uri, QNetworkAccessManager *const networkManager, const ReportContext::Ptr &context, ErrorHandling handling=FailOnError)
 Helper function that do NetworkAccessDelegator::get(), but does it blocked. More...
 
static QNetworkReplyload (const QUrl &uri, const NetworkAccessDelegator::Ptr &networkDelegator, const ReportContext::Ptr &context, ErrorHandling handling=FailOnError)
 

Private Functions

bool retrieveDocument (const QUrl &uri, const ReportContext::Ptr &context)
 
bool retrieveDocument (QIODevice *source, const QUrl &documentUri, const ReportContext::Ptr &context)
 
bool retrieveUnparsedText (const QUrl &uri, const QString &encoding, const ReportContext::Ptr &context, const SourceLocationReflection *const where)
 

Static Private Functions

static bool streamToReceiver (QIODevice *const dev, AccelTreeBuilder< true > *const receiver, const NamePool::Ptr &np, const ReportContext::Ptr &context, const QUrl &uri)
 

Properties

AccelTreeBuilder< true >::Features m_features
 
QHash< QUrl, AccelTree::Ptrm_loadedDocuments
 
const NamePool::Ptr m_namePool
 
const NetworkAccessDelegator::Ptr m_networkAccessDelegator
 
QHash< QPair< QUrl, QString >, QStringm_unparsedTexts
 

Additional Inherited Members

- Public Variables inherited from QSharedData
QAtomicInt ref
 

Detailed Description

Handles requests for documents, and instantiates them as AccelTree instances.

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

Definition at line 114 of file qacceltreeresourceloader_p.h.

Enumerations

◆ ErrorHandling

Describes the behaviour of the resource loader in case of an error.

Enumerator
FailOnError 

The resource loader will report the error via the report context.

ContinueOnError 

The resource loader will report no error and return an empty QNetworkReply.

Definition at line 121 of file qacceltreeresourceloader_p.h.

122  {
123  FailOnError,
125  };
The resource loader will report no error and return an empty QNetworkReply.
The resource loader will report the error via the report context.

Constructors and Destructors

◆ AccelTreeResourceLoader()

AccelTreeResourceLoader::AccelTreeResourceLoader ( const NamePool::Ptr np,
const NetworkAccessDelegator::Ptr networkDelegator,
AccelTreeBuilder< true >::Features  features = AccelTreeBuilder<true>::NoneFeature 
)

AccelTreeResourceLoader does not own context.

Definition at line 59 of file qacceltreeresourceloader.cpp.

62  : m_namePool(np)
63  , m_networkAccessDelegator(manager)
64  , m_features(features)
65 {
68 }
const NetworkAccessDelegator::Ptr m_networkAccessDelegator
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
AccelTreeBuilder< true >::Features m_features

Functions

◆ announceDocument()

SequenceType::Ptr AccelTreeResourceLoader::announceDocument ( const QUrl uri,
const Usage  usageHint 
)
virtual

May be called by the compilation framework at compile time to report that an XML document referenced by uri will be loaded at runtime.

This function can be called an arbitrary amount of times for the same URI, but different usageHint values. How many times it is called for a URI has no meaning(beyond the first call, that is). For what queries the compilation framework can determine what always will be loaded is generally undefined. It depends on factors such as the complexity of the query, what information that is statically available and subsequently what optimizations that can be applied.

Calls to this function are generated by calls to the fn:document() or fn:doc() function.

Parameters
uriA URI identifying the resource to retrieve. The URI is guaranteed to be valid(QUrl::isValid() returns true) and to be absolute(QUrl::isRelative() returns false).
usageHintA hint to how the URI will be used.
Returns
  • null if the ResourceLoader can determine at this stage that no document referenced by uri will ever be possible to load.
  • The appropriate sequence type if loading uri succeeds at runtime. This must be CommonSequenceTypes::zeroOrOneDocument, CommonSequenceTypes::exactlyOneDocument or a sequence type that is a sub type of it.
See also
XQuery 1.0 and XPath 2.0 Functions and Operators, 15.5.4 fn:doc
XSL Transformations (XSLT) Version 2.0, 16.1 Multiple Source Documents

Reimplemented from QPatternist::ResourceLoader.

Definition at line 296 of file qacceltreeresourceloader.cpp.

297 {
298  // TODO deal with the usage thingy
299  Q_ASSERT(uri.isValid());
300  Q_ASSERT(!uri.isRelative());
301  Q_UNUSED(uri); /* Needed when compiling in release mode. */
302 
304 }
bool isValid() const
Returns true if the URL is valid; otherwise returns false.
Definition: qurl.cpp:4303
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
bool isRelative() const
Returns true if the URL is relative; otherwise returns false.
Definition: qurl.cpp:5880
static const SequenceType::Ptr ZeroOrOneDocumentNode
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729

◆ clear()

void AccelTreeResourceLoader::clear ( const QUrl uri)
virtual

Asks to unload uri from its document pool, such that a subsequent request will require a new read.

The default implementation does nothing.

Reimplemented from QPatternist::ResourceLoader.

Definition at line 435 of file qacceltreeresourceloader.cpp.

436 {
437  m_loadedDocuments.remove(uri);
438 }
QHash< QUrl, AccelTree::Ptr > m_loadedDocuments

◆ deviceURIs()

QSet< QUrl > AccelTreeResourceLoader::deviceURIs ( ) const
virtual

Returns the URIs this AccelTreeResourceLoader has loaded which are for devices through variable bindings.

Implements QPatternist::DeviceResourceLoader.

Definition at line 418 of file qacceltreeresourceloader.cpp.

419 {
422  QSet<QUrl> retval;
423 
424  while (it != end)
425  {
426  if(it.key().toString().startsWith(QLatin1String("tag:trolltech.com,2007:QtXmlPatterns:QIODeviceVariable:")))
427  retval.insert(it.key());
428 
429  ++it;
430  }
431 
432  return retval;
433 }
The QHash::const_iterator class provides an STL-style const iterator for QHash and QMultiHash...
Definition: qhash.h:395
#define it(className, varName)
QHash< QUrl, AccelTree::Ptr > m_loadedDocuments
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
Definition: qhash.h:753
static const KeyPair *const end

◆ isDocumentAvailable()

bool AccelTreeResourceLoader::isDocumentAvailable ( const QUrl uri)
virtual

Calls to this function are generated by calls to the fn:doc-available() function.

Parameters
uriA URI identifying the resource to retrieve. The URI is guaranteed to be valid(QUrl::isValid() returns true) and to be absolute(QUrl::isRelative() returns false).
Returns
true if calling openDocument() while passing uri will successfully load the document.
See also
XQuery 1.0 and XPath 2.0 Functions and Operators, 15.5.5 fn:doc-available
XSL Transformations (XSLT) Version 2.0, 16.1 Multiple Source Documents

Reimplemented from QPatternist::ResourceLoader.

Definition at line 306 of file qacceltreeresourceloader.cpp.

307 {
308  return retrieveDocument(uri, ReportContext::Ptr());
309 }
The QExplicitlySharedDataPointer class represents a pointer to an explicitly shared object...
Definition: qshareddata.h:136
bool retrieveDocument(const QUrl &uri, const ReportContext::Ptr &context)

◆ isUnparsedTextAvailable()

bool AccelTreeResourceLoader::isUnparsedTextAvailable ( const QUrl uri,
const QString encoding 
)
virtual

Calls to this function are generated by calls to the fn:unparsed-text-available() function.

Parameters
uriA URI identifying the resource to retrieve. The URI is guaranteed to be valid(QUrl::isValid() returns true) and to be absolute(QUrl::isRelative() returns false).
Returns
true if calling openUnparsedText() while passing uri will successfully load the document.
See also
XSL Transformations (XSLT) Version 2.0, 16.2 Reading Text Files

Reimplemented from QPatternist::ResourceLoader.

Definition at line 394 of file qacceltreeresourceloader.cpp.

396 {
397  return retrieveUnparsedText(uri, encoding, ReportContext::Ptr(), 0);
398 }
The QExplicitlySharedDataPointer class represents a pointer to an explicitly shared object...
Definition: qshareddata.h:136
bool retrieveUnparsedText(const QUrl &uri, const QString &encoding, const ReportContext::Ptr &context, const SourceLocationReflection *const where)

◆ load() [1/2]

QNetworkReply * AccelTreeResourceLoader::load ( const QUrl uri,
QNetworkAccessManager *const  networkManager,
const ReportContext::Ptr context,
ErrorHandling  handling = FailOnError 
)
static

Helper function that do NetworkAccessDelegator::get(), but does it blocked.

The returned QNetworkReply has emitted QNetworkReply::finished().

The caller owns the return QIODevice instance.

context may be null or valid. If null, no error reporting is done and null is returned.

See also
NetworkAccessDelegator

Definition at line 113 of file qacceltreeresourceloader.cpp.

Referenced by QXmlSchemaPrivate::load(), load(), QPatternist::XsdValidatingInstanceReader::loadSchema(), QPatternist::XsdSchemaParser::parseImport(), QPatternist::XsdSchemaParser::parseInclude(), QPatternist::XsdSchemaParser::parseRedefine(), retrieveDocument(), retrieveUnparsedText(), QXmlQuery::setQuery(), and QXmlSchemaValidator::validate().

117 {
118  Q_ASSERT(networkManager);
119  Q_ASSERT(uri.isValid());
120 
121  NetworkLoop networkLoop;
122 
123  QNetworkRequest request(uri);
124  QNetworkReply *const reply = networkManager->get(request);
126  networkLoop.connect(reply, SIGNAL(finished()), SLOT(finished()));
127 
128  if(networkLoop.exec(QEventLoop::ExcludeUserInputEvents))
129  {
130  const QString errorMessage(escape(reply->errorString()));
131 
132  /* Note, we delete reply before we exit this function with error(). */
133  delete reply;
134 
135  const QSourceLocation location(uri);
136 
137  if(context && (errorHandling == FailOnError))
138  context->error(errorMessage, ReportContext::FODC0002, location);
139 
140  return 0;
141  }
142  else
143  return reply;
144 }
bool isValid() const
Returns true if the URL is valid; otherwise returns false.
Definition: qurl.cpp:4303
QString Q_AUTOTEST_EXPORT escape(const QString &input)
Similar to Qt::escape(), but also escapes apostrophes and quotes, such that the result is suitable as...
#define error(msg)
The QNetworkReply class contains the data and headers for a request sent with QNetworkAccessManager.
Definition: qnetworkreply.h:65
#define SLOT(a)
Definition: qobjectdefs.h:226
QString errorString() const
Returns a human-readable description of the last device error that occurred.
Definition: qiodevice.cpp:1671
NetworkError
Indicates all possible error conditions found during the processing of the request.
Definition: qnetworkreply.h:70
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
#define SIGNAL(a)
Definition: qobjectdefs.h:227
An helper class which enables QNetworkAccessManager to be used in a blocking manner.
static bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
Creates a connection of the given type from the signal in the sender object to the method in the rece...
Definition: qobject.cpp:2580
The QSourceLocation class identifies a location in a resource by URI, line, and column.
QNetworkReply * get(const QNetworkRequest &request)
Posts a request to obtain the contents of the target request and returns a new QNetworkReply object o...
static QTestResult::TestLocation location
Definition: qtestresult.cpp:63
The QNetworkRequest class holds a request to be sent with QNetworkAccessManager.
The resource loader will report the error via the report context.

◆ load() [2/2]

QNetworkReply * AccelTreeResourceLoader::load ( const QUrl uri,
const NetworkAccessDelegator::Ptr networkDelegator,
const ReportContext::Ptr context,
ErrorHandling  handling = FailOnError 
)
static

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 104 of file qacceltreeresourceloader.cpp.

107 {
108  return load(uri,
109  networkDelegator->managerFor(uri),
110  context, errorHandling);
111 }
QNetworkAccessManager * managerFor(const QUrl &uri)
static QNetworkReply * load(const QUrl &uri, QNetworkAccessManager *const networkManager, const ReportContext::Ptr &context, ErrorHandling handling=FailOnError)
Helper function that do NetworkAccessDelegator::get(), but does it blocked.

◆ openDocument() [1/2]

Item AccelTreeResourceLoader::openDocument ( const QUrl uri,
const ReportContext::Ptr context 
)
virtual

Calls to this function are generated by calls to the fn:document() or fn:doc() function.

Note
This function is responsible for execution stability. Subsequent calls to this function with the same URI should result in QXmlNodeModelIndex instances that have the same identity. However, in some cases this stability is not of interest, see the specification for details.
Parameters
uriA URI identifying the resource to retrieve. The URI is guaranteed to be valid(QUrl::isValid() returns true) and to be absolute(QUrl::isRelative() returns false).
See also
QXmlNodeModelIndex::identity()
XQuery 1.0 and XPath 2.0 Functions and Operators, 15.5.4 fn:doc
XSL Transformations (XSLT) Version 2.0, 16.1 Multiple Source Documents
Returns

Reimplemented from QPatternist::ResourceLoader.

Definition at line 264 of file qacceltreeresourceloader.cpp.

266 {
267  const AccelTree::Ptr doc(m_loadedDocuments.value(uri));
268 
269  if(doc)
270  return doc->root(QXmlNodeModelIndex()); /* Pass in dummy object. We know AccelTree doesn't use it. */
271  else
272  {
273  if(retrieveDocument(uri, context))
274  return m_loadedDocuments.value(uri)->root(QXmlNodeModelIndex()); /* Pass in dummy object. We know AccelTree doesn't use it. */
275  else
276  return Item();
277  }
278 }
The QXmlNodeModelIndex class identifies a node in an XML node model subclassed from QAbstractXmlNodeM...
QHash< QUrl, AccelTree::Ptr > m_loadedDocuments
virtual QXmlNodeModelIndex root(const QXmlNodeModelIndex &n) const
Returns the root node.
Definition: qacceltree.cpp:236
Represents an item in the XPath 2.0 Data Model.
Definition: qitem_p.h:182
bool retrieveDocument(const QUrl &uri, const ReportContext::Ptr &context)

◆ openDocument() [2/2]

Item AccelTreeResourceLoader::openDocument ( QIODevice source,
const QUrl documentUri,
const ReportContext::Ptr context 
)
virtual

Definition at line 280 of file qacceltreeresourceloader.cpp.

282 {
283  const AccelTree::Ptr doc(m_loadedDocuments.value(documentUri));
284 
285  if(doc)
286  return doc->root(QXmlNodeModelIndex()); /* Pass in dummy object. We know AccelTree doesn't use it. */
287  else
288  {
289  if(retrieveDocument(source, documentUri, context))
290  return m_loadedDocuments.value(documentUri)->root(QXmlNodeModelIndex()); /* Pass in dummy object. We know AccelTree doesn't use it. */
291  else
292  return Item();
293  }
294 }
The QXmlNodeModelIndex class identifies a node in an XML node model subclassed from QAbstractXmlNodeM...
QHash< QUrl, AccelTree::Ptr > m_loadedDocuments
virtual QXmlNodeModelIndex root(const QXmlNodeModelIndex &n) const
Returns the root node.
Definition: qacceltree.cpp:236
Represents an item in the XPath 2.0 Data Model.
Definition: qitem_p.h:182
bool retrieveDocument(const QUrl &uri, const ReportContext::Ptr &context)

◆ openUnparsedText()

Item AccelTreeResourceLoader::openUnparsedText ( const QUrl uri,
const QString encoding,
const ReportContext::Ptr context,
const SourceLocationReflection *const  where 
)
virtual

Calls to this function are generated by calls to the fn:unparsed-text() function.

Parameters
uriA URI identifying the resource to retrieve. The URI is guaranteed to be valid(QUrl::isValid() returns true) and to be absolute(QUrl::isRelative() returns false).
encodingthe encoding to use. If empty, the user hasn't expressed any encoding to use.
See also
XSL Transformations (XSLT) Version 2.0, 16.2 Reading Text Files
Returns
  • null if no unparsed file can be loaded for uri
  • An xs:string value(or subtype) containing the content of the file identified by uri as text. Remember that its type must match the sequence type returned by announceUnparsedText()

Reimplemented from QPatternist::ResourceLoader.

Definition at line 400 of file qacceltreeresourceloader.cpp.

404 {
405  const QString &text = m_unparsedTexts.value(qMakePair(uri, encoding));
406 
407  if(text.isNull())
408  {
409  if(retrieveUnparsedText(uri, encoding, context, where))
410  return openUnparsedText(uri, encoding, context, where);
411  else
412  return Item();
413  }
414  else
415  return AtomicString::fromValue(text);
416 }
The QString class provides a Unicode character string.
Definition: qstring.h:83
static AtomicString::Ptr fromValue(const QString &value)
const T value(const Key &key) const
Returns the value associated with the key.
Definition: qhash.h:606
virtual Item openUnparsedText(const QUrl &uri, const QString &encoding, const ReportContext::Ptr &context, const SourceLocationReflection *const where)
Calls to this function are generated by calls to the fn:unparsed-text() function. ...
bool retrieveUnparsedText(const QUrl &uri, const QString &encoding, const ReportContext::Ptr &context, const SourceLocationReflection *const where)
bool isNull() const
Returns true if this string is null; otherwise returns false.
Definition: qstring.h:505
QHash< QPair< QUrl, QString >, QString > m_unparsedTexts
Represents an item in the XPath 2.0 Data Model.
Definition: qitem_p.h:182
Q_OUTOFLINE_TEMPLATE QPair< T1, T2 > qMakePair(const T1 &x, const T2 &y)
Definition: qpair.h:102
#define text
Definition: qobjectdefs.h:80

◆ retrieveDocument() [1/2]

bool AccelTreeResourceLoader::retrieveDocument ( const QUrl uri,
const ReportContext::Ptr context 
)
private

Definition at line 70 of file qacceltreeresourceloader.cpp.

Referenced by isDocumentAvailable(), and openDocument().

72 {
73  Q_ASSERT(uri.isValid());
74  AccelTreeBuilder<true> builder(uri, uri, m_namePool, context.data(), m_features);
75 
76  const AutoPtr<QNetworkReply> reply(load(uri, m_networkAccessDelegator, context));
77 
78  if(!reply)
79  return false;
80 
81  bool success = false;
82  success = streamToReceiver(reply.data(), &builder, m_namePool, context, uri);
83 
84  m_loadedDocuments.insert(uri, builder.builtDocument());
85  return success;
86 }
bool isValid() const
Returns true if the URL is valid; otherwise returns false.
Definition: qurl.cpp:4303
QHash< QUrl, AccelTree::Ptr > m_loadedDocuments
A smart pointer very similar to std::auto_ptr.
Definition: qautoptr_p.h:73
const NetworkAccessDelegator::Ptr m_networkAccessDelegator
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
T * data() const
Returns a pointer to the shared data object.
Definition: qshareddata.h:145
static QNetworkReply * load(const QUrl &uri, QNetworkAccessManager *const networkManager, const ReportContext::Ptr &context, ErrorHandling handling=FailOnError)
Helper function that do NetworkAccessDelegator::get(), but does it blocked.
AccelTreeBuilder< true >::Features m_features
static bool streamToReceiver(QIODevice *const dev, AccelTreeBuilder< true > *const receiver, const NamePool::Ptr &np, const ReportContext::Ptr &context, const QUrl &uri)

◆ retrieveDocument() [2/2]

bool AccelTreeResourceLoader::retrieveDocument ( QIODevice source,
const QUrl documentUri,
const ReportContext::Ptr context 
)
private

Definition at line 88 of file qacceltreeresourceloader.cpp.

89 {
90  Q_ASSERT(source);
91  Q_ASSERT(source->isReadable());
92  Q_ASSERT(documentUri.isValid());
93 
94  AccelTreeBuilder<true> builder(documentUri, documentUri, m_namePool, context.data(), m_features);
95 
96  bool success = false;
97  success = streamToReceiver(source, &builder, m_namePool, context, documentUri);
98 
99  m_loadedDocuments.insert(documentUri, builder.builtDocument());
100 
101  return success;
102 }
bool isValid() const
Returns true if the URL is valid; otherwise returns false.
Definition: qurl.cpp:4303
bool isReadable() const
Returns true if data can be read from the device; otherwise returns false.
Definition: qiodevice.cpp:544
QHash< QUrl, AccelTree::Ptr > m_loadedDocuments
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
T * data() const
Returns a pointer to the shared data object.
Definition: qshareddata.h:145
AccelTreeBuilder< true >::Features m_features
static bool streamToReceiver(QIODevice *const dev, AccelTreeBuilder< true > *const receiver, const NamePool::Ptr &np, const ReportContext::Ptr &context, const QUrl &uri)

◆ retrieveUnparsedText()

bool AccelTreeResourceLoader::retrieveUnparsedText ( const QUrl uri,
const QString encoding,
const ReportContext::Ptr context,
const SourceLocationReflection *const  where 
)
private

If context is null, no error reporting should be done.

Definition at line 317 of file qacceltreeresourceloader.cpp.

Referenced by isUnparsedTextAvailable(), and openUnparsedText().

321 {
322  const AutoPtr<QNetworkReply> reply(load(uri, m_networkAccessDelegator, context));
323 
324  if(!reply)
325  return false;
326 
327  const QTextCodec * codec;
328  if(encoding.isEmpty())
329  {
330  /* XSL Transformations (XSLT) Version 2.0 16.2 Reading Text Files:
331  *
332  * "if the media type of the resource is text/xml or application/xml
333  * (see [RFC2376]), or if it matches the conventions text/\*+xml or
334  * application/\*+xml (see [RFC3023] and/or its successors), then the
335  * encoding is recognized as specified in [XML 1.0]"
336  */
337  codec = QTextCodec::codecForMib(106);
338  }
339  else
340  {
341  codec = QTextCodec::codecForName(encoding.toLatin1());
342  if(codec && context)
343  {
344  context->error(QtXmlPatterns::tr("%1 is an unsupported encoding.").arg(formatURI(encoding)),
346  where);
347  }
348  else
349  return false;
350  }
351 
352  QTextCodec::ConverterState converterState;
353  const QByteArray inData(reply->readAll());
354  const QString result(codec->toUnicode(inData.constData(), inData.length(), &converterState));
355 
356  if(converterState.invalidChars)
357  {
358  if(context)
359  {
360  context->error(QtXmlPatterns::tr("%1 contains octets which are disallowed in "
361  "the requested encoding %2.").arg(formatURI(uri),
362  formatURI(encoding)),
364  where);
365  }
366  else
367  return false;
368  }
369 
370  const int len = result.length();
371  /* This code is a candidate for threading. Divide and conqueror. */
372  for(int i = 0; i < len; ++i)
373  {
374  if(!QXmlUtils::isChar(result.at(i)))
375  {
376  if(context)
377  {
378  context->error(QtXmlPatterns::tr("The codepoint %1, occurring in %2 using encoding %3, "
379  "is an invalid XML character.").arg(formatData(result.at(i)),
380  formatURI(uri),
381  formatURI(encoding)),
383  where);
384  }
385  else
386  return false;
387  }
388  }
389 
390  m_unparsedTexts.insert(qMakePair(uri, encoding), result);
391  return true;
392 }
A smart pointer very similar to std::auto_ptr.
Definition: qautoptr_p.h:73
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
const NetworkAccessDelegator::Ptr m_networkAccessDelegator
static bool isChar(const QChar c)
Determines whether c is a valid instance of production [2]Char in the XML 1.0 specification.
Definition: qxmlutils.cpp:271
The QString class provides a Unicode character string.
Definition: qstring.h:83
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
Definition: qhash.h:753
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
static QTextCodec * codec(MYSQL *mysql)
Definition: qsql_mysql.cpp:220
static QTextCodec * codecForMib(int mib)
Returns the QTextCodec which matches the MIBenum mib.
QByteArray toLatin1() const Q_REQUIRED_RESULT
Returns a Latin-1 representation of the string as a QByteArray.
Definition: qstring.cpp:3993
static QString formatData(const QString &data)
static QNetworkReply * load(const QUrl &uri, QNetworkAccessManager *const networkManager, const ReportContext::Ptr &context, ErrorHandling handling=FailOnError)
Helper function that do NetworkAccessDelegator::get(), but does it blocked.
QString toUnicode(const QByteArray &) const
Converts a from the encoding of this codec to Unicode, and returns the result in a QString...
QHash< QPair< QUrl, QString >, QString > m_unparsedTexts
Q_OUTOFLINE_TEMPLATE QPair< T1, T2 > qMakePair(const T1 &x, const T2 &y)
Definition: qpair.h:102
static QTextCodec * codecForName(const QByteArray &name)
Searches all installed QTextCodec objects and returns the one which best matches name; the match is c...
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 QTextCodec class provides conversions between text encodings.
Definition: qtextcodec.h:62

◆ streamToReceiver()

bool AccelTreeResourceLoader::streamToReceiver ( QIODevice *const  dev,
AccelTreeBuilder< true > *const  receiver,
const NamePool::Ptr np,
const ReportContext::Ptr context,
const QUrl uri 
)
staticprivate

Definition at line 146 of file qacceltreeresourceloader.cpp.

Referenced by retrieveDocument().

151 {
152  Q_ASSERT(dev);
153  Q_ASSERT(receiver);
154  Q_ASSERT(np);
155 
156  QXmlStreamReader reader(dev);
157 
158  /* Optimize: change NamePool to take QStringRef such that we don't have to call toString() below. That
159  * will save us a gazillion of temporary QStrings. */
160 
161  while(!reader.atEnd())
162  {
163  reader.readNext();
164 
165  switch(reader.tokenType())
166  {
168  {
169  /* Send the name. */
170  receiver->startElement(np->allocateQName(reader.namespaceUri().toString(), reader.name().toString(),
171  reader.prefix().toString()), reader.lineNumber(), reader.columnNumber());
172 
173  /* Send namespace declarations. */
174  const QXmlStreamNamespaceDeclarations &nss = reader.namespaceDeclarations();
175 
176  /* The far most common case, is for it to be empty. */
177  if(!nss.isEmpty())
178  {
179  const int len = nss.size();
180 
181  for(int i = 0; i < len; ++i)
182  {
183  const QXmlStreamNamespaceDeclaration &ns = nss.at(i);
184  receiver->namespaceBinding(np->allocateBinding(ns.prefix().toString(), ns.namespaceUri().toString()));
185  }
186  }
187 
188  /* Send attributes. */
189  const QXmlStreamAttributes &attrs = reader.attributes();
190  const int len = attrs.size();
191 
192  for(int i = 0; i < len; ++i)
193  {
194  const QXmlStreamAttribute &attr = attrs.at(i);
195 
196  receiver->attribute(np->allocateQName(attr.namespaceUri().toString(), attr.name().toString(),
197  attr.prefix().toString()),
198  attr.value());
199  }
200 
201  continue;
202  }
204  {
205  receiver->endElement();
206  continue;
207  }
209  {
210  if(reader.isWhitespace())
211  receiver->whitespaceOnly(reader.text());
212  else
213  receiver->characters(reader.text());
214 
215  continue;
216  }
218  {
219  receiver->comment(reader.text().toString());
220  continue;
221  }
223  {
224  receiver->processingInstruction(np->allocateQName(QString(), reader.processingInstructionTarget().toString()),
225  reader.processingInstructionData().toString());
226  continue;
227  }
229  {
230  receiver->startDocument();
231  continue;
232  }
234  {
235  receiver->endDocument();
236  continue;
237  }
239  /* Fallthrough. */
241  {
242  /* We just ignore any DTD and entity references. */
243  continue;
244  }
246  {
247  if(context)
248  context->error(escape(reader.errorString()), ReportContext::FODC0002, QSourceLocation(uri, reader.lineNumber(), reader.columnNumber()));
249 
250  return false;
251  }
253  {
254  Q_ASSERT_X(false, Q_FUNC_INFO,
255  "This token is never expected to be received.");
256  return false;
257  }
258  }
259  }
260 
261  return true;
262 }
QString toString() const
Returns a copy of the string reference as a QString object.
Definition: qstring.cpp:8653
QString Q_AUTOTEST_EXPORT escape(const QString &input)
Similar to Qt::escape(), but also escapes apostrophes and quotes, such that the result is suitable as...
virtual void whitespaceOnly(const QStringRef &ch)
QXmlName allocateBinding(const QString &prefix, const QString &uri)
Allocates a namespace binding for prefix and uri.
Definition: qnamepool.cpp:275
QStringRef value() const
Returns the attribute&#39;s value.
Definition: qxmlstream.h:156
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
The QXmlStreamAttribute class represents a single XML attribute.
Definition: qxmlstream.h:135
virtual void startElement(const QXmlName &name)
virtual void namespaceBinding(const QXmlName &nb)
Signals the presence of the namespace declaration nb.
virtual void processingInstruction(const QXmlName &target, const QString &data)
The QSourceLocation class identifies a location in a resource by URI, line, and column.
QStringRef namespaceUri() const
Returns the namespaceUri.
Definition: qxmlstream.h:216
QStringRef prefix() const
Returns the prefix.
Definition: qxmlstream.h:215
QStringRef name() const
Returns the attribute&#39;s local name.
Definition: qxmlstream.h:149
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
The QXmlStreamNamespaceDeclaration class represents a namespace declaration.
Definition: qxmlstream.h:204
virtual void comment(const QString &content)
#define Q_ASSERT_X(cond, where, what)
Definition: qglobal.h:1837
virtual void endElement()
Signals the end of the current element.
The QXmlStreamAttributes class represents a vector of QXmlStreamAttribute.
Definition: qxmlstream.h:169
virtual void attribute(const QXmlName &name, const QStringRef &value)
virtual void characters(const QStringRef &ch)
QStringRef prefix() const
Returns the attribute&#39;s namespace prefix.
Definition: qxmlstream.h:151
QXmlName allocateQName(const QString &uri, const QString &localName, const QString &prefix=QString())
Definition: qnamepool.cpp:251
bool isEmpty() const
Returns true if the vector has size 0; otherwise returns false.
Definition: qvector.h:139
The QXmlStreamReader class provides a fast parser for reading well-formed XML via a simple streaming ...
Definition: qxmlstream.h:290
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137
#define Q_FUNC_INFO
Definition: qglobal.h:1871
QStringRef namespaceUri() const
Returns the attribute&#39;s resolved namespaceUri, or an empty string reference if the attribute does not...
Definition: qxmlstream.h:148

Properties

◆ m_features

AccelTreeBuilder<true>::Features QPatternist::AccelTreeResourceLoader::m_features
private

Definition at line 202 of file qacceltreeresourceloader_p.h.

Referenced by retrieveDocument().

◆ m_loadedDocuments

QHash<QUrl, AccelTree::Ptr> QPatternist::AccelTreeResourceLoader::m_loadedDocuments
private

Definition at line 198 of file qacceltreeresourceloader_p.h.

Referenced by clear(), deviceURIs(), openDocument(), and retrieveDocument().

◆ m_namePool

const NamePool::Ptr QPatternist::AccelTreeResourceLoader::m_namePool
private

Definition at line 199 of file qacceltreeresourceloader_p.h.

Referenced by AccelTreeResourceLoader(), and retrieveDocument().

◆ m_networkAccessDelegator

const NetworkAccessDelegator::Ptr QPatternist::AccelTreeResourceLoader::m_networkAccessDelegator
private

◆ m_unparsedTexts

QHash<QPair<QUrl, QString>, QString> QPatternist::AccelTreeResourceLoader::m_unparsedTexts
private

Definition at line 201 of file qacceltreeresourceloader_p.h.

Referenced by openUnparsedText(), and retrieveUnparsedText().


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