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.http.HttpServletRequest; | |
38 | import javax.servlet.http.HttpServletResponse; | |
39 | import javax.servlet.jsp.JspException; | |
40 | import javax.servlet.jsp.JspWriter; | |
41 | ||
42 | import org.chwf.taglib.base.ObjectTagSupport; | |
43 | ||
44 | /** | |
45 | * Tag handler for the <code><form></code> tag. | |
46 | * | |
47 | * @author <a href="mailto:pfstrack@users.sourceforge.net">Paul Strack</a> | |
48 | */ | |
49 | 122 | public class FormTag extends ObjectTagSupport { |
50 | ||
51 | /** The form action. */ | |
52 | private String action; | |
53 | ||
54 | /** Whether validations are supported. */ | |
55 | private Boolean validations; | |
56 | ||
57 | /** | |
58 | * Clean up data for tag handler reuse and pooling. Should be overridden in | |
59 | * tag handler. Subclasses should always invoke their superclass's cleanup | |
60 | * method: <code>super.cleanup()</code> | |
61 | */ | |
62 | public void cleanup() { | |
63 | 2 | super.cleanup(); |
64 | 2 | this.action = null; |
65 | 2 | this.validations = null; |
66 | 2 | } |
67 | ||
68 | /** | |
69 | * Sets the action. Required. If using site-relative URI (those beginning | |
70 | * with a "/"), do <i>not</i> include the context path. | |
71 | * | |
72 | * @param action The form action. | |
73 | */ | |
74 | public void setAction(String action) { | |
75 | 4 | if (action.startsWith("/")) { |
76 | 1 | HttpServletRequest request = |
77 | (HttpServletRequest) pageContext.getRequest(); | |
78 | 1 | this.action = request.getContextPath() + action; |
79 | } else { | |
80 | 3 | this.action = action; |
81 | } | |
82 | 4 | } |
83 | ||
84 | /** | |
85 | * The form action. | |
86 | * | |
87 | * @return The form action. | |
88 | */ | |
89 | public String getAction() { | |
90 | 4 | return this.action; |
91 | } | |
92 | ||
93 | /** | |
94 | * Calls superclass method. Is present here because of a bug in some servlet | |
95 | * engines that requires tag attibute setters to be defined in the tag class | |
96 | * itself. | |
97 | * | |
98 | * @param objectName The object name. | |
99 | * @throws JspException For errors. | |
100 | */ | |
101 | public void setObject(String objectName) throws JspException { | |
102 | 92 | super.setObject(objectName); |
103 | 91 | } |
104 | ||
105 | /** | |
106 | * Whether validations are supported. | |
107 | * | |
108 | * @param validations Whether validations are supported. | |
109 | */ | |
110 | public void setValidations(Boolean validations) { | |
111 | 2 | this.validations = validations; |
112 | 2 | } |
113 | ||
114 | /** | |
115 | * Whether validations are supported. May be null. | |
116 | * | |
117 | * @return Whether validations are supported. | |
118 | */ | |
119 | public Boolean getValidations() { | |
120 | 21 | return validations; |
121 | } | |
122 | ||
123 | /** | |
124 | * Pass-through attribute. Same meaning as "class" in HTML. | |
125 | * | |
126 | * @param value The attribute value. | |
127 | */ | |
128 | public void setStyleClass(String value) { | |
129 | 1 | addAttribute("class", value); |
130 | 1 | } |
131 | ||
132 | /** | |
133 | * Pass-through attribute. Same meaning as in HTML. | |
134 | * | |
135 | * @param value The attribute value. | |
136 | */ | |
137 | public void setId(String value) { | |
138 | 1 | addAttribute("id", value); |
139 | 1 | } |
140 | ||
141 | /** | |
142 | * Pass-through attribute. Same meaning as in HTML. | |
143 | * | |
144 | * @param value The attribute value. | |
145 | */ | |
146 | public void setLang(String value) { | |
147 | 1 | addAttribute("lang", value); |
148 | 1 | } |
149 | ||
150 | /** | |
151 | * Pass-through attribute. Same meaning as in HTML. | |
152 | * | |
153 | * @param value The attribute value. | |
154 | */ | |
155 | public void setStyle(String value) { | |
156 | 1 | addAttribute("style", value); |
157 | 1 | } |
158 | ||
159 | /** | |
160 | * Pass-through attribute. Same meaning as in HTML. | |
161 | * | |
162 | * @param value The attribute value. | |
163 | */ | |
164 | public void setTitle(String value) { | |
165 | 1 | addAttribute("title", value); |
166 | 1 | } |
167 | ||
168 | /** | |
169 | * Pass-through attribute. Same meaning as in HTML. | |
170 | * | |
171 | * @param value The attribute value. | |
172 | */ | |
173 | public void setAccept(String value) { | |
174 | 1 | addAttribute("accept", value); |
175 | 1 | } |
176 | ||
177 | /** | |
178 | * Pass-through attribute. Same meaning as in HTML. | |
179 | * | |
180 | * @param value The attribute value. | |
181 | */ | |
182 | public void setEnctype(String value) { | |
183 | 1 | addAttribute("enctype", value); |
184 | 1 | } |
185 | ||
186 | /** | |
187 | * Pass-through attribute. Same meaning as in HTML. | |
188 | * | |
189 | * @param value The attribute value. | |
190 | */ | |
191 | public void setMethod(String value) { | |
192 | 1 | addAttribute("method", value); |
193 | 1 | } |
194 | ||
195 | /** | |
196 | * Pass-through attribute. Same meaning as in HTML. | |
197 | * | |
198 | * @param value The attribute value. | |
199 | */ | |
200 | public void setName(String value) { | |
201 | 1 | addAttribute("name", value); |
202 | 1 | } |
203 | ||
204 | /** | |
205 | * Pass-through attribute. Same meaning as in HTML. | |
206 | * | |
207 | * @param value The attribute value. | |
208 | */ | |
209 | public void setTarget(String value) { | |
210 | 1 | addAttribute("target", value); |
211 | 1 | } |
212 | ||
213 | /** | |
214 | * Initialization. Makes "method" attribute default to "post". | |
215 | * | |
216 | * @throws JspException For errors. | |
217 | */ | |
218 | public void init() throws JspException { | |
219 | 2 | super.init(); |
220 | 2 | if (getAttribute("method") == null) { |
221 | 2 | addAttribute("method", "post"); |
222 | } | |
223 | 2 | } |
224 | ||
225 | /** | |
226 | * Initializes form data and prints open tag. | |
227 | * | |
228 | * @return EVAL_BODY_INCLUDE | |
229 | * @throws JspException If object not defined. | |
230 | * @throws IOException For write errors. | |
231 | */ | |
232 | public int doStart() throws IOException, JspException { | |
233 | 1 | storeDefaultObject(findObject()); |
234 | 1 | JspWriter out = pageContext.getOut(); |
235 | 1 | out.print("<form action='"); |
236 | 1 | out.print(getActionURL()); |
237 | 1 | out.print("'"); |
238 | 1 | printAttributes(); |
239 | 1 | out.print(">"); |
240 | 1 | return EVAL_BODY_INCLUDE; |
241 | } | |
242 | ||
243 | /** | |
244 | * Prints close tag. | |
245 | * | |
246 | * @return EVAL_PAGE | |
247 | * @throws IOException For write errors. | |
248 | */ | |
249 | public int doEnd() throws IOException { | |
250 | 1 | pageContext.getOut().print("</form>"); |
251 | 1 | return EVAL_PAGE; |
252 | } | |
253 | ||
254 | /** | |
255 | * Derive action URL by prepending context-path and URL-rewriting. | |
256 | * | |
257 | * @return The final action URL. | |
258 | */ | |
259 | private String getActionURL() { | |
260 | 1 | String action = getAction(); |
261 | 1 | if (action.charAt(0) == '/') { |
262 | 0 | HttpServletRequest request = |
263 | (HttpServletRequest) pageContext.getRequest(); | |
264 | 0 | action = request.getContextPath() + action; |
265 | } | |
266 | 1 | HttpServletResponse response = |
267 | (HttpServletResponse) pageContext.getResponse(); | |
268 | 1 | action = response.encodeURL(action); |
269 | 1 | return action; |
270 | } | |
271 | } |
this report was generated by version 1.0.5 of jcoverage. |
copyright © 2003, jcoverage ltd. all rights reserved. |