00001 /* 00002 * The Apache Software License, Version 1.1 00003 * 00004 * 00005 * Copyright (c) 1999 The Apache Software Foundation. All rights 00006 * reserved. 00007 * 00008 * Redistribution and use in source and binary forms, with or without 00009 * modification, are permitted provided that the following conditions 00010 * are met: 00011 * 00012 * 1. Redistributions of source code must retain the above copyright 00013 * notice, this list of conditions and the following disclaimer. 00014 * 00015 * 2. Redistributions in binary form must reproduce the above copyright 00016 * notice, this list of conditions and the following disclaimer in 00017 * the documentation and/or other materials provided with the 00018 * distribution. 00019 * 00020 * 3. The end-user documentation included with the redistribution, 00021 * if any, must include the following acknowledgment: 00022 * "This product includes software developed by the 00023 * Apache Software Foundation (http://www.apache.org/)." 00024 * Alternately, this acknowledgment may appear in the software itself, 00025 * if and wherever such third-party acknowledgments normally appear. 00026 * 00027 * 4. The names "Xalan" and "Apache Software Foundation" must 00028 * not be used to endorse or promote products derived from this 00029 * software without prior written permission. For written 00030 * permission, please contact apache@apache.org. 00031 * 00032 * 5. Products derived from this software may not be called "Apache", 00033 * nor may "Apache" appear in their name, without prior written 00034 * permission of the Apache Software Foundation. 00035 * 00036 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED 00037 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 00038 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00039 * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR 00040 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00041 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 00042 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 00043 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 00044 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00045 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 00046 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 00047 * SUCH DAMAGE. 00048 * ==================================================================== 00049 * 00050 * This software consists of voluntary contributions made by many 00051 * individuals on behalf of the Apache Software Foundation and was 00052 * originally based on software copyright (c) 1999, International 00053 * Business Machines, Inc., http://www.ibm.com. For more 00054 * information on the Apache Software Foundation, please see 00055 * <http://www.apache.org/>. 00056 */ 00057 #if !defined(XALAN_ELEMTEMPLATEELEMENT_HEADER_GUARD) 00058 #define XALAN_ELEMTEMPLATEELEMENT_HEADER_GUARD 00059 00060 00061 00062 // Base include file. Must be first. 00063 #include <XSLT/XSLTDefinitions.hpp> 00064 00065 00066 00067 #include <vector> 00068 #include <map> 00069 00070 00071 00072 #include <sax/Locator.hpp> 00073 00074 00075 00076 #include <XalanDOM/XalanDOMString.hpp> 00077 #include <XalanDOM/XalanElement.hpp> 00078 #include <XalanDOM/XalanEmptyNamedNodeMap.hpp> 00079 #include <XalanDOM/XalanNodeListSurrogate.hpp> 00080 00081 00082 00083 #include <PlatformSupport/DOMStringHelper.hpp> 00084 #include <PlatformSupport/PrefixResolver.hpp> 00085 00086 00087 00088 #include <XSLT/NamespacesHandler.hpp> 00089 00090 00091 00092 class AttributeList; 00093 class ElemTemplate; 00094 class NamespacesHandler; 00095 class NodeRefListBase; 00096 class NodeSorter; 00097 class Stylesheet; 00098 class StylesheetConstructionContext; 00099 class StylesheetExecutionContext; 00100 class XPath; 00101 00102 00103 00104 class XALAN_XSLT_EXPORT ElemTemplateElement : public XalanElement, public PrefixResolver 00105 { 00106 public: 00107 00118 ElemTemplateElement( 00119 StylesheetConstructionContext& constructionContext, 00120 Stylesheet& stylesheetTree, 00121 int lineNumber, 00122 int columnNumber, 00123 int xslToken); 00124 00125 virtual 00126 ~ElemTemplateElement(); 00127 00133 virtual const Locator* 00134 getLocator() const; 00135 00145 virtual bool 00146 isAttrOK( 00147 int tok, 00148 const XalanDOMChar* attrName, 00149 const AttributeList& atts, 00150 int which) const; 00151 00161 virtual bool 00162 isAttrOK( 00163 const XalanDOMChar* attrName, 00164 const AttributeList& atts, 00165 int which, 00166 StylesheetConstructionContext& constructionContext) const; 00167 00176 void 00177 processSpaceAttr( 00178 const AttributeList& atts, 00179 int which); 00180 00189 bool 00190 processSpaceAttr( 00191 const XalanDOMChar* aname, 00192 const AttributeList& atts, 00193 int which); 00194 00202 static bool 00203 isValidNCName(const XalanDOMString& s); 00204 00211 virtual void 00212 execute(StylesheetExecutionContext& executionContext) const; 00213 00219 void 00220 executeChildren(StylesheetExecutionContext& executionContext) const; 00221 00228 void 00229 executeChildren( 00230 StylesheetExecutionContext& executionContext, 00231 XalanNode* sourceNode) const; 00232 00244 const XalanDOMString& 00245 childrenToString( 00246 StylesheetExecutionContext& executionContext, 00247 XalanDOMString& result) const; 00248 00257 void 00258 childrenToResultAttribute( 00259 StylesheetExecutionContext& executionContext, 00260 const XalanDOMString& theName) const; 00261 00269 void 00270 childrenToResultComment(StylesheetExecutionContext& executionContext) const; 00271 00281 void 00282 childrenToResultPI( 00283 StylesheetExecutionContext& executionContext, 00284 const XalanDOMString& theTarget) const; 00285 00293 int 00294 getXSLToken() const 00295 { 00296 return m_xslToken; 00297 } 00298 00305 int 00306 getLineNumber() const 00307 { 00308 return m_lineNumber; 00309 } 00310 00317 int 00318 getColumnNumber() const 00319 { 00320 return m_columnNumber; 00321 } 00322 00328 virtual bool 00329 isWhitespace() const; 00330 00336 virtual void 00337 error(const XalanDOMString& msg) const; 00338 00344 virtual void 00345 error(const char* msg) const; 00346 00347 virtual const XalanDOMString& 00348 getElementName() const = 0; 00349 00350 #if defined(XALAN_NO_NAMESPACES) 00351 typedef map<XalanDOMString, 00352 XalanDOMString, 00353 less<XalanDOMString> > StringToStringMapType; 00354 #else 00355 typedef std::map<XalanDOMString, 00356 XalanDOMString> StringToStringMapType; 00357 #endif 00358 00364 const NamespacesHandler& 00365 getNamespacesHandler() const 00366 { 00367 return m_namespacesHandler; 00368 } 00369 00375 const Stylesheet& 00376 getStylesheet() const 00377 { 00378 return m_stylesheet; 00379 } 00380 00384 void 00385 finishedConstruction() 00386 { 00387 m_finishedConstruction = true; 00388 } 00389 00393 virtual void 00394 postConstruction( 00395 StylesheetConstructionContext& constructionContext, 00396 const NamespacesHandler& theParentHandler); 00397 00398 // Type-safe getters/setters... 00399 00405 virtual ElemTemplateElement* 00406 getFirstChildElem() const; 00407 00415 virtual void 00416 setFirstChildElem(ElemTemplateElement* theChild); 00417 00423 virtual ElemTemplateElement* 00424 getLastChildElem() const; 00425 00431 virtual ElemTemplateElement* 00432 getNextSiblingElem() const; 00433 00441 virtual void 00442 setNextSiblingElem(ElemTemplateElement* theSibling); 00443 00449 virtual ElemTemplateElement* 00450 getPreviousSiblingElem() const; 00451 00459 virtual void 00460 setPreviousSiblingElem(ElemTemplateElement* theSibling); 00461 00467 virtual ElemTemplateElement* 00468 getParentNodeElem() const; 00469 00477 virtual void 00478 setParentNodeElem(ElemTemplateElement* theParent); 00479 00487 virtual ElemTemplateElement* 00488 appendChildElem(ElemTemplateElement* newChild); 00489 00490 // Type-safe getters... 00491 00500 virtual ElemTemplateElement* 00501 insertBeforeElem( 00502 ElemTemplateElement* newChild, 00503 ElemTemplateElement* refChild); 00504 00513 virtual ElemTemplateElement* 00514 replaceChildElem( 00515 ElemTemplateElement* newChild, 00516 ElemTemplateElement* oldChild); 00517 00518 // These interfaces are inherited from XalanElement ... 00519 00520 virtual const XalanDOMString& 00521 getNodeName() const; 00522 00523 virtual const XalanDOMString& 00524 getNodeValue() const; 00525 00526 virtual NodeType 00527 getNodeType() const; 00528 00529 virtual XalanNode* 00530 getParentNode() const; 00531 00532 virtual const XalanNodeList* 00533 getChildNodes() const; 00534 00535 virtual XalanNode* 00536 getFirstChild() const; 00537 00538 virtual XalanNode* 00539 getLastChild() const; 00540 00541 virtual XalanNode* 00542 getPreviousSibling() const; 00543 00544 virtual XalanNode* 00545 getNextSibling() const; 00546 00547 virtual const XalanNamedNodeMap* 00548 getAttributes() const; 00549 00550 virtual XalanDocument* 00551 getOwnerDocument() const; 00552 00553 #if defined(XALAN_NO_COVARIANT_RETURN_TYPE) 00554 virtual XalanNode* 00555 #else 00556 virtual ElemTemplateElement* 00557 #endif 00558 cloneNode(bool deep) const; 00559 00560 virtual XalanNode* 00561 insertBefore( 00562 XalanNode* newChild, 00563 XalanNode* refChild); 00564 00565 virtual XalanNode* 00566 replaceChild( 00567 XalanNode* newChild, 00568 XalanNode* oldChild); 00569 00570 virtual XalanNode* 00571 removeChild(XalanNode* oldChild); 00572 00579 virtual XalanNode* 00580 appendChild(XalanNode* newChild); 00581 00582 virtual bool 00583 hasChildNodes() const; 00584 00585 virtual void 00586 setNodeValue(const XalanDOMString& nodeValue); 00587 00588 virtual void 00589 normalize(); 00590 00591 virtual bool 00592 supports( 00593 const XalanDOMString& feature, 00594 const XalanDOMString& version) const; 00595 00596 virtual const XalanDOMString& 00597 getNamespaceURI() const; 00598 00599 virtual const XalanDOMString& 00600 getPrefix() const; 00601 00602 virtual const XalanDOMString& 00603 getLocalName() const; 00604 00605 virtual void 00606 setPrefix(const XalanDOMString& prefix); 00607 00608 virtual bool 00609 isIndexed() const; 00610 00611 virtual unsigned long 00612 getIndex() const; 00613 00614 virtual const XalanDOMString& 00615 getTagName() const; 00616 00617 virtual const XalanDOMString& 00618 getAttribute(const XalanDOMString& name) const; 00619 00620 virtual XalanAttr* 00621 getAttributeNode(const XalanDOMString& name) const; 00622 00623 virtual XalanNodeList* 00624 getElementsByTagName(const XalanDOMString& name) const; 00625 00626 virtual void 00627 setAttribute( 00628 const XalanDOMString& name, 00629 const XalanDOMString& value); 00630 00631 virtual XalanAttr* 00632 setAttributeNode(XalanAttr* newAttr); 00633 00634 virtual XalanAttr* 00635 removeAttributeNode(XalanAttr* oldAttr); 00636 00637 virtual void 00638 removeAttribute(const XalanDOMString& name); 00639 00640 virtual const XalanDOMString& 00641 getAttributeNS( 00642 const XalanDOMString& namespaceURI, 00643 const XalanDOMString& localName) const; 00644 00645 virtual void 00646 setAttributeNS( 00647 const XalanDOMString& namespaceURI, 00648 const XalanDOMString& qualifiedName, 00649 const XalanDOMString& value); 00650 00651 virtual void 00652 removeAttributeNS( 00653 const XalanDOMString& namespaceURI, 00654 const XalanDOMString& localName); 00655 00656 virtual XalanAttr* 00657 getAttributeNodeNS( 00658 const XalanDOMString& namespaceURI, 00659 const XalanDOMString& localName) const; 00660 00661 virtual XalanAttr* 00662 setAttributeNodeNS(XalanAttr* newAttr); 00663 00664 virtual XalanNodeList* 00665 getElementsByTagNameNS( 00666 const XalanDOMString& namespaceURI, 00667 const XalanDOMString& localName) const; 00668 00669 00670 // These interfaces are inherited from PrefixResolver... 00671 00672 virtual const XalanDOMString* 00673 getNamespaceForPrefix(const XalanDOMString& prefix) const; 00674 00675 virtual const XalanDOMString& 00676 getURI() const; 00677 00678 00679 // These optimization interfaces are new to ElemTemplateElement... 00680 bool 00681 hasParams() const 00682 { 00683 return m_optimizationFlags & eHasParams ? true : false; 00684 } 00685 00686 bool 00687 hasVariables() const 00688 { 00689 return m_optimizationFlags & eHasVariables ? true : false; 00690 } 00691 00692 bool 00693 hasSingleTextChild() const 00694 { 00695 return m_optimizationFlags & eHasSingleTextChild ? true : false; 00696 } 00697 00698 bool 00699 hasChildren() const 00700 { 00701 return m_firstChild != 0 ? true : false; 00702 } 00703 00704 bool 00705 hasDirectTemplate() const 00706 { 00707 return m_optimizationFlags & eHasDirectTemplate ? true : false; 00708 } 00709 00714 bool 00715 canGenerateAttributes() const 00716 { 00717 return m_optimizationFlags & eCanGenerateAttributes ? true : false; 00718 } 00719 00720 protected: 00721 00722 void 00723 canGenerateAttributes(bool value) 00724 { 00725 if (value == true) 00726 { 00727 m_optimizationFlags |= eCanGenerateAttributes; 00728 } 00729 else 00730 { 00731 m_optimizationFlags &= ~eCanGenerateAttributes; 00732 } 00733 } 00734 00742 const XalanDOMString* 00743 getNamespaceForPrefixInternal( 00744 const XalanDOMString& prefix, 00745 bool fReportError) const; 00746 00759 void 00760 transformSelectedChildren( 00761 StylesheetExecutionContext& executionContext, 00762 const ElemTemplateElement& xslInstruction, 00763 const ElemTemplateElement* theTemplate, 00764 XalanNode* sourceNodeContext, 00765 const XPath& selectPattern, 00766 NodeSorter* sorter, 00767 int selectStackFrameIndex) const; 00768 00779 void 00780 transformSelectedChildren( 00781 StylesheetExecutionContext& executionContext, 00782 const ElemTemplateElement& xslInstruction, 00783 const ElemTemplateElement* theTemplate, 00784 const NodeRefListBase& sourceNodes, 00785 unsigned int sourceNodesCount) const; 00786 00798 bool 00799 transformChild( 00800 StylesheetExecutionContext& executionContext, 00801 const ElemTemplateElement& xslInstruction, 00802 const ElemTemplateElement* theTemplate, 00803 XalanNode* child) const; 00804 00817 virtual bool 00818 childTypeAllowed(int xslToken) const; 00819 00820 bool m_finishedConstruction; 00821 00822 /* 00823 * This object handles all result tree namespace processing. 00824 */ 00825 NamespacesHandler m_namespacesHandler; 00826 00827 static const XalanDOMString s_emptyString; 00828 00829 private: 00830 00831 class LocatorProxy : public Locator 00832 { 00833 public: 00834 00835 LocatorProxy(const ElemTemplateElement& theElement); 00836 00837 virtual 00838 ~LocatorProxy(); 00839 00840 virtual const XMLCh* 00841 getPublicId() const; 00842 00843 virtual const XMLCh* 00844 getSystemId() const; 00845 00846 virtual int 00847 getLineNumber() const; 00848 00849 virtual int 00850 getColumnNumber() const; 00851 00852 private: 00853 00854 const ElemTemplateElement& m_element; 00855 }; 00856 00865 XalanDOMString& 00866 doChildrenToString( 00867 StylesheetExecutionContext& executionContext, 00868 XalanDOMString& result) const; 00869 00870 Stylesheet& m_stylesheet; 00871 00872 const int m_lineNumber; 00873 const int m_columnNumber; 00874 00875 bool m_defaultSpace; 00876 00877 const int m_xslToken; 00878 00879 ElemTemplateElement* m_parentNode; 00880 ElemTemplateElement* m_nextSibling; 00881 ElemTemplateElement* m_previousSibling; 00882 00883 union 00884 { 00885 ElemTemplateElement* m_firstChild; 00886 const ElemTemplate* m_directTemplate; 00887 }; 00888 00889 XalanNodeListSurrogate m_surrogateChildren; 00890 00891 const XalanDOMString m_baseIndentifier; 00892 00893 enum { eHasParams = 1, 00894 eHasSingleTextChild = 2, 00895 eHasVariables = 4, 00896 eHasDirectTemplate = 8, 00897 eCanGenerateAttributes = 16 }; 00898 00899 unsigned m_optimizationFlags; 00900 00901 LocatorProxy m_locatorProxy; 00902 00903 static const XalanEmptyNamedNodeMap s_fakeAttributes; 00904 }; 00905 00906 00907 00908 #endif // XALAN_ELEMTEMPLATEELEMENT_HEADER_GUARD
Doxygen and GraphViz are used to generate this API documentation from the Xalan-C header files.
![]() |
Xalan-C++ XSL Transformer Version 1.1 |
|