KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > au > id > jericho > lib > html > FormControlType


1 // Jericho HTML Parser - Java based library for analysing and manipulating HTML
2
// Version 2.2
3
// Copyright (C) 2006 Martin Jericho
4
// http://sourceforge.net/projects/jerichohtml/
5
//
6
// This library is free software; you can redistribute it and/or
7
// modify it under the terms of the GNU Lesser General Public
8
// License as published by the Free Software Foundation; either
9
// version 2.1 of the License, or (at your option) any later version.
10
// http://www.gnu.org/copyleft/lesser.html
11
//
12
// This library is distributed in the hope that it will be useful,
13
// but WITHOUT ANY WARRANTY; without even the implied warranty of
14
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
// Lesser General Public License for more details.
16
//
17
// You should have received a copy of the GNU Lesser General Public
18
// License along with this library; if not, write to the Free Software
19
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20

21 package au.id.jericho.lib.html;
22
23 import java.util.*;
24
25 /**
26  * Represents the <a target="_blank" HREF="http://www.w3.org/TR/html401/interact/forms.html#h-17.2.1">control type</a>
27  * of a {@link FormControl}.
28  * <p>
29  * Use the {@link FormControl#getFormControlType()} method to determine the type of a form control.
30  * <p>
31  * The following table shows the relationship between the HTML 4.01 specification control type descriptions,
32  * their associated {@link Element} names and attributes, and the <code>FormControlType</code> constants defined in this class:
33  * <table class="bordered" style="margin: 15px" cellspacing="0">
34  * <tr>
35  * <th><a target="_blank" HREF="http://www.w3.org/TR/html401/interact/forms.html#h-17.2.1">Description</a>
36  * <th>{@linkplain Element#getName() Element Name}
37  * <th>Distinguishing Attribute
38  * <th><code>FormControlType</code>
39  * <tr>
40  * <td rowspan="3"><a name="submit-button" target="_blank" HREF="http://www.w3.org/TR/html401/interact/forms.html#buttons">buttons</a> - <a target="_blank" HREF="http://www.w3.org/TR/html401/interact/forms.html#submit-button">submit button</a>
41  * <td><code><a target="_blank" HREF="http://www.w3.org/TR/html401/interact/forms.html#edef-BUTTON">BUTTON</a></code>
42  * <td><code><a target="_blank" HREF="http://www.w3.org/TR/html401/interact/forms.html#adef-type-BUTTON">type</a>="submit"</code>
43  * <td>{@link #BUTTON}
44  * <tr>
45  * <td rowspan="2"><code><a target="_blank" HREF="http://www.w3.org/TR/html401/interact/forms.html#edef-INPUT">INPUT</a></code>
46  * <td><code><a target="_blank" HREF="http://www.w3.org/TR/html401/interact/forms.html#adef-type-INPUT">type</a>="submit"</code>
47  * <td>{@link #SUBMIT}
48  * <tr>
49  * <td><code><a target="_blank" HREF="http://www.w3.org/TR/html401/interact/forms.html#adef-type-INPUT">type</a>="<a target="_blank" HREF="http://www.w3.org/TR/html401/interact/forms.html#input-control-types">image</a>"</code>
50  * <td>{@link #IMAGE}
51  * <tr>
52  * <td><a name="reset-button-control" target="_blank" HREF="http://www.w3.org/TR/html401/interact/forms.html#buttons">buttons</a> - <a target="_blank" HREF="http://www.w3.org/TR/html401/interact/forms.html#reset-button">reset button</a>
53  * <td><code><a target="_blank" HREF="http://www.w3.org/TR/html401/interact/forms.html#edef-BUTTON">BUTTON</a></code>,
54  * <code><a target="_blank" HREF="http://www.w3.org/TR/html401/interact/forms.html#edef-INPUT">INPUT</a></code>
55  * <td><code><a target="_blank" HREF="http://www.w3.org/TR/html401/interact/forms.html#adef-type-BUTTON">type</a>="reset"</code>
56  * <td>-
57  * <tr>
58  * <td><a name="push-button-control" target="_blank" HREF="http://www.w3.org/TR/html401/interact/forms.html#buttons">buttons</a> - <a target="_blank" HREF="http://www.w3.org/TR/html401/interact/forms.html#push-button">push button</a>
59  * <td><code><a target="_blank" HREF="http://www.w3.org/TR/html401/interact/forms.html#edef-BUTTON">BUTTON</a></code>,
60  * <code><a target="_blank" HREF="http://www.w3.org/TR/html401/interact/forms.html#edef-INPUT">INPUT</a></code>
61  * <td><code><a target="_blank" HREF="http://www.w3.org/TR/html401/interact/forms.html#adef-type-BUTTON">type</a>="button"</code>
62  * <td>-
63  * <tr>
64  * <td><a name="checkbox-control" target="_blank" HREF="http://www.w3.org/TR/html401/interact/forms.html#checkbox">checkboxes</a>
65  * <td><code><a target="_blank" HREF="http://www.w3.org/TR/html401/interact/forms.html#edef-INPUT">INPUT</a></code>
66  * <td><code><a target="_blank" HREF="http://www.w3.org/TR/html401/interact/forms.html#adef-type-INPUT">type</a>="checkbox"</code>
67  * <td>{@link #CHECKBOX}
68  * <tr>
69  * <td><a name="radio-button-control" target="_blank" HREF="http://www.w3.org/TR/html401/interact/forms.html#radio">radio buttons</a>
70  * <td><code><a target="_blank" HREF="http://www.w3.org/TR/html401/interact/forms.html#edef-INPUT">INPUT</a></code>
71  * <td><code><a target="_blank" HREF="http://www.w3.org/TR/html401/interact/forms.html#adef-type-INPUT">type</a>="radio"</code>
72  * <td>{@link #RADIO}
73  * <tr>
74  * <td rowspan="2"><a name="menu-control" target="_blank" HREF="http://www.w3.org/TR/html401/interact/forms.html#menu">menus</a>
75  * <td rowspan="2"><code><a target="_blank" HREF="http://www.w3.org/TR/html401/interact/forms.html#edef-SELECT">SELECT</a></code>
76  * <td><code><a target="_blank" HREF="http://www.w3.org/TR/html401/interact/forms.html#adef-multiple">multiple</a></code>
77  * <td>{@link #SELECT_MULTIPLE}
78  * <tr>
79  * <td>absence of <code><a target="_blank" HREF="http://www.w3.org/TR/html401/interact/forms.html#adef-multiple">multiple</a></code>
80  * <td>{@link #SELECT_SINGLE}
81  * <tr>
82  * <td rowspan="3"><a name="text-input-control" target="_blank" HREF="http://www.w3.org/TR/html401/interact/forms.html#text-input">text input</a>
83  * <td rowspan="2"><code><a target="_blank" HREF="http://www.w3.org/TR/html401/interact/forms.html#edef-INPUT">INPUT</a></code>
84  * <td><code><a target="_blank" HREF="http://www.w3.org/TR/html401/interact/forms.html#adef-type-INPUT">type</a>="<a target="_blank" HREF="http://www.w3.org/TR/html401/interact/forms.html#idx-text_input_control-1">text</a>"</code>
85  * <td>{@link #TEXT}
86  * <tr>
87  * <td><code><a target="_blank" HREF="http://www.w3.org/TR/html401/interact/forms.html#adef-type-INPUT">type</a>="<a target="_blank" HREF="http://www.w3.org/TR/html401/interact/forms.html#idx-password_input_control">password</a>"</code>
88  * <td>{@link #PASSWORD}
89  * <tr>
90  * <td><code><a target="_blank" HREF="http://www.w3.org/TR/html401/interact/forms.html#edef-TEXTAREA">TEXTAREA</a></code>
91  * <td>-
92  * <td>{@link #TEXTAREA}
93  * <tr>
94  * <td><a name="file-select-control" target="_blank" HREF="http://www.w3.org/TR/html401/interact/forms.html#file-select">file select</a>
95  * <td><code><a target="_blank" HREF="http://www.w3.org/TR/html401/interact/forms.html#edef-INPUT">INPUT</a></code>
96  * <td><code><a target="_blank" HREF="http://www.w3.org/TR/html401/interact/forms.html#adef-type-INPUT">type</a>="file"</code>
97  * <td>{@link #FILE}
98  * <tr>
99  * <td><a name="hidden-control" target="_blank" HREF="http://www.w3.org/TR/html401/interact/forms.html#hidden-control">hidden controls</a>
100  * <td><code><a target="_blank" HREF="http://www.w3.org/TR/html401/interact/forms.html#edef-INPUT">INPUT</a></code>
101  * <td><code><a target="_blank" HREF="http://www.w3.org/TR/html401/interact/forms.html#adef-type-INPUT">type</a>="hidden"</code>
102  * <td>{@link #HIDDEN}
103  * <tr>
104  * <td><a name="object-control" target="_blank" HREF="http://www.w3.org/TR/html401/interact/forms.html#object-control">object controls</a>
105  * <td><code><a target="_blank" HREF="http://www.w3.org/TR/html401/struct/objects.html#edef-OBJECT">OBJECT</a></code>
106  * <td><code>-
107  * <td>-
108  * </table>
109  * <a target="_blank" HREF="http://www.w3.org/TR/html401/interact/forms.html#reset-button-control">Reset buttons</a> and
110  * <a target="_blank" HREF="http://www.w3.org/TR/html401/interact/forms.html#push-button-control">push buttons</a>
111  * have no associated <code>FormControlType</code> because they do not contribute to the
112  * <a target="_blank" HREF="http://www.w3.org/TR/html401/interact/forms.html#form-data-set">form data set</a>
113  * of a <a target="_blank" HREF="http://www.w3.org/TR/html401/interact/forms.html#submit-format">submitted</a> form,
114  * and so have no relevance to the methods provided in the {@link FormControl} and associated classes.
115  * If required they can be found and manipulated as normal {@linkplain Element elements}.
116  * <p>
117  * <a target="_blank" HREF="http://www.w3.org/TR/html401/interact/forms.html#object-control">Object controls</a>
118  * have no associated <code>FormControlType</code> because any data they might contribute to the
119  * <a target="_blank" HREF="http://www.w3.org/TR/html401/interact/forms.html#form-data-set">form data set</a>
120  * is entirely dependent on the
121  * <a target="_blank" HREF="http://www.w3.org/TR/html401/struct/objects.html#adef-classid">class</a> of object,
122  * the interpretation of which is is beyond the scope of this library.
123  * <p>
124  * This library does not consider the
125  * <code><a target="_blank" HREF="http://www.w3.org/TR/html401/interact/forms.html#edef-OPTION">OPTION</a></code>
126  * elements found within
127  * <code><a target="_blank" HREF="http://www.w3.org/TR/html401/interact/forms.html#edef-SELECT">SELECT</a></code>
128  * elements to be controls themselves, despite them being referred to as such in some
129  * <a target="_blank" HREF="http://www.w3.org/TR/html401/interact/forms.html#adef-value-OPTION">parts</a>
130  * of the HTML 4.01 specification.
131  * Hence the absence of an <code>OPTION</code> control type.
132  *
133  * @see FormControl
134  * @see FormField
135  */

