Project

Profile

Help

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

he / tags / 9.8.0.14 / hec / Saxon.C.API / XPathProcessor.h @ 02f8308b

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 XdmValue;
21
class XdmItem;
22

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

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

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

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

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

    
65
    //! Compile and evaluate an XPath expression. The result is expected to be a single XdmItem
66
   /**
67
     * @param xpathStr - supplied as a character string
68
        @return XdmItem
69
   */
70
   XdmItem * evaluateSingle(const char * xpathStr);
71

    
72
   void setContextItem(XdmItem * item);
73

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

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

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

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

    
96

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

    
105

    
106
    /**
107
     * Set a property specific to the processor in use. 
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
     /**
116
     * Declare a namespace binding as part of the static context for XPath expressions compiled using this
117
     * XPathCompiler
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 null.
126
     */
127
    void declareNamespace(const char *prefix, const char * uri);
128

    
129
     /**
130
      * Get all parameters as a std::map
131
     */
132
     std::map<std::string,XdmValue*>& getParameters();
133

    
134
     /**
135
      * Get all properties as a std::map 
136
     */
137
     std::map<std::string,std::string>& getProperties();
138

    
139
    /**
140
     * Clear parameter values set
141
     *  @param deleteValues.  Individual pointers to XdmValue objects have to be deleted in the calling program
142
     * Default behaviour (false) is to leave XdmValues in memory
143
     *  true then XdmValues are deleted
144
     */
145
    void clearParameters(bool deleteValues=false);
146

    
147
    /**
148
     * Clear property values set
149
     */
150
    void clearProperties();
151

    
152
    /**
153
     * Checks for pending exceptions without creating a local reference to the exception object
154
     * @return bool - true when there is a pending exception; otherwise return false
155
    */
156

    
157
   // const char* checkException();
158

    
159
    /**
160
     * Checks for pending exceptions without creating a local reference to the exception object
161
     * @return bool - true when there is a pending exception; otherwise return false
162
    */
163
    bool exceptionOccurred();
164

    
165
    //! Clear any exception thrown
166
    void exceptionClear();
167

    
168
     //!Get number of errors reported during evaluation of the XPath
169
    /**
170
     * After the evalution of the XPAth expression there may be a number of errors reported against it.
171
     * @return int - Count of the exceptions recorded against the transformation
172
    */
173
    int exceptionCount();
174

    
175
     //! Get the ith error message if there are any error
176
    /**
177
     * A transformation may have a number of errors reported against it.
178
     * @return char* - The message of the i'th exception 
179
    */
180
    const char * getErrorMessage(int i);
181

    
182

    
183
     //! Get the ith error code if there are any error
184
    /**
185
     * After the execution of the XPath expression there may be  a number of errors reported against it.
186
     * @return char* - The error code of the i'th exception. 
187
    */
188
    const char * getErrorCode(int i);
189

    
190
     //! Check for exception thrown.
191
        /**
192
        * @return cha*. Returns the exception message if thrown otherwise return NULL
193
        */
194
    const char* checkException();
195

    
196

    
197
private:
198
        SaxonProcessor * proc;
199
        XdmItem * contextItem;
200
        std::string cwdXP; /*!< current working directory */
201
        jclass  cppClass;
202
        jobject cppXP;
203
        std::map<std::string,XdmValue*> parameters; /*!< map of parameters used for the transformation as (string, value) pairs */
204
        std::map<std::string,std::string> properties; /*!< map of properties used for the transformation as (string, string) pairs */
205

    
206
};
207

    
208

    
209

    
210

    
211
#endif /* SAXON_XPATH_H */
(18-18/45)