Xalan-C++ API Reference  1.12.0
XalanTransformer.hpp
Go to the documentation of this file.
1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 
19 #if !defined(XALANTRANSFORMER_HEADER_GUARD)
20 #define XALANTRANSFORMER_HEADER_GUARD
21 
22 // Base include file. Must be first.
24 
25 
26 
27 #include <cassert>
28 #include <iosfwd>
29 #include <algorithm>
30 
31 
32 
34 
39 
41 
42 
43 
46 
47 
48 
49 namespace XERCES_CPP_NAMESPACE
50 {
51  class EntityResolver;
52  class ErrorHandler;
53  class XMLEntityResolver;
54 }
55 
56 
57 
58 namespace XALAN_CPP_NAMESPACE {
59 
60 
61 
62 typedef xercesc::EntityResolver EntityResolverType;
63 typedef xercesc::ErrorHandler ErrorHandlerType;
64 
65 using xercesc::EntityResolver;
66 using xercesc::ErrorHandler;
67 using xercesc::XMLEntityResolver;
68 
69 
70 
71 class Function;
72 class StylesheetExecutionContextDefault;
73 class ProblemListener;
74 class TraceListener;
75 class XSLTInit;
76 class XalanDocumentBuilder;
77 class XalanCompiledStylesheet;
78 class XalanParsedSource;
79 class XalanTransformerOutputStream;
80 
81 class XObjectFactoryDefault;
82 class XalanNode;
83 
84 /**
85  * This is a simple C++ interface for some common usage patterns. It's
86  * the user's responsibility to call initialize and terminate for Xerces
87  * and Xalan before creating and after deleting any XalanTransformer
88  * instances.
89 */
91 {
92 
93 public:
94 
95  typedef std::ostream StreamType;
96 
99 
101 
104 
105  XalanTransformer(MemoryManager& theManager = XalanMemMgrs::getDefaultXercesMemMgr());
106 
107  virtual
109 
110  MemoryManager&
112  {
113  return m_memoryManager;
114  }
115 
116  const MemoryManager&
118  {
119  return m_memoryManager;
120  }
121 
122  /**
123  * Initialize Xalan.
124  *
125  * Should be called only once per process before creating any
126  * instances of XalanTransformer. This call is not thread-safe,
127  * so you must serialize any calls to it, and you must track the
128  * initialization state, so you do not call it more than once.
129  */
130  static void
131  initialize(MemoryManager& theManager = XalanMemMgrs::getDefaultXercesMemMgr());
132 
133  /**
134  * Terminate Xalan.
135  *
136  * Should be called only once per process after deleting all
137  * instances of XalanTransformer. This call is not thread-safe,
138  * so you must serialize any calls to it, and you must track the
139  * initialization state, so you do not call it more than once.
140  *
141  * This is handy when using leak-detection software, as all
142  * static data allocated by Xalan is freed.
143  *
144  */
145  static void
147 
148  /**
149  * Clean up the ICU, if ICU integration is enabled.
150  *
151  * This should be called only once per process after calling
152  * XalanTransformer::terminate() and XMLPlatformUtils::Terminate.
153  *
154  * This must only be done if the ICU will no longer be used by
155  * the process, since the ICU will no longer be in a usable state.
156  * See the ICU documentation for more details.
157  *
158  * This call is not thread-safe, so you must serialize any calls
159  * to it, and you must track the initialization state, so you do
160  * not call it more than once.
161  *
162  * This is handy when using leak-detection software, as all
163  * static data allocated by the ICU is freed.
164  *
165  */
166  static void
168 
169 
170  static void
171  ICUStartUp(MemoryManager& theManager = XalanMemMgrs::getDefaultXercesMemMgr());
172 
173  /**
174  * Transform will apply the stylesheet source to the parsed xml source
175  * and write the transformation output to the target.
176  *
177  * @param theParsedXML the parsed input source
178  * @param theStylesheetSource stylesheet source
179  * @param theResultTarget output source
180  * @return 0 for success
181  */
182  int
184  const XalanParsedSource& theParsedXML,
185  const XSLTInputSource& theStylesheetSource,
186  const XSLTResultTarget& theResultTarget)
187  {
188  return doTransform(theParsedXML, 0, &theStylesheetSource, theResultTarget);
189  }
190 
191  /**
192  * Transform will apply the compiled stylesheet to the parsed xml source
193  * and write the transformation output to the target.
194  *
195  * @param theParsedXML the parsed input source
196  * @param theCompiledStylesheet pointer to a compiled stylesheet. Must not be null.
197  * @param theResultTarget output source
198  * @return 0 for success
199  */
200  int
202  const XalanParsedSource& theParsedXML,
203  const XalanCompiledStylesheet* theCompiledStylesheet,
204  const XSLTResultTarget& theResultTarget)
205  {
206  assert(theCompiledStylesheet != 0);
207 
208  return doTransform(theParsedXML, theCompiledStylesheet, 0, theResultTarget);
209  }
210 
211  /**
212  * Transform will apply the stylesheet provided as a PI in the
213  * XML of the parsed xml source and write the transformation output to
214  * the target.
215  *
216  * @param theParsedXML the parsed input source
217  * @param theResultTarget output source tree
218  * @return 0 for success
219  */
220  int
222  const XalanParsedSource& theParsedXML,
223  const XSLTResultTarget& theResultTarget)
224  {
225  assert(s_emptyInputSource != 0);
226 
227  return transform(theParsedXML, *s_emptyInputSource, theResultTarget);
228  }
229 
230  /**
231  * Transform will apply the stylesheet source to the input source
232  * and write the transformation output to the target. The input
233  * source and result target can be a file name, a stream or a root
234  * node.
235  *
236  * @param theInputSource input source
237  * @param theStylesheetSource stylesheet source
238  * @param theResultTarget output source
239  * @return 0 for success
240  */
241  int
243  const XSLTInputSource& theInputSource,
244  const XSLTInputSource& theStylesheetSource,
245  const XSLTResultTarget& theResultTarget);
246 
247  /**
248  * Transform will apply the stylesheet provided as a PI in the
249  * XML of the input source and write the transformation output to
250  * the target. The input source and result target can be a file
251  * name, a stream or a root node.
252  *
253  * @param theInputSource input source
254  * @param theResultTarget output source tree
255  * @return 0 for success
256  */
257  int
259  const XSLTInputSource& theInputSource,
260  const XSLTResultTarget& theResultTarget)
261  {
262  assert(s_emptyInputSource != 0);
263 
264  return transform(
265  theInputSource,
266  *s_emptyInputSource,
267  theResultTarget);
268  }
269 
270  /**
271  * Transform will apply the stylesheet source to the input source
272  * and write the transformation result to a callback function
273  * in pre-allocated blocks. The input source can be a file name,
274  * a stream or a root node. Upon termination, Xalan releases any
275  * allocated memory. Data passed to the callback is not guaranteed to
276  * be null terminated.
277  *
278  * - See XalanTransformerOutputStream and XalanOutputHandlerType
279  * for more details.
280  *
281  * @param theInputSource input source
282  * @param theStylesheetSource stylesheet source
283  * @param theOutputHandle void pointer passed through to callback.
284  * @param theOutputHandler a user defined (callback) function.
285  * @param theFlushHandler (optional) a user defined (callback) function.
286  * @return 0 for success
287  */
288  int
290  const XSLTInputSource& theInputSource,
291  const XSLTInputSource& theStylesheetSource,
292  void* theOutputHandle,
293  XalanOutputHandlerType theOutputHandler,
294  XalanFlushHandlerType theFlushHandler = 0);
295 
296  /**
297  * Transform will apply the compiled stylesheet to the input source
298  * and write the transformation output to the target. The input
299  * source and result target can be a file name, a stream or a root
300  * node.
301  *
302  * @param theInputSource input source
303  * @param theCompiledStylesheet pointer to a compiled stylesheet. Must not be null.
304  * @param theResultTarget output source
305  * @return 0 for success
306  */
307  int
309  const XSLTInputSource& theInputSource,
310  const XalanCompiledStylesheet* theCompiledStylesheet,
311  const XSLTResultTarget& theResultTarget);
312 
313  /**
314  * Transform will apply the compiled stylesheet to the source
315  * and write the transformation result to a callback function
316  * in pre-allocated blocks. The input source can be a file name,
317  * a stream or a root node. Upon termination, Xalan releases any
318  * allocated memory. Data passed to the callback is not guaranteed to
319  * be null terminated.
320  *
321  * - See XalanTransformerOutputStream and XalanOutputHandlerType
322  * for more details.
323  *
324  * @param theParsedSource Parsed source instance
325  * @param theCompiledStylesheet pointer to a compiled stylesheet. Must not be null.
326  * @param theOutputHandle void pointer passed through to callback.
327  * @param theOutputHandler a user defined callback function.
328  * @param theFlushHandler An optional user-defined callback function.
329  * @return 0 for success
330  */
331  int
333  const XalanParsedSource& theParsedSource,
334  const XalanCompiledStylesheet* theCompiledStylesheet,
335  void* theOutputHandle,
336  XalanOutputHandlerType theOutputHandler,
337  XalanFlushHandlerType theFlushHandler = 0);
338 
339  /**
340  * Transform will apply the stylesheet provided as a PI in the
341  * XML of the input source and write the transformation result to a
342  * callback function in pre-allocated blocks. The input source can be
343  * a file name, a stream or a root node. Upon termination, Xalan
344  * releases any allocated memory. Data passed to the callback is not
345  * guaranteed to be null terminated.
346  *
347  * - See XalanTransformerOutputStream and XalanOutputHandlerType
348  * for more details.
349  *
350  * @param theInputSource input source
351  * @param theOutputHandle void pointer passed through to callback.
352  * @param theOutputHandler a user defined callback function.
353  * @param theFlushHandler an optional user-defined callback function.
354  * @return 0 for success
355  */
356  int
358  const XSLTInputSource& theInputSource,
359  void* theOutputHandle,
360  XalanOutputHandlerType theOutputHandler,
361  XalanFlushHandlerType theFlushHandler = 0);
362 
363  /**
364  * Creates a compiled stylesheet. The input source can be
365  * a file name, a stream or a root node. The XalanTransformer
366  * instance owns the XalanCompiledStylesheet instance and will
367  * delete it when the XalanTransformer instance goes out of scope,
368  * or you explicitly call destroyStylesheet(). You must not delete
369  * the instance yourself.
370  *
371  * @param theStylesheetSource input source
372  * @param theCompiledStylesheet a reference to a pointer to a XalanCompileStylesheet.
373  * @return 0 for success
374  */
375  int
377  const XSLTInputSource& theStylesheetSource,
378  const XalanCompiledStylesheet*& theCompiledStylesheet);
379 
380  /**
381  * Destroy a XalanCompiledStylesheet instance created by a previous
382  * call to compileStylesheet().
383  *
384  * @param theStylesheet The instance to destroy.
385  * @return 0 for success
386  */
387  int
389 
390  /**
391  * Parse a source XML document. The input source can be
392  * a file name, a stream or a root node. The XalanTransformer
393  * instance owns the XalanParsedSource instance and will
394  * delete it when the XalanTransformer instance goes out of scope,
395  * or you explicitly call destroyParsedSource(). You must not
396  * delete the instance yourself.
397  *
398  * @param theInputSource input source
399  * @param theParsedSource a reference to a pointer to a XalanParsedSource.
400  * @param useXercesDOM input use default or xerces DOM source tree
401  * @return 0 for success
402  */
403  int
405  const XSLTInputSource& theInputSource,
406  const XalanParsedSource*& theParsedSource,
407  bool useXercesDOM = false);
408 
409  /**
410  * Destroy a parsed source created by a previous call to parseSource().
411  *
412  * @param theParsedSource The XalanParsedSource instance to destroy.
413  * @return 0 for success
414  */
415  int
416  destroyParsedSource(const XalanParsedSource* theParsedSource);
417 
418  /**
419  * Create a document builder. Using the document builder, you
420  * can construct a document using SAX2 interfaces. The XalanTransformer
421  * instance owns the document builder and will delete it when the
422  * XalanTransformer instance goes out of scope, or you explicitly call
423  * destroyDocumentBuilder(). You must not delete the instance yourself.
424  *
425  * @param theURI The base URI for the document instance.
426  * @return a pointer to a XalanDocumentBuilder instance or 0 for failure.
427  */
429  createDocumentBuilder(const XalanDOMString& theURI = XalanDOMString(XalanMemMgrs::getDummyMemMgr()));
430 
431  /**
432  * Destroy a document builder created by a previous call to createDocumentBuilder().
433  * Passing a pointer that is not created by a call to createDocumentBuilder() can
434  * result in undefined behavior.
435  *
436  * @param theDocumentBuilder The document builder to destroy.
437  */
438  void
440 
441  /**
442  * Install an external function in the local space.
443  *
444  * @param theNamespace The namespace for the functionl
445  * @param functionName The name of the function.
446  * @param function The function to install.
447  */
448  void
450  const XalanDOMString& theNamespace,
451  const XalanDOMString& functionName,
452  const Function& function);
453 
454  /**
455  * Install an external function in the global space.
456  *
457  * @param theNamespace The namespace for the functionl
458  * @param functionName The name of the function.
459  * @param function The function to install.
460  */
461  static void
463  const XalanDOMString& theNamespace,
464  const XalanDOMString& functionName,
465  const Function& function);
466 
467  /**
468  * Uninstall an external local function.
469  *
470  * @param theNamespace The namespace for the function
471  * @param functionName The name of the function.
472  */
473  void
475  const XalanDOMString& theNamespace,
476  const XalanDOMString& functionName);
477 
478  /**
479  * Uninstall an external global function.
480  *
481  * @param theNamespace The namespace for the function
482  * @param functionName The name of the function.
483  */
484  static void
486  const XalanDOMString& theNamespace,
487  const XalanDOMString& functionName);
488 
489  /**
490  * Retrieve the factory object for creating XObjects.
491  *
492  * @return factory object instance
493  */
496  {
497  assert(m_topXObjectFactory != 0);
498 
499  return *m_topXObjectFactory;
500  }
501 
502  /**
503  * Set a top-level parameter, which the stylesheet can access
504  * with a top-level xsl:param. Top-level params are "sticky,"
505  * and must be removed with a call to clearStylesheetParams().
506  *
507  * @param key name of the param
508  * @param expression expression that will be evaluated
509  */
510  void
512  const XalanDOMString& key,
513  const XalanDOMString& expression);
514 
515  /**
516  * Set a top-level parameter, which the stylesheet can access
517  * with a top-level xsl:param. Top-level params are "sticky,"
518  * and must be removed with a call to clearStylesheetParams().
519  *
520  * @param key name of the param
521  * @param expression expression that will be evaluated
522  */
523  void
525  const char* key,
526  const char* expression);
527 
528  /**
529  * Set a top-level parameter, which the stylesheet can access
530  * with a top-level xsl:param. Top-level params are "sticky,"
531  * and must be removed with a call to clearStylesheetParams().
532  *
533  * @param key name of the param
534  * @param number value to be evaluated
535  */
536  void
538  const char* key,
539  double number);
540 
541  /**
542  * Set a top-level parameter, which the stylesheet can access
543  * with a top-level xsl:param. Top-level params are "sticky,"
544  * and must be removed with a call to clearStylesheetParams().
545  *
546  * @param key name of the param
547  * @param number value to be evaluated
548  */
549  void
551  const XalanDOMString& key,
552  double number);
553 
554  /**
555  * Set a top-level parameter, which the stylesheet can access
556  * with a top-level xsl:param. Top-level params are "sticky,"
557  * and must be removed with a call to clearStylesheetParams().
558  *
559  * @param key name of the param
560  * @param nodeset XML nodeset that will be evaulated
561  */
562  void
564  const char* key,
565  XalanNode* nodeset);
566 
567  /**
568  * Set a top-level parameter, which the stylesheet can access
569  * with a top-level xsl:param. Top-level params are "sticky,"
570  * and must be removed with a call to clearStylesheetParams().
571  *
572  * @param key name of the param
573  * @param nodeset XML nodeset that will be evaluated
574  */
575  void
577  const XalanDOMString& key,
578  XalanNode* nodeset);
579 
580  /**
581  * Set a top-level parameter, which the stylesheet can access
582  * with a top-level xsl:param. Top-level params are "sticky,"
583  * and must be removed with a call to clearStylesheetParams().
584  *
585  * @param key name of the param
586  * @param object any XObject owned by the transformer
587  */
588  void
590  const char* key,
591  XObjectPtr object);
592 
593  /**
594  * Set a top-level parameter, which the stylesheet can access
595  * with a top-level xsl:param. Top-level params are "sticky,"
596  * and must be removed with a call to clearStylesheetParams().
597  *
598  * @param key name of the param
599  * @param object any XObject owned by the transformer
600  */
601  void
603  const XalanDOMString& key,
604  XObjectPtr object);
605 
606  /**
607  * Clear any stylesheet params.
608  */
609  void
611  {
612  m_params.clear();
613  m_topXObjectFactory->reset();
614  }
615 
616  /**
617  * Add a TraceListener instance. TraceListeners instances are preserved
618  * between calls to transform(), so they will be called until they are
619  * removed.
620  *
621  * @param theTraceListener The instance to add.
622  */
623  void
624  addTraceListener(TraceListener* theTraceListener)
625  {
626  m_traceListeners.push_back(theTraceListener);
627  }
628 
629  /**
630  * Remove a TraceListener instance
631  *
632  * @param theTraceListener The instance to remove.
633  * @return true if the instance was removed, false if not.
634  */
635  bool
636  removeTraceListener(TraceListener* theTraceListener);
637 
638  /**
639  * Remove all TraceListener instances.
640  */
641  void
643  {
644  m_traceListeners.clear();
645  }
646 
647  /**
648  * Set a flag to indicate whether or not the source file(s) for the
649  * transformation will be validated.
650  *
651  * @param fValue the new value for the flag.
652  */
653  bool
655  {
656  return m_useValidation;
657  }
658 
659  /**
660  * Set a flag to indicate whether or not the source file(s) for the
661  * transformation will be validated.
662  *
663  * @param fValue the new value for the flag.
664  */
665  void
666  setUseValidation(bool fValue)
667  {
668  m_useValidation = fValue;
669  }
670 
671  /**
672  * Returns the installed EntityResolver.
673  *
674  * @return The pointer to the installed EntityResolver.
675  */
676  EntityResolver*
678  {
679  return m_entityResolver;
680  }
681 
682  /**
683  * Installs the supplied EntityResolver.
684  *
685  * A call to setEntityResolver with a non-null pointer will
686  * uninstall any XMLEntityResolver previously installed.
687  *
688  * @param theResolver A pointer to the EntityResolver.
689  */
690  void
691  setEntityResolver(EntityResolver* theResolver)
692  {
693  m_entityResolver = theResolver;
694 
695  if (theResolver != 0 && m_xmlEntityResolver != 0)
696  {
697  m_xmlEntityResolver = 0;
698  }
699  }
700 
701  /**
702  * Returns the installed XMLEntityResolver.
703  *
704  * @return The pointer to the installed XMLEntityResolver.
705  */
706  XMLEntityResolver*
708  {
709  return m_xmlEntityResolver;
710  }
711 
712  /**
713  * Installs the supplied XMLEntityResolver.
714  *
715  * A call to setXMLEntityResolver with a non-null pointer will
716  * uninstall any EntityResolver previously installed.
717  *
718  * @param theResolver A pointer to the XMLEntityResolver.
719  */
720  void
721  setXMLEntityResolver(XMLEntityResolver* theResolver)
722  {
723  m_xmlEntityResolver = theResolver;
724 
725  if (theResolver != 0 && m_entityResolver != 0)
726  {
727  m_entityResolver = 0;
728  }
729  }
730 
731  /**
732  * This method returns the installed error handler.
733  *
734  * @return The pointer to the installed error handler object.
735  */
736  ErrorHandler*
738  {
739  return m_errorHandler;
740  }
741 
742  /**
743  * This method installs the user-specified error handler.
744  *
745  * @param handler A pointer to the error handler to be called upon error.
746  */
747  void
748  setErrorHandler(ErrorHandler* theErrorHandler)
749  {
750  m_errorHandler = theErrorHandler;
751  }
752 
753  /**
754  * This method returns the location for an external schema document
755  * for parsing.
756  *
757  * @return A string representing the location of the external schema document
758  */
759  const XalanDOMChar*
761  {
762  return m_externalSchemaLocation.empty() == true ? 0 : m_externalSchemaLocation.c_str();
763  }
764 
765  /**
766  * This method sets the location for an external schema document
767  * for parsing.
768  *
769  * @param location A string representing the location of the external schema document
770  */
771  void
772  setExternalSchemaLocation(const XalanDOMChar* location)
773  {
774  assert(location != 0);
775 
776  m_externalSchemaLocation = location;
777  }
778 
779  /**
780  * This method returns the location for an external schema document
781  * for parsing.
782  *
783  * @return A string representing the location of the external schema document
784  */
785  const XalanDOMChar*
787  {
788  return m_externalNoNamespaceSchemaLocation.empty() == true ? 0 : m_externalNoNamespaceSchemaLocation.c_str();
789  }
790 
791  /**
792  * This method sets the location for an external schema document
793  * for parsing.
794  *
795  * @param location A string representing the location of the external schema document
796  */
797  void
798  setExternalNoNamespaceSchemaLocation(const XalanDOMChar* location)
799  {
800  assert(location != 0);
801 
802  m_externalNoNamespaceSchemaLocation = location;
803  }
804 
805  /**
806  * This member functions gets the flag to determine of a default parsed source
807  * tree will pool the values of all of the text nodes in the XML document.
808  *
809  * @return The boolean value for the flag.
810  */
811  bool
813  {
814  return m_poolAllTextNodes;
815  }
816 
817  /**
818  * This member functions sets the flag to determine of a default parsed source
819  * tree will pool the values of all of the text nodes in the XML document. This
820  * can result in significant memory savings if there are lots of repeated values
821  * in text nodes.
822  *
823  * @param fPool The boolean value for the flag.
824  */
825  void
827  {
828  m_poolAllTextNodes = fPool;
829  }
830 
831  /**
832  * This method returns the installed ProblemListener instance.
833  *
834  * @return The pointer to the installed ProblemListener instance.
835  */
838  {
839  return m_problemListener;
840  }
841 
842  /**
843  * This method installs the user-specified ProblemListener instance.
844  *
845  * @param handler A pointer to the ProblemListener to be called when a problem occurs.
846  */
847  void
848  setProblemListener(ProblemListener* theProblemListener)
849  {
850  m_problemListener = theProblemListener;
851  }
852 
853  /**
854  * Returns the last error that occurred as a
855  * result of calling transform.
856  *
857  * @return error message const character pointer.
858  */
859  const char*
860  getLastError() const
861  {
862  assert(m_errorMessage.empty() == false);
863 
864  return &m_errorMessage[0];
865  }
866 
867  /**
868  * Get the current output encoding, if any. Note this is not the output encoding
869  * specified in a stylesheet. Rather, it can override that encoding, if the
870  *
871  * @return A string containing the current encoding
872  */
873  const XalanDOMString&
875  {
876  return m_outputEncoding;
877  }
878 
879  /**
880  * Set the current output encoding. Note this will override the encoding
881  * specified in the stylesheet, if the encoding is available. However,
882  * it will not override any encoding specified by an XSLTResultTarget
883  * parameter to one of the transform() member functions.
884  *
885  * @param theEncoding The encoding to use.
886  */
887  void
888  setOutputEncoding(const XalanDOMString& theEncoding)
889  {
890  m_outputEncoding = theEncoding;
891  }
892 
893  /**
894  * Get the current number of spaces to indent.
895  *
896  * @return number of spaces
897  */
898  int
899  getIndent() const;
900 
901  /**
902  * Set the current number of spaces to indent.
903  *
904  * @param indentAmount The number of spaces to indent. Use -1 for the default amount.
905  */
906  void
907  setIndent(int indentAmount);
908 
909  /**
910  * Enums to determine whether or not run-time escaping of URLs has been set.
911  */
913  {
914  eEscapeURLsDefault, // Use the value in the stylesheet
915  eEscapeURLsNo, // Don't escape URLs
916  eEscapeURLsYes // Escape URLs
917  };
918 
919  /**
920  * Get the value for run-time escaping of URLs. This can
921  * override the property specified by the stylesheet. The
922  * default behavior is to honor the property in the stylesheet.
923  *
924  * @return The value of the enum
925  */
926  eEscapeURLs
927  getEscapeURLs() const;
928 
929  /**
930  * Set the value for run-time escaping of URLs. This can
931  * override the property specified by the stylesheet. The
932  * default behavior is to honor the property in the stylesheet.
933  *
934  * @param value The value of the enum
935  */
936  void
938 
939  /**
940  * Enums to determine whether or not run-time omission of the META tag has been set.
941  * Relevant only for HTML output
942  */
944  {
945  eOmitMETATagDefault, // Use the value in the stylesheet
946  eOmitMETATagNo, // Don't omit the META tag
947  eOmitMETATagYes // Omit the META tag
948  };
949 
950  /**
951  * Get the value for run-time omission of the META tag. This can
952  * override the property specified by the stylesheet. The
953  * default behavior is to honor the property in the stylesheet.
954  *
955  * @return The value of the enum
956  */
957  eOmitMETATag
958  getOmitMETATag() const;
959 
960  /**
961  * Get the value for run-time omission of the META tag. This can
962  * override the property specified by the stylesheet. The
963  * default behavior is to honor the property in the stylesheet.
964  *
965  * @param value The value of the enum
966  */
967  void
969 
970  /**
971  * Set the ostream instance for reporting errors. The default
972  * is a null pointer, so errors are not reported. If there is
973  * a user-installed ProblemListener instance, this is not used, as
974  * all such warnings and messages are handled by the that
975  * ProblemListener.
976  *
977  * @param theStream A pointer to the ostream instance.
978  */
979  void
981  {
982  m_errorStream = theStream;
983  }
984 
985  /**
986  * Get the current error stream ostream instance.
987  *
988  * @return A pointer to the instance. Can be a null pointer.
989  */
990  StreamType*
992  {
993  return m_errorStream;
994  }
995 
996  /**
997  * Set the ostream instance for reporting warnings and messages. The default
998  * is std::cerr. If set to a null pointer, no warnings or messages are written.
999  * If there is a user-installed ProblemListener instance, this is not used, as
1000  * all such warnings and messages are handled by the that ProblemListener.
1001  *
1002  * @param theStream A pointer to the ostream instance.
1003  */
1004  void
1006  {
1007  m_warningStream = theStream;
1008  }
1009 
1010  /**
1011  * Get the current warning stream ostream instance.
1012  *
1013  * @return A pointer to the instance. Can be a null pointer.
1014  */
1015  StreamType*
1017  {
1018  return m_warningStream;
1019  }
1020 
1021  bool
1023 
1025  {
1026  public:
1027 
1028  EnsureFunctionsInstallation(MemoryManager& theManager) :
1029  m_memoryManagement(theManager),
1030  m_release(false)
1031  {
1032  }
1033 
1035 
1036  void
1038 
1039  void
1041  {
1042  m_release = true;
1043  }
1044 
1045  private:
1046 
1047  MemoryManager& m_memoryManagement;
1048 
1049  bool m_release;
1050  };
1051 
1053  {
1054  public:
1055 
1057  XalanTransformer& theTransformer,
1058  const XalanParsedSource* theParsedSource) :
1059  m_transformer(theTransformer),
1060  m_parsedSource(theParsedSource)
1061  {
1062  }
1063 
1065  {
1066  m_transformer.destroyParsedSource(m_parsedSource);
1067  }
1068 
1069  private:
1070 
1071  XalanTransformer& m_transformer;
1072 
1073  const XalanParsedSource* const m_parsedSource;
1074  };
1075 
1077  {
1078  public:
1079 
1081  XalanTransformer& theTransformer,
1082  const XalanCompiledStylesheet* theCompiledStylesheet) :
1083  m_transformer(theTransformer),
1084  m_compiledStylesheet(theCompiledStylesheet)
1085  {
1086  }
1087 
1089  {
1090  m_transformer.destroyStylesheet(m_compiledStylesheet);
1091  }
1092 
1093  private:
1094 
1095  XalanTransformer& m_transformer;
1096 
1097  const XalanCompiledStylesheet* const m_compiledStylesheet;
1098  };
1099 
1101  {
1103  XalanTransformer& theTransformer,
1104  XalanDocumentBuilder* theDocumentBuilder) :
1105  m_transformer(theTransformer),
1106  m_documentBuilder(theDocumentBuilder)
1107  {
1108  }
1109 
1111  {
1112  m_transformer.destroyDocumentBuilder(m_documentBuilder);
1113  }
1114 
1115  private:
1116 
1117  XalanTransformer& m_transformer;
1118 
1119  XalanDocumentBuilder* const m_documentBuilder;
1120  };
1121 
1122 protected:
1123 
1124 private:
1125 
1126  void
1127  reset();
1128 
1129  class EnsureReset
1130  {
1131  public:
1132 
1133  EnsureReset(XalanTransformer& theTransformer) :
1134  m_transformer(theTransformer)
1135  {
1136  }
1137 
1138  ~EnsureReset();
1139 
1140  private:
1141 
1142  XalanTransformer& m_transformer;
1143  };
1144 
1145  friend class EnsureReset;
1146 
1147  int
1148  doTransform(
1149  const XalanParsedSource& theParsedXML,
1150  const XalanCompiledStylesheet* theCompiledStylesheet,
1151  const XSLTInputSource* theStylesheetSource,
1152  const XSLTResultTarget& theResultTarget);
1153 
1154 
1155  // Data members...
1156  MemoryManager& m_memoryManager;
1157 
1158  CompiledStylesheetPtrVectorType m_compiledStylesheets;
1159 
1160  ParsedSourcePtrVectorType m_parsedSources;
1161 
1162  ParamMapType m_params;
1163 
1164  FunctionMapType m_functions;
1165 
1166  TraceListenerVectorType m_traceListeners;
1167 
1168  CharVectorType m_errorMessage;
1169 
1170  bool m_useValidation;
1171 
1172  EntityResolver* m_entityResolver;
1173 
1174  XMLEntityResolver* m_xmlEntityResolver;
1175 
1176  ErrorHandler* m_errorHandler;
1177 
1178  XalanDOMString m_externalSchemaLocation;
1179 
1180  XalanDOMString m_externalNoNamespaceSchemaLocation;
1181 
1182  ProblemListener* m_problemListener;
1183 
1184  StreamType* m_errorStream;
1185 
1186  StreamType* m_warningStream;
1187 
1188  XalanDOMString m_outputEncoding;
1189 
1190  bool m_poolAllTextNodes;
1191 
1192  XObjectFactoryDefault* m_topXObjectFactory;
1193 
1194  // This should always be the latest data member!!!
1195  StylesheetExecutionContextDefault* m_stylesheetExecutionContext;
1196 
1197  static const XSLTInputSource* s_emptyInputSource;
1198 
1199  static const XSLTInit* s_xsltInit;
1200 };
1201 
1202 
1203 
1204 }
1205 
1206 
1207 
1208 #endif // XALANTRANSFORMER_HEADER_GUARD
CallbackSizeType(* XalanOutputHandlerType)(const char *, CallbackSizeType, void *)
Callback function passed to the XalanTransformer APIs.
#define XALAN_TRANSFORMER_EXPORT
void(* XalanFlushHandlerType)(void *)
Callback function passed to the XalanTransformer APIs.
#define XALAN_CPP_NAMESPACE
Xalan-C++ namespace, including major and minor version.
This is the abstract class that the XSL processor uses when it has a problem of some kind,...
This class handles the creation of XObjects and manages their lifetime.
This class handles the creation of XObjects and manages their lifetime.
Class to hold XObjectPtr return types.
Definition: XObject.hpp:884
This is an abstraction of the StylesheetRoot class.
This is abstract base class designed to allow a XalanTranfomer object to use a document that is build...
This is abstract base class designed to allow a XalanTranfomer object to reuse a parsed document.
EnsureDestroyCompiledStylesheet(XalanTransformer &theTransformer, const XalanCompiledStylesheet *theCompiledStylesheet)
EnsureDestroyParsedSource(XalanTransformer &theTransformer, const XalanParsedSource *theParsedSource)
This is a simple C++ interface for some common usage patterns.
XalanMap< XalanDOMString, XalanParamHolder > ParamMapType
ErrorHandler * getErrorHandler() const
This method returns the installed error handler.
static void ICUStartUp(MemoryManager &theManager=XalanMemMgrs::getDefaultXercesMemMgr())
void setEntityResolver(EntityResolver *theResolver)
Installs the supplied EntityResolver.
void setIndent(int indentAmount)
Set the current number of spaces to indent.
void setOutputEncoding(const XalanDOMString &theEncoding)
Set the current output encoding.
const XalanDOMString & getOutputEncoding() const
Get the current output encoding, if any.
void setWarningStream(StreamType *theStream)
Set the ostream instance for reporting warnings and messages.
int getIndent() const
Get the current number of spaces to indent.
int destroyStylesheet(const XalanCompiledStylesheet *theStylesheet)
Destroy a XalanCompiledStylesheet instance created by a previous call to compileStylesheet().
void destroyDocumentBuilder(XalanDocumentBuilder *theDocumentBuilder)
Destroy a document builder created by a previous call to createDocumentBuilder().
int transform(const XSLTInputSource &theInputSource, const XSLTInputSource &theStylesheetSource, const XSLTResultTarget &theResultTarget)
Transform will apply the stylesheet source to the input source and write the transformation output to...
void setStylesheetParam(const char *key, double number)
Set a top-level parameter, which the stylesheet can access with a top-level xsl:param.
static void ICUCleanUp()
Clean up the ICU, if ICU integration is enabled.
XMLEntityResolver * getXMLEntityResolver() const
Returns the installed XMLEntityResolver.
void setProblemListener(ProblemListener *theProblemListener)
This method installs the user-specified ProblemListener instance.
XalanVector< const XalanCompiledStylesheet * > CompiledStylesheetPtrVectorType
void clearStylesheetParams()
Clear any stylesheet params.
static void initialize(MemoryManager &theManager=XalanMemMgrs::getDefaultXercesMemMgr())
Initialize Xalan.
void setExternalNoNamespaceSchemaLocation(const XalanDOMChar *location)
This method sets the location for an external schema document for parsing.
int transform(const XalanParsedSource &theParsedXML, const XSLTResultTarget &theResultTarget)
Transform will apply the stylesheet provided as a PI in the XML of the parsed xml source and write th...
void setStylesheetParam(const XalanDOMString &key, const XalanDOMString &expression)
Set a top-level parameter, which the stylesheet can access with a top-level xsl:param.
int transform(const XSLTInputSource &theInputSource, const XalanCompiledStylesheet *theCompiledStylesheet, const XSLTResultTarget &theResultTarget)
Transform will apply the compiled stylesheet to the input source and write the transformation output ...
bool getICUAvailable() const
void setExternalSchemaLocation(const XalanDOMChar *location)
This method sets the location for an external schema document for parsing.
XalanVector< const XalanParsedSource * > ParsedSourcePtrVectorType
void setStylesheetParam(const XalanDOMString &key, double number)
Set a top-level parameter, which the stylesheet can access with a top-level xsl:param.
void setEscapeURLs(eEscapeURLs value)
Set the value for run-time escaping of URLs.
XalanVector< TraceListener * > TraceListenerVectorType
static void terminate()
Terminate Xalan.
eEscapeURLs
Enums to determine whether or not run-time escaping of URLs has been set.
void setUseValidation(bool fValue)
Set a flag to indicate whether or not the source file(s) for the transformation will be validated.
const char * getLastError() const
Returns the last error that occurred as a result of calling transform.
static void installExternalFunctionGlobal(const XalanDOMString &theNamespace, const XalanDOMString &functionName, const Function &function)
Install an external function in the global space.
void installExternalFunction(const XalanDOMString &theNamespace, const XalanDOMString &functionName, const Function &function)
Install an external function in the local space.
const MemoryManager & getMemoryManager() const
const XalanDOMChar * getExternalNoNamespaceSchemaLocation() const
This method returns the location for an external schema document for parsing.
void setStylesheetParam(const char *key, XObjectPtr object)
Set a top-level parameter, which the stylesheet can access with a top-level xsl:param.
XObjectFactory & getXObjectFactory() const
Retrieve the factory object for creating XObjects.
void setPoolAllTextNodes(bool fPool)
This member functions sets the flag to determine of a default parsed source tree will pool the values...
void setOmitMETATag(eOmitMETATag value)
Get the value for run-time omission of the META tag.
void uninstallExternalFunction(const XalanDOMString &theNamespace, const XalanDOMString &functionName)
Uninstall an external local function.
XalanDocumentBuilder * createDocumentBuilder(const XalanDOMString &theURI=XalanDOMString(XalanMemMgrs::getDummyMemMgr()))
Create a document builder.
eOmitMETATag
Enums to determine whether or not run-time omission of the META tag has been set.
XalanMap< XalanQNameByValue, Function * > FunctionMapType
int transform(const XalanParsedSource &theParsedSource, const XalanCompiledStylesheet *theCompiledStylesheet, void *theOutputHandle, XalanOutputHandlerType theOutputHandler, XalanFlushHandlerType theFlushHandler=0)
Transform will apply the compiled stylesheet to the source and write the transformation result to a c...
void removeTraceListeners()
Remove all TraceListener instances.
void setStylesheetParam(const char *key, XalanNode *nodeset)
Set a top-level parameter, which the stylesheet can access with a top-level xsl:param.
int compileStylesheet(const XSLTInputSource &theStylesheetSource, const XalanCompiledStylesheet *&theCompiledStylesheet)
Creates a compiled stylesheet.
MemoryManager & getMemoryManager()
void addTraceListener(TraceListener *theTraceListener)
Add a TraceListener instance.
bool getPoolAllTextNodes() const
This member functions gets the flag to determine of a default parsed source tree will pool the values...
eEscapeURLs getEscapeURLs() const
Get the value for run-time escaping of URLs.
static void uninstallExternalFunctionGlobal(const XalanDOMString &theNamespace, const XalanDOMString &functionName)
Uninstall an external global function.
StreamType * getWarningStream() const
Get the current warning stream ostream instance.
void setStylesheetParam(const XalanDOMString &key, XObjectPtr object)
Set a top-level parameter, which the stylesheet can access with a top-level xsl:param.
void setXMLEntityResolver(XMLEntityResolver *theResolver)
Installs the supplied XMLEntityResolver.
int parseSource(const XSLTInputSource &theInputSource, const XalanParsedSource *&theParsedSource, bool useXercesDOM=false)
Parse a source XML document.
XalanTransformer(MemoryManager &theManager=XalanMemMgrs::getDefaultXercesMemMgr())
void setStylesheetParam(const char *key, const char *expression)
Set a top-level parameter, which the stylesheet can access with a top-level xsl:param.
void setErrorStream(StreamType *theStream)
Set the ostream instance for reporting errors.
int transform(const XalanParsedSource &theParsedXML, const XSLTInputSource &theStylesheetSource, const XSLTResultTarget &theResultTarget)
Transform will apply the stylesheet source to the parsed xml source and write the transformation outp...
int transform(const XSLTInputSource &theInputSource, const XSLTInputSource &theStylesheetSource, void *theOutputHandle, XalanOutputHandlerType theOutputHandler, XalanFlushHandlerType theFlushHandler=0)
Transform will apply the stylesheet source to the input source and write the transformation result to...
int transform(const XSLTInputSource &theInputSource, const XSLTResultTarget &theResultTarget)
Transform will apply the stylesheet provided as a PI in the XML of the input source and write the tra...
int destroyParsedSource(const XalanParsedSource *theParsedSource)
Destroy a parsed source created by a previous call to parseSource().
bool getUseValidation() const
Set a flag to indicate whether or not the source file(s) for the transformation will be validated.
int transform(const XSLTInputSource &theInputSource, void *theOutputHandle, XalanOutputHandlerType theOutputHandler, XalanFlushHandlerType theFlushHandler=0)
Transform will apply the stylesheet provided as a PI in the XML of the input source and write the tra...
const XalanDOMChar * getExternalSchemaLocation() const
This method returns the location for an external schema document for parsing.
EntityResolver * getEntityResolver() const
Returns the installed EntityResolver.
void setStylesheetParam(const XalanDOMString &key, XalanNode *nodeset)
Set a top-level parameter, which the stylesheet can access with a top-level xsl:param.
StreamType * getErrorStream() const
Get the current error stream ostream instance.
eOmitMETATag getOmitMETATag() const
Get the value for run-time omission of the META tag.
bool removeTraceListener(TraceListener *theTraceListener)
Remove a TraceListener instance.
int transform(const XalanParsedSource &theParsedXML, const XalanCompiledStylesheet *theCompiledStylesheet, const XSLTResultTarget &theResultTarget)
Transform will apply the compiled stylesheet to the parsed xml source and write the transformation ou...
void setErrorHandler(ErrorHandler *theErrorHandler)
This method installs the user-specified error handler.
ProblemListener * getProblemListener() const
This method returns the installed ProblemListener instance.
xercesc::ErrorHandler ErrorHandlerType
xercesc::EntityResolver EntityResolverType
EnsureDestroyDocumentBuilder(XalanTransformer &theTransformer, XalanDocumentBuilder *theDocumentBuilder)