Project

Profile

Help

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

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

1
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright (c) 2015 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
67
   /**
68
     * @param xpathStr - supplied as a character string
69
        @return XdmItem
70
   */
71
   XdmItem * evaluateSingle(const char * xpathStr);
72

    
73
   void setContextItem(XdmItem * item);
74

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

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

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

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

    
97

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

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

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

    
128
#if CVERSION_API_NO >= 121
129

    
130

    
131

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

    
143

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

    
155
    void setCaching(bool caching);
156

    
157

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

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

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

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

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

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

    
203
   // const char* checkException();
204

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

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

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

    
221

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

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

    
235

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

    
247

    
248

    
249

    
250
#endif /* SAXON_XPATH_H */
(20-20/52)