📄 formcontroltype.java
字号:
* <dd>
* <code>{@link #getElementName()} = {@link HTMLElementName#INPUT}</code><br />
* <code>{@link #hasPredefinedValue()} = true</code><br />
* <code>{@link #isSubmit()} = true</code><br />
* </dl>
*/
IMAGE (HTMLElementName.INPUT,true,true),
/**
* The form control type given to a <a href="#text-input-control">text input</a> control implemented using an
* <code><a target="_blank" href="http://www.w3.org/TR/html401/interact/forms.html#edef-INPUT">INPUT</a></code> element with attribute
* <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>.
* <p>
* <dl>
* <dt>Example:</dt>
* <dd><code><input type="password" name="FieldName" value="DefaultValue" /></code>
* <dt>Properties:</dt>
* <dd>
* <code>{@link #getElementName()} = {@link HTMLElementName#INPUT}</code><br />
* <code>{@link #hasPredefinedValue()} = false</code><br />
* <code>{@link #isSubmit()} = false</code><br />
* </dl>
*/
PASSWORD (HTMLElementName.INPUT,false,false),
/**
* The form control type given to a <a href="#radio-button-control">radio button</a> control.
* <p>
* <dl>
* <dt>Example:</dt>
* <dd><code><input type="radio" name="FieldName" value="PredefinedValue" /></code>
* <dt>Properties:</dt>
* <dd>
* <code>{@link #getElementName()} = {@link HTMLElementName#INPUT}</code><br />
* <code>{@link #hasPredefinedValue()} = true</code><br />
* <code>{@link #isSubmit()} = false</code><br />
* </dl>
*/
RADIO (HTMLElementName.INPUT,true,false),
/**
* The form control type given to a <a href="#menu-control">menu</a> control implemented using a
* <code><a target="_blank" href="http://www.w3.org/TR/html401/interact/forms.html#edef-SELECT">SELECT</a></code> element containing
* the attribute "<code><a target="_blank" href="http://www.w3.org/TR/html401/interact/forms.html#adef-multiple">multiple</a></code>".
* <p>
* <code>SELECT</code> elements that do not contain the attribute "<code>multiple</code>" are represented by the
* {@link #SELECT_SINGLE} form control type.
* <p>
* This is the only control type that can have multiple
* <a href="FormControl.html#SubmissionValue">submission values</a> within the one control.
* Contrast this with {@link #CHECKBOX} controls, which require multiple separate controls with the same
* {@linkplain FormControl#getName() name} in order to contribute multiple submission values.
* <p>
* The individual {@link HTMLElementName#OPTION OPTION} elements contained within a {@linkplain FormControl form control} of this type can be
* obtained using the {@link FormControl#getOptionElementIterator()} method.
* <p>
* The most efficient way to test whether a form control type is either <code>SELECT_MULTIPLE</code> or <code>SELECT_SINGLE</code>
* is to test for {@link #getElementName()}<code>==</code>{@link HTMLElementName#SELECT}.
* <p>
* <dl>
* <dt>Example:</dt>
* <dd>
* <code>
* <select name="FieldName" multiple><br />
* <option value="PredefinedValue1" selected>Display Text1</option><br />
* <option value="PredefinedValue2">Display Text2</option><br />
* </select>
* </code>
* <dt>Properties:</dt>
* <dd>
* <code>{@link #getElementName()} = {@link HTMLElementName#SELECT}</code><br />
* <code>{@link #hasPredefinedValue()} = true</code><br />
* <code>{@link #isSubmit()} = false</code><br />
* </dl>
*/
SELECT_MULTIPLE (HTMLElementName.SELECT,true,false),
/**
* The form control type given to a <a href="#menu-control">menu</a> control implemented using a
* <code><a target="_blank" href="http://www.w3.org/TR/html401/interact/forms.html#edef-SELECT">SELECT</a></code> element that does
* <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>".
* <p>
* <code>SELECT</code> elements that do contain the attribute "<code>multiple</code>" are represented by the
* {@link #SELECT_MULTIPLE} form control type.
* <p>
* The individual {@link HTMLElementName#OPTION OPTION} elements contained within a {@linkplain FormControl form control} of this type can be
* obtained using the {@link FormControl#getOptionElementIterator()} method.
* <p>
* The most efficient way to test whether a form control type is either <code>SELECT_MULTIPLE</code> or <code>SELECT_SINGLE</code>
* is to test for {@link #getElementName()}<code>==</code>{@link HTMLElementName#SELECT}.
* <p>
* <dl>
* <dt>Example:</dt>
* <dd>
* <code>
* <select name="FieldName"><br />
* <option value="PredefinedValue1" selected>Display Text1</option><br />
* <option value="PredefinedValue2">Display Text2</option><br />
* </select>
* </code>
* <dt>Properties:</dt>
* <dd>
* <code>{@link #getElementName()} = {@link HTMLElementName#SELECT}</code><br />
* <code>{@link #hasPredefinedValue()} = true</code><br />
* <code>{@link #isSubmit()} = false</code><br />
* </dl>
*/
SELECT_SINGLE (HTMLElementName.SELECT,true,false),
/**
* The form control type given to a <a href="#submit-button">submit button</a> control implemented using an
* <code><a target="_blank" href="http://www.w3.org/TR/html401/interact/forms.html#edef-INPUT">INPUT</a></code> element with attribute
* <code><a target="_blank" href="http://www.w3.org/TR/html401/interact/forms.html#adef-type-INPUT">type</a>="submit"</code>.
* <p>
* <dl>
* <dt>Example:</dt>
* <dd><code><input type="submit" name="FieldName" value="PredefinedValue" /></code>
* <dt>Properties:</dt>
* <dd>
* <code>{@link #getElementName()} = {@link HTMLElementName#INPUT}</code><br />
* <code>{@link #hasPredefinedValue()} = true</code><br />
* <code>{@link #isSubmit()} = true</code><br />
* </dl>
*/
SUBMIT (HTMLElementName.INPUT,true,true),
/**
* The form control type given to a <a href="#text-input-control">text input</a> control implemented using an
* <code><a target="_blank" href="http://www.w3.org/TR/html401/interact/forms.html#edef-INPUT">INPUT</a></code> element with attribute
* <code><a target="_blank" href="http://www.w3.org/TR/html401/interact/forms.html#adef-type-INPUT">type</a>="text"</code>.
* <p>
* <dl>
* <dt>Example:</dt>
* <dd><code><input type="text" name="FieldName" value="DefaultValue" /></code>
* <dt>Properties:</dt>
* <dd>
* <code>{@link #getElementName()} = {@link HTMLElementName#INPUT}</code><br />
* <code>{@link #hasPredefinedValue()} = false</code><br />
* <code>{@link #isSubmit()} = false</code><br />
* </dl>
*/
TEXT (HTMLElementName.INPUT,false,false),
/**
* The form control type given to a <a href="#text-input-control">text input</a> control implemented using a
* <code><a target="_blank" href="http://www.w3.org/TR/html401/interact/forms.html#edef-TEXTAREA">TEXTAREA</a></code> element.
* <p>
* <dl>
* <dt>Example:</dt>
* <dd><code><textarea name="FieldName">Default Value</textarea></code>
* <dt>Properties:</dt>
* <dd>
* <code>{@link #getElementName()} = {@link HTMLElementName#TEXTAREA}</code><br />
* <code>{@link #hasPredefinedValue()} = false</code><br />
* <code>{@link #isSubmit()} = false</code><br />
* </dl>
*/
TEXTAREA (HTMLElementName.TEXTAREA,false,false);
private String elementName;
private boolean hasPredefinedValue;
private boolean submit;
private static final HashMap<String,FormControlType> INPUT_ELEMENT_TYPE_MAP=new HashMap<String,FormControlType>(11,1.0F); // 8 input element types in total
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
static {
// Map each INPUT element "type" attribute value to a FormControlType:
INPUT_ELEMENT_TYPE_MAP.put("checkbox",CHECKBOX);
INPUT_ELEMENT_TYPE_MAP.put("file",FILE);
INPUT_ELEMENT_TYPE_MAP.put("hidden",HIDDEN);
INPUT_ELEMENT_TYPE_MAP.put("image",IMAGE);
INPUT_ELEMENT_TYPE_MAP.put("password",PASSWORD);
INPUT_ELEMENT_TYPE_MAP.put("radio",RADIO);
INPUT_ELEMENT_TYPE_MAP.put("submit",SUBMIT);
INPUT_ELEMENT_TYPE_MAP.put("text",TEXT);
// The following INPUT element "type" attributes do not produce a form control:
NON_FORM_CONTROL_TYPE_ATTRIBUTE_SET.add("button");
NON_FORM_CONTROL_TYPE_ATTRIBUTE_SET.add("reset");
}
private FormControlType(final String elementName, final boolean hasPredefinedValue, final boolean submit) {
this.elementName=elementName;
this.hasPredefinedValue=hasPredefinedValue;
this.submit=submit;
}
/**
* Returns the {@linkplain Element#getName() name} of the {@link Element} that constitues this form control type.
* @return the {@linkplain Element#getName() name} of the {@link Element} that constitues this form control type.
*/
public String getElementName() {
return elementName;
}
/**
* Indicates whether 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.
* <p>
* The word "typically" is used because the use of client side scripts can cause
* <a target="_blank" href="http://www.w3.org/TR/html401/interact/forms.html#h-17.2.1">control types</a>
* which normally have predefined values to be set by the user, which is a condition which is beyond
* the scope of this library to test for.
* <p>
* 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>.
* <p>
* A return value of <code>true</code> signifies that a form control of this type is a
* <a href="FormControl.html#PredefinedValueControl">predefined value control</a>.
* <p>
* A return value of <code>false</code> signifies that a form control of this type is a
* <a href="FormControl.html#UserValueControl">user value control</a>.
* <p>
* 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.
*
* @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>.
*/
public boolean hasPredefinedValue() {
return hasPredefinedValue;
}
/**
* 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>.
* <p>
* Returns <code>true</code> only for the {@link #SUBMIT}, {@link #BUTTON}, and {@link #IMAGE} instances.
*
* @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>.
*/
public boolean isSubmit() {
return submit;
}
static FormControlType getFromInputElementType(final String typeAttributeValue) {
return INPUT_ELEMENT_TYPE_MAP.get(typeAttributeValue.toLowerCase());
}
static boolean isNonFormControl(final String typeAttributeValue) {
return NON_FORM_CONTROL_TYPE_ATTRIBUTE_SET.contains(typeAttributeValue.toLowerCase());
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -