Saxon/C  1.2.1
Saxon Processor library for C/C++, PHP and Python
Xslt30Processor.h
1 // 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.
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 
25 
26 public:
27 
29 
33 
35 
39  Xslt30Processor(SaxonProcessor* proc, std::string cwd="");
40 
41  ~Xslt30Processor();
42 
44 
48 
50 
53  void setcwd(const char* cwd);
54 
55 
56 
58 
62  void setGlobalContextItem(XdmItem * value);
63 
67  void setGlobalContextFromFile(const char * filename);
68 
69 
71 
74  void setInitialMatchSelection(XdmValue * selection);
75 
77 
81  void setInitialMatchSelectionAsFile(const char * filename);
82 
86  void setOutputFile(const char* outfile);
87 
88 
104  void setJustInTimeCompilation(bool jit);
105 
106 
107 
108 
115  void setResultAsRawValue(bool option);
116 
126  void setParameter(const char* name, XdmValue*value, bool _static=false);
127 
128 
129 
135  XdmValue* getParameter(const char* name);
136 
137 
144  bool removeParameter(const char* name);
145 
154  void setProperty(const char* name, const char* value);
155 
156 
184  void setInitialTemplateParameters(std::map<std::string,XdmValue*> parameters, bool tunnel);
185 
191  const char* getProperty(const char* name);
192 
194 
200  std::map<std::string,XdmValue*>& getParameters();
201 
203 
207  std::map<std::string,std::string>& getProperties();
208 
210 
215  void clearParameters(bool deleteValues=false);
216 
218  void clearProperties();
219 
220  XdmValue ** createXdmValueArray(int len){
221  return (new XdmValue*[len]);
222  }
223 
224  void deleteXdmValueArray(XdmValue ** arr, int len){
225  for(int i =0; i< len; i++) {
226  //delete arr[i];
227  }
228  delete [] arr;
229  }
230 
235  XdmValue * getXslMessages();//TODO allow notification of message as they occur
236 
237 
239 
246  void transformFileToFile(const char* sourcefile, const char* stylesheetfile, const char* outputfile);
247 
249 
256  const char * transformFileToString(const char* sourcefile, const char* stylesheetfile);
257 
265  XdmValue * transformFileToValue(const char* sourcefile, const char* stylesheetfile);
266 
267 
269 
273  void compileFromFile(const char* stylesheet);
274 
276 
281  void compileFromString(const char* stylesheet);
282 
283 
284 
286  /* via the xml-stylesheet processing instruction (see
287  * http://www.w3.org/TR/xml-stylesheet/) with the document
288  * document specified in the source parameter, and that match
289  * the given criteria. If there are several suitable xml-stylesheet
290  * processing instructions, then the returned Source will identify
291  * a synthesized stylesheet module that imports all the referenced
292  * stylesheet module.*/
297  void compileFromAssociatedFile(const char* sourceFile);
298 
299 
301 
307  void compileFromStringAndSave(const char* stylesheet, const char* filename);
308 
309 
311 
317  void compileFromFileAndSave(const char* xslFilename, const char* filename);
318 
319 
321 
326  void compileFromXdmNodeAndSave(XdmNode * node, const char* filename);
327 
329 
333  void compileFromXdmNode(XdmNode * node);
334 
336 
343  void applyTemplatesReturningFile(const char * stylesheetFilename, const char* outfile);
344 
346 
351  const char* applyTemplatesReturningString(const char * stylesheetFilename=NULL);
352 
354 
359  XdmValue * applyTemplatesReturningValue(const char * stylesheetFilename=NULL);
360 
362 
370  void callTemplateReturningFile(const char * stylesheetFilename, const char* templateName, const char* outfile);
371 
373 
381  const char* callTemplateReturningString(const char * stylesheetFilename, const char* templateName);
382 
384 
392  XdmValue* callTemplateReturningValue(const char * stylesheetFilename, const char* templateName);
393 
394 
395 
397 
406  void callFunctionReturningFile(const char * stylesheetFilename, const char* functionName, XdmValue ** arguments, int argument_length, const char* outfile);
407 
408 
410 
419  const char * callFunctionReturningString(const char * stylesheetFilename, const char* functionName, XdmValue ** arguments, int argument_length);
420 
422 
431  XdmValue * callFunctionReturningValue(const char * stylesheetFilename, const char* functionName, XdmValue ** arguments, int argument_length);
432 
433 
435  /***
436  * The added XSLT packages will be imported later when compiling
437  * @param fileNames - packs array of file names of XSLT packages stored in filestore
438  * @param length - The number of package names in the array
439  */
440 
441  void addPackages(const char ** fileNames, int length);
442 
443  void clearPackages();
444 
445 
446 
448 
452  void releaseStylesheet();
453 
454 
456 
462  const char * transformToString(XdmNode * source);
463 
465 
471  XdmValue * transformToValue(XdmNode * source);
472 
474 
482  void transformToFile(XdmNode * source);
483 
488  bool exceptionOccurred();
489 
490 
492 
495  const char* checkException();
496 
497 
499  void exceptionClear();
500 
502 
506  int exceptionCount();
507 
509 
513  const char * getErrorMessage(int i);
514 
516 
520  const char * getErrorCode(int i);
521 
522 
523 
524 private:
525  SaxonProcessor* proc;
526  jclass cppClass;
527  jobject cppXT, stylesheetObject, xdmValuei, selection;
528  XdmValue * selectionV;
529  std::string cwdXT;
530  std::string outputfile1;
531  std::string failure; //for testing
532  bool nodeCreated;
533  bool tunnel;
534  std::map<std::string,XdmValue*> parameters;
536  std::map<std::string,std::string> properties;
538 };
539 
540 
541 #endif /* SAXON_XSLT30_H */
void setProperty(const char *name, const char *value)
Definition: Xslt30Processor.cpp:169
void compileFromXdmNode(XdmNode *node)
compile a stylesheet received as an XdmNode.
Definition: Xslt30Processor.cpp:358
void setResultAsRawValue(bool option)
Definition: Xslt30Processor.cpp:163
XdmValue * callTemplateReturningValue(const char *stylesheetFilename, const char *templateName)
Invoke a transformation by calling a named template and return result as a string.
Definition: Xslt30Processor.cpp:1024
void setInitialTemplateParameters(std::map< std::string, XdmValue *> parameters, bool tunnel)
Definition: Xslt30Processor.cpp:120
const char * applyTemplatesReturningString(const char *stylesheetFilename=NULL)
Invoke the stylesheet by applying templates to a supplied input sequence, Saving the results as seria...
Definition: Xslt30Processor.cpp:509
bool exceptionOccurred()
Definition: Xslt30Processor.cpp:64
void compileFromAssociatedFile(const char *sourceFile)
Get the stylesheet associated.
Definition: Xslt30Processor.cpp:386
void callFunctionReturningFile(const char *stylesheetFilename, const char *functionName, XdmValue **arguments, int argument_length, const char *outfile)
Call a public user-defined function in the stylesheet.
Definition: Xslt30Processor.cpp:648
void releaseStylesheet()
Internal method to release cached stylesheet.
Definition: Xslt30Processor.cpp:455
void transformFileToFile(const char *sourcefile, const char *stylesheetfile, const char *outputfile)
Perform a one shot transformation.
Definition: Xslt30Processor.cpp:1194
void transformToFile(XdmNode *source)
Execute transformation to file. Properties supplied in advance.
Definition: Xslt30Processor.cpp:1410
XdmValue * applyTemplatesReturningValue(const char *stylesheetFilename=NULL)
Invoke the stylesheet by applying templates to a supplied input sequence, Saving the results as an Xd...
Definition: Xslt30Processor.cpp:565
void setJustInTimeCompilation(bool jit)
Definition: Xslt30Processor.cpp:147
XdmValue * getXslMessages()
Definition: Xslt30Processor.cpp:1239
void compileFromFile(const char *stylesheet)
compile a stylesheet file.
Definition: Xslt30Processor.cpp:421
XdmValue * callFunctionReturningValue(const char *stylesheetFilename, const char *functionName, XdmValue **arguments, int argument_length)
Call a public user-defined function in the stylesheet.
Definition: Xslt30Processor.cpp:756
void clearParameters(bool deleteValues=false)
Clear parameter values set.
Definition: Xslt30Processor.cpp:183
Definition: Xslt30Processor.h:24
void setInitialMatchSelectionAsFile(const char *filename)
The initial filename to which templates are to be applied (equivalent to the select attribute of xsl:...
Definition: Xslt30Processor.cpp:97
SaxonProcessor * getSaxonProcessor()
Get the SaxonProcessor object.
Definition: Xslt30Processor.h:47
XdmValue * transformFileToValue(const char *sourcefile, const char *stylesheetfile)
Definition: Xslt30Processor.cpp:1108
void clearProperties()
Clear property values set.
Definition: Xslt30Processor.cpp:214
Definition: XdmNode.h:21
const char * getErrorMessage(int i)
Get the ith error message if there are any error.
Definition: Xslt30Processor.cpp:1422
Definition: XdmValue.h:46
const char * transformFileToString(const char *sourcefile, const char *stylesheetfile)
Perform a one shot transformation.
Definition: Xslt30Processor.cpp:1271
void setGlobalContextItem(XdmItem *value)
Set the source document from an XdmNode for the transformation.
Definition: Xslt30Processor.cpp:75
Xslt30Processor()
Default constructor.
Definition: Xslt30Processor.cpp:13
void setInitialMatchSelection(XdmValue *selection)
The initial value to which templates are to be applied (equivalent to the select attribute of xsl:app...
Definition: Xslt30Processor.cpp:88
void compileFromStringAndSave(const char *stylesheet, const char *filename)
compile a stylesheet received as a string and save to an exported file (SEF).
Definition: Xslt30Processor.cpp:286
const char * checkException()
Check for exception thrown.
Definition: Xslt30Processor.cpp:246
Definition: SaxonProcessor.h:296
const char * callFunctionReturningString(const char *stylesheetFilename, const char *functionName, XdmValue **arguments, int argument_length)
Call a public user-defined function in the stylesheet.
Definition: Xslt30Processor.cpp:703
Definition: XdmItem.h:15
const char * getProperty(const char *name)
Definition: Xslt30Processor.cpp:175
XdmValue * getParameter(const char *name)
Definition: Xslt30Processor.cpp:130
XdmValue * transformToValue(XdmNode *source)
Execute transformation to Xdm Value. Properties supplied in advance.
Definition: Xslt30Processor.cpp:1398
void applyTemplatesReturningFile(const char *stylesheetFilename, const char *outfile)
Invoke the stylesheet by applying templates to a supplied input sequence, Saving the results to file...
Definition: Xslt30Processor.cpp:461
std::map< std::string, XdmValue * > & getParameters()
Get all parameters as a std::map.
Definition: Xslt30Processor.cpp:221
void callTemplateReturningFile(const char *stylesheetFilename, const char *templateName, const char *outfile)
Invoke a transformation by calling a named template and save result to file.
Definition: Xslt30Processor.cpp:918
bool removeParameter(const char *name)
Definition: Xslt30Processor.cpp:143
std::map< std::string, std::string > & getProperties()
Get all properties as a std::map.
Definition: Xslt30Processor.cpp:226
const char * transformToString(XdmNode *source)
Execute transformation to string. Properties supplied in advance.
Definition: Xslt30Processor.cpp:1385
const char * getErrorCode(int i)
Get the ith error code if there are any error.
Definition: Xslt30Processor.cpp:68
void setcwd(const char *cwd)
set the current working directory
Definition: Xslt30Processor.cpp:240
int exceptionCount()
Get number of errors reported during execution or evaluate of stylesheet.
Definition: Xslt30Processor.cpp:254
void setGlobalContextFromFile(const char *filename)
Definition: Xslt30Processor.cpp:82
void exceptionClear()
Clear any exception thrown.
Definition: Xslt30Processor.cpp:231
void setParameter(const char *name, XdmValue *value, bool _static=false)
Definition: Xslt30Processor.cpp:108
void compileFromFileAndSave(const char *xslFilename, const char *filename)
compile a stylesheet received as a file and save to an exported file (SEF).
Definition: Xslt30Processor.cpp:309
void compileFromString(const char *stylesheet)
compile a stylesheet received as a string.
Definition: Xslt30Processor.cpp:331
void setOutputFile(const char *outfile)
Definition: Xslt30Processor.cpp:103
const char * callTemplateReturningString(const char *stylesheetFilename, const char *templateName)
Invoke a transformation by calling a named template and return result as a string.
Definition: Xslt30Processor.cpp:971
void addPackages(const char **fileNames, int length)
File names to XsltPackages stored on filestore are added to a set of packages.
Definition: Xslt30Processor.cpp:839
void compileFromXdmNodeAndSave(XdmNode *node, const char *filename)
compile a stylesheet received as an XdmNode.
Definition: Xslt30Processor.cpp:262