Project

Profile

Help

How to connect?
Download (9.24 KB) Statistics
| Branch: | Tag: | Revision:

he / latest9.9 / hec / Saxon.C.API / XQueryProcessor.h @ 5401a5ae

1
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright (c) 2013 Saxonica Limited.
3
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
4
// If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
5
// This Source Code Form is "Incompatible With Secondary Licenses", as defined by the Mozilla Public License, v. 2.0.
6
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
7

    
8
#ifndef SAXON_XQUERY_H
9
#define SAXON_XQUERY_H
10

    
11

    
12

    
13
#include "SaxonProcessor.h"
14
//#include "XdmValue.h"
15
#include <string>
16

    
17

    
18

    
19
class SaxonProcessor;
20
class SaxonApiException;
21
class XdmValue;
22
class XdmItem;
23

    
24
/*! An <code>XQueryProcessor</code> represents factory to compile, load and execute the query.
25
 * <p/>
26
 */
27
class XQueryProcessor {
28
public:
29

    
30
    //! Default constructor.
31
    XQueryProcessor();
32

    
33
    //! Constructor with the SaxonProcessor supplied.
34
    /*!
35
     * @param SaxonProcessor - Supplied pointer to the SaxonProcessor object
36
     * @param cwd - set the current working directory. Default is the empty string
37
    */
38
    XQueryProcessor(SaxonProcessor *p, std::string cwd="");
39

    
40
    /**
41
      * XQueryProcessor copy constructor.
42
      * @param other - XsltProcessor
43
    */
44
    XQueryProcessor(const XQueryProcessor &other);
45

    
46
    /**
47
      * Clone the XQueryProcessor with the same internal state, which can be used in separate threads.
48
    */
49
    XQueryProcessor * clone();
50

    
51
    ~XQueryProcessor(){
52
        clearProperties();
53
        clearParameters();
54
    }
55

    
56
    //!Set the initial context item for the query
57
    /**
58
      @param value - the initial context item, or null if there is to be no initial context item
59
    */
60
    void setContextItem(XdmItem * value);
61

    
62
    /**
63
     * Set the output file where the result is sent
64
    */
65
    void setOutputFile(const char* outfile);
66

    
67
    /**
68
     * Set the source from file for the query.
69
    */
70
    void setContextItemFromFile(const char * filename); 
71

    
72
    /**
73
     * Set a parameter value used in the query
74
     *s
75
     * @param name  of the parameter, as a string. For namespaced parameter use the JAXP solution i.e. "{uri}name"
76
     * @param value of the query parameter, or null to clear a previously set value
77
     */
78
    void setParameter(const char * name, XdmValue*value);
79

    
80

    
81
    /**
82
     * Remove a parameter (name, value) pair
83
     *
84
     * @param namespacei currently not used
85
     * @param name  of the parameter
86
     * @return bool - outcome of the romoval
87
     */
88
    bool removeParameter(const char * name);
89

    
90
    /**
91
     * Set a property specific to the processor in use. 
92
     * XQueryProcessor: set serialization properties (names start with '!' i.e. name "!method" -> "xml")
93
     * 'o':outfile name, 's': source as file name
94
     * 'q': query file name, 'q': current by name, 'qs': string form of the query, 'base': set the base URI of the query, 'dtd': set DTD validation 'on' or 'off'
95
     * @param name of the property
96
     * @param value of the property
97
     */
98
    void setProperty(const char * name, const char * value);
99

    
100
    /**
101
     * Clear parameter values set
102
     *  @param deleteValues.  Individual pointers to XdmValue objects have to be deleted in the calling program
103
     * Default behaviour (false) is to leave XdmValues in memory
104
     *  true then XdmValues are deleted
105
     */
106
    void clearParameters(bool deleteValues=false);
107

    
108
    /**
109
     * Clear property values set
110
     */
111
    void clearProperties();
112

    
113

    
114
    /**
115
     * Say whether the query is allowed to be updating. XQuery update syntax will be rejected
116
     * during query compilation unless this flag is set. XQuery Update is supported only under Saxon-EE.
117
     * @param updating - true if the query is allowed to use the XQuery Update facility
118
     *                 (requires Saxon-EE). If set to false, the query must not be an updating query. If set
119
     *                 to true, it may be either an updating or a non-updating query.
120
     */
121
    void setUpdating(bool updating);
122

    
123

    
124
    //!Perform the Query to file.
125
    /**
126
     * The result is is saved to file
127
     *
128
     * @param infilename - The file name of the source document
129
     * @param ofilename - The file name of where result will be stored
130
     * @param query - The query as string representation. TODO check
131
     */
132
    void executeQueryToFile(const char * infilename, const char * ofilename, const char * query);
133

    
134
     //!Perform the Query to a XdmValue representation.
135
    /**
136
     * @param infilename - The file name of the source document
137
     * @param ofilename - The file name of where result will be stored
138
     * @param query - The query as string representation
139
     * @return XdmValue - result of the the query as a XdmValue 
140
     */
141
    XdmValue * executeQueryToValue(const char * infilename, const char * query);
142

    
143

    
144
    //!Perform the Query to a string representation.
145
    /**
146
     * @param infilename - The file name of the source document
147
     * @param query - The query as string representation
148
     * @return char array - result of as a string
149
     */
150
    const char * executeQueryToString(const char * infilename, const char * query);
151

    
152
    //!Execute the Query cached.
153
    /** 
154
     * The use of the context item would have had to be set in advance
155
     * @return XdmValue of the result
156
     *
157
     */
158
    XdmValue * runQueryToValue();
159

    
160
    /**
161
     * Execute the Query cached.
162
     * The use of the context item would have had to be set in advance
163
     * @return Result as a string (i.e. pointer array of char)
164
     *
165
     */
166
    const char * runQueryToString();
167

    
168

    
169
    //!Execute the Query cached to file.
170
    /**
171
     * The use of the context item would have had to be set in advance
172
     * Assume the output filename has been set in advance
173
     * @return Result as a string (i.e. pointer array of char)
174
     *
175
     */
176
    void runQueryToFile();
177

    
178
     //!Declare a namespace binding.
179
     /**
180
     * Declare a namespace binding as part of the static context for queries compiled using this
181
     * XQueryCompiler. This binding may be overridden by a binding that appears in the query prolog.
182
     * The namespace binding will form part of the static context of the query, but it will not be copied
183
     * into result trees unless the prefix is actually used in an element or attribute name.
184
     *
185
     * @param prefix The namespace prefix. If the value is a zero-length string, this method sets the default
186
     *               namespace for elements and types.
187
     * @param uri    The namespace URI. It is possible to specify a zero-length string to "undeclare" a namespace;
188
     *               in this case the prefix will not be available for use, except in the case where the prefix
189
     *               is also a zero length string, in which case the absence of a prefix implies that the name
190
     *               is in no namespace.
191
     * Assume the prefix or uri is null.
192
     */
193
    void declareNamespace(const char *prefix, const char * uri);
194

    
195

    
196
     //!Get all parameters as a std::map
197
     /**
198
      * @return std::map  - map of the parameters string->XdmValue* 
199
     */
200
     std::map<std::string,XdmValue*>& getParameters();
201

    
202
      //!Get all properties as a std::map
203
     /**
204
      * @return std::map map of the properties string->string 
205
     */
206
     std::map<std::string,std::string>& getProperties();
207

    
208
     //!Compile a query supplied as a file name.
209
    /**
210
     * The supplied query is cached for later execution.
211
     */
212
    void setQueryFile(const char* filename);
213

    
214
     //!Compile a query supplied as a string.
215
    /**
216
     * The supplied query is cached for later execution.
217
     */
218
    void setQueryContent(const char* content);
219

    
220
     //!Set the static base URI for the query
221
     /**
222
     * @param baseURI the static base URI; or null to indicate that no base URI is available
223
     */
224
    void setQueryBaseURI(const char * baseURI);
225

    
226
    /**
227
     * set the current working directory
228
    */
229
   void setcwd(const char* cwd);
230

    
231

    
232
     //! Check for exception thrown.
233
   /**
234
    * @return char*. Returns the main exception message if thrown otherwise return NULL
235
    */
236
    const char* checkException();
237

    
238
    /**
239
     * Checks for pending exceptions without creating a local reference to the exception object
240
     * @return bool - true when there is a pending exception; otherwise return false
241
    */
242
    bool exceptionOccurred();
243

    
244
    //! Clear any exception thrown
245
    void exceptionClear();
246

    
247

    
248
     //! Get the ith error message if there are any error
249
    /**
250
     * A transformation may have a number of errors reported against it.
251
     * @return char* - The message of the exception
252
    */
253
    const char * getErrorMessage();
254

    
255

    
256
     //! Get the i'th error code if there are any error
257
    /**
258
     * After the execution of the query there may be a number of errors reported against it.
259
     * @return char* - The error code of the exception.
260
    */
261
    const char * getErrorCode();
262
    
263

    
264
private:
265
    std::string cwdXQ; /*!< current working directory */
266
        SaxonProcessor * proc;
267
        jclass  cppClass;
268
        jobject cppXQ;
269
        std::map<std::string,XdmValue*> parameters; /*!< map of parameters used for the transformation as (string, value) pairs */
270
        std::map<std::string,std::string> properties; /*!< map of properties used for the transformation as (string, string) pairs */
271
        SaxonApiException * exception;
272
};
273

    
274
#endif /* SAXON_XQUERY_H */
(22-22/52)