KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ecs > xhtml > 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.xhtml;
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.2 2003/04/27 09:40:36 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     @author <a HREF="mailto:bojan@binarix.com">Bojan Smojver</a>
69 */

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

239     public form setAcceptCharset(String JavaDoc acceptcharset)
240     {
241         addAttribute("accept-charset",acceptcharset);
242         return this;
243     }
244
245     /**
246         Sets the lang="" and xml:lang="" attributes
247         @param lang the lang="" and xml:lang="" attributes
248     */

249     public Element setLang(String JavaDoc lang)
250     {
251         addAttribute("lang",lang);
252         addAttribute("xml:lang",lang);
253         return this;
254     }
255
256     /**
257         Adds an Element to the element.
258         @param hashcode name of element for hash table
259         @param element Adds an Element to the element.
260      */

261     public form addElement(String JavaDoc hashcode,Element element)
262     {
263         addElementToRegistry(hashcode,element);
264         return(this);
265     }
266
267     /**
268         Adds an Element to the element.
269         @param hashcode name of element for hash table
270         @param element Adds an Element to the element.
271      */

272     public form addElement(String JavaDoc hashcode,String JavaDoc element)
273     {
274         addElementToRegistry(hashcode,element);
275         return(this);
276     }
277
278     /**
279         Adds an Element to the element.
280         @param element Adds an Element to the element.
281      */

282     public form addElement(Element element)
283     {
284         addElementToRegistry(element);
285         return(this);
286     }
287
288     /**
289         Adds an Element to the element.
290         @param element Adds an Element to the element.
291      */

292     public form addElement(String JavaDoc element)
293     {
294         addElementToRegistry(element);
295         return(this);
296     }
297     /**
298         Removes an Element from the element.
299         @param hashcode the name of the element to be removed.
300     */

301     public form removeElement(String JavaDoc hashcode)
302     {
303         removeElementFromRegistry(hashcode);
304         return(this);
305     }
306
307     /**
308         The onsubmit event occurs when a form is submitted. It only applies to
309         the FORM element.
310         
311         @param The script
312     */

313     public void setOnSubmit(String JavaDoc script)
314     {
315         addAttribute ( "onsubmit", script );
316     }
317
318     /**
319         The onreset event occurs when a form is reset. It only applies to the
320         FORM element.
321         
322         @param The script
323     */

324     public void setOnReset(String JavaDoc script)
325     {
326         addAttribute ( "onreset", script );
327     }
328
329     /**
330         The onselect event occurs when a user selects some text in a text
331         field. This attribute may be used with the input and textarea elements.
332         
333         @param The script
334     */

335     public void setOnSelect(String JavaDoc script)
336     {
337         addAttribute ( "onselect", script );
338     }
339
340     /**
341         The onchange event occurs when a control loses the input focus and its
342         value has been modified since gaining focus. This attribute applies to
343         the following elements: input, select, and textarea.
344         
345         @param The script
346     */

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

358     public void setOnClick(String JavaDoc script)
359     {
360         addAttribute ( "onclick", script );
361     }
362     /**
363         The ondblclick event occurs when the pointing device button is double
364         clicked over an element. This attribute may be used with most elements.
365
366         @param The script
367     */

368     public void setOnDblClick(String JavaDoc script)
369     {
370         addAttribute ( "ondblclick", script );
371     }
372     /**
373         The onmousedown event occurs when the pointing device button is pressed
374         over an element. This attribute may be used with most elements.
375
376         @param The script
377     */

378     public void setOnMouseDown(String JavaDoc script)
379     {
380         addAttribute ( "onmousedown", script );
381     }
382     /**
383         The onmouseup event occurs when the pointing device button is released
384         over an element. This attribute may be used with most elements.
385
386         @param The script
387     */

388     public void setOnMouseUp(String JavaDoc script)
389     {
390         addAttribute ( "onmouseup", script );
391     }
392     /**
393         The onmouseover event occurs when the pointing device is moved onto an
394         element. This attribute may be used with most elements.
395
396         @param The script
397     */

398     public void setOnMouseOver(String JavaDoc script)
399     {
400         addAttribute ( "onmouseover", script );
401     }
402     /**
403         The onmousemove event occurs when the pointing device is moved while it
404         is over an element. This attribute may be used with most elements.
405
406         @param The script
407     */

408     public void setOnMouseMove(String JavaDoc script)
409     {
410         addAttribute ( "onmousemove", script );
411     }
412     /**
413         The onmouseout event occurs when the pointing device is moved away from
414         an element. This attribute may be used with most elements.
415
416         @param The script
417     */

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

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

440     public void setOnKeyDown(String JavaDoc script)
441     {
442         addAttribute ( "onkeydown", script );
443     }
444
445     /**
446         The onkeyup event occurs when a key is released over an element. This
447         attribute may be used with most elements.
448         
449         @param The script
450     */

451     public void setOnKeyUp(String JavaDoc script)
452     {
453         addAttribute ( "onkeyup", script );
454     }
455 }
456
Popular Tags