Xalan-C++ API Documentation

The Xalan C++ XSLT Processor Version 1.11


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

Interpreting class diagrams

Doxygen and GraphViz are used to generate this API documentation from the Xalan-C header files.

Xalan-C++ XSLT Processor Version 1.11
Copyright © 1999-2012 The Apache Software Foundation.
All Rights Reserved.

Apache Logo