1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** All rights reserved.
|
---|
5 | ** Contact: Nokia Corporation ([email protected])
|
---|
6 | **
|
---|
7 | ** This file is part of the QtXmlPatterns module of the Qt Toolkit.
|
---|
8 | **
|
---|
9 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
10 | ** Commercial Usage
|
---|
11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
12 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
13 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
14 | ** a written agreement between you and Nokia.
|
---|
15 | **
|
---|
16 | ** GNU Lesser General Public License Usage
|
---|
17 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
18 | ** General Public License version 2.1 as published by the Free Software
|
---|
19 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
20 | ** packaging of this file. Please review the following information to
|
---|
21 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
23 | **
|
---|
24 | ** In addition, as a special exception, Nokia gives you certain additional
|
---|
25 | ** rights. These rights are described in the Nokia Qt LGPL Exception
|
---|
26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
---|
27 | **
|
---|
28 | ** GNU General Public License Usage
|
---|
29 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
30 | ** General Public License version 3.0 as published by the Free Software
|
---|
31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
32 | ** packaging of this file. Please review the following information to
|
---|
33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
35 | **
|
---|
36 | ** If you have questions regarding the use of this file, please contact
|
---|
37 | ** Nokia at [email protected].
|
---|
38 | ** $QT_END_LICENSE$
|
---|
39 | **
|
---|
40 | ****************************************************************************/
|
---|
41 |
|
---|
42 | //
|
---|
43 | // W A R N I N G
|
---|
44 | // -------------
|
---|
45 | //
|
---|
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.
|
---|
49 | //
|
---|
50 | // We mean it.
|
---|
51 |
|
---|
52 | #ifndef Patternist_AccelTreeResourceLoader_H
|
---|
53 | #define Patternist_AccelTreeResourceLoader_H
|
---|
54 |
|
---|
55 | #include <QtCore/QEventLoop>
|
---|
56 | #include <QtNetwork/QNetworkReply>
|
---|
57 |
|
---|
58 | #include "qabstractxmlreceiver.h"
|
---|
59 | #include "qacceltree_p.h"
|
---|
60 | #include "qacceltreebuilder_p.h"
|
---|
61 | #include "qdeviceresourceloader_p.h"
|
---|
62 | #include "qnamepool_p.h"
|
---|
63 | #include "qnetworkaccessdelegator_p.h"
|
---|
64 | #include "qreportcontext_p.h"
|
---|
65 |
|
---|
66 | QT_BEGIN_HEADER
|
---|
67 |
|
---|
68 | QT_BEGIN_NAMESPACE
|
---|
69 |
|
---|
70 | class QIODevice;
|
---|
71 |
|
---|
72 | namespace QPatternist
|
---|
73 | {
|
---|
74 | /**
|
---|
75 | * @short An helper class which enables QNetworkAccessManager
|
---|
76 | * to be used in a blocking manner.
|
---|
77 | *
|
---|
78 | * @see AccelTreeResourceLoader::load()
|
---|
79 | * @author Frans Englich <[email protected]>
|
---|
80 | */
|
---|
81 | class NetworkLoop : public QEventLoop
|
---|
82 | {
|
---|
83 | Q_OBJECT
|
---|
84 | public:
|
---|
85 | NetworkLoop() : m_hasReceivedError(false)
|
---|
86 | {
|
---|
87 | }
|
---|
88 |
|
---|
89 | public Q_SLOTS:
|
---|
90 | void error(QNetworkReply::NetworkError code)
|
---|
91 | {
|
---|
92 | Q_UNUSED(code);
|
---|
93 | m_hasReceivedError = true;
|
---|
94 | exit(1);
|
---|
95 | }
|
---|
96 |
|
---|
97 | void finished()
|
---|
98 | {
|
---|
99 | if(m_hasReceivedError)
|
---|
100 | exit(1);
|
---|
101 | else
|
---|
102 | exit(0);
|
---|
103 | }
|
---|
104 | private:
|
---|
105 | bool m_hasReceivedError;
|
---|
106 | };
|
---|
107 |
|
---|
108 | /**
|
---|
109 | * @short Handles requests for documents, and instantiates
|
---|
110 | * them as AccelTree instances.
|
---|
111 | *
|
---|
112 | * @author Frans Englich <[email protected]>
|
---|
113 | */
|
---|
114 | class Q_AUTOTEST_EXPORT AccelTreeResourceLoader : public DeviceResourceLoader
|
---|
115 | {
|
---|
116 | public:
|
---|
117 | /**
|
---|
118 | * Describes the behaviour of the resource loader in case of an
|
---|
119 | * error.
|
---|
120 | */
|
---|
121 | enum ErrorHandling
|
---|
122 | {
|
---|
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.
|
---|
125 | };
|
---|
126 |
|
---|
127 | /**
|
---|
128 | * AccelTreeResourceLoader does not own @p context.
|
---|
129 | */
|
---|
130 | AccelTreeResourceLoader(const NamePool::Ptr &np,
|
---|
131 | const NetworkAccessDelegator::Ptr &networkDelegator, AccelTreeBuilder<true>::Features = AccelTreeBuilder<true>::NoneFeature);
|
---|
132 |
|
---|
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);
|
---|
139 |
|
---|
140 | virtual bool isUnparsedTextAvailable(const QUrl &uri,
|
---|
141 | const QString &encoding);
|
---|
142 |
|
---|
143 | virtual Item openUnparsedText(const QUrl &uri,
|
---|
144 | const QString &encoding,
|
---|
145 | const ReportContext::Ptr &context,
|
---|
146 | const SourceLocationReflection *const where);
|
---|
147 |
|
---|
148 | /**
|
---|
149 | * @short Helper function that do NetworkAccessDelegator::get(), but
|
---|
150 | * does it blocked.
|
---|
151 | *
|
---|
152 | * The returned QNetworkReply has emitted QNetworkReply::finished().
|
---|
153 | *
|
---|
154 | * The caller owns the return QIODevice instance.
|
---|
155 | *
|
---|
156 | * @p context may be @c null or valid. If @c null, no error reporting
|
---|
157 | * is done and @c null is returned.
|
---|
158 | *
|
---|
159 | * @see NetworkAccessDelegator
|
---|
160 | */
|
---|
161 | static QNetworkReply *load(const QUrl &uri,
|
---|
162 | QNetworkAccessManager *const networkManager,
|
---|
163 | const ReportContext::Ptr &context, ErrorHandling handling = FailOnError);
|
---|
164 |
|
---|
165 | /**
|
---|
166 | * @overload
|
---|
167 | */
|
---|
168 | static QNetworkReply *load(const QUrl &uri,
|
---|
169 | const NetworkAccessDelegator::Ptr &networkDelegator,
|
---|
170 | const ReportContext::Ptr &context, ErrorHandling handling = FailOnError);
|
---|
171 |
|
---|
172 | /**
|
---|
173 | * @short Returns the URIs this AccelTreeResourceLoader has loaded
|
---|
174 | * which are for devices through variable bindings.
|
---|
175 | */
|
---|
176 | virtual QSet<QUrl> deviceURIs() const;
|
---|
177 |
|
---|
178 | virtual void clear(const QUrl &uri);
|
---|
179 |
|
---|
180 | private:
|
---|
181 | static bool streamToReceiver(QIODevice *const dev,
|
---|
182 | AccelTreeBuilder<true> *const receiver,
|
---|
183 | const NamePool::Ptr &np,
|
---|
184 | const ReportContext::Ptr &context,
|
---|
185 | const QUrl &uri);
|
---|
186 | bool retrieveDocument(const QUrl &uri,
|
---|
187 | const ReportContext::Ptr &context);
|
---|
188 | bool retrieveDocument(QIODevice *source, const QUrl &documentUri,
|
---|
189 | const ReportContext::Ptr &context);
|
---|
190 | /**
|
---|
191 | * If @p context is @c null, no error reporting should be done.
|
---|
192 | */
|
---|
193 | bool retrieveUnparsedText(const QUrl &uri,
|
---|
194 | const QString &encoding,
|
---|
195 | const ReportContext::Ptr &context,
|
---|
196 | const SourceLocationReflection *const where);
|
---|
197 |
|
---|
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;
|
---|
203 | };
|
---|
204 | }
|
---|
205 |
|
---|
206 | QT_END_NAMESPACE
|
---|
207 |
|
---|
208 | QT_END_HEADER
|
---|
209 |
|
---|
210 | #endif
|
---|