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(STYLESHEETCONSTRUCTIONCONTEXTDEFAULT_HEADER_GUARD_1357924680) 00017 #define STYLESHEETCONSTRUCTIONCONTEXTDEFAULT_HEADER_GUARD_1357924680 00018 00019 00020 00021 // Base include file. Must be first. 00022 #include <xalanc/XSLT/XSLTDefinitions.hpp> 00023 00024 00025 00026 #include <xalanc/Include/XalanVector.hpp> 00027 00028 00029 00030 #include <xalanc/PlatformSupport/ArenaAllocator.hpp> 00031 #include <xalanc/PlatformSupport/XalanArrayAllocator.hpp> 00032 #include <xalanc/PlatformSupport/XalanDOMStringPool.hpp> 00033 00034 00035 00036 #if defined(XALAN_AUTO_PTR_REQUIRES_DEFINITION) || (XALAN_ALLINONE_BUILD_DLL) 00037 #include <xalanc/XPath/XPathProcessor.hpp> 00038 #endif 00039 00040 00041 00042 #include <xalanc/Include/XalanMemMgrAutoPtr.hpp> 00043 00044 00045 00046 #include <xalanc/PlatformSupport/XalanDOMStringCache.hpp> 00047 00048 00049 00050 #include <xalanc/XPath/XalanQNameByReference.hpp> 00051 #include <xalanc/XPath/XalanQNameByValue.hpp> 00052 #include <xalanc/XPath/XalanQNameByValueAllocator.hpp> 00053 00054 00055 00056 // Base class header file... 00057 #include <xalanc/XSLT/StylesheetConstructionContext.hpp> 00058 00059 00060 00061 #include <xalanc/XSLT/AVT.hpp> 00062 #include <xalanc/XSLT/XalanAVTAllocator.hpp> 00063 #include <xalanc/XSLT/AVTPartSimple.hpp> 00064 #include <xalanc/XSLT/XalanAVTPartSimpleAllocator.hpp> 00065 #include <xalanc/XSLT/AVTPartXPath.hpp> 00066 #include <xalanc/XSLT/XalanAVTPartXPathAllocator.hpp> 00067 #include <xalanc/XSLT/XalanElemApplyTemplatesAllocator.hpp> 00068 #include <xalanc/XSLT/XalanElemAttributeAllocator.hpp> 00069 #include <xalanc/XSLT/XalanElemAttributeSetAllocator.hpp> 00070 #include <xalanc/XSLT/XalanElemCallTemplateAllocator.hpp> 00071 #include <xalanc/XSLT/XalanElemElementAllocator.hpp> 00072 #include <xalanc/XSLT/XalanElemLiteralResultAllocator.hpp> 00073 #include <xalanc/XSLT/XalanElemTemplateAllocator.hpp> 00074 #include <xalanc/XSLT/XalanElemTextLiteralAllocator.hpp> 00075 #include <xalanc/XSLT/XalanElemValueOfAllocator.hpp> 00076 #include <xalanc/XSLT/XalanElemVariableAllocator.hpp> 00077 #include "xalanc/XSLT/XalanMatchPatternDataAllocator.hpp" 00078 00079 00080 00081 XALAN_CPP_NAMESPACE_BEGIN 00082 00083 00084 00085 class XPathEnvSupport; 00086 class XPathFactory; 00087 class XPathProcessor; 00088 class XSLTEngineImpl; 00089 00090 00091 00098 class XALAN_XSLT_EXPORT StylesheetConstructionContextDefault : public StylesheetConstructionContext 00099 { 00100 public: 00101 00102 typedef XalanArrayAllocator<XalanDOMChar> XalanDOMCharVectorAllocatorType; 00103 typedef XalanArrayAllocator<const void*> PointerVectorAllocatorType; 00104 typedef XalanDOMCharVectorAllocatorType::size_type VectorAllocatorSizeType; 00105 00106 // Default size for vector allocation. 00107 enum { 00108 eDefaultXalanDOMCharVectorBlockSize = 1024, 00109 eDefaultAVTBlockSize = 128, 00110 eDefaultAVTPartSimpleBlockSize = 128, 00111 eDefaultAVTPartXPathBlockSize = 128, 00112 eDefaultXalanQNameByValueBlockSize = 32, 00113 eDefaultPointerVectorBlockSize = 512, 00114 eDefaultElemApplyTemplatesBlockSize = 10, 00115 eDefaultElemAttributeBlockSize = 10, 00116 eDefaultElemAttributeSetBlockSize = 10, 00117 eDefaultElemCallTemplateBlockSize = 10, 00118 eDefaultElemElementBlockSize = 10, 00119 eDefaultElemLiteralResultBlockSize = 20, 00120 eDefaultElemTemplateBlockSize = 10, 00121 eDefaultElemTextLiteralBlockSize = 20, 00122 eDefaultElemValueOfBlockSize = 10, 00123 eDefaultElemVariableBlockSize = 10, 00124 eDefaultMatchPatternDataBlockSize = 10 }; 00125 00126 /* 00127 * Construct an instance. If the stylesheet(s) constructed is/are meant to be reused (a.k.a. "compiled"), 00128 * the XObjectFactory and XPathFactory instance must exist for the lifetime of the construction context 00129 * and, therefore, for the lifetime of the stylesheet(s). Otherwise, XObject and XPath instance will be 00130 * destroyed when the corresponding factories are destryed, leaving pointers to destroyed objects in the. 00131 * stylesheet(s). 00132 * 00133 * @param processor a reference to an XSLTEngineImpl instance. Used for error reporting. 00134 * @param xpathFactory a reference to an XPathFactory instance. See comments above for important details. 00135 * @param theXalanDOMCharVectorAllocatorBlockSize The block size to use for allocating vectors of XalanDOMChars 00136 * @param theAVTAllocatorBlockSize The block size to use for allocating AVT instances. 00137 * @param theAVTPartSimpleAllocatorBlockSize The block size to use for allocating AVTPartSimple instances. 00138 * @param theAVTPartXPathAllocatorBlockSize The block size to use for allocating AVTPartXPath instances. 00139 * @param theXalanQNameByValueAllocatorBlockSize The block size to use for allocating XalanQNameByValue instances. 00140 * @param thePointerVectorAllocatorBlockSize The block size to use for allocating vectors of pointers. 00141 */ 00142 StylesheetConstructionContextDefault( 00143 MemoryManagerType& theManager, 00144 XSLTEngineImpl& processor, 00145 XPathFactory& xpathFactory, 00146 VectorAllocatorSizeType theXalanDOMCharVectorAllocatorBlockSize = eDefaultXalanDOMCharVectorBlockSize, 00147 XalanAVTAllocator::size_type theAVTAllocatorBlockSize = eDefaultAVTBlockSize, 00148 XalanAVTPartSimpleAllocator::size_type theAVTPartSimpleAllocatorBlockSize = eDefaultAVTPartSimpleBlockSize, 00149 XalanAVTPartXPathAllocator::size_type theAVTPartXPathAllocatorBlockSize = eDefaultAVTPartXPathBlockSize, 00150 XalanQNameByValueAllocator::size_type theXalanQNameByValueAllocatorBlockSize = eDefaultXalanQNameByValueBlockSize, 00151 VectorAllocatorSizeType thePointerVectorAllocatorBlockSize = eDefaultPointerVectorBlockSize); 00152 00153 virtual 00154 ~StylesheetConstructionContextDefault(); 00155 00156 00157 virtual void 00158 error( 00159 const XalanDOMString& msg, 00160 const XalanNode* sourceNode = 0, 00161 const ElemTemplateElement* styleNode = 0) const; 00162 00163 virtual void 00164 error( 00165 const XalanDOMString& msg, 00166 const XalanNode* sourceNode, 00167 const LocatorType* locator) const; 00168 00169 virtual void 00170 warn( 00171 const XalanDOMString& msg, 00172 const XalanNode* sourceNode = 0, 00173 const ElemTemplateElement* styleNode = 0) const; 00174 00175 virtual void 00176 warn( 00177 const XalanDOMString& msg, 00178 const XalanNode* sourceNode, 00179 const LocatorType* locator) const; 00180 00181 virtual void 00182 message( 00183 const XalanDOMString& msg, 00184 const XalanNode* sourceNode = 0, 00185 const ElemTemplateElement* styleNode = 0) const; 00186 00187 virtual void 00188 message( 00189 const XalanDOMString& msg, 00190 const XalanNode* sourceNode, 00191 const LocatorType* locator) const; 00192 00193 // These interfaces are inherited from StylesheetConstructionContext... 00194 00195 virtual void 00196 reset(); 00197 00198 virtual StylesheetRoot* 00199 create(const XalanDOMString& theBaseIdentifier); 00200 00201 virtual StylesheetRoot* 00202 create(const XSLTInputSource& theInputSource); 00203 00204 virtual Stylesheet* 00205 create( 00206 StylesheetRoot& theStylesheetRoot, 00207 const XalanDOMString& theBaseIdentifier); 00208 00209 virtual void 00210 destroy(StylesheetRoot* theStylesheetRoot); 00211 00212 virtual URLAutoPtrType 00213 getURLFromString(const XalanDOMString& urlString); 00214 00215 virtual XalanDOMString& 00216 getURLStringFromString(const XalanDOMString& urlString, 00217 XalanDOMString& theResult); 00218 00219 virtual URLAutoPtrType 00220 getURLFromString( 00221 const XalanDOMString& urlString, 00222 const XalanDOMString& base); 00223 00224 virtual XalanDOMString& 00225 getURLStringFromString( 00226 const XalanDOMString& urlString, 00227 const XalanDOMString& base, 00228 XalanDOMString& theResult); 00229 00230 virtual const XalanDOMString& 00231 getXSLTNamespaceURI() const; 00232 00233 virtual XPath* 00234 createMatchPattern( 00235 const LocatorType* locator, 00236 const XalanDOMString& str, 00237 const PrefixResolver& resolver); 00238 00239 virtual XPath* 00240 createMatchPattern( 00241 const LocatorType* locator, 00242 const XalanDOMChar* str, 00243 const PrefixResolver& resolver); 00244 00245 virtual XPath* 00246 createXPath( 00247 const LocatorType* locator, 00248 const XalanDOMString& str, 00249 const PrefixResolver& resolver); 00250 00251 virtual XPath* 00252 createXPath( 00253 const LocatorType* locator, 00254 const XalanDOMChar* str, 00255 XalanDOMString::size_type len, 00256 const PrefixResolver& resolver); 00257 00258 virtual XPath* 00259 createXPath( 00260 const LocatorType* locator, 00261 const XalanDOMChar* str, 00262 const PrefixResolver& resolver); 00263 00264 virtual const LocatorType* 00265 getLocatorFromStack() const; 00266 00267 virtual void 00268 pushLocatorOnStack(const LocatorType* locator); 00269 00270 virtual void 00271 popLocatorStack(); 00272 00273 virtual const XalanDOMString& 00274 getXalanXSLNameSpaceURL() const; 00275 00276 virtual XalanDocument* 00277 parseXML( 00278 const XalanDOMString& urlString, 00279 DocumentHandlerType* docHandler, 00280 XalanDocument* docToRegister); 00281 00282 virtual bool 00283 isXMLSpaceAttribute( 00284 const XalanDOMChar* theAttributeName, 00285 const Stylesheet& theStylesheet, 00286 const LocatorType* theLocator = 0); 00287 00288 virtual bool 00289 isXSLUseAttributeSetsAttribute( 00290 const XalanDOMChar* theAttributeName, 00291 const Stylesheet& theStylesheet, 00292 const LocatorType* theLocator = 0); 00293 00294 virtual bool 00295 isValidQName( 00296 const XalanDOMChar* theName, 00297 const Stylesheet& theStylesheet, 00298 const LocatorType* theLocator = 0); 00299 00300 virtual eElementToken 00301 getElementToken(const XalanDOMString& name) const; 00302 00303 virtual double 00304 getXSLTVersionSupported() const; 00305 00306 virtual const XalanDOMString& 00307 getPooledString(const XalanDOMString& theString); 00308 00309 virtual const XalanDOMString& 00310 getPooledString( 00311 const XalanDOMChar* theString, 00312 XalanDOMString::size_type theLength = XalanDOMString::npos); 00313 00314 virtual XalanDOMString& 00315 getCachedString(); 00316 00317 virtual bool 00318 releaseCachedString(XalanDOMString& theString); 00319 00320 virtual XalanDOMChar* 00321 allocateXalanDOMCharVector(XalanDOMString::size_type theLength); 00322 00323 virtual XalanDOMChar* 00324 allocateXalanDOMCharVector( 00325 const XalanDOMChar* theString, 00326 XalanDOMString::size_type theLength = XalanDOMString::npos, 00327 bool fTerminate = true); 00328 00329 virtual const AVT* 00330 createAVT( 00331 const LocatorType* locator, 00332 const XalanDOMChar* name, 00333 const XalanDOMChar* stringedValue, 00334 const PrefixResolver& resolver); 00335 00336 virtual const AVTPart* 00337 createAVTPart( 00338 const XalanDOMChar* theString, 00339 XalanDOMString::size_type theLength = XalanDOMString::npos); 00340 00341 virtual const AVTPart* 00342 createAVTPart( 00343 const LocatorType* locator, 00344 const XalanDOMChar* str, 00345 XalanDOMString::size_type len, 00346 const PrefixResolver& resolver); 00347 00348 virtual const AVT** 00349 allocateAVTPointerVector(size_type theLength); 00350 00351 virtual const AVTPart** 00352 allocateAVTPartPointerVector(size_type theLength); 00353 00354 virtual const XalanQName* 00355 createXalanQName( 00356 const XalanDOMString& qname, 00357 const NamespacesStackType& namespaces, 00358 const LocatorType* locator = 0, 00359 bool fUseDefault = false); 00360 00361 virtual const XalanQName* 00362 createXalanQName( 00363 const XalanDOMChar* qname, 00364 const NamespacesStackType& namespaces, 00365 const LocatorType* locator = 0, 00366 bool fUseDefault = false); 00367 00368 virtual const XalanQName** 00369 tokenizeQNames( 00370 size_type& count, 00371 const XalanDOMChar* qnameTokens, 00372 const NamespacesStackType& namespaces, 00373 const LocatorType* locator = 0, 00374 bool fUseDefault = false); 00375 00376 virtual ElemTemplateElement* 00377 createElement( 00378 int token, 00379 Stylesheet& stylesheetTree, 00380 const AttributeListType& atts, 00381 const LocatorType* locator = 0); 00382 00383 virtual ElemTemplateElement* 00384 createElement( 00385 int token, 00386 Stylesheet& stylesheetTree, 00387 const XalanDOMChar* name, 00388 const AttributeListType& atts, 00389 const LocatorType* locator = 0); 00390 00391 virtual ElemTemplateElement* 00392 createElement( 00393 Stylesheet& stylesheetTree, 00394 const XalanDOMChar* chars, 00395 XalanDOMString::size_type length, 00396 bool preserveSpace, 00397 bool disableOutputEscaping, 00398 const LocatorType* locator = 0); 00399 00400 virtual ElemTemplateElement* 00401 createElement( 00402 Stylesheet& stylesheetTree, 00403 const XalanDOMChar* name, 00404 const AttributeListType& atts, 00405 ExtensionNSHandler& handler, 00406 const LocatorType* locator = 0); 00407 00408 virtual const XalanMatchPatternData* 00409 createXalanMatchPatternData( 00410 const ElemTemplate& theTemplate, 00411 size_type thePosition, 00412 const XalanDOMString& theTargetString, 00413 const XPath& theMatchPattern, 00414 const XalanDOMString& thePatternString, 00415 XPath::eMatchScore thePriority); 00416 00417 static eElementToken 00418 getElementNameToken(const XalanDOMString& name); 00419 00420 typedef XalanVector<StylesheetRoot*> StylesheetVectorType; 00421 typedef XalanVector<ElemTemplateElement*> ElemTemplateElementVectorType; 00422 00423 private: 00424 00425 const AVT** 00426 doAllocateAVTPointerVector(size_type theSize) 00427 { 00428 assert(sizeof(AVT**) == sizeof(PointerVectorAllocatorType::value_type)); 00429 00430 #if defined(XALAN_OLD_STYLE_CASTS) 00431 return (const AVT**)m_pointerVectorAllocator.allocate(theSize); 00432 #else 00433 return reinterpret_cast<const AVT**>(m_pointerVectorAllocator.allocate(theSize)); 00434 #endif 00435 } 00436 00437 const AVTPart** 00438 doAllocateAVTPartPointerVector(size_type theSize) 00439 { 00440 assert(sizeof(AVTPart**) == sizeof(PointerVectorAllocatorType::value_type)); 00441 00442 #if defined(XALAN_OLD_STYLE_CASTS) 00443 return (const AVTPart**)m_pointerVectorAllocator.allocate(theSize); 00444 #else 00445 return reinterpret_cast<const AVTPart**>(m_pointerVectorAllocator.allocate(theSize)); 00446 #endif 00447 } 00448 00449 const XalanQName** 00450 doAllocateXalanQNamePointerVector(size_type theSize) 00451 { 00452 assert(sizeof(XalanQName**) == sizeof(PointerVectorAllocatorType::value_type)); 00453 00454 #if defined(XALAN_OLD_STYLE_CASTS) 00455 return (const XalanQName**)m_pointerVectorAllocator.allocate(theSize); 00456 #else 00457 return reinterpret_cast<const XalanQName**>(m_pointerVectorAllocator.allocate(theSize)); 00458 #endif 00459 } 00460 00461 00462 XSLTEngineImpl& m_processor; 00463 00464 XPathFactory& m_xpathFactory; 00465 00466 typedef XalanMemMgrAutoPtr<XPathProcessor, true> XPathProcessAutoPtr; 00467 00468 XPathProcessAutoPtr m_xpathProcessor; 00469 00470 StylesheetVectorType m_stylesheets; 00471 00472 XalanDOMStringPool m_stringPool; 00473 00474 XalanDOMCharVectorAllocatorType m_xalanDOMCharVectorAllocator; 00475 00476 mutable XalanDOMString m_tempBuffer; 00477 00478 XalanQNameByValue m_scratchQName; 00479 00480 XalanDOMStringCache m_stringCache; 00481 00482 XalanAVTAllocator m_avtAllocator; 00483 00484 XalanAVTPartSimpleAllocator m_avtPartSimpleAllocator; 00485 00486 XalanAVTPartXPathAllocator m_avtPartXPathAllocator; 00487 00488 XalanQNameByValueAllocator m_xalanQNameByValueAllocator; 00489 00490 const XalanQNameByReference m_useAttributeSetsQName; 00491 00492 PointerVectorAllocatorType m_pointerVectorAllocator; 00493 00494 ElemTemplateElementVectorType m_allocatedElements; 00495 00496 XalanElemApplyTemplatesAllocator m_elemApplyTemplatesAllocator; 00497 00498 XalanElemAttributeAllocator m_elemAttributeAllocator; 00499 00500 XalanElemAttributeSetAllocator m_elemAttributeSetAllocator; 00501 00502 XalanElemCallTemplateAllocator m_elemCallTemplateAllocator; 00503 00504 XalanElemElementAllocator m_elemElementAllocator; 00505 00506 XalanElemLiteralResultAllocator m_elemLiteralResultAllocator; 00507 00508 XalanElemTemplateAllocator m_elemTemplateAllocator; 00509 00510 XalanElemTextLiteralAllocator m_elemTextLiteralAllocator; 00511 00512 XalanElemValueOfAllocator m_elemValueOfAllocator; 00513 00514 XalanElemVariableAllocator m_elemVariableAllocator; 00515 00516 XalanMatchPatternDataAllocator m_matchPatternDataAllocator; 00517 00518 const XalanQNameByReference m_spaceAttrQName; 00519 00520 // Static strings for stylesheet compilation... 00521 00522 // The string "if" 00523 static const XalanDOMChar s_if[]; 00524 00525 // The string "key" 00526 static const XalanDOMChar s_key[]; 00527 00528 // The string "copy" 00529 static const XalanDOMChar s_copy[]; 00530 00531 // The string "sort" 00532 static const XalanDOMChar s_sort[]; 00533 00534 // The string "text" 00535 static const XalanDOMChar s_text[]; 00536 00537 // The string "when" 00538 static const XalanDOMChar s_when[]; 00539 00540 // The string "empty" 00541 static const XalanDOMChar s_empty[]; 00542 00543 // The string "param" 00544 static const XalanDOMChar s_param[]; 00545 00546 // The string "choose" 00547 static const XalanDOMChar s_choose[]; 00548 00549 // The string "import" 00550 static const XalanDOMChar s_import[]; 00551 00552 // The string "number" 00553 static const XalanDOMChar s_number[]; 00554 00555 // The string "output" 00556 static const XalanDOMChar s_output[]; 00557 00558 // The string "comment" 00559 static const XalanDOMChar s_comment[]; 00560 00561 // The string "copy-of" 00562 static const XalanDOMChar s_copyOf[]; 00563 00564 // The string "element" 00565 static const XalanDOMChar s_element[]; 00566 00567 // The string "include" 00568 static const XalanDOMChar s_include[]; 00569 00570 // The string "message" 00571 static const XalanDOMChar s_message[]; 00572 00573 // The string "fallback" 00574 static const XalanDOMChar s_fallback[]; 00575 00576 // The string "for-each" 00577 static const XalanDOMChar s_forEach[]; 00578 00579 // The string "template" 00580 static const XalanDOMChar s_template[]; 00581 00582 // The string "value-of" 00583 static const XalanDOMChar s_valueOf[]; 00584 00585 // The string "variable" 00586 static const XalanDOMChar s_variable[]; 00587 00588 // The string "attribute" 00589 static const XalanDOMChar s_attribute[]; 00590 00591 // The string "otherwise" 00592 static const XalanDOMChar s_otherwise[]; 00593 00594 // The string "transform" 00595 static const XalanDOMChar s_transform[]; 00596 00597 // The string "stylesheet" 00598 static const XalanDOMChar s_stylesheet[]; 00599 00600 // The string "with-param" 00601 static const XalanDOMChar s_withParam[]; 00602 00603 // The string "strip-space" 00604 static const XalanDOMChar s_stripSpace[]; 00605 00606 // The string "apply-imports" 00607 static const XalanDOMChar s_applyImports[]; 00608 00609 // The string "attribute-set" 00610 static const XalanDOMChar s_attributeSet[]; 00611 00612 // The string "call-template" 00613 static const XalanDOMChar s_callTemplate[]; 00614 00615 // The string "decimal-format" 00616 static const XalanDOMChar s_decimalFormat[]; 00617 00618 // The string "preserve-space" 00619 static const XalanDOMChar s_preserveSpace[]; 00620 00621 // The string "apply-templates" 00622 static const XalanDOMChar s_applyTemplates[]; 00623 00624 // The string "namespace-alias" 00625 static const XalanDOMChar s_namespaceAlias[]; 00626 00627 // The string "processing-instruction" 00628 static const XalanDOMChar s_processingInstruction[]; 00629 00630 // A struct for an array that maps stylesheet element names 00631 // to int tokens. 00632 struct ElementTokenTableEntry 00633 { 00634 const XalanDOMChar* m_name; 00635 00636 eElementToken m_token; 00637 }; 00638 00639 static const ElementTokenTableEntry s_elementTokenTable[]; 00640 00641 static const unsigned int s_elementTokenTableSize; 00642 00643 static const ElementTokenTableEntry& s_elementTokenTableLast; 00644 00645 static const ElementTokenTableEntry& s_elementTokenTableDummy; 00646 }; 00647 00648 00649 00650 XALAN_CPP_NAMESPACE_END 00651 00652 00653 00654 #endif // STYLESHEETCONSTRUCTIONCONTEXTDEFAULT_HEADER_GUARD_1357924680
Doxygen and GraphViz are used to generate this API documentation from the Xalan-C header files.
![]() |
Xalan-C++ XSLT Processor Version 1.9 |
|