KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > mlw > vlh > web > tag > ConfigurableTag


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;
22
23 import javax.servlet.jsp.JspException JavaDoc;
24 import javax.servlet.jsp.tagext.BodyTagSupport JavaDoc;
25
26 import net.mlw.vlh.web.tag.support.Attributeable;
27 import net.mlw.vlh.web.tag.support.Attributes;
28
29 /**
30  * @author mwilson, azachar
31  * @todo refactor resetCellAtributes to resetAttributes and include attributesString = null.
32  */

33 public class ConfigurableTag extends BodyTagSupport JavaDoc implements Attributeable
34 {
35    private Attributes cellAttributes = new Attributes();
36
37    private String JavaDoc attributesString = null;
38
39    private String JavaDoc initialClassCellAttributes = null;
40
41    /**
42     * It sets initialClassCellAttibutes, if found as name 'class'
43     * @see net.mlw.vlh.web.tag.support.Attributeable#setCellAttribute(java.lang.String,
44     * java.lang.String)
45     */

46    public void setCellAttribute(String JavaDoc name, String JavaDoc value)
47    {
48       cellAttributes.setCellAttribute(name, value);
49       if (name.equalsIgnoreCase("class"))
50       {
51          initialClassCellAttributes = value;
52       }
53    }
54
55    /**
56     * Append to initialClassCellAttibutes this class attribute value
57     * @param value The class attribute value
58     */

59    public void appendClassCellAttribute(String JavaDoc value)
60    {
61       cellAttributes.setCellAttribute("class", initialClassCellAttributes);
62       cellAttributes.appendCellAttribute("class", value);
63    }
64
65    public Attributes getCellAttributes()
66    {
67       return cellAttributes;
68    }
69
70    /**
71     * @return Returns the attributes.
72     */

73    public String JavaDoc getAttributes()
74    {
75       return attributesString;
76    }
77
78    /**
79     * @param attributes
80     * The attributes to set.
81     */

82    public void setAttributes(String JavaDoc attributes)
83    {
84       this.attributesString = attributes;
85    }
86
87    /**
88     * @see javax.servlet.jsp.tagext.Tag#doEndTag()
89     */

90    public int doEndTag() throws JspException JavaDoc
91    {
92       int result = super.doEndTag();
93       resetAttributes();
94       return result;
95    }
96
97    protected void resetAttributes()
98    {
99       cellAttributes.reset();
100       initialClassCellAttributes = null;
101       attributesString = null;
102    }
103
104    /**
105     * Called on a Tag handler to release state.
106     * The page compiler guarantees that JSP page implementation
107     * objects will invoke this method on all tag handlers,
108     * but there may be multiple invocations on doStartTag and doEndTag in between.
109     *
110     * @see javax.servlet.jsp.tagext.Tag#release()
111     */

112    public void release()
113    {
114       super.release();
115       resetAttributes();
116    }
117 }
Popular Tags