Project

Profile

Help

Revision 1117bc69

Added by O'Neil Delpratt almost 2 years ago

Saxon/C Development - Multithreading feature

View differences:

latest9.9/hec/Saxon.C.API/Xslt30Processor.h
46 46

  
47 47
     ~Xslt30Processor();
48 48

  
49
	/**
50
	 * Clone the Xslt30Processor with the same internal state, which can be used in separate threads.
51
	 */
52
    Xslt30Processor * clone();
53

  
54 49
	//! Get the SaxonProcessor object
55 50
	/**
56 51
	* @return SaxonProcessor - Pointer to the object
......
67 62
   void setcwd(const char* cwd);
68 63

  
69 64

  
70
      //!Set the base output URI.
71
          /**
72
           * <p>This defaults to the base URI of the {@link Destination} for the principal output
73
           * of the transformation if a destination is supplied and its base URI is known.</p>
74
           * <p>If a base output URI is supplied using this method then it takes precedence
75
           * over any base URI defined in the supplied {@code Destination} object, and
76
           * it may cause the base URI of the {@code Destination} object to be modified in situ.</p>
77
           * <p> The base output URI is used for resolving relative URIs in the <code>href</code> attribute
78
           * of the <code>xsl:result-document</code> instruction; it is accessible to XSLT stylesheet
79
           * code using the XPath {@code current-output-uri()} function</p>
80
           *
81
           * @param baseUri - the base output URI
82
           */
83
      void setBaseOutputURI(const char * baseURI);
84

  
85

  
86

  
87
    //!Set the source document from an XdmNode for the transformation.
88
     /**
89
	* @param value - The source to the stylesheet as a pointer to the XdmNode object.
90
	*/	
91

  
92
    void setGlobalContextItem(XdmItem * value);
93

  
94
    /**
95
     * Set the source from file for the transformation.
96
    */
97
    void setGlobalContextFromFile(const char * filename);
98

  
99

  
100
    //!The initial value to which templates are to be applied (equivalent to the <code>select</code> attribute of <code>xsl:apply-templates</code>)
101
    /**
102
    *  @param selection - The value to which the templates are to be applied
103
    */
104
    void setInitialMatchSelection(XdmValue * selection);
105

  
106
        //!The initial filename to which templates are to be applied (equivalent to the <code>select</code> attribute of <code>xsl:apply-templates</code>).
107
        /**
108
        * The file is parsed internall
109
        *  @param filename - The file name to which the templates are to be applied
110
        */
111
    void setInitialMatchSelectionAsFile(const char * filename);
112

  
113
    /**
114
     * Set the output file of where the transformation result is sent
115
    */
116
    void setOutputFile(const char* outfile);
117

  
118 65

  
119 66
    /**
120 67
    * Say whether just-in-time compilation of template rules should be used.
......
134 81
    void setJustInTimeCompilation(bool jit);
135 82

  
136 83

  
137

  
138

  
139
    /**
140
    *Set true if the return type of callTemplate, applyTemplates and transform methods is to return XdmValue,
141
    *otherwise return XdmNode object with root Document node
142
    * @param option true if return raw result, i.e. XdmValue, otherwise return XdmNode
143
    *
144
    */	
145
    void setResultAsRawValue(bool option);
146

  
147 84
    /**
148
     * Set the value of a stylesheet parameter
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.
149 89
     *
150 90
     * @param name  the name of the stylesheet parameter, as a string. For namespaced parameter use the JAXP solution i.e. "{uri}name"
151 91
     * @param value the value of the stylesheet parameter, or null to clear a previously set value
......
153 93
     * must be set on the XsltCompiler object, prior to stylesheet compilation. The default is false. Non-static parameters
154 94
     * may also be provided.
155 95
     */
156
    void setParameter(const char* name, XdmValue*value, bool _static=false);
96
    void setParameter(const char* name, XdmValue*value);
157 97

  
158 98

  
159 99

  
......
173 113
     */
174 114
    bool removeParameter(const char* name);
175 115

  
176
    /**
177
     * Set a property specific to the processor in use. 
178
     * XsltProcessor: set serialization properties (names start with '!' i.e. name "!method" -> "xml")
179
     * 'o':outfile name, 'it': initial template, 'im': initial mode, 's': source as file name
180
     * 'm': switch on message listener for xsl:message instructions (TODO: this feature should be event based), 'item'| 'node' : source supplied as an XdmNode object
181
     * @param name of the property
182
     * @param value of the property
183
     */
184
    void setProperty(const char* name, const char* value);
