Qt 4.8
Public Types | Public Functions | List of all members
QPatternist::ResourceLoader Class Reference

Responsible for handling requests for opening files and node collections. More...

#include <qresourceloader_p.h>

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

Public Types

typedef QExplicitlySharedDataPointer< ResourceLoaderPtr
 
enum  Usage { MayUse, WillUse }
 

Public Functions

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 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 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 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 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::Iterator::Ptr openCollection (const QUrl &uri)
 Calls to this function are generated by calls to the fn:collection() 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 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...
 
 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...
 

Additional Inherited Members

- Public Variables inherited from QSharedData
QAtomicInt ref
 

Detailed Description

Responsible for handling requests for opening files and node collections.

ResourceLoader is a callback used for opening files, requested via the functions fn:document() and fn:unparsed-text(); and node collections, requested via fn:collection(). Patternist uses the ResourceLoader at compile time, via StaticContext::resourceLoader(), and at runtime, via DynamicContext::resourceLoader().

The ResourceLoader takes care of loading "external resources" in a way specific to the data model Patternist is using. For example, perhaps the opening of documents should pass a security policy, or a collection should map to nodes in a virtual filesystem or a database.

From Patternist's perspective, the ResourceLoader provides two things:

From the user's or the data model's perspective, the ResourceLoader most notably provides a hint to what resources a query will load at runtime, and therefore provides an opportunity to prepare in advance for that. For example, between the compile and runtime stage, the ResourceLoader sub-class can be asked to pre-load documents in an asynchronous and simultaneous way, such that the runtime stage is faster and doesn't freeze a graphical interface.

The announce functions are not guaranteed to be called. The loading functions can be called with an URI that an announce function hasn't been called with.

The default implementations of ResourceLoader's virtual functions all signals that no resources can be loaded. This means ResourceLoader must be sub-classed, in order to be able to load resources.

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

Definition at line 106 of file qresourceloader_p.h.

Typedefs

◆ Ptr

Definition at line 128 of file qresourceloader_p.h.

Enumerations

◆ Usage

Enumerator
MayUse 

Communicates that the URI may be used during query evaluation. For example, zero times or very many times.

Typically this hint is given when the URI is available at compile-time, but it is used inside a conditional statement whose branching cannot be determined at compile time.

WillUse 

Communicates that the URI will always be used at query evaluation.

Definition at line 109 of file qresourceloader_p.h.

Constructors and Destructors

◆ ResourceLoader()

QPatternist::ResourceLoader::ResourceLoader ( )
inline

Definition at line 129 of file qresourceloader_p.h.

129 {}

◆ ~ResourceLoader()

ResourceLoader::~ResourceLoader ( )
virtual

Definition at line 51 of file qresourceloader.cpp.

52 {
53 }

Functions

◆ announceCollection()

SequenceType::Ptr ResourceLoader::announceCollection ( const QUrl uri)
virtual

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

This function can be called an arbitrary amount of times for the same URI. 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 how simple the query is what information that is statically available and subsequently what optimizations that can apply.

Calls to this function are generated by calls to the fn:collection() 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).
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::zeroOrMoreNodes 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.6 fn:collection

Reimplemented in QPatternist::ResourceDelegator.

Definition at line 121 of file qresourceloader.cpp.

Referenced by QPatternist::ResourceDelegator::announceCollection().

122 {
123  Q_ASSERT(uri.isValid());
124  Q_ASSERT(!uri.isRelative());
125  Q_UNUSED(uri); /* Needed when compiling in release mode. */
126  return SequenceType::Ptr();
127 }
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
QExplicitlySharedDataPointer< const SequenceType > Ptr
#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

◆ announceDocument()

SequenceType::Ptr ResourceLoader::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 in QPatternist::AccelTreeResourceLoader, and QPatternist::ResourceDelegator.

Definition at line 97 of file qresourceloader.cpp.

Referenced by QPatternist::ResourceDelegator::announceDocument(), and QPatternist::DocFN::typeCheck().

98 {
99  Q_ASSERT(uri.isValid());
100  Q_ASSERT(!uri.isRelative());
101  Q_UNUSED(uri); /* Needed when compiling in release mode. */
102  return SequenceType::Ptr();
103 }
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
QExplicitlySharedDataPointer< const SequenceType > Ptr
#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

◆ announceUnparsedText()

ItemType::Ptr ResourceLoader::announceUnparsedText ( const QUrl uri)
virtual

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.

