Project

Profile

Help

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

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

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

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

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

    
54
    //! Compile and evaluate an XPath expression
55
   /**
56
     * @param xpathStr - supplied as a character string
57
        @return XdmValue
58
   */
59
   XdmValue * evaluate(const char * xpathStr);
60
   
61

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

    
70
   void setContextItem(XdmItem * item);
71

    
72
    /**
73
     * set the current working directory
74
    */
75
   void setcwd(const char* cwd);
76

    
77
    //! Set the context item from  file
78
    void setContextFile(const char * filename); //TODO: setContextItemFromFile
79

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

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

    
94

    
95
    /**
96
     * Remove a parameter (name, value) pair
97
     *
98
     * @param name  of the parameter
99
     * @return bool - outcome of the romoval
100
     */
101
    bool removeParameter(const char * name);
102

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

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

    
125
#if CVERSION_API_NO >= 121
126

    
127

    
128

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

    
140

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

    
152
    void setCaching(bool caching);
153

    
154

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

    
171
#endif
172
     /**
173
      * Get all parameters as a std::map
174
     */
175
     std::map<std::string,XdmValue*>& getParameters();
176

    
177
     /**
178
      * Get all properties as a std::map 
179
     */
180
     std::map<std::string,std::string>& getProperties();
181

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

    
190
    /**
191
     * Clear property values set
192
     */
193
    void clearProperties();
194

    
195
    /**
196
     * Checks for pending exceptions without creating a local reference to the exception object
197
     * @return bool - true when there is a pending exception; otherwise return false
198
    */
199

    
200
   // const char* checkException();
201

    
202
    /**
203
     * Checks for pending exceptions without creating a local reference to the exception object
204
     * @return bool - true when there is a pending exception; otherwise return false
205
    */
206
    bool exceptionOccurred();
207

    
208
    //! Clear any exception thrown
209
    void exceptionClear();
210

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

    
218

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

    
226

    
227
    //! Get the SaxonApiException object created when we have an error
228
    /**
229
     * After the execution of the processor if there is an error, then a SaxonApiException is created.
230
     * NULL returned if there is no error.
231
     * @return SaxomApiException object of the exception thrown.
232
     */
233
    SaxonApiException * getException();
234

    
235
private:
236

    
237
    void createException(const char * message=nullptr);
238

    
239
        SaxonProcessor * proc;
240
        std::string cwdXP; /*!< current working directory */
241
        jclass  cppClass;
242
        jobject cppXP;
243
        std::map<std::string,XdmValue*> parameters; /*!< map of parameters used for the transformation as (string, value) pairs */
244
        std::map<std::string,std::string> properties; /*!< map of properties used for the transformation as (string, string) pairs */
245
    SaxonApiException * exception;
246
};
247

    
248

    
249

    
250

    
251
#endif /* SAXON_XPATH_H */
(21-21/56)