185

  
186

  
187
    /**
188
     * Set parameters to be passed to the initial template. These are used
189
     * whether the transformation is invoked by applying templates to an initial source item,
190
     * or by invoking a named template. The parameters in question are the xsl:param elements
191
     * appearing as children of the xsl:template element.
192
     * <p>The parameters are supplied in the form of a map; the key is a QName given as a string which must
193
     * match the name of the parameter; the associated value is an XdmValue containing the
194
     * value to be used for the parameter. If the initial template defines any required
195
     * parameters, the map must include a corresponding value. If the initial template defines
196
     * any parameters that are not present in the map, the default value is used. If the map
197
     * contains any parameters that are not defined in the initial template, these values
198
     * are silently ignored.</p>
199
     * <p>The supplied values are converted to the required type using the function conversion
200
     * rules. If conversion is not possible, a run-time error occurs (not now, but later, when
201
     * the transformation is actually run).</p>
202
     * <p>The <code>XsltTransformer</code> retains a reference to the supplied map, so parameters can be added or
203
     * changed until the point where the transformation is run.</p>
204
     * <p>The XSLT 3.0 specification makes provision for supplying parameters to the initial
205
     * template, as well as global stylesheet parameters. Although there is no similar provision
206
     * in the XSLT 1.0 or 2.0 specifications, this method works for all stylesheets, regardless whether
207
     * XSLT 3.0 is enabled or not.</p>
208
     *
209
     * @param parameters the parameters to be used for the initial template
210
     * @param tunnel     true if these values are to be used for setting tunnel parameters;
211
     *                   false if they are to be used for non-tunnel parameters
212
     */
213

  
214
    void setInitialTemplateParameters(std::map<std::string,XdmValue*> parameters, bool tunnel);
215

  
216
    /**
217
     * Get a property value by name
218
     * @param name - Specified paramater name to get
219
     * @return string - Get string of the property as char pointer array
220
    */
221
    const char* getProperty(const char* name);
222

  
223 116
	//! Get all parameters as a std::map
224 117
     /**
225 118
      * 
......
229 122
     */
230 123
     std::map<std::string,XdmValue*>& getParameters();
231 124

  
232
	//! Get all properties as a std::map
233
     /**
234
      *  
235
      * @return std:map with key as string name mapped to string values.
236
     */
237
     std::map<std::string,std::string>& getProperties();
238 125

  
239 126
    //!Clear parameter values set
240 127
    /**
......
244 131
     */
245 132
    void clearParameters(bool deleteValues=false);
246 133

  
247
     //! Clear property values set
248
    void clearProperties();
249 134

  
250 135
    /**
251 136
    * Utility method for working with Saxon/C on Python
......
278 163
    void setupXslMessage(bool show, const char* filename=NULL);
279 164

  
280 165

  
166

  
281 167
      //!Perform a one shot transformation.
282 168
    /**
283 169
     * The result is stored in the supplied outputfile.
......
312 198
    /**
313 199
     * The compiled stylesheet is cached and available for execution later.
314 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.
315 203
     */
316
    void compileFromFile(const char* stylesheet);
204
    XsltExecutable * compileFromFile(const char* stylesheet);
317 205

  
318 206
     //!compile a stylesheet received as a string.
319 207
    /**
320 208
     * 
321 209
     * The compiled stylesheet is cached and available for execution later.
322 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.
323 213
     */
324
    void compileFromString(const char* stylesheet);
214
    XsltExecutable * compileFromString(const char* stylesheet);
325 215

  
326 216

  
327 217

  
......
336 226
    /**
337 227
     * The compiled stylesheet is cached and available for execution later.
338 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.
339 231
     */
340
    void compileFromAssociatedFile(const char* sourceFile);
232
    XsltExecutable * compileFromAssociatedFile(const char* sourceFile);
341 233

  
342 234

  
343 235
     //!compile a stylesheet received as a string and save to an exported file (SEF).
......
372 264
    /**
373 265
     * The compiled stylesheet is cached and available for execution later.
374 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.
375 269
     */
376
    void compileFromXdmNode(XdmNode * node);
270
    XsltExecutable * compileFromXdmNode(XdmNode * node);
377 271

  
378
     //!Invoke the stylesheet by applying templates to a supplied input sequence, Saving the results to file.
