1. /*
  2. * The Apache Software License, Version 1.1
  3. *
  4. *
  5. * Copyright (c) 1999 The Apache Software Foundation. All rights
  6. * reserved.
  7. *
  8. * Redistribution and use in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions
  10. * are met:
  11. *
  12. * 1. Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions and the following disclaimer.
  14. *
  15. * 2. Redistributions in binary form must reproduce the above copyright
  16. * notice, this list of conditions and the following disclaimer in
  17. * the documentation and/or other materials provided with the
  18. * distribution.
  19. *
  20. * 3. The end-user documentation included with the redistribution,
  21. * if any, must include the following acknowledgment:
  22. * "This product includes software developed by the
  23. * Apache Software Foundation (http://www.apache.org/)."
  24. * Alternately, this acknowledgment may appear in the software itself,
  25. * if and wherever such third-party acknowledgments normally appear.
  26. *
  27. * 4. The names "Xalan" and "Apache Software Foundation" must
  28. * not be used to endorse or promote products derived from this
  29. * software without prior written permission. For written
  30. * permission, please contact apache@apache.org.
  31. *
  32. * 5. Products derived from this software may not be called "Apache",
  33. * nor may "Apache" appear in their name, without prior written
  34. * permission of the Apache Software Foundation.
  35. *
  36. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  37. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  38. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  39. * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  40. * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  41. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  42. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  43. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  44. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  45. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  46. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  47. * SUCH DAMAGE.
  48. * ====================================================================
  49. *
  50. * This software consists of voluntary contributions made by many
  51. * individuals on behalf of the Apache Software Foundation and was
  52. * originally based on software copyright (c) 1999, Lotus
  53. * Development Corporation., http://www.lotus.com. For more
  54. * information on the Apache Software Foundation, please see
  55. * <http://www.apache.org/>.
  56. */
  57. package org.apache.xalan.templates;
  58. import org.w3c.dom.Node;
  59. import org.w3c.dom.DOMException;
  60. import javax.xml.transform.TransformerException;
  61. import org.apache.xml.utils.QName;
  62. import org.apache.xalan.res.XSLTErrorResources;
  63. import org.apache.xalan.res.XSLMessages;
  64. import java.util.Stack;
  65. import org.apache.xalan.transformer.TransformerImpl;
  66. /**
  67. * <meta name="usage" content="advanced"/>
  68. * Implement xsl:attribute-set.
  69. * <pre>
  70. * &!ELEMENT xsl:attribute-set (xsl:attribute)*>
  71. * &!ATTLIST xsl:attribute-set
  72. * name %qname; #REQUIRED
  73. * use-attribute-sets %qnames; #IMPLIED
  74. * &
  75. * </pre>
  76. * @see <a href="http://www.w3.org/TR/xslt#attribute-sets">attribute-sets in XSLT Specification</a>
  77. */
  78. public class ElemAttributeSet extends ElemUse
  79. {
  80. /**
  81. * The name attribute specifies the name of the attribute set.
  82. * @serial
  83. */
  84. public QName m_qname = null;
  85. /**
  86. * Set the "name" attribute.
  87. * The name attribute specifies the name of the attribute set.
  88. *
  89. * @param name Name attribute to set
  90. */
  91. public void setName(QName name)
  92. {
  93. m_qname = name;
  94. }
  95. /**
  96. * Get the "name" attribute.
  97. * The name attribute specifies the name of the attribute set.
  98. *
  99. * @return The name attribute of the attribute set
  100. */
  101. public QName getName()
  102. {
  103. return m_qname;
  104. }
  105. /**
  106. * Get an int constant identifying the type of element.
  107. * @see org.apache.xalan.templates.Constants
  108. *
  109. * @return Token ID of the element
  110. */
  111. public int getXSLToken()
  112. {
  113. return Constants.ELEMNAME_DEFINEATTRIBUTESET;
  114. }
  115. /**
  116. * Return the node name.
  117. *
  118. * @return The name of this element
  119. */
  120. public String getNodeName()
  121. {
  122. return Constants.ELEMNAME_ATTRIBUTESET_STRING;
  123. }
  124. /**
  125. * Apply a set of attributes to the element.
  126. *
  127. * @param transformer non-null reference to the the current transform-time state.
  128. * @param sourceNode non-null reference to the <a href="http://www.w3.org/TR/xslt#dt-current-node">current source node</a>.
  129. * @param mode reference, which may be null, to the <a href="http://www.w3.org/TR/xslt#modes">current mode</a>.
  130. *
  131. * @throws TransformerException
  132. */
  133. public void execute(
  134. TransformerImpl transformer)
  135. throws TransformerException
  136. {
  137. if (transformer.isRecursiveAttrSet(this))
  138. {
  139. throw new TransformerException(
  140. XSLMessages.createMessage(
  141. XSLTErrorResources.ER_XSLATTRSET_USED_ITSELF,
  142. new Object[]{ m_qname.getLocalPart() })); //"xsl:attribute-set '"+m_qname.m_localpart+
  143. }
  144. transformer.pushElemAttributeSet(this);
  145. super.execute(transformer);
  146. ElemAttribute attr = (ElemAttribute) getFirstChildElem();
  147. while (null != attr)
  148. {
  149. attr.execute(transformer);
  150. attr = (ElemAttribute) attr.getNextSiblingElem();
  151. }
  152. transformer.popElemAttributeSet();
  153. }
  154. /**
  155. * Add a child to the child list.
  156. * <!ELEMENT xsl:attribute-set (xsl:attribute)*>
  157. * <!ATTLIST xsl:attribute-set
  158. * name %qname; #REQUIRED
  159. * use-attribute-sets %qnames; #IMPLIED
  160. * >
  161. *
  162. * @param newChild Child to be added to this node's list of children
  163. *
  164. * @return The child that was just added to the list of children
  165. *
  166. * @throws DOMException
  167. */
  168. public ElemTemplateElement appendChildElem(ElemTemplateElement newChild)
  169. {
  170. int type = ((ElemTemplateElement) newChild).getXSLToken();
  171. switch (type)
  172. {
  173. case Constants.ELEMNAME_ATTRIBUTE :
  174. break;
  175. default :
  176. error(XSLTErrorResources.ER_CANNOT_ADD,
  177. new Object[]{ newChild.getNodeName(),
  178. this.getNodeName() }); //"Can not add " +((ElemTemplateElement)newChild).m_elemName +
  179. //" to " + this.m_elemName);
  180. }
  181. return super.appendChild(newChild);
  182. }
  183. /**
  184. * This function is called during recomposition to
  185. * control how this element is composed.
  186. * @param root The root stylesheet for this transformation.
  187. */
  188. public void recompose(StylesheetRoot root)
  189. {
  190. root.recomposeAttributeSets(this);
  191. }
  192. }