Xalan-C++ API Documentation

The Xalan C++ XSLT Processor Version 1.9

Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

StylesheetHandler.hpp

Go to the documentation of this file.
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 <xalanc/Include/XalanVector.hpp>
00026 #include <xalanc/Include/XalanSet.hpp>
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     typedef XalanVector<ElemTemplateElement*>       ElemTemplateStackType;
00073     typedef XalanVector<ElemTemplateElement*>       ElemTextLiteralStackType;
00074 
00075     typedef XalanVector<bool>                       BoolStackType;
00076     typedef XalanSet<XalanQNameByReference>         QNameSetType;
00077     typedef XalanVector<QNameSetType, ConstructWithMemoryManagerTraits<QNameSetType> >
00078                                                     QNameSetVectorType;
00079 
00083     static void
00084     initialize(MemoryManagerType&  theManager);
00085 
00089     static void
00090     terminate();
00091 
00096     StylesheetHandler(
00097             Stylesheet&                     stylesheetTree,
00098             StylesheetConstructionContext&  constructionContext);
00099 
00100     MemoryManagerType&
00101     getMemoryManager()
00102     {
00103         return m_constructionContext.getMemoryManager();
00104     }
00105 
00106     virtual
00107     ~StylesheetHandler();
00108 
00132     virtual void characters (const XMLCh* const chars, const unsigned int length);
00133 
00144     virtual void charactersRaw(const XMLCh* const chars, const unsigned int length);
00145 
00169     virtual void cdata(const XMLCh* const ch, const unsigned int length);
00170 
00194     virtual void ignorableWhitespace (const XMLCh* const chars, const unsigned int length);
00195 
00212     virtual void processingInstruction (const XMLCh* const target, const XMLCh* const data);
00213 
00220     virtual void comment(const XMLCh* const data);
00221 
00228     virtual void entityReference(const XMLCh* const data);
00229 
00230     // These methods are inherited DocumentHandler ...
00231     
00232     // $$$ Theoretically, shouldn't need javadoc for these, since they are
00233     // inherited from DocumentHandler, but let's leave them in for now -- JMD
00234 
00260     virtual void setDocumentLocator(const LocatorType* const    locator);
00261 
00271     virtual void startDocument();
00272 
00284     virtual void endDocument();
00285     
00307     virtual void startElement(const XMLCh* const name, AttributeListType& attrs);
00308     
00323     virtual void endElement(const XMLCh* const name);
00324     
00330     virtual void resetDocument();
00331 
00332 protected:
00333 
00343     bool
00344     isAttrOK(
00345             const XalanDOMChar*         attrName,
00346             const AttributeListType&    atts,
00347             int                         which);
00348 
00359     bool
00360     processSpaceAttr(
00361             const XalanDOMChar*         aname,
00362             const AttributeListType&    atts,
00363             int                         which,
00364             const LocatorType*          locator,
00365             bool&                       fPreserve);
00366 
00375     bool
00376     processSpaceAttr(
00377             const AttributeListType&    atts,
00378             const LocatorType*          locator,
00379             bool&                       fPreserve);
00380 
00384     void
00385     processImport(
00386             const XalanDOMChar*         name,
00387             const AttributeListType&    atts,
00388             const LocatorType*          locator);
00389 
00393     void
00394     processInclude(
00395             const XalanDOMChar*         name,
00396             const AttributeListType&    atts,
00397             const LocatorType*          locator);
00398 
00399     void
00400     doCleanup();
00401 
00402 private:
00403 
00404     enum { eElemEmptyAllocatorBlockSize = 10, eElemTextBlockSize = 10 };
00405 
00406     // not implemented
00407     StylesheetHandler(const StylesheetHandler&);
00408 
00409     StylesheetHandler&
00410     operator=(const StylesheetHandler&);
00411 
00412     // Utility functions...
00413     void
00414     illegalAttributeError(
00415             const XalanDOMChar*     theElementName,
00416             const XalanDOMChar*     theAttributeName,
00417             const LocatorType*      theLocator) const;
00418 
00419     void
00420     error(
00421             const XalanDOMChar*     theMessage1,
00422             const XalanDOMChar*     theMessage2,
00423             const LocatorType*      theLocator) const;
00424 
00425     void
00426     error(
00427             const XalanDOMChar*     theMessage1,
00428             const XalanDOMString&   theMessage2,
00429             const LocatorType*      theLocator) const;
00430 
00431     void
00432     error(
00433             const XalanDOMString&   theMessage1,
00434             const XalanDOMChar*     theMessage2,
00435             const LocatorType*      theLocator) const;
00436 
00437     void
00438     error(
00439             const XalanDOMString&   theMessage1,
00440             const XalanDOMString&   theMessage2,
00441             const LocatorType*      theLocator) const;
00442 
00443     void
00444     warn(
00445             const XalanDOMChar*     theMessage1,
00446             const XalanDOMChar*     theMessage2,
00447             const LocatorType*      theLocator) const;
00448 
00449     void
00450     warn(
00451             const XalanDOMChar*     theMessage1,
00452             const XalanDOMString&   theMessage2,
00453             const LocatorType*      theLocator) const;
00454     void
00455     warn(
00456             const XalanDOMString&   theMessage,
00457             const LocatorType*      theLocator) const;
00458 
00459     void
00460     error(
00461             const XalanDOMString&   theMessage,
00462             const LocatorType*      theLocator) const;
00463 
00464     void
00465     processText(
00466             const XMLCh*                chars,
00467             XalanDOMString::size_type   length);
00468 
00469     void
00470     accumulateText(
00471             const XMLCh*                chars,
00472             XalanDOMString::size_type   length);
00473 
00474     void
00475     processAccumulatedText();
00476 
00477     void
00478     processTopLevelElement(
00479             const XalanDOMChar*         name,
00480             const AttributeListType&    atts,
00481             int                         xslToken,
00482             const LocatorType*          locator,
00483             bool&                       fPreserveSpace,
00484             bool&                       fSpaceAttrProcessed);
00485 
00486     void
00487     processStylesheet(
00488             const XalanDOMChar*         name,
00489             const AttributeListType&    atts,
00490             const LocatorType*          locator,
00491             bool&                       fPreserveSpace,
00492             bool&                       fSpaceAttrProcessed);
00493 
00494     void
00495     processPreserveStripSpace(
00496             const XalanDOMChar*         name,
00497             const AttributeListType&    atts,
00498             const LocatorType*          locator,
00499             int                         xslToken);
00500 
00501     void
00502     appendChildElementToParent(
00503             ElemTemplateElement*    elem,
00504             const LocatorType*      locator);
00505 
00506     void
00507     appendChildElementToParent(
00508             ElemTemplateElement*    parent,
00509             ElemTemplateElement*    elem);
00510 
00511     void
00512     appendChildElementToParent(
00513             ElemTemplateElement*    parent,
00514             ElemTemplateElement*    elem,
00515             const LocatorType*      locator);
00516 
00517     bool
00518     inExtensionElement() const;
00519 
00520     void
00521     processExtensionElement(
00522             const XalanDOMChar*         name,
00523             const XalanDOMString&       localName,
00524             const AttributeListType&    atts,
00525             const LocatorType*          locator);
00526 
00527     void
00528     checkForOrAddVariableName(
00529             const XalanQName&   theVariableName,
00530             const LocatorType*  theLocator);
00531 
00532     // Data members...
00533 
00537     Stylesheet&     m_stylesheet;
00538 
00542     StylesheetConstructionContext&  m_constructionContext;
00543 
00547     XalanElemEmptyAllocator     m_elemEmptyAllocator;
00548 
00552     XalanElemTextAllocator      m_elemTextAllocator;
00553 
00557     ElemTemplateStackType   m_elemStack;
00558 
00564     ElemTextLiteralStackType    m_whiteSpaceElems;
00565 
00569     ElemTemplateElement*    m_pTemplate;
00570 
00571     class LastPoppedHolder
00572     {
00573     public:
00574 
00575         LastPoppedHolder(StylesheetHandler&     theStylesheetHandler) :
00576             m_stylesheetHandler(theStylesheetHandler),
00577             m_lastPopped(0)
00578         {
00579         }
00580 
00581         ~LastPoppedHolder()
00582         {
00583             cleanup();
00584         }
00585 
00586         ElemTemplateElement*
00587         operator->() const
00588         {
00589             return m_lastPopped;
00590         }
00591 
00592         bool
00593         operator==(ElemTemplateElement*     theRHS)
00594         {
00595             return m_lastPopped == theRHS;
00596         }
00597 
00598         bool
00599         operator!=(ElemTemplateElement*     theRHS)
00600         {
00601             return m_lastPopped != theRHS;
00602         }
00603 
00604         void
00605         operator=(ElemTemplateElement*  theRHS)
00606         {
00607             if (theRHS != m_lastPopped)
00608             {
00609                 cleanup();
00610 
00611                 m_lastPopped = theRHS;
00612             }
00613         }
00614 
00615         void
00616         swap(LastPoppedHolder&  theOther)
00617         {
00618             ElemTemplateElement* const  theTemp = m_lastPopped;
00619 
00620             m_lastPopped = theOther.m_lastPopped;
00621 
00622             theOther.m_lastPopped = theTemp;
00623         }
00624 
00625         ElemTemplateElement*
00626         get() const
00627         {
00628             return m_lastPopped;
00629         }
00630 
00631     private:
00632 
00633         void
00634         set(ElemTemplateElement*    theNewElement)
00635         {
00636             if (theNewElement != m_lastPopped)
00637             {
00638                 cleanup();
00639 
00640                 m_lastPopped = theNewElement;
00641             }
00642         }
00643 
00644         // Not implemented...
00645         LastPoppedHolder&
00646         operator=(const LastPoppedHolder&);
00647 
00648         LastPoppedHolder(const LastPoppedHolder&);
00649 
00650         // Helper functions...
00651         void
00652         cleanup();
00653 
00654         // Data members...
00655         StylesheetHandler&      m_stylesheetHandler;
00656 
00657         ElemTemplateElement*    m_lastPopped;
00658     };
00659 
00660     friend class LastPoppedHolder;
00661 
00665     LastPoppedHolder    m_lastPopped;
00666     
00670     bool m_inTemplate;
00671     
00676     bool m_foundStylesheet;
00677     
00683     bool m_foundNotImport;
00684 
00685     XalanDOMString      m_elementLocalName;
00686 
00691     XalanDOMString  m_accumulateText;
00692 
00693     XalanDOMString  m_includeBase;
00694 
00695     BoolStackType   m_inExtensionElementStack;
00696 
00697     BoolStackType   m_preserveSpaceStack;
00698 
00699     // Note that these variables must not be saved by
00700     // PushPopIncludeState...
00701     unsigned long   m_locatorsPushed;
00702 
00703     QNameSetType    m_globalVariableNames;
00704 
00705     enum { eVariablesStackDefault = 20 };
00706 
00707     QNameSetVectorType  m_inScopeVariableNamesStack;
00708 
00712     ElemTemplateElement*
00713     initWrapperless(
00714             const XalanDOMChar*         name,
00715             const AttributeListType&    atts,
00716             const LocatorType*          locator);
00717 
00718     const XalanDOMString*
00719     getNamespaceFromStack(const XalanDOMChar*   theName,
00720                             XalanDOMString&     theBuffer) const;
00721 
00722     const XalanDOMString*
00723     getNamespaceForPrefixFromStack(const XalanDOMString&    thePrefix) const;
00724 
00725     class PushPopIncludeState;
00726 
00727     friend class StylesheetHandler::PushPopIncludeState;
00728 
00729     class PushPopIncludeState
00730     {
00731     public:
00732 
00733         PushPopIncludeState(StylesheetHandler&      theHandler);
00734 
00735         ~PushPopIncludeState();
00736 
00737     private:
00738 
00739         StylesheetHandler&                  m_handler;
00740 
00741         ElemTemplateStackType               m_elemStack;
00742 
00743         ElemTemplateElement* const          m_pTemplate;
00744 
00745         LastPoppedHolder                    m_lastPopped;       
00746 
00747         const bool                          m_inTemplate;       
00748 
00749         const bool                          m_foundStylesheet;
00750 
00751         const XalanDOMString                m_XSLNameSpaceURL;
00752 
00753         const bool                          m_foundNotImport;
00754 
00755         Stylesheet::NamespaceVectorType     m_namespaceDecls;
00756 
00757         Stylesheet::NamespacesStackType     m_namespaces;
00758 
00759         NamespacesHandler                   m_namespacesHandler;
00760 
00761         BoolStackType                       m_inExtensionElementStack;
00762 
00763         BoolStackType                       m_preserveSpaceStack;
00764     };
00765 
00766     static const XalanDOMString             s_emptyString;
00767 };
00768 
00769 
00770 
00771 XALAN_CPP_NAMESPACE_END
00772 
00773 
00774 
00775 #endif  // XALAN_STYLESHEETHANDLER_HEADER_GUARD

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.9
Copyright © 1999-2004 The Apache Software Foundation. All Rights Reserved.