379
    /**
380
     * The initial match selection must be set using one of the two methods setInitialMatchSelection or setInitialMatchSelectionFile.
381
     * The result is stored in the supplied output file.
382
     *
383
     * @param stylesheetFile - The file name of the stylesheet document. If NULL the most recently compiled stylesheet is used. It is possible to set the stylsheet using one of the following methods: compileFromFile, compileFromString or compileFromAssociatedFile
384
     * @param outputfile - The file name where results will be stored
385
     */
386
    void applyTemplatesReturningFile(const char * stylesheetFilename, const char* outfile);
387

  
388
     //!Invoke the stylesheet by applying templates to a supplied input sequence, Saving the results as serialized string.
389
    /**
390
     * The initial match selection must be set using one of the two methods setInitialMatchSelection or setInitialMatchSelectionFile.
391
     *
392
     * @param stylesheetFile - The file name of the stylesheet document. If NULL the most recently compiled stylesheet is used. It is possible to set the stylsheet using one of the following methods: compileFromFile, compileFromString or compileFromAssociatedFile
393
     */
394
    const char* applyTemplatesReturningString(const char * stylesheetFilename=NULL);
395

  
396
     //!Invoke the stylesheet by applying templates to a supplied input sequence, Saving the results as an XdmValue.
397
    /**
398
     * The initial match selection must be set using one of the two methods setInitialMatchSelection or setInitialMatchSelectionFile.
399
     *
400
     * @param stylesheetfile - The file name of the stylesheet document. If NULL the most recently compiled stylesheet is used. It is possible to set the stylsheet using one of the following methods: compileFromFile, compileFromString or compileFromAssociatedFile
401
     */
402
    XdmValue * applyTemplatesReturningValue(const char * stylesheetFilename=NULL);
403

  
404
    //! Invoke a transformation by calling a named template and save result to file.
405
    /** The results of calling the template are wrapped in a document node, which is then sent to the specified
406
    * file destination. If setInitialTemplateParameters(std::Map, boolean) has been
407
    * called, then the parameters supplied are made available to the called template (no error
408
    * occurs if parameters are supplied that are not used).
409
    * @param stylesheetfile - The file name of the stylesheet document. If NULL the most recently compiled stylesheet is used. It is possible to set the stylsheet using one of the following methods: compileFromFile, compileFromString or compileFromAssociatedFile
410
    * @param templateName - The name of the initial template. This must match the name of a public named template in the stylesheet. If the value is null, the clark name for xsl:initial-template is used.
411
    * @param outputfile - The file name where results will be stored,
412
    */
413
    void callTemplateReturningFile(const char * stylesheetFilename, const char* templateName, const char* outfile);
414

  
415
    //! Invoke a transformation by calling a named template and return result as a string.
416
    /** The results of calling the template are wrapped in a document node, which is then serialized as a string.
417
    * If setInitialTemplateParameters(std::Map, boolean) has been
418
    * called, then the parameters supplied are made available to the called template (no error
419
    * occurs if parameters are supplied that are not used).
420
    * @param stylesheetfile - The file name of the stylesheet document. If NULL the most recently compiled stylesheet is used. It is possible to set the stylsheet using one of the following methods: compileFromFile, compileFromString or compileFromAssociatedFile
421
    * @param templateName - the name of the initial template. This must match the name of a public named template in the stylesheet. If the value is null, the clark name for xsl:initial-template is used.
422
    * @param outputfile - The file name where results will be stored,
423
    */
424
    const char* callTemplateReturningString(const char * stylesheetFilename, const char* templateName);
425

  
426
    //! Invoke a transformation by calling a named template and return result as a string.
427
    /** The results of calling the template are wrapped in a document node, which is then returned as an XdmValue.
428
    * If setInitialTemplateParameters(std::Map, boolean) has been
429
    * called, then the parameters supplied are made available to the called template (no error
430
    * occurs if parameters are supplied that are not used).
431
    * @param stylesheetfile - The file name of the stylesheet document. If NULL the most recently compiled stylesheet is used. It is possible to set the stylsheet using one of the following methods: compileFromFile, compileFromString or compileFromAssociatedFile
432
    * @param templateName - the name of the initial template. This must match the name of a public named template in the stylesheet. If the value is null, the clark name for xsl:initial-template is used.
433
    * @param outputfile - The file name where results will be stored,
434
    */
435
    XdmValue* callTemplateReturningValue(const char * stylesheetFilename, const char* templateName);
436

  
437

  
438

  
439
    //! Call a public user-defined function in the stylesheet
