1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.commons.jelly.tags.xml;
17
18 import org.apache.commons.jelly.JellyTagException;
19 import org.apache.commons.jelly.TagSupport;
20 import org.apache.commons.jelly.XMLOutput;
21
22 /*** Adds an XML attribute to the parent element tag like
23 * the <code><xsl:attribute></code> tag.
24 *
25 * @author James Strachan
26 * @version $Revision: 1.6 $
27 */
28 public class AttributeTag extends TagSupport {
29
30 /*** the name of the attribute. */
31 private String name;
32
33
34 public AttributeTag() {
35 }
36
37
38
39 public void doTag(XMLOutput output) throws JellyTagException {
40 ElementTag tag = (ElementTag) findAncestorWithClass( ElementTag.class );
41 if ( tag == null ) {
42 throw new JellyTagException( "<attribute> tag must be enclosed inside an <element> tag" );
43 }
44 tag.setAttributeValue( getName(), getBodyText( false ) );
45 }
46
47
48
49
50 /***
51 * @return the name of the attribute.
52 */
53 public String getName() {
54 return name;
55 }
56 /***
57 * Sets the name of the attribute
58 */
59 public void setName(String name) {
60 this.name = name;
61 }
62 }