KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > uitags > tag > AttributeTag


1 /**
2  * Jun 24, 2005
3  *
4  * Copyright 2004 uitags
5  *
6  * Licensed 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 package net.sf.uitags.tag;
19
20 import javax.servlet.jsp.JspException JavaDoc;
21 import javax.servlet.jsp.tagext.Tag JavaDoc;
22
23 import net.sf.uitags.tagutil.AttributeSupport;
24 import net.sf.uitags.tagutil.validation.TlvLeakageException;
25
26 /**
27  * A tag that allows you to add an additional HTML attribute for the
28  * enclosing JSP tag (must be a tag that has a corresponding HTML tag).
29  *
30  * @author hgani
31  * @version $Id$
32  */

33 public class AttributeTag extends AbstractUiTag {
34
35   ///////////////////////////////
36
////////// Constants //////////
37
///////////////////////////////
38

39   /**
40    * Serial Version UID.
41    */

42   private static final long serialVersionUID = 100L;
43
44
45   ////////////////////////////
46
////////// Fields //////////
47
////////////////////////////
48

49   /**
50    * The 'name' tag attribute.
51    */

52   private String JavaDoc name;
53   /**
54    * The 'value' tag attribute.
55    */

56   private String JavaDoc value;
57
58
59   ///////////////////////////////////////////
60
////////// Tag attribute setters //////////
61
///////////////////////////////////////////
62

63   /**
64    * Tag attribute setter.
65    *
66    * @param name name of the tag attribute
67    */

68   public void setName(String JavaDoc name) {
69     this.name = name;
70   }
71
72   /**
73    * Tag attribute setter.
74    *
75    * @param value value of the tag attribute
76    */

77   public void setValue(String JavaDoc value) {
78     this.value = value;
79   }
80
81
82   ///////////////////////////////
83
////////// Tag logic //////////
84
///////////////////////////////
85

86   /**
87    * Invokes the {@link AttributeSupport#addAttribute(String, String)} of
88    * the enclosing tag.
89    *
90    * @see javax.servlet.jsp.tagext.Tag#doStartTag()
91    * @return <code>SKIP_BODY</code>
92    * @throws JspException to communicate error
93    */

94   public int doStartTag() throws JspException JavaDoc {
95     Tag JavaDoc parentTag = getParent();
96     if (!(parentTag instanceof AttributeSupport)) {
97       throw new TlvLeakageException("Invalid use of tag outside " +
98           "legitimate parent tag: " + parentTag.getClass().getName());
99     }
100     AttributeSupport attributeSupport = (AttributeSupport) parentTag;
101     attributeSupport.addAttribute(this.name, this.value);
102
103     return SKIP_BODY;
104   }
105 }
106
Popular Tags