440
    /** Here we wrap the result in an XML document, and sending this document to a specified file
441
    * @param stylesheetfile - The file name of the stylesheet document. If NULL the most recently compiled stylesheet is used. It is possible to set the stylsheet using one of the following methods: compileFromFile, compileFromString or compileFromAssociatedFile
442
    * @param functionName - The name of the function to be called
443
    * @param arguments - Pointer array of XdmValue object - he values of the arguments to be supplied to the function. These
444
    *                    will be converted if necessary to the type as defined in the function signature, using
445
    *                    the function conversion rules.
446
    * @param argument_length - the Coutn of arguments objects in the array
447
    * @param outputfile - The file name where results will be stored,
448
    */
449
    void callFunctionReturningFile(const char * stylesheetFilename, const char* functionName, XdmValue ** arguments, int argument_length, const char* outfile);
450

  
451

  
452
    //! Call a public user-defined function in the stylesheet
453
    /** Here we wrap the result in an XML document, and serialized this document to string value
454
    * @param stylesheetfile - The file name of the stylesheet document. If NULL the most recently compiled stylesheet is used. It is possible to set the stylsheet using one of the following methods: compileFromFile, compileFromString or compileFromAssociatedFile
455
    * @param functionName - The name of the function to be called
456
    * @param arguments - Pointer array of XdmValue object - he values of the arguments to be supplied to the function. These
457
    *                    will be converted if necessary to the type as defined in the function signature, using
458
    *                    the function conversion rules.
459
    * @param argument_length - the Coutn of arguments objects in the array
460
    * @param outputfile - The file name where results will be stored,
461
    */
462
    const char * callFunctionReturningString(const char * stylesheetFilename, const char* functionName, XdmValue ** arguments, int argument_length);
463

  
464
    //! Call a public user-defined function in the stylesheet
465
    /** Here we wrap the result in an XML document, and return the document as an XdmValue
466
    * @param stylesheetfile - The file name of the stylesheet document. If NULL the most recently compiled stylesheet is used. It is possible to set the stylsheet using one of the following methods: compileFromFile, compileFromString or compileFromAssociatedFile
467
    * @param functionName - The name of the function to be called
468
    * @param arguments - Pointer array of XdmValue object - he values of the arguments to be supplied to the function. These
469
    *                    will be converted if necessary to the type as defined in the function signature, using
470
    *                    the function conversion rules.
471
    * @param argument_length - the Coutn of arguments objects in the array
472
    * @param outputfile - The file name where results will be stored,
473
    */
474
    XdmValue * callFunctionReturningValue(const char * stylesheetFilename, const char* functionName, XdmValue ** arguments, int argument_length);
475

  
476

  
477

  
478
    //! Internal method to release cached stylesheet
479
    /**
480
     *
481
     * @param void
482
     */
483
    void releaseStylesheet();
484

  
485

  
486
    //! Execute transformation to string. Properties supplied in advance.
487
    /**
488
     * Perform the transformation based upon what has been cached.
489
     * @param source - source document suppplied as an XdmNode object
490
     * @return char*. Pointer to Array of chars. Result returned as a string.
491
     *
492
     */
493
    const char * transformToString(XdmNode * source);
494

  
495
    //! Execute transformation to Xdm Value. Properties supplied in advance.
496
    /**
497
     * Perform the transformation based upon cached stylesheet and any source document.
498
     * @param source - source document suppplied as an XdmNode object
499
     * @return as an XdmValue.
500
     *
501
     */
502
    XdmValue * transformToValue(XdmNode * source);
503

  
504
    //! Execute transformation to file. Properties supplied in advance.
505
    /**
506
     * Perform the transformation based upon cached stylesheet and source document.
507
     * Assume the outputfile has been set in advance
508
     * @param source - source document suppplied as an XdmNode object
509
     * @return as an XdmValue.
510
     *
511

  
512
     */
513
    void transformToFile(XdmNode * source);
514 272

  
515 273
    /**
516 274
     * Checks for pending exceptions without creating a local reference to the exception object
......
555 313
private:
556 314
	SaxonProcessor* proc;/*! */
557 315
	jclass  cppClass;
558
	jobject cppXT, stylesheetObject, selection;
559
	XdmValue * selectionV;
316
	jobject cppXT;
560 317
    std::string cwdXT; /*!< current working directory */
561 318
	bool tunnel, jitCompilation;
562 319
	std::map<std::string,XdmValue*> parameters; /*!< map of parameters used for the transformation as (string, value) pairs */
563
	
564
	std::map<std::string,std::string> properties; /*!< map of properties used for the transformation as (string, string) pairs */
565 320

  
566 321
};
567 322

  

Also available in: Unified diff