SaxonC  11.6
Saxon Processor library for C/C++, PHP and Python
XsltExecutable.h
1 // Copyright (c) 2022 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_XSLT_EXEC_H
9 #define SAXON_XSLT_EXEC_H
10 
11 
12 #include "SaxonProcessor.h"
13 //#include "XdmValue.h"
14 #include <string>
15 
16 class SaxonProcessor;
17 class SaxonApiException;
18 class Xslt30Processor;
19 class XdmValue;
20 class XdmItem;
21 class XdmNode;
22 class XdmFunctionItem;
23 class XdmMap;
24 class XdmArray;
25 
31 
32 friend class Xslt30Processor;
33 
34 
35 public:
36 
37 
38  ~XsltExecutable();
39 
41  // static base URI for XSLT stylesheets when supplied as lexical string.
47  void setcwd(const char* cwd);
48 
49 
51 
58  void setBaseOutputURI(const char * baseURI);
59 
60 
61 
63 
67  void setGlobalContextItem(XdmItem * value);
68 
72  void setGlobalContextFromFile(const char * filename);
73 
74 
76 
81 
82 
84 
93  void setInitialMode(const char * modeName);
94 
95 
97 
100  void setInitialMatchSelection(XdmValue * selection);
101 
103 
107  void setInitialMatchSelectionAsFile(const char * filename);
108 
112  void setOutputFile(const char* outfile);
113 
114 
115 
116 
123  void setResultAsRawValue(bool option);
124 
131  void setParameter(const char* name, XdmValue * value);
132 
133 
140  std::map<std::string,XdmValue*>& getResultDocuments();
141 
142 
143 
149  XdmValue* getParameter(const char* name);
150 
151 
158  bool removeParameter(const char* name);
159 
160 
161 
162 
169  bool removeProperty(const char* name);
170 
179  void setProperty(const char* name, const char* value);
180 
181 
209  void setInitialTemplateParameters(std::map<std::string,XdmValue*> parameters, bool tunnel);
210 
216  const char* getProperty(const char* name);
217 
219 
225  std::map<std::string,XdmValue*>& getParameters();
226 
228 
232  std::map<std::string,std::string>& getProperties();
233 
235 
240  void clearParameters(bool deleteValues=false);
241 
243  void clearProperties();
244 
249  return (new XdmValue*[len]);
250  }
251 
255  char** createCharArray(int len){
256  return (new char*[len]);
257  }
258 
260 
265  void deleteXdmValueArray(XdmValue ** arr, int len){
266  for(int i =0; i< len; i++) {
267  //delete arr[i];
268  }
269  delete [] arr;
270  }
271 
273 
280  void setSaveXslMessage(bool show, const char* filename=nullptr);
281 
283 
292  void setCaptureResultDocuments(bool flag, bool rawResults=false);
293 
294 
296 
306  void exportStylesheet(const char * filename);
307 
308 
310 
316  void transformFileToFile(const char* sourcefile, const char* outputfile);
317 
319 
325  const char * transformFileToString(const char* sourcefile);
326 
333  XdmValue * transformFileToValue(const char* sourcefile);
334 
335 
336 
338 
344  void applyTemplatesReturningFile(const char* outfile);
345 
347 
351  const char* applyTemplatesReturningString();
352 
354 
359 
361 
368  void callTemplateReturningFile(const char* templateName, const char* outfile);
369 
371 
377  const char* callTemplateReturningString(const char* templateName=nullptr);
378 
380 
386  XdmValue* callTemplateReturningValue(const char* templateName=nullptr);
387 
388 
389 
391 
399  void callFunctionReturningFile(const char* functionName, XdmValue ** arguments, int argument_length, const char* outfile);
400 
401 
403 
410  const char * callFunctionReturningString(const char* functionName, XdmValue ** arguments, int argument_length);
411 
413 
420  XdmValue * callFunctionReturningValue(const char* functionName, XdmValue ** arguments, int argument_length);
421 
422 
423 
424 
426 
432  const char * transformToString(XdmNode * source=nullptr);
433 
435 
441  XdmValue * transformToValue(XdmNode * source=nullptr);
442 
444 
451  void transformToFile(XdmNode * source=nullptr);
452 
457  bool exceptionOccurred();
458 
459 
460 
461 
463 
467 
469 
473  const char * getErrorMessage();
474 
475 
477  void exceptionClear();
478 
479 
480 
481 private:
483 
486  XsltExecutable();
487 
489 
493  XsltExecutable(jobject exObject, std::string cwd, std::string resources);
494 
499  XsltExecutable(const XsltExecutable &other);
500 
501 
502  jclass cppClass;
503  jclass messageListenerClass, resultDocumentClass;
504  jobject executableObject, selection, saxonMessageListenerObj, saxonResultDocObj;
505  XdmValue * selectionV;
506  std::string cwdXE;
507  std::string resources_dir;
508  bool tunnel, jitCompilation, rawResultsFlag;
509  std::map<std::string,XdmValue*> parameters;
510  std::map<std::string,std::string> properties;
511  std::map<std::string,XdmValue*> resultDocumentMap;
512 };
513 
514 
515 #endif /* SAXON_XSLT_EXEC_H */
Definition: SaxonApiException.h:19
The SaxonProcessor class acts as a factory for generating XQuery, XPath, Schema and XSLT compilers.
Definition: SaxonProcessor.h:119
Definition: XdmArray.h:25
Definition: XdmFunctionItem.h:23
Definition: XdmItem.h:29
Definition: XdmMap.h:29
Definition: XdmNode.h:31
Definition: XdmValue.h:50
Definition: Xslt30Processor.h:26
Definition: XsltExecutable.h:30
XdmValue * applyTemplatesReturningValue()
Invoke the compiled stylesheet by applying templates to a supplied input sequence,...
Definition: XsltExecutable.cpp:625
const char * callFunctionReturningString(const char *functionName, XdmValue **arguments, int argument_length)
Call a public user-defined function in the compiled stylesheet.
Definition: XsltExecutable.cpp:805
void setInitialMatchSelectionAsFile(const char *filename)
The initial filename to which templates are to be applied (equivalent to the select attribute of xsl:...
Definition: XsltExecutable.cpp:148
char ** createCharArray(int len)
Definition: XsltExecutable.h:255
const char * transformFileToString(const char *sourcefile)
Perform a one shot transformation.
Definition: XsltExecutable.cpp:1483
void exportStylesheet(const char *filename)
Produce a representation of the compiled stylesheet.
Definition: XsltExecutable.cpp:463
const char * transformToString(XdmNode *source=nullptr)
Execute transformation to string. Properties supplied in advance.
Definition: XsltExecutable.cpp:1557
void setCaptureResultDocuments(bool flag, bool rawResults=false)
Enable the capture of the result-document output into an std:map. This overrides the default mechanis...
Definition: XsltExecutable.cpp:206
void clearParameters(bool deleteValues=false)
Clear parameter values set.
Definition: XsltExecutable.cpp:413
void transformToFile(XdmNode *source=nullptr)
Execute transformation to file. Properties supplied in advance.
Definition: XsltExecutable.cpp:1576
void applyTemplatesReturningFile(const char *outfile)
Invoke the stylesheet by applying templates to a supplied input sequence, Saving the results to file.
Definition: XsltExecutable.cpp:485
const char * callTemplateReturningString(const char *templateName=nullptr)
Invoke a transformation by calling a named template and return result as a string.
Definition: XsltExecutable.cpp:1047
XdmValue * getParameter(const char *name)
Definition: XsltExecutable.cpp:351
const char * getProperty(const char *name)
Definition: XsltExecutable.cpp:405
SaxonApiException * getException()
Check for exception thrown and return the SaxonApiException object.
Definition: XsltExecutable.cpp:1586
XdmValue * callFunctionReturningValue(const char *functionName, XdmValue **arguments, int argument_length)
Call a public user-defined function in the already compiled stylesheet.
Definition: XsltExecutable.cpp:881
void clearProperties()
Clear property values set.
Definition: XsltExecutable.cpp:430
void setInitialMatchSelection(XdmValue *selection)
The initial value to which templates are to be applied (equivalent to the select attribute of xsl:app...
Definition: XsltExecutable.cpp:129
void exceptionClear()
Clear any exception thrown.
Definition: XsltExecutable.cpp:451
bool removeParameter(const char *name)
Definition: XsltExecutable.cpp:364
void setSaveXslMessage(bool show, const char *filename=nullptr)
This method gives users the option to switch on or off the xsl:message feature.
Definition: XsltExecutable.cpp:1407
void setGlobalContextFromFile(const char *filename)
Definition: XsltExecutable.cpp:123
void setProperty(const char *name, const char *value)
Definition: XsltExecutable.cpp:385
XsltExecutable * clone()
Create a clone object of this XsltExecutable object.
Definition: XsltExecutable.cpp:379
XdmValue * transformToValue(XdmNode *source=nullptr)
Execute transformation to Xdm Value. Properties supplied in advance.
Definition: XsltExecutable.cpp:1567
void setResultAsRawValue(bool option)
Definition: XsltExecutable.cpp:369
const char * applyTemplatesReturningString()
Invoke the compiled stylesheet by applying templates to a supplied input sequence,...
Definition: XsltExecutable.cpp:546
void setParameter(const char *name, XdmValue *value)
Definition: XsltExecutable.cpp:180
std::map< std::string, XdmValue * > & getResultDocuments()
Definition: XsltExecutable.cpp:258
void setcwd(const char *cwd)
set the current working directory (cwd). This method also applies to the
Definition: XsltExecutable.cpp:456
void callTemplateReturningFile(const char *templateName, const char *outfile)
Invoke a transformation by calling a named template and save result to file.
Definition: XsltExecutable.cpp:988
XdmValue * transformFileToValue(const char *sourcefile)
Definition: XsltExecutable.cpp:1246
void transformFileToFile(const char *sourcefile, const char *outputfile)
Perform a one shot transformation.
Definition: XsltExecutable.cpp:1350
const char * getErrorMessage()
Get the error message if there are any error.
Definition: XsltExecutable.cpp:1592
void setBaseOutputURI(const char *baseURI)
Set the base output URI.
Definition: XsltExecutable.cpp:166
XdmValue ** createXdmValueArray(int len)
Definition: XsltExecutable.h:248
XdmValue * callTemplateReturningValue(const char *templateName=nullptr)
Invoke a transformation by calling a named template and return result as an XdmValue.
Definition: XsltExecutable.cpp:1137
std::map< std::string, std::string > & getProperties()
Get all properties as a std::map.
Definition: XsltExecutable.cpp:446
void setOutputFile(const char *outfile)
Definition: XsltExecutable.cpp:162
void setInitialMode(const char *modeName)
Set the initial mode for the transformation.
Definition: XsltExecutable.cpp:172
std::map< std::string, XdmValue * > & getParameters()
Get all parameters as a std::map.
Definition: XsltExecutable.cpp:441
void callFunctionReturningFile(const char *functionName, XdmValue **arguments, int argument_length, const char *outfile)
Call a public user-defined function in the already compiled stylesheet.
Definition: XsltExecutable.cpp:732
void setGlobalContextItem(XdmItem *value)
Set the source document from an XdmNode for the transformation.
Definition: XsltExecutable.cpp:116
bool exceptionOccurred()
Definition: XsltExecutable.cpp:111
void deleteXdmValueArray(XdmValue **arr, int len)
Utility method for Python API - internal use only.
Definition: XsltExecutable.h:265
void setInitialTemplateParameters(std::map< std::string, XdmValue * > parameters, bool tunnel)
Definition: XsltExecutable.cpp:195
bool removeProperty(const char *name)
Definition: XsltExecutable.cpp:401