Coverage details for org.chwf.taglib.jhtml.FormTag

LineHitsSource
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>&lt;form&gt;</code> tag.
46  *
47  * @author <a href="mailto:pfstrack@users.sourceforge.net">Paul Strack</a>
48  */
49122public 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() {
632    super.cleanup();
642    this.action = null;
652    this.validations = null;
662  }
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) {
754    if (action.startsWith("/")) {
761      HttpServletRequest request =
77         (HttpServletRequest) pageContext.getRequest();
781      this.action = request.getContextPath() + action;
79     } else {
803      this.action = action;
81     }
824  }
83  
84   /**
85    * The form action.
86    *
87    * @return The form action.
88    */
89   public String getAction() {
904    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 {
10292    super.setObject(objectName);
10391  }
104  
105   /**
106    * Whether validations are supported.
107    *
108    * @param validations Whether validations are supported.
109    */
110   public void setValidations(Boolean validations) {
1112    this.validations = validations;
1122  }
113  
114   /**
115    * Whether validations are supported. May be null.
116    *
117    * @return Whether validations are supported.
118    */
119   public Boolean getValidations() {
12021    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) {
1291    addAttribute("class", value);
1301  }
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) {
1381    addAttribute("id", value);
1391  }
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) {
1471    addAttribute("lang", value);
1481  }
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) {
1561    addAttribute("style", value);
1571  }
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) {
1651    addAttribute("title", value);
1661  }
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) {
1741    addAttribute("accept", value);
1751  }
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) {
1831    addAttribute("enctype", value);
1841  }
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) {
1921    addAttribute("method", value);
1931  }
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) {
2011    addAttribute("name", value);
2021  }
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) {
2101    addAttribute("target", value);
2111  }
212  
213   /**
214    * Initialization. Makes "method" attribute default to "post".
215    *
216    * @throws JspException For errors.
217    */
218   public void init() throws JspException {
2192    super.init();
2202    if (getAttribute("method") == null) {
2212      addAttribute("method", "post");
222     }
2232  }
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 {
2331    storeDefaultObject(findObject());
2341    JspWriter out = pageContext.getOut();
2351    out.print("<form action='");
2361    out.print(getActionURL());
2371    out.print("'");
2381    printAttributes();
2391    out.print(">");
2401    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 {
2501    pageContext.getOut().print("</form>");
2511    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() {
2601    String action = getAction();
2611    if (action.charAt(0) == '/') {
2620      HttpServletRequest request =
263         (HttpServletRequest) pageContext.getRequest();
2640      action = request.getContextPath() + action;
265     }
2661    HttpServletResponse response =
267       (HttpServletResponse) pageContext.getResponse();
2681    action = response.encodeURL(action);
2691    return action;
270   }
271 }

this report was generated by version 1.0.5 of jcoverage.
visit www.jcoverage.com for updates.

copyright © 2003, jcoverage ltd. all rights reserved.
Java is a trademark of Sun Microsystems, Inc. in the United States and other countries.