Line | Hits | Source |
---|---|---|
1 | /* | |
2 | Chrysalis Web Framework [http://chrysalis.sourceforge.net] | |
3 | Copyright (c) 2002, 2003, 2004, Paul Strack | |
4 | ||
5 | All rights reserved. | |
6 | ||
7 | Redistribution and use in source and binary forms, with or without | |
8 | modification, are permitted provided that the following conditions are met: | |
9 | ||
10 | 1. Redistributions of source code must retain the above copyright notice, this | |
11 | list of conditions and the following disclaimer. | |
12 | ||
13 | 2. Redistributions in binary form must reproduce the above copyright notice, | |
14 | this list of conditions and the following disclaimer in the documentation | |
15 | and/or other materials provided with the distribution. | |
16 | ||
17 | 3. Neither the name of the copyright holder nor the names of its contributors | |
18 | may be used to endorse or promote products derived from this software without | |
19 | specific prior written permission. | |
20 | ||
21 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | |
22 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | |
23 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
24 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR | |
25 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | |
26 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | |
27 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON | |
28 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
29 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | |
30 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
31 | */ | |
32 | ||
33 | package org.chwf.taglib.jhtml; | |
34 | ||
35 | import java.io.IOException; | |
36 | ||
37 | import javax.servlet.jsp.JspException; | |
38 | import javax.servlet.jsp.JspWriter; | |
39 | ||
40 | /** | |
41 | * Tag handler for the <code><label></code> tag. | |
42 | * | |
43 | * @author <a href="mailto:pfstrack@users.sourceforge.net">Paul Strack</a> | |
44 | */ | |
45 | 14 | public class LabelTag extends FieldTagSupport { |
46 | ||
47 | /** The field that this label is for. */ | |
48 | private String forField; | |
49 | ||
50 | /** | |
51 | * Clean up data for tag handler reuse and pooling. Should be overridden in | |
52 | * tag handler. Subclasses should always invoke their superclass's cleanup | |
53 | * method: <code>super.cleanup()</code> | |
54 | */ | |
55 | public void cleanup() { | |
56 | 1 | super.cleanup(); |
57 | 1 | this.forField = null; |
58 | 1 | } |
59 | ||
60 | /** | |
61 | * Calls superclass method. Is present here because of a bug in some servlet | |
62 | * engines that requires tag attibute setters to be defined in the tag class | |
63 | * itself. | |
64 | * | |
65 | * @param objectName The object name. | |
66 | * @throws JspException For errors. | |
67 | */ | |
68 | public void setObject(String objectName) throws JspException { | |
69 | 0 | super.setObject(objectName); |
70 | 0 | } |
71 | ||
72 | /** | |
73 | * Calls superclass method. Is present here because of a bug in some servlet | |
74 | * engines that requires tag attibute setters to be defined in the tag class | |
75 | * itself. | |
76 | * | |
77 | * @param property The property name. | |
78 | * @throws JspException For errors. | |
79 | */ | |
80 | public void setProperty(String property) throws JspException { | |
81 | 4 | super.setProperty(property); |
82 | 4 | } |
83 | ||
84 | /** | |
85 | * The form field name. Defaults to the property value if absent. Effectively | |
86 | * equivalent to the "name" attribute. | |
87 | * | |
88 | * @param value The field name. | |
89 | */ | |
90 | public void setFor(String value) { | |
91 | 2 | setName(value); |
92 | 2 | } |
93 | ||
94 | /** | |
95 | * The form field name. Defaults to the property value if absent. Effectively | |
96 | * equivalent to the "name" attribute. | |
97 | * | |
98 | * @return The field name. | |
99 | */ | |
100 | public String getFor() { | |
101 | 6 | return getName(); |
102 | } | |
103 | ||
104 | /** | |
105 | * Pass-through attribute. Same meaning as in HTML. | |
106 | * | |
107 | * @param value The attribute value. | |
108 | */ | |
109 | public void setAccesskey(String value) { | |
110 | 1 | addAttribute("accesskey", value); |
111 | 1 | } |
112 | ||
113 | /** | |
114 | * Print the property's label using BeanFilter metadata. | |
115 | * | |
116 | * @return SKIP_BODY. | |
117 | * @throws IOException For write errors. | |
118 | * @throws JspException If the property cannot be initialized. | |
119 | */ | |
120 | public int doStart() throws IOException, JspException { | |
121 | 2 | printLabel(); |
122 | 2 | return SKIP_BODY; |
123 | } | |
124 | ||
125 | /** | |
126 | * Print the field label. | |
127 | * | |
128 | * @throws IOException For write errors. | |
129 | * @throws JspException If object not defined. | |
130 | */ | |
131 | private void printLabel() throws IOException, JspException { | |
132 | 2 | JspWriter out = pageContext.getOut(); |
133 | 2 | out.print("<label for='"); |
134 | 2 | out.print(getFor()); |
135 | 2 | out.print("'"); |
136 | 2 | printAttributes(); |
137 | 2 | out.print(">"); |
138 | 2 | out.print(deriveLabel()); |
139 | 2 | out.print("</label>"); |
140 | 2 | } |
141 | ||
142 | /** | |
143 | * Pass-through attribute. Same meaning as "class" in HTML. | |
144 | * | |
145 | * @param value The attribute value. | |
146 | */ | |
147 | public void setStyleClass(String value) { | |
148 | 1 | addAttribute("class", value); |
149 | 1 | } |
150 | ||
151 | /** | |
152 | * Pass-through attribute. Same meaning as in HTML. | |
153 | * | |
154 | * @param value The attribute value. | |
155 | */ | |
156 | public void setId(String value) { | |
157 | 1 | addAttribute("id", value); |
158 | 1 | } |
159 | ||
160 | /** | |
161 | * Pass-through attribute. Same meaning as in HTML. | |
162 | * | |
163 | * @param value The attribute value. | |
164 | */ | |
165 | public void setLang(String value) { | |
166 | 1 | addAttribute("lang", value); |
167 | 1 | } |
168 | ||
169 | /** | |
170 | * Pass-through attribute. Same meaning as in HTML. | |
171 | * | |
172 | * @param value The attribute value. | |
173 | */ | |
174 | public void setStyle(String value) { | |
175 | 1 | addAttribute("style", value); |
176 | 1 | } |
177 | ||
178 | /** | |
179 | * Pass-through attribute. Same meaning as in HTML. | |
180 | * | |
181 | * @param value The attribute value. | |
182 | */ | |
183 | public void setTitle(String value) { | |
184 | 1 | addAttribute("title", value); |
185 | 1 | } |
186 | } |
this report was generated by version 1.0.5 of jcoverage. |
copyright © 2003, jcoverage ltd. all rights reserved. |