This function can be called an arbitrary amount of times for the same URI. 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 how simple the query is what information that is statically available and subsequently what optimizations that can apply.

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).
See also
XSL Transformations (XSLT) Version 2.0, 16.2 Reading Text Files
Returns
  • null if no unparsed file can be loaded for uri
  • The item type that the value loaded by uri will be an instance of. This is typically xs:string

Reimplemented in QPatternist::ResourceDelegator.

Definition at line 65 of file qresourceloader.cpp.

Referenced by QPatternist::ResourceDelegator::announceUnparsedText().

66 {
67  Q_ASSERT(uri.isValid());
68  Q_ASSERT(!uri.isRelative());
69  Q_UNUSED(uri); /* Needed when compiling in release mode. */
70  return ItemType::Ptr();
71 }
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
QExplicitlySharedDataPointer< ItemType > Ptr
Definition: qitemtype_p.h:88
#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 ResourceLoader::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 in QPatternist::AccelTreeResourceLoader.

Definition at line 129 of file qresourceloader.cpp.

130 {
131  Q_UNUSED(uri);
132 }
#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

◆ isDocumentAvailable()

bool ResourceLoader::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 in QPatternist::AccelTreeResourceLoader, and QPatternist::ResourceDelegator.

Definition at line 105 of file qresourceloader.cpp.

Referenced by QPatternist::DocAvailableFN::evaluateEBV(), and QPatternist::ResourceDelegator::isDocumentAvailable().

106 {
107  Q_ASSERT(uri.isValid());
108  Q_ASSERT(!uri.isRelative());
109  Q_UNUSED(uri); /* Needed when compiling in release mode. */
110  return false;
111 }
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
#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

◆ isUnparsedTextAvailable()

bool ResourceLoader::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 in QPatternist::AccelTreeResourceLoader, and QPatternist::ResourceDelegator.

Definition at line 55 of file qresourceloader.cpp.

Referenced by QPatternist::UnparsedTextAvailableFN::evaluateEBV(), and QPatternist::ResourceDelegator::isUnparsedTextAvailable().

57 {
58  Q_ASSERT(uri.isValid());
59  Q_ASSERT(!uri.isRelative());
60  Q_UNUSED(uri); /* Needed when compiling in release mode. */
61  Q_UNUSED(encoding);
62  return false;
63 }
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
#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

◆ openCollection()

Item::Iterator::Ptr ResourceLoader::openCollection ( const QUrl uri)
virtual

Calls to this function are generated by calls to the fn:collection() 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).
See also
XQuery 1.0 and XPath 2.0 Functions and Operators, 15.5.6 fn:collection
Returns

Reimplemented in QPatternist::ResourceDelegator.

Definition at line 113 of file qresourceloader.cpp.

Referenced by QPatternist::ResourceDelegator::openCollection().

114 {
115  Q_ASSERT(uri.isValid());
116  Q_ASSERT(!uri.isRelative());
117  Q_UNUSED(uri); /* Needed when compiling in release mode. */
118  return Item::Iterator::Ptr();
119 }
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
QExplicitlySharedDataPointer< QAbstractXmlForwardIterator< Item > > Ptr
A smart pointer wrapping an instance of a QAbstractXmlForwardIterator subclass.
#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

◆ openDocument()

Item ResourceLoader::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 in QPatternist::AccelTreeResourceLoader, and QPatternist::ResourceDelegator.

Definition at line 87 of file qresourceloader.cpp.

Referenced by QPatternist::DocFN::evaluateSingleton(), and QPatternist::ResourceDelegator::openDocument().

89 {
90  Q_ASSERT(uri.isValid());
91  Q_ASSERT(!uri.isRelative());
92  Q_UNUSED(uri); /* Needed when compiling in release mode. */
93  Q_UNUSED(context); /* Needed when compiling in release mode. */
94  return Item();
95 }
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
Represents an item in the XPath 2.0 Data Model.
Definition: qitem_p.h:182
#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

◆ openUnparsedText()

Item ResourceLoader::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 in QPatternist::AccelTreeResourceLoader, and QPatternist::ResourceDelegator.

Definition at line 73 of file qresourceloader.cpp.

Referenced by QPatternist::UnparsedTextFN::evaluateSingleton(), and QPatternist::ResourceDelegator::openUnparsedText().

77 {
78  Q_ASSERT(uri.isValid());
79  Q_ASSERT(!uri.isRelative());
80  Q_UNUSED(uri); /* Needed when compiling in release mode. */
81  Q_UNUSED(encoding);
82  Q_UNUSED(context);
83  Q_UNUSED(where);
84  return Item();
85 }
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
Represents an item in the XPath 2.0 Data Model.
Definition: qitem_p.h:182
#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

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