1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the QtXmlPatterns module of the Qt Toolkit.
7**
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 The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
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 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40//
41// W A R N I N G
42// -------------
43//
44// This file is not part of the Qt API. It exists purely as an
45// implementation detail. This header file may change from version to
46// version without notice, or even be removed.
47//
48// We mean it.
49
50#ifndef Patternist_AccelTreeResourceLoader_H
51#define Patternist_AccelTreeResourceLoader_H
52
53#include <QtCore/QEventLoop>
54#include <QtNetwork/QNetworkReply>
55
56#include <QAbstractXmlReceiver>
57#include <private/qacceltree_p.h>
58#include <private/qacceltreebuilder_p.h>
59#include <private/qdeviceresourceloader_p.h>
60#include <private/qnamepool_p.h>
61#include <private/qnetworkaccessdelegator_p.h>
62#include <private/qreportcontext_p.h>
63
64QT_BEGIN_NAMESPACE
65
66class QIODevice;
67
68namespace QPatternist
69{
70 /**
71 * @short Handles requests for documents, and instantiates
72 * them as AccelTree instances.
73 *
74 * @author Frans Englich <frans.englich@nokia.com>
75 */
76 class Q_AUTOTEST_EXPORT AccelTreeResourceLoader : public DeviceResourceLoader
77 {
78 public:
79 /**
80 * Describes the behaviour of the resource loader in case of an
81 * error.
82 */
83 enum ErrorHandling
84 {
85 FailOnError, ///< The resource loader will report the error via the report context.
86 ContinueOnError ///< The resource loader will report no error and return an empty QNetworkReply.
87 };
88
89 /**
90 * AccelTreeResourceLoader does not own @p context.
91 */
92 AccelTreeResourceLoader(const NamePool::Ptr &np,
93 const NetworkAccessDelegator::Ptr &networkDelegator, AccelTreeBuilder<true>::Features = AccelTreeBuilder<true>::NoneFeature);
94
95 virtual Item openDocument(const QUrl &uri,
96 const ReportContext::Ptr &context);
97 virtual Item openDocument(QIODevice *source, const QUrl &documentUri,
98 const ReportContext::Ptr &context);
99 virtual SequenceType::Ptr announceDocument(const QUrl &uri, const Usage usageHint);
100 virtual bool isDocumentAvailable(const QUrl &uri);
101
102 virtual bool isUnparsedTextAvailable(const QUrl &uri,
103 const QString &encoding);
104
105 virtual Item openUnparsedText(const QUrl &uri,
106 const QString &encoding,
107 const ReportContext::Ptr &context,
108 const SourceLocationReflection *const where);
109
110 /**
111 * @short Helper function that do NetworkAccessDelegator::get(), but
112 * does it blocked.
113 *
114 * The returned QNetworkReply has emitted QNetworkReply::finished().
115 *
116 * The caller owns the return QIODevice instance.
117 *
118 * @p context may be @c null or valid. If @c null, no error reporting
119 * is done and @c null is returned.
120 *
121 * @see NetworkAccessDelegator
122 */
123 static QNetworkReply *load(const QUrl &uri,
124 QNetworkAccessManager *const networkManager,
125 const ReportContext::Ptr &context, ErrorHandling handling = FailOnError);
126
127 /**
128 * @overload
129 */
130 static QNetworkReply *load(const QUrl &uri,
131 const NetworkAccessDelegator::Ptr &networkDelegator,
132 const ReportContext::Ptr &context, ErrorHandling handling = FailOnError);
133
134 /**
135 * @short Returns the URIs this AccelTreeResourceLoader has loaded
136 * which are for devices through variable bindings.
137 */
138 virtual QSet<QUrl> deviceURIs() const;
139
140 virtual void clear(const QUrl &uri);
141
142 private:
143 static bool streamToReceiver(QIODevice *const dev,
144 AccelTreeBuilder<true> *const receiver,
145 const NamePool::Ptr &np,
146 const ReportContext::Ptr &context,
147 const QUrl &uri);
148 bool retrieveDocument(const QUrl &uri,
149 const ReportContext::Ptr &context);
150 bool retrieveDocument(QIODevice *source, const QUrl &documentUri,
151 const ReportContext::Ptr &context);
152 /**
153 * If @p context is @c null, no error reporting should be done.
154 */
155 bool retrieveUnparsedText(const QUrl &uri,
156 const QString &encoding,
157 const ReportContext::Ptr &context,
158 const SourceLocationReflection *const where);
159
160 QHash<QUrl, AccelTree::Ptr> m_loadedDocuments;
161 const NamePool::Ptr m_namePool;
162 const NetworkAccessDelegator::Ptr m_networkAccessDelegator;
163 QHash<QPair<QUrl, QString>, QString> m_unparsedTexts;
164 AccelTreeBuilder<true>::Features m_features;
165 };
166}
167
168QT_END_NAMESPACE
169
170#endif
171

source code of qtxmlpatterns/src/xmlpatterns/acceltree/qacceltreeresourceloader_p.h