KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > mlw > vlh > web > tag > support > AttributeTag


1 /**
2  * Copyright (c) 2003 held jointly by the individual authors.
3  *
4  * This library is free software; you can redistribute it and/or modify it
5  * under the terms of the GNU Lesser General Public License as published
6  * by the Free Software Foundation; either version 2.1 of the License, or
7  * (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; with out even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with this library; if not, write to the Free Software Foundation,
16  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
17  *
18  * > http://www.gnu.org/copyleft/lesser.html
19  * > http://www.opensource.org/licenses/lgpl-license.php
20  */

21 package net.mlw.vlh.web.tag.support;
22
23 import javax.servlet.jsp.JspException JavaDoc;
24 import javax.servlet.jsp.tagext.BodyTagSupport JavaDoc;
25
26 import net.mlw.vlh.web.util.JspUtils;
27
28 /**
29  * Tag Library that sets properties on a Attributable.
30  *
31  * @author Matthew L. Wilson
32  * @version $Revision: 1.5 $ $Date: 2005/11/23 14:37:38 $
33  */

34 public class AttributeTag extends BodyTagSupport JavaDoc
35 {
36    /** The name of this property. */
37    private String JavaDoc name;
38
39    /** The value of this property. */
40    private String JavaDoc value;
41
42    /**
43     * @see javax.servlet.jsp.tagext.Tag#doStartTag()
44     */

45    public int doStartTag() throws JspException JavaDoc
46    {
47       Attributeable parent = (Attributeable) JspUtils.getParent(this, Attributeable.class);
48       if (value != null)
49       {
50          parent.setCellAttribute(name, value);
51          value = null;
52          return SKIP_BODY;
53       }
54       else
55       {
56          return EVAL_BODY_AGAIN;
57       }
58    }
59
60    /**
61     * @see javax.servlet.jsp.tagext.IterationTag#doAfterBody()
62     */

63    public int doAfterBody() throws JspException JavaDoc
64    {
65       Attributeable parent = (Attributeable) getParent();
66       parent.setCellAttribute(name, bodyContent.getString());
67       bodyContent.clearBody();
68       return SKIP_BODY;
69    }
70
71    /**
72     * @see javax.servlet.jsp.tagext.Tag#doEndTag()
73     */

74    public int doEndTag() throws JspException JavaDoc
75    {
76       int result = super.doEndTag();
77       reset();
78       return result;
79    }
80
81    /**
82     * @return Returns the name.
83     */

84    public String JavaDoc getName()
85    {
86       return name;
87    }
88
89    /**
90     * Set the name of this property.
91     *
92     * @param name
93     * The name of this property.
94     */

95    public void setName(String JavaDoc name)
96    {
97       this.name = name;
98    }
99
100    /**
101     * @return Returns the value.
102     */

103    public String JavaDoc getValue()
104    {
105       return value;
106    }
107
108    /**
109     * Sets the value of this property.
110     *
111     * @param value
112     * The value of this property.
113     */

114    public void setValue(String JavaDoc value)
115    {
116       this.value = value;
117    }
118
119    private void reset()
120    {
121       this.name = null;
122       this.value = null;
123    }
124
125    /**
126     * Called on a Tag handler to release state.
127     * The page compiler guarantees that JSP page implementation
128     * objects will invoke this method on all tag handlers,
129     * but there may be multiple invocations on doStartTag and doEndTag in between.
130     *
131     * @see javax.servlet.jsp.tagext.Tag#release()
132     */

133    public void release()
134    {
135       super.release();
136       reset();
137    }
138 }
Popular Tags