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: 219726 $
27 */
28 public class AttributeTag extends TagSupport {
29 /*** The namespace URI. */
30 private String namespace;
31
32 /*** the name of the attribute. */
33 private String name;
34
35
36 public AttributeTag() {
37 }
38
39
40
41 public void doTag(XMLOutput output) throws JellyTagException {
42 ElementTag tag = (ElementTag) findAncestorWithClass( ElementTag.class );
43 if (tag == null) {
44 throw new JellyTagException(
45 "<attribute> tag must be enclosed inside an <element> tag" );
46 }
47 tag.setAttributeValue(getName(), getBodyText(false), getURI());
48 }
49
50
51
52
53 /***
54 * @return the name of the attribute.
55 */
56 public String getName() {
57 return name;
58 }
59
60 /***
61 * Sets the name of the attribute.
62 */
63 public void setName(String name) {
64 this.name = name;
65 }
66
67 /***
68 * @return the namespace URI of the element
69 */
70 public String getURI() {
71 return namespace;
72 }
73
74 /***
75 * Sets the namespace URI of the element
76 */
77 public void setURI(String namespace) {
78 this.namespace = namespace;
79 }
80 }