Project

Profile

Help

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

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

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_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 SaxonApiException;
18
class XsltExecutable;
19
class XdmValue;
20
class XdmItem;
21
class XdmNode;
22

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

    
28
public:
29

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

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

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

    
49
     ~Xslt30Processor();
50

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

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

    
66

    
67

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

    
85

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

    
100

    
101

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

    
109

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

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

    
127

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

    
136

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

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

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

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

    
167

    
168

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

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

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

    
198

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

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

    
218

    
219

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

    
236

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

    
246

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

    
256

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

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

    
274

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

    
281

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

    
288

    
289
     //! Clear any exception thrown
290
    void exceptionClear();
291

    
292

    
293
     //! Get the ith error message if there are any error
294
    /**
295
     * A transformation may have a number of errors reported against it.
296
     * @return char* - The message of the exception
297
    */
298
    const char * getErrorMessage();
299

    
300
     //! Get the ith error code if there are any error
301
    /**
302
     * A transformation may have a number of errors reported against it.
303
     * @return char* - The error code of the exception. The error code are related to the specific specification
304
    */
305
    const char * getErrorCode();
306

    
307

    
308

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

    
319

    
320
#endif /* SAXON_XSLT30_H */
(35-35/52)