KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > jcorporate > expresso > services > html > Form


1 /* ====================================================================
2  * The Jcorporate Apache Style Software License, Version 1.2 05-07-2002
3  *
4  * Copyright (c) 1995-2002 Jcorporate Ltd. All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  *
10  * 1. Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  *
13  * 2. Redistributions in binary form must reproduce the above copyright
14  * notice, this list of conditions and the following disclaimer in
15  * the documentation and/or other materials provided with the
16  * distribution.
17  *
18  * 3. The end-user documentation included with the redistribution,
19  * if any, must include the following acknowledgment:
20  * "This product includes software developed by Jcorporate Ltd.
21  * (http://www.jcorporate.com/)."
22  * Alternately, this acknowledgment may appear in the software itself,
23  * if and wherever such third-party acknowledgments normally appear.
24  *
25  * 4. "Jcorporate" and product names such as "Expresso" must
26  * not be used to endorse or promote products derived from this
27  * software without prior written permission. For written permission,
28  * please contact info@jcorporate.com.
29  *
30  * 5. Products derived from this software may not be called "Expresso",
31  * or other Jcorporate product names; nor may "Expresso" or other
32  * Jcorporate product names appear in their name, without prior
33  * written permission of Jcorporate Ltd.
34  *
35  * 6. No product derived from this software may compete in the same
36  * market space, i.e. framework, without prior written permission
37  * of Jcorporate Ltd. For written permission, please contact
38  * partners@jcorporate.com.
39  *
40  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
41  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
42  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
43  * DISCLAIMED. IN NO EVENT SHALL JCORPORATE LTD OR ITS CONTRIBUTORS
44  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
45  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
46  * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
47  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
48  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
49  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
50  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51  * SUCH DAMAGE.
52  * ====================================================================
53  *
54  * This software consists of voluntary contributions made by many
55  * individuals on behalf of the Jcorporate Ltd. Contributions back
56  * to the project(s) are encouraged when you make modifications.
57  * Please send them to support@jcorporate.com. For more information
58  * on Jcorporate Ltd. and its products, please see
59  * <http://www.jcorporate.com/>.
60  *
61  * Portions of this software are based upon other open source
62  * products and are subject to their respective licenses.
63  */

64
65 package com.jcorporate.expresso.services.html;
66
67 /**
68  * Form.java
69  *
70  * Copyright 1999, 2000, 2001 Jcorporate Ltd.
71  */

72
73 import java.io.PrintWriter JavaDoc;
74 import java.util.Enumeration JavaDoc;
75
76
77 /**
78  * An HTML form
79  *
80  * @author Michael Nash
81  * @version $Revision $Date: 2004/11/17 20:48:18 $
82  */

83 public class Form
84         extends HtmlElement {
85     private String JavaDoc action = null;
86     private String JavaDoc encoding = null;
87     private String JavaDoc method = ("POST");
88     private String JavaDoc thisClass = (this.getClass().getName() + ".");
89
90     /**
91      * Constructor
92      *
93      * @throws HtmlException If the superclass constructor fails
94      */

95     public Form()
96             throws HtmlException {
97         super();
98     } /* Form() */
99
100     /**
101      * Constructor
102      * Create a form with the contents of the given element
103      *
104      * @param newElement An HTML element to be the contents of this form
105      * @throws HtmlException If the parameter is invalid
106      */

107     public Form(HtmlElement newElement)
108             throws HtmlException {
109         super(newElement);
110     } /* Form(HtmlElemnet) */
111
112     /**
113      * Constructor
114      *
115      * @param newName Name of the form
116      * @throws HtmlException if the parameter is invalid or the superclass
117      * constructor fails
118      */

119     public Form(String JavaDoc newName)
120             throws HtmlException {
121         super(newName);
122     } /* Form(String) */
123
124     /**
125      * Display the form
126      *
127      * @param depth the number of tabs to indent
128      * @param out PrintWriter for display
129      * @throws HtmlException If there is an error displaying the form
130      */

131     protected synchronized void display(PrintWriter JavaDoc out, int depth)
132             throws HtmlException {
133         String JavaDoc myName = (thisClass + "display(PrintWriter)");
134
135         if (contents.size() == 0) {
136             throw new HtmlException(myName + ":Form " + getName() +
137                     " has no contents");
138         }
139
140         this.padWithTabs(out, depth);
141         out.print("<form");
142
143         if (cSSClass != null) {
144             out.print(" class=\"" + cSSClass + "\"");
145         }
146         if (cSSID != null) {
147             out.print(" id=\"" + cSSID + "\"");
148         }
149
150         out.print(" action=\"" + action + "\" method=\"" + method + "\"");
151
152         if (encoding != null) {
153             out.print(" enctype=\"" + encoding + "\"");
154         }
155
156         out.println(">");
157
158         HtmlElement oneElement = null;
159
160         for (Enumeration JavaDoc e = contents.elements(); e.hasMoreElements();) {
161             oneElement = (HtmlElement) e.nextElement();
162             oneElement.display(out, depth + 1);
163         }
164
165         this.padWithTabs(out, depth);
166         out.println("</form>");
167         setDisplayed();
168     } /* display(PrintWriter) */
169
170
171     /**
172      * Set the "action" field of this form - what happens when the form
173      * is submitted
174      *
175      * @param newAction New Action field for this form
176      * @throws HtmlException if the parameter is invalid
177      */

178     public void setAction(String JavaDoc newAction)
179             throws HtmlException {
180         action = newAction;
181     } /* setAction(String) */
182
183
184     /**
185      * Set the "enctype" field of this form - sets the encoding of the request to
186      * the server
187      *
188      * @param newEncoding New ENCTYPE field for this form
189      * @throws HtmlException if the parameter is invalid
190      */

191     public void setEncoding(String JavaDoc newEncoding)
192             throws HtmlException {
193         encoding = newEncoding;
194     } /* setAction(String) */
195
196
197     /**
198      * Set the "method" of this form - post or get
199      *
200      * @param newMethod POST or GET
201      * @throws HtmlException If the parameter is invalid
202      */

203     public void setMethod(String JavaDoc newMethod)
204             throws HtmlException {
205         String JavaDoc myName = (thisClass + "setMethod(String)");
206
207         if (newMethod == null) {
208             throw new HtmlException(myName + ":Method must be specified for " +
209                     getName());
210         }
211
212         method = newMethod;
213     } /* setMethod(String) */
214
215
216 } /* Form */
217
218 /* Form */
Popular Tags