View Javadoc

1   /*
2    * Copyright 2002,2004 The Apache Software Foundation.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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>&lt;xsl:attribute&gt;</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      // Tag interface
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      // Properties
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  }