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 00017 #if !defined(XALAN_STYLESHEETHANDLER_HEADER_GUARD) 00018 #define XALAN_STYLESHEETHANDLER_HEADER_GUARD 00019 00020 // Base include file. Must be first. 00021 #include "XSLTDefinitions.hpp" 00022 00023 00024 00025 #include <vector> 00026 #include <set> 00027 00028 00029 00030 #include <xalanc/XalanDOM/XalanDOMString.hpp> 00031 00032 00033 00034 #include <xalanc/PlatformSupport/FormatterListener.hpp> 00035 00036 00037 00038 #include <xalanc/XPath/XalanQNameByValue.hpp> 00039 00040 00041 00042 #include <xalanc/XSLT/NamespacesHandler.hpp> 00043 #include <xalanc/XSLT/Stylesheet.hpp> 00044 #include <xalanc/XSLT/XalanElemEmptyAllocator.hpp> 00045 #include <xalanc/XSLT/XalanElemTextAllocator.hpp> 00046 00047 00048 00049 XALAN_CPP_NAMESPACE_BEGIN 00050 00051 00052 00053 class ElemTemplate; 00054 class ElemTemplateElement; 00055 class ElemTextLiteral; 00056 class ExtensionNSHandler; 00057 class StylesheetConstructionContext; 00058 00059 00060 00067 class XALAN_XSLT_EXPORT StylesheetHandler : public FormatterListener 00068 { 00069 00070 public: 00071 00072 #if defined(XALAN_NO_STD_NAMESPACE) 00073 typedef vector<ElemTemplateElement*> ElemTemplateStackType; 00074 typedef vector<ElemTemplateElement*> ElemTextLiteralStackType; 00075 #if defined(XALAN_USE_DEQUE_FOR_VECTOR_BOOL) 00076 typedef deque<bool> BoolVectorType; 00077 #else 00078 typedef vector<bool> BoolStackType; 00079 #endif 00080 typedef set<XalanQNameByReference, 00081 less<XalanQName> > QNameSetType; 00082 typedef vector<QNameSetType> QNameSetVectorType; 00083 #else 00084 typedef std::vector<ElemTemplateElement*> ElemTemplateStackType; 00085 typedef std::vector<ElemTemplateElement*> ElemTextLiteralStackType; 00086 #if defined(XALAN_USE_DEQUE_FOR_VECTOR_BOOL) 00087 typedef std::deque<bool> BoolVectorType; 00088 #else 00089 typedef std::vector<bool> BoolStackType; 00090 #endif 00091 typedef std::set<XalanQNameByReference, 00092 std::less<XalanQName> > QNameSetType; 00093 typedef std::vector<QNameSetType> QNameSetVectorType; 00094 #endif 00095 00099 static void 00100 initialize(); 00101 00105 static void 00106 terminate(); 00107 00112 StylesheetHandler( 00113 Stylesheet& stylesheetTree, 00114 StylesheetConstructionContext& constructionContext); 00115 00116 virtual 00117 ~StylesheetHandler(); 00118 00142 virtual void characters (const XMLCh* const chars, const unsigned int length); 00143 00154 virtual void charactersRaw(const XMLCh* const chars, const unsigned int length); 00155 00179 virtual void cdata(const XMLCh* const ch, const unsigned int length); 00180 00204 virtual void ignorableWhitespace (const XMLCh* const chars, const unsigned int length); 00205 00222 virtual void processingInstruction (const XMLCh* const target, const XMLCh* const data); 00223 00230 virtual void comment(const XMLCh* const data); 00231 00238 virtual void entityReference(const XMLCh* const data); 00239 00240 // These methods are inherited DocumentHandler ... 00241 00242 // $$$ Theoretically, shouldn't need javadoc for these, since they are 00243 // inherited from DocumentHandler, but let's leave them in for now -- JMD 00244 00270 virtual void setDocumentLocator(const LocatorType* const locator); 00271 00281 virtual void startDocument(); 00282 00294 virtual void endDocument(); 00295 00317 virtual void startElement(const XMLCh* const name, AttributeListType& attrs); 00318 00333 virtual void endElement(const XMLCh* const name); 00334 00340 virtual void resetDocument(); 00341 00342 protected: 00343 00353 bool 00354 isAttrOK( 00355 const XalanDOMChar* attrName, 00356 const AttributeListType& atts, 00357 int which); 00358 00369 bool 00370 processSpaceAttr( 00371 const XalanDOMChar* aname, 00372 const AttributeListType& atts, 00373 int which, 00374 const LocatorType* locator, 00375 bool& fPreserve); 00376 00385 bool 00386 processSpaceAttr( 00387 const AttributeListType& atts, 00388 const LocatorType* locator, 00389 bool& fPreserve); 00390 00394 void 00395 processImport( 00396 const XalanDOMChar* name, 00397 const AttributeListType& atts, 00398 const LocatorType* locator); 00399 00403 void 00404 processInclude( 00405 const XalanDOMChar* name, 00406 const AttributeListType& atts, 00407 const LocatorType* locator); 00408 00409 void 00410 doCleanup(); 00411 00412 private: 00413 00414 enum { eElemEmptyAllocatorBlockSize = 10, eElemTextBlockSize = 10 }; 00415 00416 // not implemented 00417 StylesheetHandler(const StylesheetHandler&); 00418 00419 StylesheetHandler& 00420 operator=(const StylesheetHandler&); 00421 00422 // Utility functions... 00423 void 00424 error( 00425 const char* theMessage, 00426 const LocatorType* theLocator) const; 00427 00428 void 00429 illegalAttributeError( 00430 const XalanDOMChar* theElementName, 00431 const XalanDOMChar* theAttributeName, 00432 const LocatorType* theLocator) const; 00433 00434 void 00435 error( 00436 const XalanDOMChar* theMessage1, 00437 const XalanDOMChar* theMessage2, 00438 const LocatorType* theLocator) const; 00439 00440 void 00441 error( 00442 const XalanDOMChar* theMessage1, 00443 const XalanDOMString& theMessage2, 00444 const LocatorType* theLocator) const; 00445 00446 void 00447 error( 00448 const XalanDOMString& theMessage1, 00449 const XalanDOMChar* theMessage2, 00450 const LocatorType* theLocator) const; 00451 00452 void 00453 error( 00454 const XalanDOMString& theMessage1, 00455 const XalanDOMString& theMessage2, 00456 const LocatorType* theLocator) const; 00457 00458 void 00459 warn( 00460 const XalanDOMChar* theMessage1, 00461 const XalanDOMChar* theMessage2, 00462 const LocatorType* theLocator) const; 00463 00464 void 00465 warn( 00466 const XalanDOMChar* theMessage1, 00467 const XalanDOMString& theMessage2, 00468 const LocatorType* theLocator) const; 00469 void 00470 warn( 00471 const XalanDOMString& theMessage, 00472 const LocatorType* theLocator) const; 00473 00474 void 00475 error( 00476 const XalanDOMString& theMessage, 00477 const LocatorType* theLocator) const; 00478 00479 void 00480 processText( 00481 const XMLCh* chars, 00482 XalanDOMString::size_type length); 00483 00484 void 00485 accumulateText( 00486 const XMLCh* chars, 00487 XalanDOMString::size_type length); 00488 00489 void 00490 processAccumulatedText(); 00491 00492 void 00493 processTopLevelElement( 00494 const XalanDOMChar* name, 00495 const AttributeListType& atts, 00496 int xslToken, 00497 const LocatorType* locator, 00498 bool& fPreserveSpace, 00499 bool& fSpaceAttrProcessed); 00500 00501 void 00502 processStylesheet( 00503 const XalanDOMChar* name, 00504 const AttributeListType& atts, 00505 const LocatorType* locator, 00506 bool& fPreserveSpace, 00507 bool& fSpaceAttrProcessed); 00508 00509 void 00510 processPreserveStripSpace( 00511 const XalanDOMChar* name, 00512 const AttributeListType& atts, 00513 const LocatorType* locator, 00514 int xslToken); 00515 00516 void 00517 appendChildElementToParent( 00518 ElemTemplateElement* elem, 00519 const LocatorType* locator); 00520 00521 void 00522 appendChildElementToParent( 00523 ElemTemplateElement* parent, 00524 ElemTemplateElement* elem); 00525 00526 void 00527 appendChildElementToParent( 00528 ElemTemplateElement* parent, 00529 ElemTemplateElement* elem, 00530 const LocatorType* locator); 00531 00532 bool 00533 inExtensionElement() const; 00534 00535 void 00536 processExtensionElement( 00537 const XalanDOMChar* name, 00538 const XalanDOMString& localName, 00539 const AttributeListType& atts, 00540 const LocatorType* locator); 00541 00542 void 00543 checkForOrAddVariableName( 00544 const XalanQName& theVariableName, 00545 const LocatorType* theLocator); 00546 00547 // Data members... 00548 00552 Stylesheet& m_stylesheet; 00553 00557 StylesheetConstructionContext& m_constructionContext; 00558 00562 XalanElemEmptyAllocator m_elemEmptyAllocator; 00563 00567 XalanElemTextAllocator m_elemTextAllocator; 00568 00572 ElemTemplateStackType m_elemStack; 00573 00579 ElemTextLiteralStackType m_whiteSpaceElems; 00580 00584 ElemTemplateElement* m_pTemplate; 00585 00586 class LastPoppedHolder 00587 { 00588 public: 00589 00590 LastPoppedHolder(StylesheetHandler& theStylesheetHandler) : 00591 m_stylesheetHandler(theStylesheetHandler), 00592 m_lastPopped(0) 00593 { 00594 } 00595 00596 ~LastPoppedHolder() 00597 { 00598 cleanup(); 00599 } 00600 00601 ElemTemplateElement* 00602 operator->() const 00603 { 00604 return m_lastPopped; 00605 } 00606 00607 bool 00608 operator==(ElemTemplateElement* theRHS) 00609 { 00610 return m_lastPopped == theRHS; 00611 } 00612 00613 bool 00614 operator!=(ElemTemplateElement* theRHS) 00615 { 00616 return m_lastPopped != theRHS; 00617 } 00618 00619 void 00620 operator=(ElemTemplateElement* theRHS) 00621 { 00622 if (theRHS != m_lastPopped) 00623 { 00624 cleanup(); 00625 00626 m_lastPopped = theRHS; 00627 } 00628 } 00629 00630 void 00631 swap(LastPoppedHolder& theOther) 00632 { 00633 ElemTemplateElement* const theTemp = m_lastPopped; 00634 00635 m_lastPopped = theOther.m_lastPopped; 00636 00637 theOther.m_lastPopped = theTemp; 00638 } 00639 00640 ElemTemplateElement* 00641 get() const 00642 { 00643 return m_lastPopped; 00644 } 00645 00646 private: 00647 00648 void 00649 set(ElemTemplateElement* theNewElement) 00650 { 00651 if (theNewElement != m_lastPopped) 00652 { 00653 cleanup(); 00654 00655 m_lastPopped = theNewElement; 00656 } 00657 } 00658 00659 // Not implemented... 00660 LastPoppedHolder& 00661 operator=(const LastPoppedHolder&); 00662 00663 LastPoppedHolder(const LastPoppedHolder&); 00664 00665 // Helper functions... 00666 void 00667 cleanup(); 00668 00669 // Data members... 00670 StylesheetHandler& m_stylesheetHandler; 00671 00672 ElemTemplateElement* m_lastPopped; 00673 }; 00674 00675 friend class LastPoppedHolder; 00676 00680 LastPoppedHolder m_lastPopped; 00681 00685 bool m_inTemplate; 00686 00691 bool m_foundStylesheet; 00692 00698 bool m_foundNotImport; 00699 00700 XalanDOMString m_elementLocalName; 00701 00706 XalanDOMString m_accumulateText; 00707 00708 XalanDOMString m_includeBase; 00709 00710 BoolStackType m_inExtensionElementStack; 00711 00712 BoolStackType m_preserveSpaceStack; 00713 00714 // Note that these variables must not be saved by 00715 // PushPopIncludeState... 00716 unsigned long m_locatorsPushed; 00717 00718 QNameSetType m_globalVariableNames; 00719 00720 enum { eVariablesStackDefault = 20 }; 00721 00722 QNameSetVectorType m_inScopeVariableNamesStack; 00723 00727 ElemTemplateElement* 00728 initWrapperless( 00729 const XalanDOMChar* name, 00730 const AttributeListType& atts, 00731 const LocatorType* locator); 00732 00733 const XalanDOMString* 00734 getNamespaceFromStack(const XalanDOMChar* theName) const; 00735 00736 const XalanDOMString* 00737 getNamespaceForPrefixFromStack(const XalanDOMString& thePrefix) const; 00738 00739 class PushPopIncludeState; 00740 00741 friend class StylesheetHandler::PushPopIncludeState; 00742 00743 class PushPopIncludeState 00744 { 00745 public: 00746 00747 PushPopIncludeState(StylesheetHandler& theHandler); 00748 00749 ~PushPopIncludeState(); 00750 00751 private: 00752 00753 StylesheetHandler& m_handler; 00754 00755 ElemTemplateStackType m_elemStack; 00756 00757 ElemTemplateElement* const m_pTemplate; 00758 00759 LastPoppedHolder m_lastPopped; 00760 00761 const bool m_inTemplate; 00762 00763 const bool m_foundStylesheet; 00764 00765 const XalanDOMString m_XSLNameSpaceURL; 00766 00767 const bool m_foundNotImport; 00768 00769 Stylesheet::NamespaceVectorType m_namespaceDecls; 00770 00771 Stylesheet::NamespacesStackType m_namespaces; 00772 00773 NamespacesHandler m_namespacesHandler; 00774 00775 BoolStackType m_inExtensionElementStack; 00776 00777 BoolStackType m_preserveSpaceStack; 00778 }; 00779 00780 static const XalanDOMString s_emptyString; 00781 }; 00782 00783 00784 00785 XALAN_CPP_NAMESPACE_END 00786 00787 00788 00789 #endif // XALAN_STYLESHEETHANDLER_HEADER_GUARD
Doxygen and GraphViz are used to generate this API documentation from the Xalan-C header files.
![]() |
Xalan-C++ XSLT Processor Version 1.8 |
|