summaryrefslogtreecommitdiffstats
path: root/src/xmlpatterns/acceltree/qacceltreeresourceloader.cpp
diff options
context:
space:
mode:
authorTobias Koenig <tokoe@kde.org>2009-05-16 10:19:10 (GMT)
committerTobias Koenig <tokoe@kde.org>2009-05-16 10:19:10 (GMT)
commit135a028d9dc9a28a0a072665a7dc43b7e9e187be (patch)
treed259e1d265589d10a541899d4982ab4e656900eb /src/xmlpatterns/acceltree/qacceltreeresourceloader.cpp
parent210bd7b6033e41aad61fe131002dc5e496d7427a (diff)
downloadQt-135a028d9dc9a28a0a072665a7dc43b7e9e187be.zip
Qt-135a028d9dc9a28a0a072665a7dc43b7e9e187be.tar.gz
Qt-135a028d9dc9a28a0a072665a7dc43b7e9e187be.tar.bz2
Add W3C XML Schema validation support
This was done by Tobias Koenig, as part of an internship at Trolltech/Qt Software, started at Wed Oct 1 18:32:43 2008 +0200, and the last commit being part of this commit dating Tue Feb 24 11:03:36 2009 +0100. This is work consisting of about 650 commits squashed into one, where the first commit was 61b280386c1905a15690fdd917dcbc8eb09b6283, in the repository before Qt's history cut.
Diffstat (limited to 'src/xmlpatterns/acceltree/qacceltreeresourceloader.cpp')
-rw-r--r--src/xmlpatterns/acceltree/qacceltreeresourceloader.cpp60
1 files changed, 45 insertions, 15 deletions
diff --git a/src/xmlpatterns/acceltree/qacceltreeresourceloader.cpp b/src/xmlpatterns/acceltree/qacceltreeresourceloader.cpp
index 4a5c219..7c3d2c0 100644
--- a/src/xmlpatterns/acceltree/qacceltreeresourceloader.cpp
+++ b/src/xmlpatterns/acceltree/qacceltreeresourceloader.cpp
@@ -46,7 +46,6 @@
#include <QtNetwork/QNetworkRequest>
-#include "qacceltreebuilder_p.h"
#include "qatomicstring_p.h"
#include "qautoptr_p.h"
#include "qcommonsequencetypes_p.h"
@@ -57,14 +56,12 @@ QT_BEGIN_NAMESPACE
using namespace QPatternist;
-static inline uint qHash(const QUrl &uri)
-{
- return qHash(uri.toString());
-}
-
AccelTreeResourceLoader::AccelTreeResourceLoader(const NamePool::Ptr &np,
- const NetworkAccessDelegator::Ptr &manager) : m_namePool(np)
- , m_networkAccessDelegator(manager)
+ const NetworkAccessDelegator::Ptr &manager,
+ AccelTreeBuilder<true>::Features features)
+ : m_namePool(np)
+ , m_networkAccessDelegator(manager)
+ , m_features(features)
{
Q_ASSERT(m_namePool);
Q_ASSERT(m_networkAccessDelegator);
@@ -74,7 +71,7 @@ bool AccelTreeResourceLoader::retrieveDocument(const QUrl &uri,
const ReportContext::Ptr &context)
{
Q_ASSERT(uri.isValid());
- AccelTreeBuilder<true> builder(uri, uri, m_namePool, context.data());
+ AccelTreeBuilder<true> builder(uri, uri, m_namePool, context.data(), m_features);
const AutoPtr<QNetworkReply> reply(load(uri, m_networkAccessDelegator, context));
@@ -88,18 +85,35 @@ bool AccelTreeResourceLoader::retrieveDocument(const QUrl &uri,
return success;
}
+bool AccelTreeResourceLoader::retrieveDocument(QIODevice *source, const QUrl &documentUri, const ReportContext::Ptr &context)
+{
+ Q_ASSERT(source);
+ Q_ASSERT(source->isReadable());
+ Q_ASSERT(documentUri.isValid());
+
+ AccelTreeBuilder<true> builder(documentUri, documentUri, m_namePool, context.data(), m_features);
+
+ bool success = false;
+ success = streamToReceiver(source, &builder, m_namePool, context, documentUri);
+
+ m_loadedDocuments.insert(documentUri, builder.builtDocument());
+
+ return success;
+}
+
QNetworkReply *AccelTreeResourceLoader::load(const QUrl &uri,
const NetworkAccessDelegator::Ptr &networkDelegator,
- const ReportContext::Ptr &context)
+ const ReportContext::Ptr &context, ErrorHandling errorHandling)
{
return load(uri,
networkDelegator->managerFor(uri),
- context);
+ context, errorHandling);
}
QNetworkReply *AccelTreeResourceLoader::load(const QUrl &uri,
QNetworkAccessManager *const networkManager,
- const ReportContext::Ptr &context)
+ const ReportContext::Ptr &context, ErrorHandling errorHandling)
+
{
Q_ASSERT(networkManager);
Q_ASSERT(uri.isValid());
@@ -120,7 +134,7 @@ QNetworkReply *AccelTreeResourceLoader::load(const QUrl &uri,
const QSourceLocation location(uri);
- if(context)
+ if(context && (errorHandling == FailOnError))
context->error(errorMessage, ReportContext::FODC0002, location);
return 0;
@@ -130,7 +144,7 @@ QNetworkReply *AccelTreeResourceLoader::load(const QUrl &uri,
}
bool AccelTreeResourceLoader::streamToReceiver(QIODevice *const dev,
- QAbstractXmlReceiver *const receiver,
+ AccelTreeBuilder<true> *const receiver,
const NamePool::Ptr &np,
const ReportContext::Ptr &context,
const QUrl &uri)
@@ -154,7 +168,7 @@ bool AccelTreeResourceLoader::streamToReceiver(QIODevice *const dev,
{
/* Send the name. */
receiver->startElement(np->allocateQName(reader.namespaceUri().toString(), reader.name().toString(),
- reader.prefix().toString()));
+ reader.prefix().toString()), reader.lineNumber(), reader.columnNumber());
/* Send namespace declarations. */
const QXmlStreamNamespaceDeclarations &nss = reader.namespaceDeclarations();
@@ -263,6 +277,22 @@ Item AccelTreeResourceLoader::openDocument(const QUrl &uri,
}
}
+Item AccelTreeResourceLoader::openDocument(QIODevice *source, const QUrl &documentUri,
+ const ReportContext::Ptr &context)
+{
+ const AccelTree::Ptr doc(m_loadedDocuments.value(documentUri));
+
+ if(doc)
+ return doc->root(QXmlNodeModelIndex()); /* Pass in dummy object. We know AccelTree doesn't use it. */
+ else
+ {
+ if(retrieveDocument(source, documentUri, context))
+ return m_loadedDocuments.value(documentUri)->root(QXmlNodeModelIndex()); /* Pass in dummy object. We know AccelTree doesn't use it. */
+ else
+ return Item();
+ }
+}
+
SequenceType::Ptr AccelTreeResourceLoader::announceDocument(const QUrl &uri, const Usage)
{
// TODO deal with the usage thingy