00001 /* 00002 * Copyright 1999-2004 The Apache Software Foundation. 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 #if !defined(XALANTRANSFORMER_HEADER_GUARD) 00017 #define XALANTRANSFORMER_HEADER_GUARD 00018 00019 00020 00021 // Base include file. Must be first. 00022 #include <xalanc/XalanTransformer/XalanTransformerDefinitions.hpp> 00023 00024 00025 00026 #include <cassert> 00027 #if defined(XALAN_CLASSIC_IOSTREAMS) 00028 class ostream; 00029 #else 00030 #include <iosfwd> 00031 #endif 00032 #include <algorithm> 00033 00034 00035 00036 #include <xalanc/Include/XalanVector.hpp> 00037 00038 00039 00040 #include <xalanc/XPath/XalanQNameByValue.hpp> 00041 00042 00043 00044 #include <xalanc/XSLT/XSLTInputSource.hpp> 00045 #include <xalanc/XSLT/XSLTResultTarget.hpp> 00046 00047 00048 00049 XALAN_DECLARE_XERCES_CLASS(EntityResolver) 00050 XALAN_DECLARE_XERCES_CLASS(ErrorHandler) 00051 00052 00053 00054 XALAN_CPP_NAMESPACE_BEGIN 00055 00056 00057 00058 typedef XERCES_CPP_NAMESPACE_QUALIFIER EntityResolver EntityResolverType; 00059 typedef XERCES_CPP_NAMESPACE_QUALIFIER ErrorHandler ErrorHandlerType; 00060 00061 00062 00063 class Function; 00064 class StylesheetExecutionContextDefault; 00065 class ProblemListener; 00066 class TraceListener; 00067 class XSLTInit; 00068 class XalanDocumentBuilder; 00069 class XalanCompiledStylesheet; 00070 class XalanParsedSource; 00071 class XalanTransformerOutputStream; 00072 00073 00074 00081 class XALAN_TRANSFORMER_EXPORT XalanTransformer 00082 { 00083 00084 public: 00085 00086 #if defined(XALAN_NO_STD_NAMESPACE) 00087 typedef ostream StreamType; 00088 #else 00089 typedef std::ostream StreamType; 00090 #endif 00091 00092 XalanTransformer(MemoryManagerType& theManager = XalanMemMgrs::getDefaultXercesMemMgr()); 00093 00094 virtual 00095 ~XalanTransformer(); 00096 00097 MemoryManagerType& 00098 getMemoryManager(); 00099 00100 00109 static void 00110 initialize(MemoryManagerType& theManager = XalanMemMgrs::getDefaultXercesMemMgr()); 00111 00124 static void 00125 terminate(); 00126 00145 static void 00146 ICUCleanUp(); 00147 00148 00149 static void 00150 ICUStartUp(MemoryManagerType& theManager = XalanMemMgrs::getDefaultXercesMemMgr()); 00151 00161 int 00162 transform( 00163 const XalanParsedSource& theParsedXML, 00164 const XSLTInputSource& theStylesheetSource, 00165 const XSLTResultTarget& theResultTarget) 00166 { 00167 return doTransform(theParsedXML, 0, &theStylesheetSource, theResultTarget); 00168 } 00169 00179 int 00180 transform( 00181 const XalanParsedSource& theParsedXML, 00182 const XalanCompiledStylesheet* theCompiledStylesheet, 00183 const XSLTResultTarget& theResultTarget) 00184 { 00185 assert(theCompiledStylesheet != 0); 00186 00187 return doTransform(theParsedXML, theCompiledStylesheet, 0, theResultTarget); 00188 } 00189 00199 int 00200 transform( 00201 const XalanParsedSource& theParsedXML, 00202 const XSLTResultTarget& theResultTarget) 00203 { 00204 assert(s_emptyInputSource != 0); 00205 00206 return transform(theParsedXML, *s_emptyInputSource, theResultTarget); 00207 } 00208 00220 int 00221 transform( 00222 const XSLTInputSource& theInputSource, 00223 const XSLTInputSource& theStylesheetSource, 00224 const XSLTResultTarget& theResultTarget); 00225 00236 int 00237 transform( 00238 const XSLTInputSource& theInputSource, 00239 const XSLTResultTarget& theResultTarget) 00240 { 00241 assert(s_emptyInputSource != 0); 00242 00243 return transform( 00244 theInputSource, 00245 *s_emptyInputSource, 00246 theResultTarget); 00247 } 00248 00267 int 00268 transform( 00269 const XSLTInputSource& theInputSource, 00270 const XSLTInputSource& theStylesheetSource, 00271 void* theOutputHandle, 00272 XalanOutputHandlerType theOutputHandler, 00273 XalanFlushHandlerType theFlushHandler = 0); 00274 00286 int 00287 transform( 00288 const XSLTInputSource& theInputSource, 00289 const XalanCompiledStylesheet* theCompiledStylesheet, 00290 const XSLTResultTarget& theResultTarget); 00291 00310 int 00311 transform( 00312 const XalanParsedSource& theParsedSource, 00313 const XalanCompiledStylesheet* theCompiledStylesheet, 00314 void* theOutputHandle, 00315 XalanOutputHandlerType theOutputHandler, 00316 XalanFlushHandlerType theFlushHandler = 0); 00317 00335 int 00336 transform( 00337 const XSLTInputSource& theInputSource, 00338 void* theOutputHandle, 00339 XalanOutputHandlerType theOutputHandler, 00340 XalanFlushHandlerType theFlushHandler = 0); 00341 00354 int 00355 compileStylesheet( 00356 const XSLTInputSource& theStylesheetSource, 00357 const XalanCompiledStylesheet*& theCompiledStylesheet); 00358 00366 int 00367 destroyStylesheet(const XalanCompiledStylesheet* theStylesheet); 00368 00382 int 00383 parseSource( 00384 const XSLTInputSource& theInputSource, 00385 const XalanParsedSource*& theParsedSource, 00386 bool useXercesDOM = false); 00387 00394 int 00395 destroyParsedSource(const XalanParsedSource* theParsedSource); 00396 00407 XalanDocumentBuilder* 00408 createDocumentBuilder(const XalanDOMString& theURI = XalanDOMString(XalanMemMgrs::getDummyMemMgr())); 00409 00417 void 00418 destroyDocumentBuilder(XalanDocumentBuilder* theDocumentBuilder); 00419 00427 void 00428 installExternalFunction( 00429 const XalanDOMString& theNamespace, 00430 const XalanDOMString& functionName, 00431 const Function& function); 00432 00440 static void 00441 installExternalFunctionGlobal( 00442 const XalanDOMString& theNamespace, 00443 const XalanDOMString& functionName, 00444 const Function& function); 00445 00452 void 00453 uninstallExternalFunction( 00454 const XalanDOMString& theNamespace, 00455 const XalanDOMString& functionName); 00456 00463 static void 00464 uninstallExternalFunctionGlobal( 00465 const XalanDOMString& theNamespace, 00466 const XalanDOMString& functionName); 00467 00475 void 00476 setStylesheetParam( 00477 const XalanDOMString& key, 00478 const XalanDOMString& expression); 00479 00487 void 00488 setStylesheetParam( 00489 const char* key, 00490 const char* expression); 00491 00499 void 00500 addTraceListener(TraceListener* theTraceListener) 00501 { 00502 m_traceListeners.push_back(theTraceListener); 00503 } 00504 00511 bool 00512 removeTraceListener(TraceListener* theTraceListener); 00513 00517 void 00518 removeTraceListeners() 00519 { 00520 m_traceListeners.clear(); 00521 } 00522 00529 bool 00530 getUseValidation() const 00531 { 00532 return m_useValidation; 00533 } 00534 00541 void 00542 setUseValidation(bool fValue) 00543 { 00544 m_useValidation = fValue; 00545 } 00546 00552 EntityResolverType* 00553 getEntityResolver() const 00554 { 00555 return m_entityResolver; 00556 } 00557 00567 void 00568 setEntityResolver(EntityResolverType* theResolver) 00569 { 00570 m_entityResolver = theResolver; 00571 } 00572 00578 ErrorHandlerType* 00579 getErrorHandler() const 00580 { 00581 return m_errorHandler; 00582 } 00583 00589 void 00590 setErrorHandler(ErrorHandlerType* theErrorHandler) 00591 { 00592 m_errorHandler = theErrorHandler; 00593 } 00594 00601 const XalanDOMChar* 00602 getExternalSchemaLocation() const 00603 { 00604 return m_externalSchemaLocation.empty() == true ? 0 : m_externalSchemaLocation.c_str(); 00605 } 00606 00613 void 00614 setExternalSchemaLocation(const XalanDOMChar* location) 00615 { 00616 assert(location != 0); 00617 00618 m_externalSchemaLocation = location; 00619 } 00620 00627 const XalanDOMChar* 00628 getExternalNoNamespaceSchemaLocation() const 00629 { 00630 return m_externalNoNamespaceSchemaLocation.empty() == true ? 0 : m_externalNoNamespaceSchemaLocation.c_str(); 00631 } 00632 00639 void 00640 setExternalNoNamespaceSchemaLocation(const XalanDOMChar* location) 00641 { 00642 assert(location != 0); 00643 00644 m_externalNoNamespaceSchemaLocation = location; 00645 } 00646 00653 bool 00654 getPoolAllTextNodes() const 00655 { 00656 return m_poolAllTextNodes; 00657 } 00658 00667 void 00668 setPoolAllTextNodes(bool fPool) 00669 { 00670 m_poolAllTextNodes = fPool; 00671 } 00672 00678 ProblemListener* 00679 getProblemListener() const 00680 { 00681 return m_problemListener; 00682 } 00683 00689 void 00690 setProblemListener(ProblemListener* theProblemListener) 00691 { 00692 m_problemListener = theProblemListener; 00693 } 00694 00701 const char* 00702 getLastError() const 00703 { 00704 assert(m_errorMessage.empty() == false); 00705 00706 return &m_errorMessage[0]; 00707 } 00708 00715 const XalanDOMString& 00716 getOutputEncoding() const 00717 { 00718 return m_outputEncoding; 00719 } 00720 00729 void 00730 setOutputEncoding(const XalanDOMString& theEncoding) 00731 { 00732 m_outputEncoding = theEncoding; 00733 } 00734 00740 int 00741 getIndent() const; 00742 00748 void 00749 setIndent(int indentAmount); 00750 00754 enum eEscapeURLs 00755 { 00756 eEscapeURLsDefault, // Use the value in the stylesheet 00757 eEscapeURLsNo, // Don't escape URLs 00758 eEscapeURLsYes // Escape URLs 00759 }; 00760 00768 eEscapeURLs 00769 getEscapeURLs() const; 00770 00778 void 00779 setEscapeURLs(eEscapeURLs value); 00780 00785 enum eOmitMETATag 00786 { 00787 eOmitMETATagDefault, // Use the value in the stylesheet 00788 eOmitMETATagNo, // Don't omit the META tag 00789 eOmitMETATagYes // Omit the META tag 00790 }; 00791 00799 eOmitMETATag 00800 getOmitMETATag() const; 00801 00809 void 00810 setOmitMETATag(eOmitMETATag value); 00811 00820 void 00821 setWarningStream(StreamType* theStream) 00822 { 00823 m_warningStream = theStream; 00824 } 00825 00831 StreamType* 00832 getWarningStream() const 00833 { 00834 return m_warningStream; 00835 } 00836 00837 typedef XalanVector<const XalanCompiledStylesheet*> CompiledStylesheetPtrVectorType; 00838 typedef XalanVector<const XalanParsedSource*> ParsedSourcePtrVectorType; 00839 typedef XALAN_STD_QUALIFIER pair<XalanDOMString*, XalanDOMString*> ParamPairType; 00840 typedef XalanVector<ParamPairType> ParamPairVectorType; 00841 typedef XALAN_STD_QUALIFIER pair<XalanQNameByValue*, Function*> FunctionPairType; 00842 typedef XalanVector<FunctionPairType> FunctionParamPairVectorType; 00843 typedef XalanVector<TraceListener*> TraceListenerVectorType; 00844 00845 class EnsureFunctionsInstallation 00846 { 00847 public: 00848 00849 EnsureFunctionsInstallation(MemoryManagerType& theManager) : 00850 m_memoryManagement(theManager), 00851 m_release(false) 00852 { 00853 } 00854 00855 ~EnsureFunctionsInstallation(); 00856 00857 void 00858 install(); 00859 00860 void 00861 release() 00862 { 00863 m_release = true; 00864 } 00865 00866 private: 00867 MemoryManagerType& m_memoryManagement; 00868 00869 bool m_release; 00870 }; 00871 00872 class EnsureDestroyParsedSource 00873 { 00874 public: 00875 00876 EnsureDestroyParsedSource( 00877 XalanTransformer& theTransformer, 00878 const XalanParsedSource* theParsedSource) : 00879 m_transformer(theTransformer), 00880 m_parsedSource(theParsedSource) 00881 { 00882 } 00883 00884 ~EnsureDestroyParsedSource() 00885 { 00886 m_transformer.destroyParsedSource(m_parsedSource); 00887 } 00888 00889 private: 00890 00891 XalanTransformer& m_transformer; 00892 00893 const XalanParsedSource* const m_parsedSource; 00894 }; 00895 00896 struct EnsureDestroyCompiledStylesheet 00897 { 00898 EnsureDestroyCompiledStylesheet( 00899 XalanTransformer& theTransformer, 00900 const XalanCompiledStylesheet* theCompiledStylesheet) : 00901 m_transformer(theTransformer), 00902 m_compiledStylesheet(theCompiledStylesheet) 00903 { 00904 } 00905 00906 ~EnsureDestroyCompiledStylesheet() 00907 { 00908 m_transformer.destroyStylesheet(m_compiledStylesheet); 00909 } 00910 00911 private: 00912 00913 XalanTransformer& m_transformer; 00914 00915 const XalanCompiledStylesheet* const m_compiledStylesheet; 00916 }; 00917 00918 struct EnsureDestroyDocumentBuilder 00919 { 00920 EnsureDestroyDocumentBuilder( 00921 XalanTransformer& theTransformer, 00922 XalanDocumentBuilder* theDocumentBuilder) : 00923 m_transformer(theTransformer), 00924 m_documentBuilder(theDocumentBuilder) 00925 { 00926 } 00927 00928 ~EnsureDestroyDocumentBuilder() 00929 { 00930 m_transformer.destroyDocumentBuilder(m_documentBuilder); 00931 } 00932 00933 private: 00934 00935 XalanTransformer& m_transformer; 00936 00937 XalanDocumentBuilder* const m_documentBuilder; 00938 }; 00939 template <class T> 00940 #if defined(XALAN_NO_STD_NAMESPACE) 00941 struct DeleteParamPairFunctor : public unary_function<T&, void> 00942 #else 00943 struct DeleteParamPairFunctor : public std::unary_function<T&, void> 00944 #endif 00945 { 00946 #if defined(XALAN_NO_STD_NAMESPACE) 00947 typedef unary_function<T&, void> BaseClassType; 00948 #else 00949 typedef std::unary_function<T&, void> BaseClassType; 00950 #endif 00951 00952 typedef typename BaseClassType::result_type result_type; 00953 typedef typename BaseClassType::argument_type argument_type; 00954 00955 DeleteParamPairFunctor(MemoryManagerType& theManager) : 00956 m_memoryManager(theManager) 00957 { 00958 } 00959 00960 template<class PtrT> 00961 void 00962 deletePtr(PtrT* ptr)const 00963 { 00964 ptr->~PtrT(); 00965 } 00966 00972 result_type 00973 operator()(argument_type thePair) const 00974 { 00975 T& tmpPair = const_cast<T&>(thePair); 00976 00977 if (tmpPair.first != 0) 00978 { 00979 deletePtr(tmpPair.first); 00980 00981 m_memoryManager.deallocate((void*)tmpPair.first); 00982 } 00983 00984 if (tmpPair.second != 0) 00985 { 00986 deletePtr(tmpPair.second); 00987 00988 m_memoryManager.deallocate((void*)tmpPair.second); 00989 } 00990 00991 00992 } 00993 00994 private: 00995 00996 MemoryManagerType& m_memoryManager; 00997 00998 }; 00999 protected: 01000 01001 private: 01002 01003 void 01004 reset(); 01005 01006 class EnsureReset 01007 { 01008 public: 01009 01010 EnsureReset(XalanTransformer& theTransformer) : 01011 m_transformer(theTransformer) 01012 { 01013 } 01014 01015 ~EnsureReset(); 01016 01017 private: 01018 01019 XalanTransformer& m_transformer; 01020 }; 01021 01022 friend class EnsureReset; 01023 01024 int 01025 doTransform( 01026 const XalanParsedSource& theParsedXML, 01027 const XalanCompiledStylesheet* theCompiledStylesheet, 01028 const XSLTInputSource* theStylesheetSource, 01029 const XSLTResultTarget& theResultTarget); 01030 01031 01032 // Data members... 01033 MemoryManagerType& m_memoryManager; 01034 01035 CompiledStylesheetPtrVectorType m_compiledStylesheets; 01036 01037 ParsedSourcePtrVectorType m_parsedSources; 01038 01039 ParamPairVectorType m_paramPairs; 01040 01041 FunctionParamPairVectorType m_functionPairs; 01042 01043 TraceListenerVectorType m_traceListeners; 01044 01045 CharVectorType m_errorMessage; 01046 01047 bool m_useValidation; 01048 01049 EntityResolverType* m_entityResolver; 01050 01051 ErrorHandlerType* m_errorHandler; 01052 01053 XalanDOMString m_externalSchemaLocation; 01054 01055 XalanDOMString m_externalNoNamespaceSchemaLocation; 01056 01057 ProblemListener* m_problemListener; 01058 01059 StreamType* m_warningStream; 01060 01061 XalanDOMString m_outputEncoding; 01062 01063 bool m_poolAllTextNodes; 01064 01065 // This should always be the latest data member!!! 01066 StylesheetExecutionContextDefault* m_stylesheetExecutionContext; 01067 01068 static const XSLTInputSource* s_emptyInputSource; 01069 01070 static const XSLTInit* s_xsltInit; 01071 }; 01072 01073 01074 01075 XALAN_CPP_NAMESPACE_END 01076 01077 01078 01079 #endif // XALANTRANSFORMER_HEADER_GUARD
Doxygen and GraphViz are used to generate this API documentation from the Xalan-C header files.
![]() |
Xalan-C++ XSLT Processor Version 1.9 |
|