1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** Contact: Qt Software Information ([email protected])
|
---|
5 | **
|
---|
6 | ** This file is part of the QtXmlPatterns module of the Qt Toolkit.
|
---|
7 | **
|
---|
8 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
9 | ** Commercial Usage
|
---|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
11 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
12 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
13 | ** a written agreement between you and Nokia.
|
---|
14 | **
|
---|
15 | ** GNU Lesser General Public License Usage
|
---|
16 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
17 | ** General Public License version 2.1 as published by the Free Software
|
---|
18 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
19 | ** packaging of this file. Please review the following information to
|
---|
20 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
21 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
22 | **
|
---|
23 | ** In addition, as a special exception, Nokia gives you certain
|
---|
24 | ** additional rights. These rights are described in the Nokia Qt LGPL
|
---|
25 | ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
|
---|
26 | ** 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 are unsure which license is appropriate for your use, please
|
---|
37 | ** contact the sales department 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/QHash>
|
---|
56 | #include <QtCore/QEventLoop>
|
---|
57 | #include <QtNetwork/QNetworkReply>
|
---|
58 |
|
---|
59 | #include "qabstractxmlreceiver.h"
|
---|
60 | #include "qacceltree_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 | * AccelTreeResourceLoader does not own @p context.
|
---|
119 | */
|
---|
120 | AccelTreeResourceLoader(const NamePool::Ptr &np,
|
---|
121 | const NetworkAccessDelegator::Ptr &networkDelegator);
|
---|
122 |
|
---|
123 | virtual Item openDocument(const QUrl &uri,
|
---|
124 | const ReportContext::Ptr &context);
|
---|
125 | virtual SequenceType::Ptr announceDocument(const QUrl &uri, const Usage usageHint);
|
---|
126 | virtual bool isDocumentAvailable(const QUrl &uri);
|
---|
127 |
|
---|
128 | virtual bool isUnparsedTextAvailable(const QUrl &uri,
|
---|
129 | const QString &encoding);
|
---|
130 |
|
---|
131 | virtual Item openUnparsedText(const QUrl &uri,
|
---|
132 | const QString &encoding,
|
---|
133 | const ReportContext::Ptr &context,
|
---|
134 | const SourceLocationReflection *const where);
|
---|
135 |
|
---|
136 |
|
---|
137 | /**
|
---|
138 | * @short Helper function that do NetworkAccessDelegator::get(), but
|
---|
139 | * does it blocked.
|
---|
140 | *
|
---|
141 | * The returned QNetworkReply has emitted QNetworkReply::finished().
|
---|
142 | *
|
---|
143 | * The caller owns the return QIODevice instance.
|
---|
144 | *
|
---|
145 | * @p context may be @c null or valid. If @c null, no error reporting
|
---|
146 | * is done and @c null is returned.
|
---|
147 | *
|
---|
148 | * @see NetworkAccessDelegator
|
---|
149 | */
|
---|
150 | static QNetworkReply *load(const QUrl &uri,
|
---|
151 | QNetworkAccessManager *const networkManager,
|
---|
152 | const ReportContext::Ptr &context);
|
---|
153 |
|
---|
154 | /**
|
---|
155 | * @overload
|
---|
156 | */
|
---|
157 | static QNetworkReply *load(const QUrl &uri,
|
---|
158 | const NetworkAccessDelegator::Ptr &networkDelegator,
|
---|
159 | const ReportContext::Ptr &context);
|
---|
160 |
|
---|
161 | /**
|
---|
162 | * @short Returns the URIs this AccelTreeResourceLoader has loaded
|
---|
163 | * which are for devices through variable bindings.
|
---|
164 | */
|
---|
165 | virtual QSet<QUrl> deviceURIs() const;
|
---|
166 |
|
---|
167 | virtual void clear(const QUrl &uri);
|
---|
168 | private:
|
---|
169 | static bool streamToReceiver(QIODevice *const dev,
|
---|
170 | QAbstractXmlReceiver *const receiver,
|
---|
171 | const NamePool::Ptr &np,
|
---|
172 | const ReportContext::Ptr &context,
|
---|
173 | const QUrl &uri);
|
---|
174 | bool retrieveDocument(const QUrl &uri,
|
---|
175 | const ReportContext::Ptr &context);
|
---|
176 | /**
|
---|
177 | * If @p context is @c null, no error reporting should be done.
|
---|
178 | */
|
---|
179 | bool retrieveUnparsedText(const QUrl &uri,
|
---|
180 | const QString &encoding,
|
---|
181 | const ReportContext::Ptr &context,
|
---|
182 | const SourceLocationReflection *const where);
|
---|
183 |
|
---|
184 | QHash<QUrl, AccelTree::Ptr> m_loadedDocuments;
|
---|
185 | const NamePool::Ptr m_namePool;
|
---|
186 | const NetworkAccessDelegator::Ptr m_networkAccessDelegator;
|
---|
187 | QHash<QPair<QUrl, QString>, QString> m_unparsedTexts;
|
---|
188 | };
|
---|
189 | }
|
---|
190 |
|
---|
191 | QT_END_NAMESPACE
|
---|
192 |
|
---|
193 | QT_END_HEADER
|
---|
194 |
|
---|
195 | #endif
|
---|