| 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 test suite of the Qt Toolkit. |
| 7 | ** |
| 8 | ** $QT_BEGIN_LICENSE:GPL-EXCEPT$ |
| 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 General Public License Usage |
| 18 | ** Alternatively, this file may be used under the terms of the GNU |
| 19 | ** General Public License version 3 as published by the Free Software |
| 20 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT |
| 21 | ** included in the packaging of this file. Please review the following |
| 22 | ** information to ensure the GNU General Public License requirements will |
| 23 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
| 24 | ** |
| 25 | ** $QT_END_LICENSE$ |
| 26 | ** |
| 27 | ****************************************************************************/ |
| 28 | |
| 29 | #ifndef PatternistSDK_ExternalSourceLoader_H |
| 30 | #define PatternistSDK_ExternalSourceLoader_H |
| 31 | |
| 32 | #include <QHash> |
| 33 | #include <QUrl> |
| 34 | #include <QXmlQuery> |
| 35 | |
| 36 | #include <private/qdynamiccontext_p.h> |
| 37 | #include <private/qresourceloader_p.h> |
| 38 | #include <private/qexternalvariableloader_p.h> |
| 39 | |
| 40 | QT_BEGIN_NAMESPACE |
| 41 | |
| 42 | namespace QPatternistSDK |
| 43 | { |
| 44 | /** |
| 45 | * @short Handles external variables in XQTS queries, such as <tt>$input-context</tt>, |
| 46 | * by loading appropriate XML source files. |
| 47 | * |
| 48 | * @ingroup PatternistSDK |
| 49 | * @author Frans Englich <frans.englich@nokia.com> |
| 50 | */ |
| 51 | class ExternalSourceLoader : public QPatternist::ExternalVariableLoader |
| 52 | { |
| 53 | public: |
| 54 | enum TargetOfURI |
| 55 | { |
| 56 | /** |
| 57 | * Identifies @c input-file. |
| 58 | */ |
| 59 | Document, |
| 60 | |
| 61 | /** |
| 62 | * Identifies @c input-URI. |
| 63 | */ |
| 64 | URI, |
| 65 | |
| 66 | /** |
| 67 | * Identifies @c input-query. |
| 68 | */ |
| 69 | Query |
| 70 | }; |
| 71 | |
| 72 | /** |
| 73 | * The first is the complete, absolute, final URI to the file to be loaded, |
| 74 | * and the second is the type of source found at that URI. |
| 75 | */ |
| 76 | typedef QPair<QUrl, TargetOfURI> VariableValue; |
| 77 | |
| 78 | /** |
| 79 | * In the XQTSCatalog.xml each source file in each test is referred to |
| 80 | * by a key, which can be fully looked up in the @c sources element. This QHash |
| 81 | * maps the keys to absolute URIs pointing to the source file. |
| 82 | */ |
| 83 | typedef QHash<QString, QUrl> SourceMap; |
| 84 | |
| 85 | /** |
| 86 | * The first value is the variable name, and the second is the URI identifying |
| 87 | * the XML source file that's supposed to be loaded as a document. |
| 88 | * |
| 89 | * This is one for every test case, except for @c rdb-queries-results-q5, |
| 90 | * @c rdb-queries-results-q17 and @c rdb-queries-results-q18(at least in XQTS 1.0). |
| 91 | */ |
| 92 | typedef QHash<QString, VariableValue> VariableMap; |
| 93 | |
| 94 | ExternalSourceLoader(const VariableMap &varMap, |
| 95 | const QPatternist::ResourceLoader::Ptr &resourceLoader); |
| 96 | |
| 97 | virtual QPatternist::SequenceType::Ptr |
| 98 | announceExternalVariable(const QXmlName name, |
| 99 | const QPatternist::SequenceType::Ptr &declaredType); |
| 100 | |
| 101 | virtual QPatternist::Item |
| 102 | evaluateSingleton(const QXmlName name, |
| 103 | const QPatternist::DynamicContext::Ptr &context); |
| 104 | |
| 105 | VariableMap variableMap() const |
| 106 | { |
| 107 | return m_variableMap; |
| 108 | } |
| 109 | |
| 110 | private: |
| 111 | const VariableMap m_variableMap; |
| 112 | const QPatternist::ResourceLoader::Ptr m_resourceLoader; |
| 113 | QXmlQuery m_query; |
| 114 | }; |
| 115 | } |
| 116 | |
| 117 | QT_END_NAMESPACE |
| 118 | |
| 119 | #endif |
| 120 | // vim: et:ts=4:sw=4:sts=4 |
| 121 | |