1 |
// Jericho HTML Parser - Java based library for analysing and manipulating HTML
|
2 |
// Version 3.2
|
3 |
// Copyright (C) 2004-2009 Martin Jericho
|
4 |
// http://jericho.htmlparser.net/
|
5 |
//
|
6 |
// This library is free software; you can redistribute it and/or
|
7 |
// modify it under the terms of either one of the following licences:
|
8 |
//
|
9 |
// 1. The Eclipse Public License (EPL) version 1.0,
|
10 |
// included in this distribution in the file licence-epl-1.0.html
|
11 |
// or available at http://www.eclipse.org/legal/epl-v10.html
|
12 |
//
|
13 |
// 2. The GNU Lesser General Public License (LGPL) version 2.1 or later,
|
14 |
// included in this distribution in the file licence-lgpl-2.1.txt
|
15 |
// or available at http://www.gnu.org/licenses/lgpl.txt
|
16 |
//
|
17 |
// This library is distributed on an "AS IS" basis,
|
18 |
// WITHOUT WARRANTY OF ANY KIND, either express or implied.
|
19 |
// See the individual licence texts for more details.
|
20 |
|
21 |
package net.htmlparser.jericho;
|
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 enum FormControlType {
|
137 |
/**
|
138 |
* The form control type given to a <a href="#submit-button">submit button</a> control implemented using a
|
139 |
* <code><a target="_blank" href="http://www.w3.org/TR/html401/interact/forms.html#edef-BUTTON">BUTTON</a></code> element.
|
140 |
* <p>
|
141 |
* <dl>
|
142 |
* <dt>Example:</dt>
|
143 |
* <dd><code><button type="submit" name="FieldName" value="PredefinedValue">Send</button></code>
|
144 |
* <dt>Properties:</dt>
|
145 |
* <dd>
|
146 |
* <code>{@link #getElementName()} = {@link HTMLElementName#BUTTON}</code><br />
|
147 |
* <code>{@link #hasPredefinedValue()} = true</code><br />
|
148 |
* <code>{@link #isSubmit()} = true</code><br />
|
149 |
* </dl>
|
150 |
*/
|
151 |
BUTTON (HTMLElementName.BUTTON,true,true),
|
152 |
|
153 |
/**
|
154 |
* The form control type given to a <a href="#checkbox-control">checkbox</a> control.
|
155 |
* <p>
|
156 |
* <dl>
|
157 |
* <dt>Example:</dt>
|
158 |
* <dd><code><input type="checkbox" name="FieldName" value="PredefinedValue" /></code>
|
159 |
* <dt>Properties:</dt>
|
160 |
* <dd>
|
161 |
* <code>{@link #getElementName()} = {@link HTMLElementName#INPUT}</code><br />
|
162 |
* <code>{@link #hasPredefinedValue()} = true</code><br />
|
163 |
* <code>{@link #isSubmit()} = false</code><br />
|
164 |
* </dl>
|
165 |
*/
|
166 |
CHECKBOX (HTMLElementName.INPUT,true,false),
|
167 |
|
168 |
/**
|
169 |
* The form control type given to a <a href="#file-select-control">file select</a> control.
|
170 |
* <p>
|
171 |
* This library considers the <a href="FormControl.html#SubmissionValue">submission value</a> of this type of control
|
172 |
* to be consist of only the selected file name, regardless of whether the file content would normally be included in the
|
173 |
* <a target="_blank" href="http://www.w3.org/TR/html401/interact/forms.html#form-data-set">form data set</a>.
|
174 |
* <p>
|
175 |
* To determine manually whether the file content is included in the form data set, the
|
176 |
* <code><a target="_blank" href="http://www.w3.org/TR/html401/interact/forms.html#adef-enctype">enctype</a></code>
|
177 |
* attribute of the control's associated <a target="_blank" href="http://www.w3.org/TR/html401/interact/forms.html#edef-FORM">FORM</a>
|
178 |
* element can be examined.
|
179 |
* Although the exact behaviour is not defined in the HTML 4.01 specification, the convention is that the content
|
180 |
* is not included unless an <code>enctype</code> value of
|
181 |
* "<code><a target="_blank" href="http://www.w3.org/TR/html401/interact/forms.html#didx-multipartform-data">multipart/form-data</a></code>"
|
182 |
* is specified.
|
183 |
* <p>
|
184 |
* For more information see the
|
185 |
* <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>.
|
186 |
* <p>
|
187 |
* <dl>
|
188 |
* <dt>Example:</dt>
|
189 |
* <dd><code><input type="file" name="FieldName" value="DefaultFileName" /></code>
|
190 |
* <dt>Properties:</dt>
|
191 |
* <dd>
|
192 |
* <code>{@link #getElementName()} = {@link HTMLElementName#INPUT}</code><br />
|
193 |
* <code>{@link #hasPredefinedValue()} = false</code><br />
|
194 |
* <code>{@link #isSubmit()} = false</code><br />
|
195 |
* </dl>
|
196 |
*/
|
197 |
FILE (HTMLElementName.INPUT,false,false),
|
198 |
|
199 |
/**
|
200 |
* The form control type given to a <a href="#hidden-control">hidden</a> control.
|
201 |
* <p>
|
202 |
* <dl>
|
203 |
* <dt>Example:</dt>
|
204 |
* <dd><code><input type="hidden" name="FieldName" value="DefaultValue" /></code>
|
205 |
* <dt>Properties:</dt>
|
206 |
* <dd>
|
207 |
* <code>{@link #getElementName()} = {@link HTMLElementName#INPUT}</code><br />
|
208 |
* <code>{@link #hasPredefinedValue()} = false</code><br />
|
209 |
* <code>{@link #isSubmit()} = false</code><br />
|
210 |
* </dl>
|
211 |
* Note that {@link #hasPredefinedValue()} returns <code>false</code> for this control type
|
212 |
* because the value of hidden fields is usually set via server or client side scripting.
|
213 |
*/
|
214 |
HIDDEN (HTMLElementName.INPUT,false,false),
|
215 |
|
216 |
/**
|
217 |
* The form control type given to a <a href="#submit-button">submit button</a> control implemented using an
|
218 |
* <code><a target="_blank" href="http://www.w3.org/TR/html401/interact/forms.html#edef-INPUT">INPUT</a></code> element with attribute
|
219 |
* <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>.
|
220 |
* <p>
|
221 |
* See the description under the heading "image" in the
|
222 |
* <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>.
|
223 |
* <p>
|
224 |
* When a {@linkplain FormControl form control} of type <code>IMAGE</code> is present in the form used to
|
225 |
* {@linkplain FormFields#FormFields(Collection) construct} a {@link FormFields} instance, three separate
|
226 |
* {@link FormField} objects are created for the one control.
|
227 |
* One has the {@linkplain FormField#getName() name} specified in the
|
228 |
* <code><a target="_blank" href="http://www.w3.org/TR/html401/interact/forms.html#adef-name-INPUT">name</a></code>
|
229 |
* attribute of the <code>INPUT</code> element, and the other two have this name with the suffixes
|
230 |
* "<code>.x</code>" and "<code>.y</code>" appended to them to represent the additional
|
231 |
* <a target="_blank" href="http://www.w3.org/TR/html401/interact/forms.html#idx-coordinates">click coordinates</a>
|
232 |
* submitted by this control when activated using a pointing device.
|
233 |
* <p>
|
234 |
* This type of control is also mentioned in the
|
235 |
* <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>.
|
236 |
* <p>
|
237 |
* <dl>
|
238 |
* <dt>Example:</dt>
|
239 |
* <dd><code><input type="image" name="FieldName" src="ImageURL" value="PredefinedValue" /></code>
|
240 |
* <dt>Properties:</dt>
|
241 |
* <dd>
|
242 |
* <code>{@link #getElementName()} = {@link HTMLElementName#INPUT}</code><br />
|
243 |
* <code>{@link #hasPredefinedValue()} = true</code><br />
|
244 |
* <code>{@link #isSubmit()} = true</code><br />
|
245 |
* </dl>
|
246 |
*/
|
247 |
IMAGE (HTMLElementName.INPUT,true,true),
|
248 |
|
249 |
/**
|
250 |
* The form control type given to a <a href="#text-input-control">text input</a> control implemented using an
|
251 |
* <code><a target="_blank" href="http://www.w3.org/TR/html401/interact/forms.html#edef-INPUT">INPUT</a></code> element with attribute
|
252 |
* <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>.
|
253 |
* <p>
|
254 |
* <dl>
|
255 |
* <dt>Example:</dt>
|
256 |
* <dd><code><input type="password" name="FieldName" value="DefaultValue" /></code>
|
257 |
* <dt>Properties:</dt>
|
258 |
* <dd>
|
259 |
* <code>{@link #getElementName()} = {@link HTMLElementName#INPUT}</code><br />
|
260 |
* <code>{@link #hasPredefinedValue()} = false</code><br />
|
261 |
* <code>{@link #isSubmit()} = false</code><br />
|
262 |
* </dl>
|
263 |
*/
|
264 |
PASSWORD (HTMLElementName.INPUT,false,false),
|
265 |
|
266 |
/**
|
267 |
* The form control type given to a <a href="#radio-button-control">radio button</a> control.
|
268 |
* <p>
|
269 |
* <dl>
|
270 |
* <dt>Example:</dt>
|
271 |
* <dd><code><input type="radio" name="FieldName" value="PredefinedValue" /></code>
|
272 |
* <dt>Properties:</dt>
|
273 |
* <dd>
|
274 |
* <code>{@link #getElementName()} = {@link HTMLElementName#INPUT}</code><br />
|
275 |
* <code>{@link #hasPredefinedValue()} = true</code><br />
|
276 |
* <code>{@link #isSubmit()} = false</code><br />
|
277 |
* </dl>
|
278 |
*/
|
279 |
RADIO (HTMLElementName.INPUT,true,false),
|
280 |
|
281 |
/**
|
282 |
* The form control type given to a <a href="#menu-control">menu</a> control implemented using a
|
283 |
* <code><a target="_blank" href="http://www.w3.org/TR/html401/interact/forms.html#edef-SELECT">SELECT</a></code> element containing
|
284 |
* the attribute "<code><a target="_blank" href="http://www.w3.org/TR/html401/interact/forms.html#adef-multiple">multiple</a></code>".
|
285 |
* <p>
|
286 |
* <code>SELECT</code> elements that do not contain the attribute "<code>multiple</code>" are represented by the
|
287 |
* {@link #SELECT_SINGLE} form control type.
|
288 |
* <p>
|
289 |
* This is the only control type that can have multiple
|
290 |
* <a href="FormControl.html#SubmissionValue">submission values</a> within the one control.
|
291 |
* Contrast this with {@link #CHECKBOX} controls, which require multiple separate controls with the same
|
292 |
* {@linkplain FormControl#getName() name} in order to contribute multiple submission values.
|
293 |
* <p>
|
294 |
* The individual {@link HTMLElementName#OPTION OPTION} elements contained within a {@linkplain FormControl form control} of this type can be
|
295 |
* obtained using the {@link FormControl#getOptionElementIterator()} method.
|
296 |
* <p>
|
297 |
* The most efficient way to test whether a form control type is either <code>SELECT_MULTIPLE</code> or <code>SELECT_SINGLE</code>
|
298 |
* is to test for {@link #getElementName()}<code>==</code>{@link HTMLElementName#SELECT}.
|
299 |
* <p>
|
300 |
* <dl>
|
301 |
* <dt>Example:</dt>
|
302 |
* <dd>
|
303 |
* <code>
|
304 |
* <select name="FieldName" multiple><br />
|
305 |
* <option value="PredefinedValue1" selected>Display Text1</option><br />
|
306 |
* <option value="PredefinedValue2">Display Text2</option><br />
|
307 |
* </select>
|
308 |
* </code>
|
309 |
* <dt>Properties:</dt>
|
310 |
* <dd>
|
311 |
* <code>{@link #getElementName()} = {@link HTMLElementName#SELECT}</code><br />
|
312 |
* <code>{@link #hasPredefinedValue()} = true</code><br />
|
313 |
* <code>{@link #isSubmit()} = false</code><br />
|
314 |
* </dl>
|
315 |
*/
|
316 |
SELECT_MULTIPLE (HTMLElementName.SELECT,true,false),
|
317 |
|
318 |
/**
|
319 |
* The form control type given to a <a href="#menu-control">menu</a> control implemented using a
|
320 |
* <code><a target="_blank" href="http://www.w3.org/TR/html401/interact/forms.html#edef-SELECT">SELECT</a></code> element that does
|
321 |
* <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>".
|
322 |
* <p>
|
323 |
* <code>SELECT</code> elements that do contain the attribute "<code>multiple</code>" are represented by the
|
324 |
* {@link #SELECT_MULTIPLE} form control type.
|
325 |
* <p>
|
326 |
* The individual {@link HTMLElementName#OPTION OPTION} elements contained within a {@linkplain FormControl form control} of this type can be
|
327 |
* obtained using the {@link FormControl#getOptionElementIterator()} method.
|
328 |
* <p>
|
329 |
* The most efficient way to test whether a form control type is either <code>SELECT_MULTIPLE</code> or <code>SELECT_SINGLE</code>
|
330 |
* is to test for {@link #getElementName()}<code>==</code>{@link HTMLElementName#SELECT}.
|
331 |
* <p>
|
332 |
* <dl>
|
333 |
* <dt>Example:</dt>
|
334 |
* <dd>
|
335 |
* <code>
|
336 |
* <select name="FieldName"><br />
|
337 |
* <option value="PredefinedValue1" selected>Display Text1</option><br />
|
338 |
* <option value="PredefinedValue2">Display Text2</option><br />
|
339 |
* </select>
|
340 |
* </code>
|
341 |
* <dt>Properties:</dt>
|
342 |
* <dd>
|
343 |
* <code>{@link #getElementName()} = {@link HTMLElementName#SELECT}</code><br />
|
344 |
* <code>{@link #hasPredefinedValue()} = true</code><br />
|
345 |
* <code>{@link #isSubmit()} = false</code><br />
|
346 |
* </dl>
|
347 |
*/
|
348 |
SELECT_SINGLE (HTMLElementName.SELECT,true,false),
|
349 |
|
350 |
/**
|
351 |
* The form control type given to a <a href="#submit-button">submit button</a> control implemented using an
|
352 |
* <code><a target="_blank" href="http://www.w3.org/TR/html401/interact/forms.html#edef-INPUT">INPUT</a></code> element with attribute
|
353 |
* <code><a target="_blank" href="http://www.w3.org/TR/html401/interact/forms.html#adef-type-INPUT">type</a>="submit"</code>.
|
354 |
* <p>
|
355 |
* <dl>
|
356 |
* <dt>Example:</dt>
|
357 |
* <dd><code><input type="submit" name="FieldName" value="PredefinedValue" /></code>
|
358 |
* <dt>Properties:</dt>
|
359 |
* <dd>
|
360 |
* <code>{@link #getElementName()} = {@link HTMLElementName#INPUT}</code><br />
|
361 |
* <code>{@link #hasPredefinedValue()} = true</code><br />
|
362 |
* <code>{@link #isSubmit()} = true</code><br />
|
363 |
* </dl>
|
364 |
*/
|
365 |
SUBMIT (HTMLElementName.INPUT,true,true),
|
366 |
|
367 |
/**
|
368 |
* The form control type given to a <a href="#text-input-control">text input</a> control implemented using an
|
369 |
* <code><a target="_blank" href="http://www.w3.org/TR/html401/interact/forms.html#edef-INPUT">INPUT</a></code> element with attribute
|
370 |
* <code><a target="_blank" href="http://www.w3.org/TR/html401/interact/forms.html#adef-type-INPUT">type</a>="text"</code>.
|
371 |
* <p>
|
372 |
* <dl>
|
373 |
* <dt>Example:</dt>
|
374 |
* <dd><code><input type="text" name="FieldName" value="DefaultValue" /></code>
|
375 |
* <dt>Properties:</dt>
|
376 |
* <dd>
|
377 |
* <code>{@link #getElementName()} = {@link HTMLElementName#INPUT}</code><br />
|
378 |
* <code>{@link #hasPredefinedValue()} = false</code><br />
|
379 |
* <code>{@link #isSubmit()} = false</code><br />
|
380 |
* </dl>
|
381 |
*/
|
382 |
TEXT (HTMLElementName.INPUT,false,false),
|
383 |
|
384 |
/**
|
385 |
* The form control type given to a <a href="#text-input-control">text input</a> control implemented using a
|
386 |
* <code><a target="_blank" href="http://www.w3.org/TR/html401/interact/forms.html#edef-TEXTAREA">TEXTAREA</a></code> element.
|
387 |
* <p>
|
388 |
* <dl>
|
389 |
* <dt>Example:</dt>
|
390 |
* <dd><code><textarea name="FieldName">Default Value</textarea></code>
|
391 |
* <dt>Properties:</dt>
|
392 |
* <dd>
|
393 |
* <code>{@link #getElementName()} = {@link HTMLElementName#TEXTAREA}</code><br />
|
394 |
* <code>{@link #hasPredefinedValue()} = false</code><br />
|
395 |
* <code>{@link #isSubmit()} = false</code><br />
|
396 |
* </dl>
|
397 |
*/
|
398 |
TEXTAREA (HTMLElementName.TEXTAREA,false,false);
|
399 |
|
400 |
private String elementName;
|
401 |
private boolean hasPredefinedValue;
|
402 |
private boolean submit;
|
403 |
|
404 |
private static final HashMap<String,FormControlType> INPUT_ELEMENT_TYPE_MAP=new HashMap<String,FormControlType>(11,1.0F); // 8 input element types in total
|
405 |
private static final HashSet<String> NON_FORM_CONTROL_TYPE_ATTRIBUTE_SET=new HashSet<String>(3,1.0F); // 2 non form control input element types in total
|
406 |
|
407 |
static {
|
408 |
// Map each INPUT element "type" attribute value to a FormControlType:
|
409 |
INPUT_ELEMENT_TYPE_MAP.put("checkbox",CHECKBOX);
|
410 |
INPUT_ELEMENT_TYPE_MAP.put("file",FILE);
|
411 |
INPUT_ELEMENT_TYPE_MAP.put("hidden",HIDDEN);
|
412 |
INPUT_ELEMENT_TYPE_MAP.put("image",IMAGE);
|
413 |
INPUT_ELEMENT_TYPE_MAP.put("password",PASSWORD);
|
414 |
INPUT_ELEMENT_TYPE_MAP.put("radio",RADIO);
|
415 |
INPUT_ELEMENT_TYPE_MAP.put("submit",SUBMIT);
|
416 |
INPUT_ELEMENT_TYPE_MAP.put("text",TEXT);
|
417 |
// The following INPUT element "type" attributes do not produce a form control:
|
418 |
NON_FORM_CONTROL_TYPE_ATTRIBUTE_SET.add("button");
|
419 |
NON_FORM_CONTROL_TYPE_ATTRIBUTE_SET.add("reset");
|
420 |
}
|
421 |
|
422 |
private FormControlType(final String elementName, final boolean hasPredefinedValue, final boolean submit) {
|
423 |
this.elementName=elementName;
|
424 |
this.hasPredefinedValue=hasPredefinedValue;
|
425 |
this.submit=submit;
|
426 |
}
|
427 |
|
428 |
/**
|
429 |
* Returns the {@linkplain Element#getName() name} of the {@link Element} that constitues this form control type.
|
430 |
* @return the {@linkplain Element#getName() name} of the {@link Element} that constitues this form control type.
|
431 |
*/
|
432 |
public String getElementName() {
|
433 |
return elementName;
|
434 |
}
|
435 |
|
436 |
/**
|
437 |
* Indicates whether any <a target="_blank" href="http://www.w3.org/TR/html401/interact/forms.html#current-value">value</a>
|
438 |
* submitted by this type of control is predefined in the HTML and typically not modified by the user or server/client scripts.
|
439 |
* <p>
|
440 |
* The word "typically" is used because the use of client side scripts can cause
|
441 |
* <a target="_blank" href="http://www.w3.org/TR/html401/interact/forms.html#h-17.2.1">control types</a>
|
442 |
* which normally have predefined values to be set by the user, which is a condition which is beyond
|
443 |
* the scope of this library to test for.
|
444 |
* <p>
|
445 |
* 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>.
|
446 |
* <p>
|
447 |
* A return value of <code>true</code> signifies that a form control of this type is a
|
448 |
* <a href="FormControl.html#PredefinedValueControl">predefined value control</a>.
|
449 |
* <p>
|
450 |
* A return value of <code>false</code> signifies that a form control of this type is a
|
451 |
* <a href="FormControl.html#UserValueControl">user value control</a>.
|
452 |
* <p>
|
453 |
* 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.
|
454 |
*
|
455 |
* @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>.
|
456 |
*/
|
457 |
public boolean hasPredefinedValue() {
|
458 |
return hasPredefinedValue;
|
459 |
}
|
460 |
|
461 |
/**
|
462 |
* 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>.
|
463 |
* <p>
|
464 |
* Returns <code>true</code> only for the {@link #SUBMIT}, {@link #BUTTON}, and {@link #IMAGE} instances.
|
465 |
*
|
466 |
* @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>.
|
467 |
*/
|
468 |
public boolean isSubmit() {
|
469 |
return submit;
|
470 |
}
|
471 |
|
472 |
static FormControlType getFromInputElementType(final String typeAttributeValue) {
|
473 |
return INPUT_ELEMENT_TYPE_MAP.get(typeAttributeValue.toLowerCase());
|
474 |
}
|
475 |
|
476 |
static boolean isNonFormControl(final String typeAttributeValue) {
|
477 |
return NON_FORM_CONTROL_TYPE_ATTRIBUTE_SET.contains(typeAttributeValue.toLowerCase());
|
478 |
}
|
479 |
}
|