Project

Profile

Help

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

he / tags / 9.8.0.14 / hec / Saxon.C.API / XsltProcessor.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_XSLT_H
9
#define SAXON_XSLT_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>XsltProcessor</code> represents factory to compile, load and execute a stylesheet.
22
 * It is possible to cache the context and the stylesheet in the <code>XsltProcessor</code>.
23
 */
24
class XsltProcessor {
25

    
26
public:
27

    
28
    //! Default constructor.
29
    /*!
30
      Creates a Saxon-HE product
31
    */
32
    XsltProcessor();
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
    XsltProcessor(SaxonProcessor* proc, std::string cwd="");
40

    
41
     ~XsltProcessor(){
42
        clearProperties();
43
        clearParameters();
44
     }
45

    
46
    //!set the current working directory
47
    /**
48
      * @param cwd - Current working directory
49
     */
50
   void setcwd(const char* cwd);
51

    
52

    
53
    //!Set the source document from a XdmValue for the transformation.
54
     /**
55
        * @param value - The source to the stylesheet as a pointer to the XdmItem object.
56
        */        
57
    void setSourceFromXdmValue(XdmItem * value); 
58

    
59
    /**
60
     * Set the source from file for the transformation.
61
    */
62
    void setSourceFromFile(const char * filename);
63

    
64
    /**
65
     * Set the output file of where the transformation result is sent
66
    */
67
    void setOutputFile(const char* outfile);
68

    
69
    /**
70
     * Set the value of a stylesheet parameter
71
     *
72
     * @param name  the name of the stylesheet parameter, as a string. For namespaced parameter use the JAXP solution i.e. "{uri}name"
73
     * @param value the value of the stylesheet parameter, or null to clear a previously set value
74
     */
75
    void setParameter(const char* name, XdmValue*value);
76

    
77
    /**
78
     * Get a parameter value by name
79
     * @param name - Specified paramater name to get
80
     * @return XdmValue
81
    */
82
     XdmValue* getParameter(const char* name);
83

    
84

    
85
    /**
86
     * Remove a parameter (name, value) pair from a stylesheet
87
     *
88
     * @param name  the name of the stylesheet parameter
89
     * @return bool - outcome of the romoval
90
     */
91
    bool removeParameter(const char* name);
92

    
93
    /**
94
     * Set a property specific to the processor in use. 
95
     * XsltProcessor: set serialization properties (names start with '!' i.e. name "!method" -> "xml")
96
     * 'o':outfile name, 'it': initial template, 'im': initial mode, 's': source as file name
97
     * 'm': switch on message listener for xsl:message instructions (TODO: this feature should be event based), 'item'| 'node' : source supplied as an XdmNode object
98
     * @param name of the property
99
     * @param value of the property
100
     */
101
    void setProperty(const char* name, const char* value);
102

    
103
    /**
104
     * Get a property value by name
105
     * @param name - Specified paramater name to get
106
     * @return string - Get string of the property as char pointer array
107
    */
108
    const char* getProperty(const char* name);
109

    
110
        //! Get all parameters as a std::map
111
     /**
112
      * 
113
      * Please note that the key name has been prefixed with 'param:', for example 'param:name'
114
      * @return std:map with key as string name mapped to XdmValue. 
115
      * 
116
     */
117
     std::map<std::string,XdmValue*>& getParameters();
118

    
119
        //! Get all properties as a std::map
120
     /**
121
      *  
122
      * @return std:map with key as string name mapped to string values.
123
     */
124
     std::map<std::string,std::string>& getProperties();
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
     //! Clear property values set
135
    void clearProperties();
136

    
137
    /**
138
     * Get the messages written using the <code>xsl:message</code> instruction
139
     * @return XdmValue - Messages returns as a XdmValue.
140
     */
141
    XdmValue * getXslMessages();//TODO allow notification of message as they occur
142

    
143

    
144
      //!Perform a one shot transformation.
145
    /**
146
     * The result is stored in the supplied outputfile.
147
     *
148
     * @param sourcefile - The file name of the source document
149
     * @param stylesheetfile - The file name of the stylesheet document. If NULL the most recently compiled stylesheet is used
150
     * @param outputfile - The file name where results will be stored
151
     */
152
    void transformFileToFile(const char* sourcefile, const char* stylesheetfile, const char* outputfile); 
153

    
154
        //!Perform a one shot transformation.
155
    /**
156
     * The result is returned as a string
157
     *
158
     * @param sourcefile - The file name of the source document
159
     * @param stylesheetfile - The file name of the stylesheet document. If NULL the most recently compiled stylesheet is used
160
     * @return char array - result of the transformation
161
     */
162
    const char * transformFileToString(const char* sourcefile, const char* stylesheetfile);
163

    
164
    /**
165
     * Perform a one shot transformation. The result is returned as an XdmValue
166
     *
167
     * @param sourcefile - The file name of the source document
168
     * @param stylesheetfile - The file name of the stylesheet document. If NULL the most recently compiled stylesheet is used
169
     * @return XdmValue - result of the transformation
170
     */
171
    XdmValue * transformFileToValue(const char* sourcefile, const char* stylesheetfile);
172

    
173

    
174
     //! compile a stylesheet file.
175
    /**
176
     * The compiled stylesheet is cached and available for execution later.
177
     * @param stylesheet  - The file name of the stylesheet document.
178
     */
179
    void compileFromFile(const char* stylesheet);
180

    
181
     //!compile a stylesheet received as a string.
182
    /**
183
     * 
184
     * The compiled stylesheet is cached and available for execution later.
185
     * @param stylesheet as a lexical string representation
186
     */
187
    void compileFromString(const char* stylesheet);
188

    
189
     //!compile a stylesheet received as an XdmNode.
190
    /**
191
     * The compiled stylesheet is cached and available for execution later.
192
     * @param stylesheet as a lexical string representation
193
     */
194
    void compileFromXdmNode(XdmNode * node);
195

    
196

    
197
    //! Internal method to release cached stylesheet
198
    /**
199
     *
200
     * @param void
201
     */
202
    void releaseStylesheet();
203

    
204

    
205
    //! Execute transformation to string. Properties supplied in advance.
206
    /**
207
     * Perform the transformation based upon what has been cached.
208
     * @return char*. Pointer to Array of chars. Result returned as a string.
209
     *
210
     */
211
    const char * transformToString();
212

    
213
    //! Execute transformation to Xdm Value. Properties supplied in advance.
214
    /**
215
     * Perform the transformation based upon cached stylesheet and any source document.
216
     * @return as an XdmValue.
217
     *
218
     */
219
    XdmValue * transformToValue();
220

    
221
    //! Execute transformation to file. Properties supplied in advance.
222
    /**
223
     * Perform the transformation based upon cached stylesheet and source document.
224
     * Assume the outputfile has been set in advance
225
     * @return as an XdmValue.
226
     *
227

228
     */
229
    void transformToFile();
230

    
231
    /**
232
     * Checks for pending exceptions without creating a local reference to the exception object
233
     * @return bool - true when there is a pending exception; otherwise return false
234
    */
235
    bool exceptionOccurred();
236

    
237

    
238
     //! Check for exception thrown.
239
        /**
240
        * @return cha*. Returns the exception message if thrown otherwise return NULL
241
        */
242
    const char* checkException();
243

    
244

    
245
     //! Clear any exception thrown
246
    void exceptionClear();
247

    
248
     //!Get number of errors reported during execution or evaluate of stylesheet
249
    /**
250
     * A transformation may have a number of errors reported against it.
251
     * @return int - Count of the exceptions recorded against the transformation
252
    */
253
    int exceptionCount();
254

    
255
     //! Get the ith error message if there are any error
256
    /**
257
     * A transformation may have a number of errors reported against it.
258
     * @return char* - The message of the i'th exception 
259
    */
260
    const char * getErrorMessage(int i);
261

    
262
     //! Get the ith error code if there are any error
263
    /**
264
     * A transformation may have a number of errors reported against it.
265
     * @return char* - The error code of the i'th exception. The error code are related to the specific specification 
266
    */
267
    const char * getErrorCode(int i);
268

    
269

    
270

    
271

    
272
        //! Get the SaxonProcessor object
273
        /**
274
        * @return SaxonProcessor - Pointer to the object
275
        */
276
    SaxonProcessor * getSaxonProcessor(){return proc;}
277

    
278

    
279
private:
280
        SaxonProcessor* proc;/*! */
281
        jclass  cppClass;
282
        jobject cppXT, stylesheetObject, xdmValuei;
283
        std::string cwdXT; /*!< current working directory */
284
        std::string outputfile1; /*!< output file where result will be saved */
285
        std::string failure; //for testing
286
        bool nodeCreated;
287
        std::map<std::string,XdmValue*> parameters; /*!< map of parameters used for the transformation as (string, value) pairs */
288
        std::map<std::string,std::string> properties; /*!< map of properties used for the transformation as (string, string) pairs */
289

    
290
};
291

    
292

    
293
#endif /* SAXON_XSLT_H */
(30-30/45)