Project

Profile

Help

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

he / latest9.9 / hec / Saxon.C.API / Xslt30Processor.h @ 1117bc69

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_XSLT30_H
9
#define SAXON_XSLT30_H
10

    
11

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

    
16
class SaxonProcessor;
17
class XdmValue;
18
class XdmItem;
19
class XdmNode;
20

    
21
/*! An <code>Xslt30Processor</code> represents factory to compile, load and execute a stylesheet.
22
 * It is possible to cache the context and the stylesheet in the <code>Xslt30Processor</code>.
23
 */
24
class Xslt30Processor {
25

    
26
public:
27

    
28
    //! Default constructor.
29
    /*!
30
      Creates a Saxon-HE product
31
    */
32
    Xslt30Processor();
33

    
34
    //! Constructor with the SaxonProcessor supplied.
35
    /*!
36
      @param proc - Supplied pointer to the SaxonProcessor object
37
      cwd - The current working directory
38
    */
39
    Xslt30Processor(SaxonProcessor* proc, std::string cwd="");
40

    
41
        /**
42
         * Xslt30Processor copy constructor.
43
         * @param other - Xslt30Processor
44
         */
45
    Xslt30Processor(const Xslt30Processor &other);
46

    
47
     ~Xslt30Processor();
48

    
49
        //! Get the SaxonProcessor object
50
        /**
51
        * @return SaxonProcessor - Pointer to the object
52
        */
53
    SaxonProcessor * getSaxonProcessor(){return proc;}
54

    
55
    //!set the current working directory (cwd). This method also applies to the
56
    // static base URI for XSLT stylesheets when supplied as lexical string.
57
    /**
58
      * The cwd is used to set the base URI is part of the static context, and is used to resolve
59
      * any relative URIs appearing within XSLT.
60
      * @param cwd - Current working directory
61
     */
62
   void setcwd(const char* cwd);
63

    
64

    
65

    
66
    /**
67
    * Say whether just-in-time compilation of template rules should be used.
68
    * @param jit true if just-in-time compilation is to be enabled. With this option enabled,
69
    *            static analysis of a template rule is deferred until the first time that the
70
    *            template is matched. This can improve performance when many template
71
    *            rules are rarely used during the course of a particular transformation; however,
72
    *            it means that static errors in the stylesheet will not necessarily cause the
73
    *            {@link #compile(Source)} method to throw an exception (errors in code that is
74
    *            actually executed will still be notified to the registered <code>ErrorListener</code>
75
    *            or <code>ErrorList</code>, but this may happen after the {@link #compile(Source)}
76
    *            method returns). This option is enabled by default in Saxon-EE, and is not available
77
    *            in Saxon-HE or Saxon-PE.
78
    *            <p><b>Recommendation:</b> disable this option unless you are confident that the
79
    *            stylesheet you are compiling is error-free.</p>
80
    */
81
    void setJustInTimeCompilation(bool jit);
82

    
83

    
84
    /**
85
     * Set the value of a stylesheet parameter. Static (compile-time) parameters must be provided using
86
     * this method on the XsltCompiler object, prior to stylesheet compilation. Non-static parameters
87
     * may also be provided using this method if their values will not vary from one transformation
88
     * to another.
89
     *
90
     * @param name  the name of the stylesheet parameter, as a string. For namespaced parameter use the JAXP solution i.e. "{uri}name"
91
     * @param value the value of the stylesheet parameter, or null to clear a previously set value
92
     * @param _static For static (compile-time) parameters we set this flag to true, which means the parameter is
93
     * must be set on the XsltCompiler object, prior to stylesheet compilation. The default is false. Non-static parameters
94
     * may also be provided.
95
     */
96
    void setParameter(const char* name, XdmValue*value);
97

    
98

    
99

    
100
    /**
101
     * Get a parameter value by name
102
     * @param name - Specified paramater name to get
103
     * @return XdmValue
104
    */
105
     XdmValue* getParameter(const char* name);
106

    
107

    
108
    /**
109
     * Remove a parameter (name, value) pair from a stylesheet
110
     *
111
     * @param name  the name of the stylesheet parameter
112
     * @return bool - outcome of the romoval
113
     */
114
    bool removeParameter(const char* name);
115

    
116
        //! Get all parameters as a std::map
117
     /**
118
      * 
119
      * Please note that the key name has been prefixed with 'param:', for example 'param:name'
120
      * @return std:map with key as string name mapped to XdmValue. 
121
      * 
122
     */
123
     std::map<std::string,XdmValue*>& getParameters();
124

    
125

    
126
    //!Clear parameter values set
127
    /**
128
     * Default behaviour (false) is to leave XdmValues in memory
129
     *  true then XdmValues are deleted
130
     *  @param deleteValues.  Individual pointers to XdmValue objects have to be deleted in the calling program
131
     */
132
    void clearParameters(bool deleteValues=false);
133

    
134

    
135
    /**
136
    * Utility method for working with Saxon/C on Python
137
    */
138
    XdmValue ** createXdmValueArray(int len){
139
        return (new XdmValue*[len]);
140
    }
141

    
142
    /**
143
    * Utility method for working with Saxon/C on Python
144
    */
145
    char** createCharArray(int len){
146
        return (new char*[len]);
147
    }
148

    
149
    void deleteXdmValueArray(XdmValue ** arr, int len){
150
        for(int i =0; i< len; i++) {
151
                //delete arr[i];        
152
        }
153
        delete [] arr;
154
    }
155

    
156
    /**
157
     * This method gives users the option to switch on or off the <code>xsl:message</code> feature. It is also possible
158
     * to send the <code>xsl:message</code> outputs to file given by file name.
159
     * @param show - boolean to indicate if xsl:message should be outputted. Default is on.
160
     * @param  filename - If the filename argument is present then the xsl:message output is appended to the given
161
     *                    filename with location cwd+filename
162
     */
163
    void setupXslMessage(bool show, const char* filename=NULL);
164

    
165

    
166

    
167
      //!Perform a one shot transformation.
168
    /**
169
     * The result is stored in the supplied outputfile.
170
     *
171
     * @param sourcefile - The file name of the source document
172
     * @param stylesheetfile - The file name of the stylesheet document. If NULL the most recently compiled stylesheet is used
173
     * @param outputfile - The file name where results will be stored
174
     */
175
    void transformFileToFile(const char* sourcefile, const char* stylesheetfile, const char* outputfile); 
176

    
177
        //!Perform a one shot transformation.
178
    /**
179
     * The result is returned as a string
180
     *
181
     * @param sourcefile - The file name of the source document
182
     * @param stylesheetfile - The file name of the stylesheet document. If NULL the most recently compiled stylesheet is used
183
     * @return char array - result of the transformation
184
     */
185
    const char * transformFileToString(const char* sourcefile, const char* stylesheetfile);
186

    
187
    /**
188
     * Perform a one shot transformation. The result is returned as an XdmValue
189
     *
190
     * @param sourcefile - The file name of the source document
191
     * @param stylesheetfile - The file name of the stylesheet document. If NULL the most recently compiled stylesheet is used
192
     * @return XdmValue - result of the transformation
193
     */
194
    XdmValue * transformFileToValue(const char* sourcefile, const char* stylesheetfile);
195

    
196

    
197
     //! compile a stylesheet file.
198
    /**
199
     * The compiled stylesheet is cached and available for execution later.
200
     * @param stylesheet  - The file name of the stylesheet document.
201
     * @return an XsltExecutable, which represents the compiled stylesheet. The XsltExecutable
202
     * is immutable and thread-safe; it may be used to run multiple transformations, in series or concurrently.
203
     */
204
    XsltExecutable * compileFromFile(const char* stylesheet);
205

    
206
     //!compile a stylesheet received as a string.
207
    /**
208
     * 
209
     * The compiled stylesheet is cached and available for execution later.
210
     * @param stylesheet as a lexical string representation
211
     * @return an XsltExecutable, which represents the compiled stylesheet. The XsltExecutable
212
     * is immutable and thread-safe; it may be used to run multiple transformations, in series or concurrently.
213
     */
214
    XsltExecutable * compileFromString(const char* stylesheet);
215

    
216

    
217

    
218
     //! Get the stylesheet associated
219
     /* via the xml-stylesheet processing instruction (see
220
     * http://www.w3.org/TR/xml-stylesheet/) with the document
221
     * document specified in the source parameter, and that match
222
     * the given criteria.  If there are several suitable xml-stylesheet
223
     * processing instructions, then the returned Source will identify
224
     * a synthesized stylesheet module that imports all the referenced
225
     * stylesheet module.*/
226
    /**
227
     * The compiled stylesheet is cached and available for execution later.
228
     * @param sourceFile  - The file name of the XML document.
229
     * @return an XsltExecutable, which represents the compiled stylesheet. The XsltExecutable
230
     * is immutable and thread-safe; it may be used to run multiple transformations, in series or concurrently.
231
     */
232
    XsltExecutable * compileFromAssociatedFile(const char* sourceFile);
233

    
234

    
235
     //!compile a stylesheet received as a string and save to an exported file (SEF).
236
    /**
237
     * 
238
     * The compiled stylesheet is saved as SEF to file store
239
     * @param stylesheet as a lexical string representation
240
     * @param filename - the file to which the compiled package should be saved
241
     */
242
    void compileFromStringAndSave(const char* stylesheet, const char* filename);
243

    
244

    
245
     //!compile a stylesheet received as a file and save to an exported file (SEF).
246
    /**
247
     * 
248
     * The compiled stylesheet is saved as SEF to file store
249
     * @param xslFilename - file name of the stylesheet
250
     * @param filename - the file to which the compiled package should be saved
251
     */
252
    void compileFromFileAndSave(const char* xslFilename, const char* filename);
253

    
254

    
255
     //!compile a stylesheet received as an XdmNode.
256
    /**
257
     * The compiled stylesheet is cached and available for execution later.
258
     * @param stylesheet as a lexical string representation
259
     * @param filename - the file to which the compiled package should be saved
260
     */
261
    void compileFromXdmNodeAndSave(XdmNode * node, const char* filename);
262

    
263
     //!compile a stylesheet received as an XdmNode.
264
    /**
265
     * The compiled stylesheet is cached and available for execution later.
266
     * @param stylesheet as a lexical string representation
267
     * @return an XsltExecutable, which represents the compiled stylesheet. The XsltExecutable
268
     * is immutable and thread-safe; it may be used to run multiple transformations, in series or concurrently.
269
     */
270
    XsltExecutable * compileFromXdmNode(XdmNode * node);
271

    
272

    
273
    /**
274
     * Checks for pending exceptions without creating a local reference to the exception object
275
     * @return bool - true when there is a pending exception; otherwise return false
276
    */
277
    bool exceptionOccurred();
278

    
279

    
280
     //! Check for exception thrown.
281
        /**
282
        * @return cha*. Returns the exception message if thrown otherwise return NULL
283
        */
284
    const char* checkException();
285

    
286

    
287
     //! Clear any exception thrown
288
    void exceptionClear();
289

    
290
     //!Get number of errors reported during execution or evaluate of stylesheet
291
    /**
292
     * A transformation may have a number of errors reported against it.
293
     * @return int - Count of the exceptions recorded against the transformation
294
    */
295
    int exceptionCount();
296

    
297
     //! Get the ith error message if there are any error
298
    /**
299
     * A transformation may have a number of errors reported against it.
300
     * @return char* - The message of the i'th exception 
301
    */
302
    const char * getErrorMessage(int i);
303

    
304
     //! Get the ith error code if there are any error
305
    /**
306
     * A transformation may have a number of errors reported against it.
307
     * @return char* - The error code of the i'th exception. The error code are related to the specific specification 
308
    */
309
    const char * getErrorCode(int i);
310

    
311

    
312

    
313
private:
314
        SaxonProcessor* proc;/*! */
315
        jclass  cppClass;
316
        jobject cppXT;
317
    std::string cwdXT; /*!< current working directory */
318
        bool tunnel, jitCompilation;
319
        std::map<std::string,XdmValue*> parameters; /*!< map of parameters used for the transformation as (string, value) pairs */
320

    
321
};
322

    
323

    
324
#endif /* SAXON_XSLT30_H */
(33-33/50)