KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ecs > html > Form


1 /*
2  * ====================================================================
3  *
4  * The Apache Software License, Version 1.1
5  *
6  * Copyright (c) 1999-2003 The Apache Software Foundation. All rights
7  * reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  *
13  * 1. Redistributions of source code must retain the above copyright
14  * notice, this list of conditions and the following disclaimer.
15  *
16  * 2. Redistributions in binary form must reproduce the above copyright
17  * notice, this list of conditions and the following disclaimer in
18  * the documentation and/or other materials provided with the
19  * distribution.
20  *
21  * 3. The end-user documentation included with the redistribution, if
22  * any, must include the following acknowlegement:
23  * "This product includes software developed by the
24  * Apache Software Foundation (http://www.apache.org/)."
25  * Alternately, this acknowlegement may appear in the software itself,
26  * if and wherever such third-party acknowlegements normally appear.
27  *
28  * 4. The names "The Jakarta Project", "Jakarta Element Construction Set",
29  * "Jakarta ECS" , and "Apache Software Foundation" must not be used
30  * to endorse or promote products derived
31  * from this software without prior written permission. For written
32  * permission, please contact apache@apache.org.
33  *
34  * 5. Products derived from this software may not be called "Apache",
35  * "Jakarta Element Construction Set" nor "Jakarta ECS" nor may "Apache"
36  * appear in their names without prior written permission of the Apache Group.
37  *
38  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
39  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
40  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
41  * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
42  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
43  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
44  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
45  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
46  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
47  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
48  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
49  * SUCH DAMAGE.
50  * ====================================================================
51  *
52  * This software consists of voluntary contributions made by many
53  * individuals on behalf of the Apache Software Foundation. For more
54  * information on the Apache Software Foundation, please see
55  * <http://www.apache.org/>.
56  *
57  */

58 package org.apache.ecs.html;
59
60 import org.apache.ecs.*;
61
62 /**
63     This class creates a &lt;FORM&gt; tag.
64
65     @version $Id: Form.java,v 1.5 2003/04/27 09:21:50 rdonkin Exp $
66     @author <a HREF="mailto:snagy@servletapi.com">Stephan Nagy</a>
67     @author <a HREF="mailto:jon@clearink.com">Jon S. Stevens</a>
68 */

