Project

Profile

Help

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

he / src / main / c / Saxon.C.API / XPathProcessor.h @ a69dd173

1
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright (c) 2020 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_XPATH_H
9
#define SAXON_XPATH_H
10

    
11

    
12

    
13
#include "SaxonProcessor.h"
14
//#include "XdmValue.h"
15
//#include "XdmItem.h"
16

    
17
#include <string>
18

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

    
24
/*! An <code>XPathProcessor</code> represents factory to compile, load and execute the XPath query.
25
 * <p/>
26
 */
27
class XPathProcessor {
28
public:
29
        
30
    //! Default constructor.
31
    /*!
32
      Creates a Saxon-HE XPath product
33
    */
34
    XPathProcessor();
35

    
36
    ~XPathProcessor(){
37
        clearProperties();
38
        clearParameters(false);
39
        //delete contextItem;
40
    }
41

    
42
    //! Constructor with the SaxonProcessor supplied.
43
    /*!
44
      @param proc - Pointer to the SaxonProcessor object
45
      @param cwd - The current working directory
46
    */
47
    XPathProcessor(SaxonProcessor* proc, std::string cwd="");
48

    
49
    //! Set the static base URI for XPath expressions compiled using this XPathCompiler.
50
    /**
51
     * The base URI is part of the static context, and is used to resolve any relative URIs appearing within an XPath
52
     * expression, for example a relative URI passed as an argument to the doc() function. If no
53
     * static base URI is supplied, then the current working directory is used.
54
     * @param uriStr
55
     */
56
     void setBaseURI(const char * uriStr);
57

    
58
    //! Compile and evaluate an XPath expression
59
   /**
60
     * @param xpathStr - supplied as a character string
61
        @return XdmValue
62
   */
63
   XdmValue * evaluate(const char * xpathStr);
64
   
65

    
66
    //! Compile and evaluate an XPath expression. The result is expected to be a single XdmItem or nullptr
67
   /**
68
     * @param xpathStr - supplied as a character string
69
        @return XdmItem - XdmItem object or nullptr if the expression returns an empty sequence.
70
    * If the expression returns a sequence of more than one item, any items after the first are ignored.
71
   */
72
   XdmItem * evaluateSingle(const char * xpathStr);
73

    
74
   void setContextItem(XdmItem * item);
75

    
76
    /**
77
     * set the current working directory
78
    */
79
   void setcwd(const char* cwd);
80

    
81
    //! Set the context item from  file
82
    void setContextFile(const char * filename); //TODO: setContextItemFromFile
83

    
84
    //! Evaluate the XPath expression, returning the effective boolean value of the result.
85
     /** @param xpathStr - supplied as a character string
86
        @return bool
87
   */
88
   bool effectiveBooleanValue(const char * xpathStr);
89

    
90
    /**
91
     * Set a parameter value used in the query
92
     *s
93
     * @param name  of the parameter, as a string. For namespaced parameter use the JAXP solution i.e. "{uri}name"
94
     * @param value of the query parameter, or nullptr to clear a previously set value
95
     */
96
    void setParameter(const char * name, XdmValue*value);
97

    
98

    
99
    /**
100
     * Remove a parameter (name, value) pair
101
     *
102
     * @param name  of the parameter
103
     * @return bool - outcome of the romoval
104
     */
105
    bool removeParameter(const char * name);
106

    
107
    //!Set a property specific to the processor in use.
108
    /**
109
     * XPathProcessor: set serialization properties (names start with '!' i.e. name "!method" -> "xml")
110
     * 'o':outfile name, 's': context item supplied as file name
111
     * @param name of the property
112
     * @param value of the property
113
     */
114
    void setProperty(const char * name, const char * value);
115

    
116
    //!Declare a namespace binding as part of the static context for XPath expressions compiled using this XPathCompiler
117
     /**
118
     *
119
     * @param prefix The namespace prefix. If the value is a zero-length string, this method sets the default
120
     *               namespace for elements and types.
121
     * @param uri    The namespace URI. It is possible to specify a zero-length string to "undeclare" a namespace;
122
     *               in this case the prefix will not be available for use, except in the case where the prefix
123
     *               is also a zero length string, in which case the absence of a prefix implies that the name
124
     *               is in no namespace.
125
     * Assume the prefix or uri is nullptr.
126
     */
127
    void declareNamespace(const char *prefix, const char * uri);
128

    
129
#if CVERSION_API_NO >= 121
130

    
131

    
132

    
133
    //! Say whether XPath 1.0 backwards compatibility mode is to be used
134
    /**
135
    * In backwards compatibility
136
    * mode, more implicit type conversions are allowed in XPath expressions, for example it
137
    * is possible to compare a number with a string. The default is false (backwards compatibility
138
    * mode is off).
139
    *
140
    * @param option true if XPath 1.0 backwards compatibility is to be enabled, false if it is to be disabled.
141
    */
142
    void setBackwardsCompatible(bool option);
143

    
144

    
145
    //! Say whether the compiler should maintain a cache of compiled expressions.
146
    /**
147
     * @param caching if set to true, caching of compiled expressions is enabled.
148
     *                If set to false, any existing cache is cleared, and future compiled expressions
149
     *                will not be cached until caching is re-enabled. The cache is also cleared
150
     *                (but without disabling future caching)
151
     *                if any method is called that changes the static context for compiling
152
     *                expressions, for example {@link #declareVariable(QName)} or
153
     *                {@link #declareNamespace(String, String)}.
154
    */
155

    
156
    void setCaching(bool caching);
157

    
158

    
159
    //! Import a schema namespace
160
    /**
161
     * Here we add the element and attribute declarations and type definitions
162
     * contained in a given namespace to the static context for the XPath expression.
163
     * <p>This method will not cause the schema to be loaded. That must be done separately, using the
164
     * {@link SchemaManager}. This method will not fail if the schema has not been loaded (but in that case
165
     * the set of declarations and definitions made available to the XPath expression is empty). The schema
166
     * document for the specified namespace may be loaded before or after this method is called.</p>
167
     * <p>This method does not bind a prefix to the namespace. That must be done separately, using the
168
     * {@link #declareNamespace(String, String)} method.</p>
169
     *
170
     * @param uri The schema namespace to be imported. To import declarations in a no-namespace schema,
171
     *            supply a zero-length string.
172
     */
173
    void importSchemaNamespace(const char * uri);
174

    
175
#endif
176
     /**
177
      * Get all parameters as a std::map
178
     */
179
     std::map<std::string,XdmValue*>& getParameters();
180

    
181
     /**
182
      * Get all properties as a std::map 
183
     */
184
     std::map<std::string,std::string>& getProperties();
185

    
186
    /**
187
     * Clear parameter values set
188
     *  @param deleteValues.  Individual pointers to XdmValue objects have to be deleted in the calling program
189
     * Default behaviour (false) is to leave XdmValues in memory
190
     *  true then XdmValues are deleted
191
     */
192
    void clearParameters(bool deleteValues=false);
193

    
194
    /**
195
     * Clear property values set
196
     */
197
    void clearProperties();
198

    
199
    /**
200
     * Checks for pending exceptions without creating a local reference to the exception object
201
     * @return bool - true when there is a pending exception; otherwise return false
202
    */
203

    
204
   // const char* checkException();
205

    
206
    /**
207
     * Checks for pending exceptions without creating a local reference to the exception object
208
     * @return bool - true when there is a pending exception; otherwise return false
209
    */
210
    bool exceptionOccurred();
211

    
212
    //! Clear any exception thrown
213
    void exceptionClear();
214

    
215
     //! Get the ith error message if there are any error
216
    /**
217
     * A transformation may have a number of errors reported against it.
218
     * @return char* - The message of the exception
219
    */
220
    const char * getErrorMessage();
221

    
222

    
223
     //! Get the ith error code if there are any error
224
    /**
225
     * After the execution of the XPath expression there may be  a number of errors reported against it.
226
     * @return char* - The error code of the exception.
227
    */
228
    const char * getErrorCode();
229

    
230
     //! Check for exception thrown.
231
        /**
232
        * @return char*. Returns the exception message if thrown otherwise return nullptr
233
        */
234
    const char* checkException();
235

    
236
    //! Get the SaxonApiException object created when we have an error
237
    /**
238
     * After the execution of the processor if there is an error, then a SaxonApiException is created.
239
     * NULL returned if there is no error.
240
     * @return SaxomApiException object of the exception thrown.
241
     */
242
    SaxonApiException * getException();
243

    
244

    
245
private:
246
        SaxonProcessor * proc;
247
        XdmItem * contextItem;
248
        std::string cwdXP; /*!< current working directory */
249
        jclass  cppClass;
250
        jobject cppXP;
251
        std::map<std::string,XdmValue*> parameters; /*!< map of parameters used for the transformation as (string, value) pairs */
252
        std::map<std::string,std::string> properties; /*!< map of properties used for the transformation as (string, string) pairs */
253
    SaxonApiException * exception;
254
};
255

    
256

    
257

    
258

    
259
#endif /* SAXON_XPATH_H */
(20-20/55)