136 public final class FormControlType {
137     private String JavaDoc formControlTypeId;
138     private String JavaDoc elementName;
139     private boolean hasPredefinedValue;
140     private boolean submit;
141
142     private static final HashMap ID_MAP=new HashMap(16,1.0F); // 12 types in total
143
private static final HashMap INPUT_ELEMENT_TYPE_MAP=new HashMap(11,1.0F); // 8 input element types in total
144

145     /**
146      * The form control type given to a <a HREF="#submit-button">submit button</a> control implemented using a
147      * <code><a target="_blank" HREF="http://www.w3.org/TR/html401/interact/forms.html#edef-BUTTON">BUTTON</a></code> element.
148      * <p>
149      * <dl>
150      * <dt>Example:</dt>
151      * <dd><code>&lt;button type="submit" name="FieldName" value="PredefinedValue"&gt;Send&lt;/button&gt;</code>
152      * <dt>Properties:</dt>
153      * <dd>
154      * <code>{@link #getElementName()} = {@link Tag#BUTTON}</code><br />
155      * <code>{@link #hasPredefinedValue()} = true</code><br />
156      * <code>{@link #isSubmit()} = true</code><br />
157      * </dl>
158      */

159     public static final FormControlType BUTTON=new FormControlType("button",Tag.BUTTON,true,true).register();
160
161     /**
162      * The form control type given to a <a HREF="#checkbox-control">checkbox</a> control.
163      * <p>
164      * <dl>
165      * <dt>Example:</dt>
166      * <dd><code>&lt;input type="checkbox" name="FieldName" value="PredefinedValue" /&gt;</code>
167      * <dt>Properties:</dt>
168      * <dd>
169      * <code>{@link #getElementName()} = {@link Tag#INPUT}</code><br />
170      * <code>{@link #hasPredefinedValue()} = true</code><br />
171      * <code>{@link #isSubmit()} = false</code><br />
172      * </dl>
173      */

174     public static final FormControlType CHECKBOX=new FormControlType("checkbox",Tag.INPUT,true,false).register();
175
176     /**
177      * The form control type given to a <a HREF="#file-select-control">file select</a> control.
178      * <p>
179      * This library considers the <a HREF="FormControl.html#SubmissionValue">submission value</a> of this type of control
180      * to be consist of only the selected file name, regardless of whether the file content would normally be included in the
181      * <a target="_blank" HREF="http://www.w3.org/TR/html401/interact/forms.html#form-data-set">form data set</a>.
182      * <p>
183      * To determine manually whether the file content is included in the form data set, the
184      * <code><a target="_blank" HREF="http://www.w3.org/TR/html401/interact/forms.html#adef-enctype">enctype</a></code>
185      * attribute of the control's associated <a target="_blank" HREF="http://www.w3.org/TR/html401/interact/forms.html#edef-FORM">FORM</a>
186      * element can be examined.
187      * Although the exact behaviour is not defined in the HTML 4.01 specification, the convention is that the content
188      * is not included unless an <code>enctype</code> value of
189      * "<code><a target="_blank" HREF="http://www.w3.org/TR/html401/interact/forms.html#didx-multipartform-data">multipart/form-data</a></code>"
190      * is specified.
191      * <p>
192      * For more information see the
193      * <a target="_blank" HREF="http://www.w3.org/TR/html401/interact/forms.html#h-17.13.4">HTML 4.01 specification section 17.13.4 - Form content types</a>.
194      * <p>
195      * <dl>
196      * <dt>Example:</dt>
197      * <dd><code>&lt;input type="file" name="FieldName" value="DefaultFileName" /&gt;</code>
198      * <dt>Properties:</dt>
199      * <dd>
200      * <code>{@link #getElementName()} = {@link Tag#INPUT}</code><br />
201      * <code>{@link #hasPredefinedValue()} = false</code><br />
202      * <code>{@link #isSubmit()} = false</code><br />
203      * </dl>
204      */

205     public static final FormControlType FILE=new FormControlType("file",Tag.INPUT,false,false).register();
206
207     /**
208      * The form control type given to a <a HREF="#hidden-control">hidden</a> control.
209      * <p>
210      * <dl>
211      * <dt>Example:</dt>
212      * <dd><code>&lt;input type="hidden" name="FieldName" value="DefaultValue" /&gt;</code>
213      * <dt>Properties:</dt>
214      * <dd>
215      * <code>{@link #getElementName()} = {@link Tag#INPUT}</code><br />
216      * <code>{@link #hasPredefinedValue()} = false</code><br />
217      * <code>{@link #isSubmit()} = false</code><br />
218      * </dl>
219      * Note that {@link #hasPredefinedValue()} returns <code>false</code> for this control type
220      * because the value of hidden fields is usually set via server or client side scripting.
221      */

222     public static final FormControlType HIDDEN=new FormControlType("hidden",Tag.INPUT,false,false).register();
223
224     /**
225      * The form control type given to a <a HREF="#submit-button">submit button</a> control implemented using an
226      * <code><a target="_blank" HREF="http://www.w3.org/TR/html401/interact/forms.html#edef-INPUT">INPUT</a></code> element with attribute
227      * <code><a target="_blank" HREF="http://www.w3.org/TR/html401/interact/forms.html#adef-type-INPUT">type</a>="<a target="_blank" HREF="http://www.w3.org/TR/html401/interact/forms.html#input-control-types">image</a>"</code>.
228      * <p>
229      * See the description under the heading "image" in the
230      * <a target="_blank" HREF="http://www.w3.org/TR/html401/interact/forms.html#h-17.4.1">HTML 4.01 specification section 17.4.1 - Form control types created with INPUT</a>.
231      * <p>
232      * When a {@linkplain FormControl form control} of type <code>IMAGE</code> is present in the form used to
233      * {@linkplain FormFields#FormFields(Collection) construct} a {@link FormFields} instance, three separate
234      * {@link FormField} objects are created for the one control.
235      * One has the {@linkplain FormField#getName() name} specified in the
236      * <code><a target="_blank" HREF="http://www.w3.org/TR/html401/interact/forms.html#adef-name-INPUT">name</a></code>
237      * attribute of the <code>INPUT</code> element, and the other two have this name with the suffixes
238      * "<code>.x</code>" and "<code>.y</code>" appended to them to represent the additional
239      * <a target="_blank" HREF="http://www.w3.org/TR/html401/interact/forms.html#idx-coordinates">click coordinates</a>
240      * submitted by this control when activated using a pointing device.
241      * <p>
242      * This type of control is also mentioned in the
243      * <a target="_blank" HREF="http://www.w3.org/TR/html401/struct/objects.html#h-13.6.2">HTML 4.01 specification section 13.6.2 - Server-side image maps</a>.
244      * <p>
245      * <dl>
246      * <dt>Example:</dt>
247      * <dd><code>&lt;input type="image" name="FieldName" SRC="ImageURL" value="PredefinedValue" /&gt;</code>
248      * <dt>Properties:</dt>
249      * <dd>
250      * <code>{@link #getElementName()} = {@link Tag#INPUT}</code><br />
251      * <code>{@link #hasPredefinedValue()} = true</code><br />
252      * <code>{@link #isSubmit()} = true</code><br />
253      * </dl>
254      */

255     public static final FormControlType IMAGE=new FormControlType("image",Tag.INPUT,true,true).register();
256
257     /**
258      * The form control type given to a <a HREF="#text-input-control">text input</a> control implemented using an
259      * <code><a target="_blank" HREF="http://www.w3.org/TR/html401/interact/forms.html#edef-INPUT">INPUT</a></code> element with attribute
260      * <code><a target="_blank" HREF="http://www.w3.org/TR/html401/interact/forms.html#adef-type-INPUT">type</a>="<a target="_blank" HREF="http://www.w3.org/TR/html401/interact/forms.html#idx-password_input_control">password</a>"</code>.
261      * <p>
262      * <dl>
263      * <dt>Example:</dt>
264      * <dd><code>&lt;input type="password" name="FieldName" value="DefaultValue" /&gt;</code>
265      * <dt>Properties:</dt>
266      * <dd>
267      * <code>{@link #getElementName()} = {@link Tag#INPUT}</code><br />
268      * <code>{@link #hasPredefinedValue()} = false</code><br />
269      * <code>{@link #isSubmit()} = false</code><br />
270      * </dl>
271      */

272     public static final FormControlType PASSWORD=new FormControlType("password",Tag.INPUT,false,false).register();
273
274     /**
275      * The form control type given to a <a HREF="#radio-button-control">radio button</a> control.
276      * <p>
277      * <dl>
278      * <dt>Example:</dt>
279      * <dd><code>&lt;input type="radio" name="FieldName" value="PredefinedValue" /&gt;</code>
280      * <dt>Properties:</dt>
281      * <dd>
282      * <code>{@link #getElementName()} = {@link Tag#INPUT}</code><br />
283      * <code>{@link #hasPredefinedValue()} = true</code><br />
284      * <code>{@link #isSubmit()} = false</code><br />
285      * </dl>
286      */

287     public static final FormControlType RADIO=new FormControlType("radio",Tag.INPUT,true,false).register();
288
289     /**
290      * The form control type given to a <a HREF="#menu-control">menu</a> control implemented using a
291      * <code><a target="_blank" HREF="http://www.w3.org/TR/html401/interact/forms.html#edef-SELECT">SELECT</a></code> element containing
292      * the attribute "<code><a target="_blank" HREF="http://www.w3.org/TR/html401/interact/forms.html#adef-multiple">multiple</a></code>".
293      * <p>
294      * <code>SELECT</code> elements that do not contain the attribute "<code>multiple</code>" are represented by the
295      * {@link #SELECT_SINGLE} form control type.
296      * <p>
297      * This is the only control type that can have multiple
298      * <a HREF="FormControl.html#SubmissionValue">submission values</a> within the one control.
299      * Contrast this with {@link #CHECKBOX} controls, which require multiple separate controls with the same
300      * {@linkplain FormControl#getName() name} in order to contribute multiple submission values.
301      * <p>
302      * The individual {@link Tag#OPTION OPTION} elements contained within a {@linkplain FormControl form control} of this type can be
303      * obtained using the {@link FormControl#getOptionElementIterator()} method.
304      * <p>
305      * The most efficient way to test whether a form control type is either <code>SELECT_MULTIPLE</code> or <code>SELECT_SINGLE</code>
306      * is to test for {@link #getElementName()}<code>==</code>{@link Tag#SELECT}.
307      * <p>
308      * <dl>
309      * <dt>Example:</dt>
310      * <dd>
311      * <code>
312      * &lt;select name="FieldName" multiple&gt;<br />
313      * &nbsp; &lt;option value="PredefinedValue1" selected&gt;Display Text1&lt;/option&gt;<br />
314      * &nbsp; &lt;option value="PredefinedValue2"&gt;Display Text2&lt;/option&gt;<br />
315      * &lt;/select&gt;
316      * </code>
317      * <dt>Properties:</dt>
318      * <dd>
319      * <code>{@link #getElementName()} = {@link Tag#SELECT}</code><br />
320      * <code>{@link #hasPredefinedValue()} = true</code><br />
321      * <code>{@link #isSubmit()} = false</code><br />
322      * </dl>
323      */

324     public static final FormControlType SELECT_MULTIPLE=new FormControlType("select_multiple",Tag.SELECT,true,false).register();
325
326     /**
327      * The form control type given to a <a HREF="#menu-control">menu</a> control implemented using a
328      * <code><a target="_blank" HREF="http://www.w3.org/TR/html401/interact/forms.html#edef-SELECT">SELECT</a></code> element that does
329      * <b>not</b> contain the attribute "<code><a target="_blank" HREF="http://www.w3.org/TR/html401/interact/forms.html#adef-multiple">multiple</a></code>".
330      * <p>
331      * <code>SELECT</code> elements that do contain the attribute "<code>multiple</code>" are represented by the
332      * {@link #SELECT_MULTIPLE} form control type.
333      * <p>
334      * The individual {@link Tag#OPTION OPTION} elements contained within a {@linkplain FormControl form control} of this type can be
335      * obtained using the {@link FormControl#getOptionElementIterator()} method.
336      * <p>
337      * The most efficient way to test whether a form control type is either <code>SELECT_MULTIPLE</code> or <code>SELECT_SINGLE</code>
338      * is to test for {@link #getElementName()}<code>==</code>{@link Tag#SELECT}.
339      * <p>
340      * <dl>
341      * <dt>Example:</dt>
342      * <dd>
343      * <code>
344      * &lt;select name="FieldName"&gt;<br />
345      * &nbsp; &lt;option value="PredefinedValue1" selected&gt;Display Text1&lt;/option&gt;<br />
346      * &nbsp; &lt;option value="PredefinedValue2"&gt;Display Text2&lt;/option&gt;<br />
347      * &lt;/select&gt;
348      * </code>
349      * <dt>Properties:</dt>
350      * <dd>
351      * <code>{@link #getElementName()} = {@link Tag#SELECT}</code><br />
352      * <code>{@link #hasPredefinedValue()} = true</code><br />
353      * <code>{@link #isSubmit()} = false</code><br />
354      * </dl>
355      */

356     public static final FormControlType SELECT_SINGLE=new FormControlType("select_single",Tag.SELECT,true,false).register();
357
358     /**
359      * The form control type given to a <a HREF="#submit-button">submit button</a> control implemented using an
360      * <code><a target="_blank" HREF="http://www.w3.org/TR/html401/interact/forms.html#edef-INPUT">INPUT</a></code> element with attribute
361      * <code><a target="_blank" HREF="http://www.w3.org/TR/html401/interact/forms.html#adef-type-INPUT">type</a>="submit"</code>.
362      * <p>
363      * <dl>
364      * <dt>Example:</dt>
365      * <dd><code>&lt;input type="submit" name="FieldName" value="PredefinedValue" /&gt;</code>
366      * <dt>Properties:</dt>
367      * <dd>
368      * <code>{@link #getElementName()} = {@link Tag#INPUT}</code><br />
369      * <code>{@link #hasPredefinedValue()} = true</code><br />
370      * <code>{@link #isSubmit()} = true</code><br />
371      * </dl>
372      */

373     public static final FormControlType SUBMIT=new FormControlType("submit",Tag.INPUT,true,true).register();
374
375     /**
376      * The form control type given to a <a HREF="#text-input-control">text input</a> control implemented using an
377      * <code><a target="_blank" HREF="http://www.w3.org/TR/html401/interact/forms.html#edef-INPUT">INPUT</a></code> element with attribute
378      * <code><a target="_blank" HREF="http://www.w3.org/TR/html401/interact/forms.html#adef-type-INPUT">type</a>="text"</code>.
379      * <p>
380      * <dl>
381      * <dt>Example:</dt>
382      * <dd><code>&lt;input type="text" name="FieldName" value="DefaultValue" /&gt;</code>
383      * <dt>Properties:</dt>
384      * <dd>
385      * <code>{@link #getElementName()} = {@link Tag#INPUT}</code><br />
386      * <code>{@link #hasPredefinedValue()} = false</code><br />
387      * <code>{@link #isSubmit()} = false</code><br />
388      * </dl>
389      */

390     public static final FormControlType TEXT=new FormControlType("text",Tag.INPUT,false,false).register();
391
392     /**
393      * The form control type given to a <a HREF="#text-input-control">text input</a> control implemented using a
394      * <code><a target="_blank" HREF="http://www.w3.org/TR/html401/interact/forms.html#edef-TEXTAREA">TEXTAREA</a></code> element.
395      * <p>
396      * <dl>
397      * <dt>Example:</dt>
398      * <dd><code>&lt;textarea name="FieldName"&gt;Default Value&lt;/textarea&gt;</code>
399      * <dt>Properties:</dt>
400      * <dd>
401      * <code>{@link #getElementName()} = {@link Tag#TEXTAREA}</code><br />
402      * <code>{@link #hasPredefinedValue()} = false</code><br />
403      * <code>{@link #isSubmit()} = false</code><br />
404      * </dl>
405      */

406     public static final FormControlType TEXTAREA=new FormControlType("textarea",Tag.TEXTAREA,false,false).register();
407
408     private FormControlType(final String JavaDoc formControlTypeId, final String JavaDoc elementName, final boolean hasPredefinedValue, final boolean submit) {
409         this.formControlTypeId=formControlTypeId;
410         this.elementName=elementName;
411         this.hasPredefinedValue=hasPredefinedValue;
412         this.submit=submit;
413     }
414
415     private FormControlType register() {
416         ID_MAP.put(formControlTypeId,this);
417         if (elementName==Tag.INPUT) INPUT_ELEMENT_TYPE_MAP.put(formControlTypeId,this);
418         return this;
419     }
420
421     /**
422      * Returns the {@linkplain Element#getName() name} of the {@link Element} that constitues this form control type.
423      * @return the {@linkplain Element#getName() name} of the {@link Element} that constitues this form control type.
424      */

425     public String JavaDoc getElementName() {
426         return elementName;
427     }
428
429     /**
430      * Indicates whether any <a target="_blank" HREF="http://www.w3.org/TR/html401/interact/forms.html#current-value">value</a>
431      * submitted by this type of control is predefined in the HTML and typically not modified by the user or server/client scripts.
432      * <p>
433      * The word "typically" is used because the use of client side scripts can cause
434      * <a target="_blank" HREF="http://www.w3.org/TR/html401/interact/forms.html#h-17.2.1">control types</a>
435      * which normally have predefined values to be set by the user, which is a condition which is beyond
436      * the scope of this library to test for.
437      * <p>
438      * The predefined value is defined by the control's <a target="_blank" HREF="http://www.w3.org/TR/html401/interact/forms.html#initial-value">initial value</a>.
439      * <p>
440      * A return value of <code>true</code> signifies that a form control of this type is a
441      * <a HREF="FormControl.html#PredefinedValueControl">predefined value control</a>.
442      * <p>
443      * A return value of <code>false</code> signifies that a form control of this type is a
444      * <a HREF="FormControl.html#UserValueControl">user value control</a>.
445      * <p>
446      * Note that the {@link #HIDDEN} type returns <code>false</code> for this method because the value of hidden fields is usually set via server or client side scripting.
447      *
448      * @return <code>true</code> if any <a target="_blank" HREF="http://www.w3.org/TR/html401/interact/forms.html#current-value">value</a> submitted by this type of control is predefined in the HTML and typically not modified by the user or server/client scripts, otherwise <code>false</code>.
449      */

450     public boolean hasPredefinedValue() {
451         return hasPredefinedValue;
452     }
453
454     /**
455      * Indicates whether this control type causes the form to be <a target="_blank" HREF="http://www.w3.org/TR/html401/interact/forms.html#submit-format">submitted</a>.
456      * <p>
457      * Returns <code>true</code> only for the {@link #SUBMIT}, {@link #BUTTON}, and {@link #IMAGE} instances.
458      *
459      * @return <code>true</code> if this control type causes the form to be <a target="_blank" HREF="http://www.w3.org/TR/html401/interact/forms.html#submit-format">submitted</a>, otherwise <code>false</code>.
460      */

461     public boolean isSubmit() {
462         return submit;
463     }
464
465     /**
466      * Returns the {@linkplain Element#getName() name} of the {@link Element} that constitues this form control type.
467      * <p>
468      * This method has been deprecated as of version 2.0 and replaced with the exactly equivalent
469      * {@link #getElementName()} method for aesthetical reasons.
470      *
471      * @return the {@linkplain Element#getName() name} of the {@link Element} that constitues this form control type.
472      * @deprecated Use {@link #getElementName() getElementName()} instead.
473      */

474     public String JavaDoc getTagName() {
475         return elementName;
476     }
477
478     /**
479      * Indicates whether any <a target="_blank" HREF="http://www.w3.org/TR/html401/interact/forms.html#current-value">value</a>
480      * submitted by this type of control is predefined in the HTML and typically not modified by the user or server/client scripts.
481      * <p>
482      * This method has been deprecated as of version 2.0 and replaced with the exactly equivalent
483      * {@link #hasPredefinedValue()} method for aesthetical reasons.
484      *
485      * @return <code>true</code> if any <a target="_blank" HREF="http://www.w3.org/TR/html401/interact/forms.html#current-value">value</a> submitted by this type of control is predefined in the HTML and typically not modified by the user or server/client scripts, otherwise <code>false</code>.
486      * @deprecated Use {@link #hasPredefinedValue() hasPredefinedValue()} instead.
487      */

488     public boolean isPredefinedValue() {
489         return hasPredefinedValue;
490     }
491
492     /**
493      * Indicates whether more than one control of this type with the same <a target="_blank" HREF="http://www.w3.org/TR/html401/interact/forms.html#control-name">name</a> can be <a target="_blank" HREF="http://www.w3.org/TR/html401/interact/forms.html#successful-controls">successful</a>.
494      * <p>
495      * Returns <code>false</code> only for the {@link #RADIO}, {@link #SUBMIT}, {@link #BUTTON}, and {@link #IMAGE} instances.
496      * <p>
497      * Note that before version 1.4.1 this method also returned <code>false</code> for the {@link #SELECT_SINGLE} instance.
498      * This was a bug resulting from confusion as to whether each <code>OPTION</code> element in a
499      * <code>SELECT</code> element constituted a control (since it is possible for multiple options to be
500      * <a target="_blank" HREF="http://www.w3.org/TR/html401/interact/forms.html#successful-controls">successful</a>)
501      * or only the <code>SELECT</code> element as a whole.
502      * Now that the control is clearly defined as the entire <code>SELECT</code> element,
503      * it is clear that multiple {@link #SELECT_SINGLE} controls with the same name result in multiple values.
504      * <p>
505      * Because this may not be immediately intuitive, and the method is no longer used internally,
506      * this method has been deprecated as of version 2.0 to avoid any further confusion.
507      *
508      * @return <code>true</code> if more than one control of this type with the same <a target="_blank" HREF="http://www.w3.org/TR/html401/interact/forms.html#control-name">name</a> can be <a target="_blank" HREF="http://www.w3.org/TR/html401/interact/forms.html#successful-controls">successful</a>, otherwise <code>false</code>.
509      * @deprecated Use the more useful {@link FormField#allowsMultipleValues()} method instead.
510      */

511     public boolean allowsMultipleValues() {
512         return !(this==RADIO || isSubmit());
513     }
514
515     /**
516      * Returns a string which identifies this form control type.
517      * <p>
518      * This is the same as the control type's static field name in lower case, which is one of<br />
519      * <code>button</code>, <code>checkbox</code>, <code>file</code>, <code>hidden</code>, <code>image</code>,
520      * <code>password</code>, <code>radio</code>, <code>select_multiple</code>, <code>select_single</code>,
521      * <code>submit</code>, <code>text</code>, or <code>textarea</code>.
522      * <p>
523      * This method has been deprecated as of version 2.0 as it has no practical use.
524      *
525      * @return a string which identifies this form control type.
526      * @deprecated Use {@link #toString() toString()} instead.
527      */

528     public String JavaDoc getFormControlTypeId() {
529         return formControlTypeId;
530     }
531
532     /**
533      * Returns the {@link FormControlType} with the specified {@linkplain #getFormControlTypeId() ID}.
534      * <p>
535      * This method has been deprecated as of version 2.0 as it has no practical use.
536      * <p>
537      * @param formControlTypeId the ID of a form control type.
538      * @return the {@link FormControlType} with the specified ID, or <code>null</code> if no such control exists.
539      * @see #getFormControlTypeId()
540      * @deprecated no replacement
541      */

542     public static FormControlType get(final String JavaDoc formControlTypeId) {
543         return (FormControlType)ID_MAP.get(formControlTypeId);
544     }
545
546     /**
547      * Returns an array containing the additional field names submitted if a control of this type with the specified <a target="_blank" HREF="http://www.w3.org/TR/html401/interact/forms.html#control-name">name</a> is <a target="_blank" HREF="http://www.w3.org/TR/html401/interact/forms.html#successful-controls">successful</a>.
548      * <p>
549      * Returns <code>null</code> for all control types except {@link #IMAGE}.
550      * It relates to the extra <code><i>name</i>.x</code> and <code><i>name</i>.y</code> data submitted when a pointing device is used to activate an IMAGE control.
551      * <p>
552      * This method has been deprecated as of version 2.0 as it is no longer used internally and
553      * has no practical use as a public method.
554      *
555      * @param name the <a target="_blank" HREF="http://www.w3.org/TR/html401/interact/forms.html#control-name">name</a> of a form control.
556      * @return an array containing the additional field names submitted if a control of this type with the specified <a target="_blank" HREF="http://www.w3.org/TR/html401/interact/forms.html#control-name">name</a> is <a target="_blank" HREF="http://www.w3.org/TR/html401/interact/forms.html#successful-controls">successful</a>, or <code>null</code> if none.
557      * @deprecated no replacement
558      */

559     public String JavaDoc[] getAdditionalSubmitNames(final String JavaDoc name) {
560         if (this!=IMAGE) return null;
561         final String JavaDoc[] names=new String JavaDoc[2];
562         names[0]=name+".x";
563         names[1]=name+".y";
564         return names;
565     }
566
567     /**
568      * Indicates whether an HTML tag with the specified name is potentially a form <a target="_blank" HREF="http://www.w3.org/TR/html401/interact/forms.html#form-controls">control</a>.
569      * <p>
570      * Returns <code>true</code> if the specified tag name is one of
571      * "input", "textarea", "button" or "select" (ignoring case).
572      * <p>
573      * This method has been deprecated as of version 2.0 as it is no longer used internally and
574      * has no practical use as a public method.
575      *
576      * @param tagName the name of an HTML tag.
577      * @return <code>true</code> if an HTML tag with the specified name is potentially a form <a target="_blank" HREF="http://www.w3.org/TR/html401/interact/forms.html#form-controls">control</a>, otherwise <code>false</code>.
578      * @deprecated no replacement
579      */

580     public static boolean isPotentialControl(final String JavaDoc tagName) {
581         return tagName.equalsIgnoreCase(Tag.INPUT) || tagName.equalsIgnoreCase(Tag.TEXTAREA) || tagName.equalsIgnoreCase(Tag.BUTTON) || tagName.equalsIgnoreCase(Tag.SELECT);
582     }
583
584     /**
585      * Returns a string representation of this object useful for debugging purposes.
586      * @return a string representation of this object useful for debugging purposes.
587      */

588     public String JavaDoc toString() {
589         return formControlTypeId;
590     }
591
592     static FormControlType getFromInputElementType(final String JavaDoc typeAttributeValue) {
593         return (FormControlType)INPUT_ELEMENT_TYPE_MAP.get(typeAttributeValue);
594     }
595 }
596
Popular Tags