69 public class Form extends MultiPartElement implements Printable, FormEvents, MouseEvents, KeyEvents
70 {
71     public static final String JavaDoc GET = "GET";
72     public static final String JavaDoc get = "get";
73     public static final String JavaDoc POST = "POST";
74     public static final String JavaDoc post = "post";
75
76     public static final String JavaDoc ENC_DEFAULT = "application/x-www-form-urlencoded";
77     public static final String JavaDoc ENC_UPLOAD = "multipart/form-data";
78     
79     /**
80         Private initialization routine.
81     */

82     {
83         setElementType("form");
84         setEncType ( ENC_DEFAULT );
85         setAcceptCharset("UNKNOWN");
86     }
87
88     /**
89         Basic constructor. You need to set the attributes using the
90         set* methods.
91     */

92     public Form()
93     {
94     }
95
96     /**
97         Use the set* methods to set the values
98         of the attributes.
99
100         @param element set the value of &lt;FORM&gt;value&lt;/FORM&gt;
101     */

102     public Form(Element element)
103     {
104         addElement(element);
105     }
106
107     /**
108         Use the set* methods to set the values
109         of the attributes.
110
111         @param action set the value of ACTION=""
112     */

113     public Form(String JavaDoc action)
114     {
115         setAction(action);
116     }
117
118     /**
119         Use the set* methods to set the values
120         of the attributes.
121
122         @param element set the value of &lt;FORM&gt;value&lt;/FORM&gt;
123         @param action set the value of ACTION=""
124     */

125     public Form(String JavaDoc action, Element element)
126     {
127         addElement(element);
128         setAction(action);
129     }
130
131     /**
132         Use the set* methods to set the values
133         of the attributes.
134
135         @param action set the value of ACTION=""
136         @param method set the value of METHOD=""
137         @param element set the value of &lt;FORM&gt;value&lt;/FORM&gt;
138     */

139     public Form(String JavaDoc action, String JavaDoc method, Element element)
140     {
141         addElement(element);
142         setAction(action);
143         setMethod(method);
144     }
145
146     /**
147         Use the set* methods to set the values
148         of the attributes.
149
150         @param action set the value of ACTION=""
151         @param method set the value of METHOD=""
152     */

153     public Form(String JavaDoc action, String JavaDoc method)
154     {
155         setAction(action);
156         setMethod(method);
157     }
158
159     /**
160         Use the set* methods to set the values
161         of the attributes.
162
163         @param action set the value of ACTION=""
164         @param method set the value of METHOD=""
165         @param enctype set the value of ENCTYPE=""
166     */

167     public Form(String JavaDoc action, String JavaDoc method, String JavaDoc enctype)
168     {
169         setAction(action);
170         setMethod(method);
171         setEncType(enctype);
172     }
173
174     /**
175         Sets the ACTION="" attribute
176         @param action the ACTION="" attribute
177     */

178     public Form setAction(String JavaDoc action)
179     {
180         addAttribute("action",action);
181         return this;
182     }
183
184     /**
185         Sets the METHOD="" attribute
186         @param method the METHOD="" attribute
187     */

188     public Form setMethod(String JavaDoc method)
189     {
190         addAttribute("method",method);
191         return this;
192     }
193
194     /**
195         Sets the ENCTYPE="" attribute
196         @param enctype the ENCTYPE="" attribute
197     */

198     public Form setEncType(String JavaDoc enctype)
199     {
200         addAttribute("enctype",enctype);
201         return this;
202     }
203
204     /**
205         Sets the ACCEPT="" attribute
206         @param accept the ACCEPT="" attribute
207     */

208     public Form setAccept(String JavaDoc accept)
209     {
210         addAttribute("accept",accept);
211         return this;
212     }
213
214     /**
215         Sets the NAME="" attribute
216         @param name the NAME="" attribute
217     */

218     public Form setName(String JavaDoc name)
219     {
220         addAttribute("name",name);
221         return this;
222     }
223
224     /**
225         Sets the TARGET="" attribute
226         @param target the TARGET="" attribute
227     */

228     public Form setTarget(String JavaDoc target)
229     {
230         addAttribute("target",target);
231         return this;
232     }
233
234     /**
235         Sets the ACCEPT-CHARSET="" attribute
236         @param accept the ACCEPT-CHARSET="" attribute
237     */

238     public Form setAcceptCharset(String JavaDoc acceptcharset)
239     {
240         addAttribute("accept-charset",acceptcharset);
241         return this;
242     }
243
244     /**
245         Adds an Element to the element.
246         @param hashcode name of element for hash table
247         @param element Adds an Element to the element.
248      */

249     public Form addElement(String JavaDoc hashcode,Element element)
250     {
251         addElementToRegistry(hashcode,element);
252         return(this);
253     }
254
255     /**
256         Adds an Element to the element.
257         @param hashcode name of element for hash table
258         @param element Adds an Element to the element.
259      */

260     public Form addElement(String JavaDoc hashcode,String JavaDoc element)
261     {
262         addElementToRegistry(hashcode,element);
263         return(this);
264     }
265
266     /**
267         Adds an Element to the element.
268         @param element Adds an Element to the element.
269      */

270     public Form addElement(Element element)
271     {
272         addElementToRegistry(element);
273         return(this);
274     }
275
276     /**
277         Adds an Element to the element.
278         @param element Adds an Element to the element.
279      */

280     public Form addElement(String JavaDoc element)
281     {
282         addElementToRegistry(element);
283         return(this);
284     }
285     /**
286         Removes an Element from the element.
287         @param hashcode the name of the element to be removed.
288     */

289     public Form removeElement(String JavaDoc hashcode)
290     {
291         removeElementFromRegistry(hashcode);
292         return(this);
293     }
294
295     /**
296         The onsubmit event occurs when a form is submitted. It only applies to
297         the FORM element.
298         
299         @param The script
300     */

301     public void setOnSubmit(String JavaDoc script)
302     {
303         addAttribute ( "onSubmit", script );
304     }
305
306     /**
307         The onreset event occurs when a form is reset. It only applies to the
308         FORM element.
309         
310         @param The script
311     */

312     public void setOnReset(String JavaDoc script)
313     {
314         addAttribute ( "onReset", script );
315     }
316
317     /**
318         The onselect event occurs when a user selects some text in a text
319         field. This attribute may be used with the INPUT and TEXTAREA elements.
320         
321         @param The script
322     */

323     public void setOnSelect(String JavaDoc script)
324     {
325         addAttribute ( "onSelect", script );
326     }
327
328     /**
329         The onchange event occurs when a control loses the input focus and its
330         value has been modified since gaining focus. This attribute applies to
331         the following elements: INPUT, SELECT, and TEXTAREA.
332         
333         @param The script
334     */

335     public void setOnChange(String JavaDoc script)
336     {
337         addAttribute ( "onChange", script );
338     }
339
340     /**
341         The onclick event occurs when the pointing device button is clicked
342         over an element. This attribute may be used with most elements.
343         
344         @param The script
345     */

346     public void setOnClick(String JavaDoc script)
347     {
348         addAttribute ( "onClick", script );
349     }
350     /**
351         The ondblclick event occurs when the pointing device button is double
352         clicked over an element. This attribute may be used with most elements.
353
354         @param The script
355     */

356     public void setOnDblClick(String JavaDoc script)
357     {
358         addAttribute ( "onDblClick", script );
359     }
360     /**
361         The onmousedown event occurs when the pointing device button is pressed
362         over an element. This attribute may be used with most elements.
363
364         @param The script
365     */

366     public void setOnMouseDown(String JavaDoc script)
367     {
368         addAttribute ( "onMouseDown", script );
369     }
370     /**
371         The onmouseup event occurs when the pointing device button is released
372         over an element. This attribute may be used with most elements.
373
374         @param The script
375     */

376     public void setOnMouseUp(String JavaDoc script)
377     {
378         addAttribute ( "onMouseUp", script );
379     }
380     /**
381         The onmouseover event occurs when the pointing device is moved onto an
382         element. This attribute may be used with most elements.
383
384         @param The script
385     */

386     public void setOnMouseOver(String JavaDoc script)
387     {
388         addAttribute ( "onMouseOver", script );
389     }
390     /**
391         The onmousemove event occurs when the pointing device is moved while it
392         is over an element. This attribute may be used with most elements.
393
394         @param The script
395     */

396     public void setOnMouseMove(String JavaDoc script)
397     {
398         addAttribute ( "onMouseMove", script );
399     }
400     /**
401         The onmouseout event occurs when the pointing device is moved away from
402         an element. This attribute may be used with most elements.
403
404         @param The script
405     */

406     public void setOnMouseOut(String JavaDoc script)
407     {
408         addAttribute ( "onMouseOut", script );
409     }
410
411     /**
412         The onkeypress event occurs when a key is pressed and released over an
413         element. This attribute may be used with most elements.
414         
415         @param The script
416     */

417     public void setOnKeyPress(String JavaDoc script)
418     {
419         addAttribute ( "onKeyPress", script );
420     }
421
422     /**
423         The onkeydown event occurs when a key is pressed down over an element.
424         This attribute may be used with most elements.
425         
426         @param The script
427     */

428     public void setOnKeyDown(String JavaDoc script)
429     {
430         addAttribute ( "onKeyDown", script );
431     }
432
433     /**
434         The onkeyup event occurs when a key is released over an element. This
435         attribute may be used with most elements.
436         
437         @param The script
438     */

439     public void setOnKeyUp(String JavaDoc script)
440     {
441         addAttribute ( "onKeyUp", script );
442     }
443 }
444
Popular Tags