tests/auto/xmlpatternsxqts/lib/ExternalSourceLoader.h
changeset 0 1918ee327afb
child 4 3b1da2848fc7
equal deleted inserted replaced
-1:000000000000 0:1918ee327afb
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
     6 **
       
     7 ** This file is part of the test suite of the Qt Toolkit.
       
     8 **
       
     9 ** $QT_BEGIN_LICENSE:LGPL$
       
    10 ** No Commercial Usage
       
    11 ** This file contains pre-release code and may not be distributed.
       
    12 ** You may use this file in accordance with the terms and conditions
       
    13 ** contained in the Technology Preview License Agreement accompanying
       
    14 ** this package.
       
    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 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    32 **
       
    33 **
       
    34 **
       
    35 **
       
    36 **
       
    37 **
       
    38 ** $QT_END_LICENSE$
       
    39 **
       
    40 ****************************************************************************/
       
    41 
       
    42 #ifndef PatternistSDK_ExternalSourceLoader_H
       
    43 #define PatternistSDK_ExternalSourceLoader_H
       
    44 
       
    45 #include <QHash>
       
    46 #include <QUrl>
       
    47 #include <QXmlQuery>
       
    48 
       
    49 #include "qdynamiccontext_p.h"
       
    50 #include "qresourceloader_p.h"
       
    51 #include "qexternalvariableloader_p.h"
       
    52 
       
    53 QT_BEGIN_HEADER
       
    54 
       
    55 QT_BEGIN_NAMESPACE
       
    56 
       
    57 namespace QPatternistSDK
       
    58 {
       
    59     /**
       
    60      * @short Handles external variables in XQTS queries, such as <tt>$input-context</tt>,
       
    61      * by loading appropriate XML source files.
       
    62      *
       
    63      * @ingroup PatternistSDK
       
    64      * @author Frans Englich <frans.englich@nokia.com>
       
    65      */
       
    66     class Q_PATTERNISTSDK_EXPORT ExternalSourceLoader : public QPatternist::ExternalVariableLoader
       
    67     {
       
    68     public:
       
    69         enum TargetOfURI
       
    70         {
       
    71             /**
       
    72              * Identifies @c input-file.
       
    73              */
       
    74             Document,
       
    75 
       
    76             /**
       
    77              * Identifies @c input-URI.
       
    78              */
       
    79             URI,
       
    80 
       
    81             /**
       
    82              * Identifies @c input-query.
       
    83              */
       
    84             Query
       
    85         };
       
    86 
       
    87         /**
       
    88          * The first is the complete, absolute, final URI to the file to be loaded,
       
    89          * and the second is the type of source found at that URI.
       
    90          */
       
    91         typedef QPair<QUrl, TargetOfURI> VariableValue;
       
    92 
       
    93         /**
       
    94          * In the XQTSCatalog.xml each source file in each test is referred to
       
    95          * by a key, which can be fully looked up in the @c sources element. This QHash
       
    96          * maps the keys to absolute URIs pointing to the source file.
       
    97          */
       
    98         typedef QHash<QString, QUrl> SourceMap;
       
    99 
       
   100         /**
       
   101          * The first value is the variable name, and the second is the URI identifying
       
   102          * the XML source file that's supposed to be loaded as a document.
       
   103          *
       
   104          * This is one for every test case, except for @c rdb-queries-results-q5,
       
   105          * @c rdb-queries-results-q17 and @c rdb-queries-results-q18(at least in XQTS 1.0).
       
   106          */
       
   107         typedef QHash<QString, VariableValue> VariableMap;
       
   108 
       
   109         ExternalSourceLoader(const VariableMap &varMap,
       
   110                              const QPatternist::ResourceLoader::Ptr &resourceLoader);
       
   111 
       
   112         virtual QPatternist::SequenceType::Ptr
       
   113         announceExternalVariable(const QXmlName name,
       
   114                                  const QPatternist::SequenceType::Ptr &declaredType);
       
   115 
       
   116         virtual QPatternist::Item
       
   117         evaluateSingleton(const QXmlName name,
       
   118                           const QPatternist::DynamicContext::Ptr &context);
       
   119 
       
   120         VariableMap variableMap() const
       
   121         {
       
   122             return m_variableMap;
       
   123         }
       
   124 
       
   125     private:
       
   126         const VariableMap                       m_variableMap;
       
   127         const QPatternist::ResourceLoader::Ptr  m_resourceLoader;
       
   128         QXmlQuery                               m_query;
       
   129     };
       
   130 }
       
   131 
       
   132 QT_END_NAMESPACE
       
   133 
       
   134 QT_END_HEADER
       
   135 
       
   136 #endif
       
   137 // vim: et:ts=4:sw=4:sts=4