1 /****************************************************************************
3 ** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
6 ** This file is part of the QtXmlPatterns module of the Qt Toolkit.
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.
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.
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.
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.
40 ****************************************************************************/
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.
52 #ifndef Patternist_AccelTreeResourceLoader_H
53 #define Patternist_AccelTreeResourceLoader_H
55 #include <QtCore/QEventLoop>
56 #include <QtNetwork/QNetworkReply>
58 #include <QAbstractXmlReceiver>
59 #include <private/qacceltree_p.h>
60 #include <private/qacceltreebuilder_p.h>
61 #include <private/qdeviceresourceloader_p.h>
62 #include <private/qnamepool_p.h>
63 #include <private/qnetworkaccessdelegator_p.h>
64 #include <private/qreportcontext_p.h>
75 * @short An helper class which enables QNetworkAccessManager
76 * to be used in a blocking manner.
78 * @see AccelTreeResourceLoader::load()
79 * @author Frans Englich <frans.englich@nokia.com>
81 class NetworkLoop : public QEventLoop
85 NetworkLoop() : m_hasReceivedError(false)
90 void error(QNetworkReply::NetworkError code)
93 m_hasReceivedError = true;
99 if(m_hasReceivedError)
105 bool m_hasReceivedError;
109 * @short Handles requests for documents, and instantiates
110 * them as AccelTree instances.
112 * @author Frans Englich <frans.englich@nokia.com>
114 class Q_AUTOTEST_EXPORT AccelTreeResourceLoader : public DeviceResourceLoader
118 * Describes the behaviour of the resource loader in case of an
123 FailOnError, ///< The resource loader will report the error via the report context.
124 ContinueOnError ///< The resource loader will report no error and return an empty QNetworkReply.
128 * AccelTreeResourceLoader does not own @p context.
130 AccelTreeResourceLoader(const NamePool::Ptr &np,
131 const NetworkAccessDelegator::Ptr &networkDelegator, AccelTreeBuilder<true>::Features = AccelTreeBuilder<true>::NoneFeature);
133 virtual Item openDocument(const QUrl &uri,
134 const ReportContext::Ptr &context);
135 virtual Item openDocument(QIODevice *source, const QUrl &documentUri,
136 const ReportContext::Ptr &context);
137 virtual SequenceType::Ptr announceDocument(const QUrl &uri, const Usage usageHint);
138 virtual bool isDocumentAvailable(const QUrl &uri);
140 virtual bool isUnparsedTextAvailable(const QUrl &uri,
141 const QString &encoding);
143 virtual Item openUnparsedText(const QUrl &uri,
144 const QString &encoding,
145 const ReportContext::Ptr &context,
146 const SourceLocationReflection *const where);
149 * @short Helper function that do NetworkAccessDelegator::get(), but
152 * The returned QNetworkReply has emitted QNetworkReply::finished().
154 * The caller owns the return QIODevice instance.
156 * @p context may be @c null or valid. If @c null, no error reporting
157 * is done and @c null is returned.
159 * @see NetworkAccessDelegator
161 static QNetworkReply *load(const QUrl &uri,
162 QNetworkAccessManager *const networkManager,
163 const ReportContext::Ptr &context, ErrorHandling handling = FailOnError);
168 static QNetworkReply *load(const QUrl &uri,
169 const NetworkAccessDelegator::Ptr &networkDelegator,
170 const ReportContext::Ptr &context, ErrorHandling handling = FailOnError);
173 * @short Returns the URIs this AccelTreeResourceLoader has loaded
174 * which are for devices through variable bindings.
176 virtual QSet<QUrl> deviceURIs() const;
178 virtual void clear(const QUrl &uri);
181 static bool streamToReceiver(QIODevice *const dev,
182 AccelTreeBuilder<true> *const receiver,
183 const NamePool::Ptr &np,
184 const ReportContext::Ptr &context,
186 bool retrieveDocument(const QUrl &uri,
187 const ReportContext::Ptr &context);
188 bool retrieveDocument(QIODevice *source, const QUrl &documentUri,
189 const ReportContext::Ptr &context);
191 * If @p context is @c null, no error reporting should be done.
193 bool retrieveUnparsedText(const QUrl &uri,
194 const QString &encoding,
195 const ReportContext::Ptr &context,
196 const SourceLocationReflection *const where);
198 QHash<QUrl, AccelTree::Ptr> m_loadedDocuments;
199 const NamePool::Ptr m_namePool;
200 const NetworkAccessDelegator::Ptr m_networkAccessDelegator;
201 QHash<QPair<QUrl, QString>, QString> m_unparsedTexts;
202 AccelTreeBuilder<true>::Features m_features;