1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 */ 18 /* 19 * $Id: ElemAttributeSet.java 468643 2006-10-28 06:56:03Z minchau $ 20 */ 21 package org.apache.xalan.templates; 22 23 import javax.xml.transform.TransformerException; 24 25 import org.apache.xalan.res.XSLMessages; 26 import org.apache.xalan.res.XSLTErrorResources; 27 import org.apache.xalan.transformer.TransformerImpl; 28 import org.apache.xml.utils.QName; 29 30 /** 31 * Implement xsl:attribute-set. 32 * <pre> 33 * &!ELEMENT xsl:attribute-set (xsl:attribute)*> 34 * &!ATTLIST xsl:attribute-set 35 * name %qname; #REQUIRED 36 * use-attribute-sets %qnames; #IMPLIED 37 * & 38 * </pre> 39 * @see <a href="http://www.w3.org/TR/xslt#attribute-sets">attribute-sets in XSLT Specification</a> 40 * @xsl.usage advanced 41 */ 42 public class ElemAttributeSet extends ElemUse 43 { 44 static final long serialVersionUID = -426740318278164496L; 45 46 /** 47 * The name attribute specifies the name of the attribute set. 48 * @serial 49 */ 50 public QName m_qname = null; 51 52 /** 53 * Set the "name" attribute. 54 * The name attribute specifies the name of the attribute set. 55 * 56 * @param name Name attribute to set 57 */ 58 public void setName(QName name) 59 { 60 m_qname = name; 61 } 62 63 /** 64 * Get the "name" attribute. 65 * The name attribute specifies the name of the attribute set. 66 * 67 * @return The name attribute of the attribute set 68 */ 69 public QName getName() 70 { 71 return m_qname; 72 } 73 74 /** 75 * Get an int constant identifying the type of element. 76 * @see org.apache.xalan.templates.Constants 77 * 78 * @return Token ID of the element 79 */ 80 public int getXSLToken() 81 { 82 return Constants.ELEMNAME_DEFINEATTRIBUTESET; 83 } 84 85 /** 86 * Return the node name. 87 * 88 * @return The name of this element 89 */ 90 public String getNodeName() 91 { 92 return Constants.ELEMNAME_ATTRIBUTESET_STRING; 93 } 94 95 /** 96 * Apply a set of attributes to the element. 97 * 98 * @param transformer non-null reference to the the current transform-time state. 99 * 100 * @throws TransformerException 101 */ 102 public void execute( 103 TransformerImpl transformer) 104 throws TransformerException 105 { 106 107 if (transformer.isRecursiveAttrSet(this)) 108 { 109 throw new TransformerException( 110 XSLMessages.createMessage( 111 XSLTErrorResources.ER_XSLATTRSET_USED_ITSELF, 112 new Object[]{ m_qname.getLocalPart() })); //"xsl:attribute-set '"+m_qname.m_localpart+ 113 } 114 115 transformer.pushElemAttributeSet(this); 116 super.execute(transformer); 117 118 ElemAttribute attr = (ElemAttribute) getFirstChildElem(); 119 120 while (null != attr) 121 { 122 attr.execute(transformer); 123 124 attr = (ElemAttribute) attr.getNextSiblingElem(); 125 } 126 127 transformer.popElemAttributeSet(); 128 } 129 130 /** 131 * Add a child to the child list. 132 * <!ELEMENT xsl:attribute-set (xsl:attribute)*> 133 * <!ATTLIST xsl:attribute-set 134 * name %qname; #REQUIRED 135 * use-attribute-sets %qnames; #IMPLIED 136 * > 137 * 138 * @param newChild Child to be added to this node's list of children 139 * 140 * @return The child that was just added to the list of children 141 * 142 * @throws DOMException 143 */ 144 public ElemTemplateElement appendChildElem(ElemTemplateElement newChild) 145 { 146 147 int type = ((ElemTemplateElement) newChild).getXSLToken(); 148 149 switch (type) 150 { 151 case Constants.ELEMNAME_ATTRIBUTE : 152 break; 153 default : 154 error(XSLTErrorResources.ER_CANNOT_ADD, 155 new Object[]{ newChild.getNodeName(), 156 this.getNodeName() }); //"Can not add " +((ElemTemplateElement)newChild).m_elemName + 157 158 //" to " + this.m_elemName); 159 } 160 161 return super.appendChild(newChild); 162 } 163 164 /** 165 * This function is called during recomposition to 166 * control how this element is composed. 167 * @param root The root stylesheet for this transformation. 168 */ 169 public void recompose(StylesheetRoot root) 170 { 171 root.recomposeAttributeSets(this); 172 } 173 174 } 175