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 |
* An enumerated type representing the three major output styles of a {@linkplain FormControl form control's}
|
27 |
* <a href="FormControl.html#OutputElement">output element</a>.
|
28 |
* <p>
|
29 |
* A form control's output style is set using the {@link FormControl#setOutputStyle(FormControlOutputStyle)} method.
|
30 |
*/
|
31 |
public enum FormControlOutputStyle {
|
32 |
/**
|
33 |
* Normal display of the <a href="FormControl.html#OutputElement">output element</a>.
|
34 |
* <p>
|
35 |
* This is the default display style.
|
36 |
*/
|
37 |
NORMAL,
|
38 |
|
39 |
/**
|
40 |
* Remove the <a href="FormControl.html#OutputElement">output element</a> from the {@linkplain OutputDocument output document} completely.
|
41 |
*/
|
42 |
REMOVE,
|
43 |
|
44 |
/**
|
45 |
* The {@linkplain #NORMAL normal} <a href="FormControl.html#OutputElement">output element</a> is replaced with a simple representation
|
46 |
* of the {@linkplain FormControl form control's} <a href="FormControl.html#SubmissionValue">submission value(s)</a>.
|
47 |
* <p>
|
48 |
* The implementation of this functionality is highly subjective, but provides a more aesthetic way of displaying a read-only version
|
49 |
* of a form without having to resort to using {@linkplain FormControl#isDisabled() disabled} controls.
|
50 |
* <p>
|
51 |
* The representation is dependent on the {@linkplain FormControlType form control type}, and can be configured using the
|
52 |
* static properties of the {@link ConfigDisplayValue ConfigDisplayValue} nested class.
|
53 |
* <p>
|
54 |
* Unless specified otherwise below, the {@linkplain #NORMAL normal} <a href="FormControl.html#OutputElement">output element</a> is
|
55 |
* replaced with a <i><a name="DisplayValueElement">display value element</a></i> having the {@linkplain Element#getName() name}
|
56 |
* specified in the static {@link ConfigDisplayValue#ElementName ConfigDisplayValue.ElementName} property
|
57 |
* (<code>div</code> by default).
|
58 |
* The attributes specified in the static {@link ConfigDisplayValue#AttributeNames ConfigDisplayValue.AttributeNames} list
|
59 |
* (<code>id</code>, <code>class</code> and <code>style</code> by default) are copied from
|
60 |
* the {@linkplain #NORMAL normal} <a href="FormControl.html#OutputElement">output element</a> into the
|
61 |
* <a href="#DisplayValueElement">display value element</a>.
|
62 |
* <p>
|
63 |
* Details of the content of the <a href="#DisplayValueElement">display value element</a> or other representation of the
|
64 |
* control value are as follows:
|
65 |
* <p>
|
66 |
* <dl>
|
67 |
* <dt>{@link FormControlType#TEXT TEXT}, {@link FormControlType#FILE FILE}
|
68 |
* <dd>The content of the <a href="#DisplayValueElement">display value element</a> is the
|
69 |
* {@linkplain CharacterReference#reencode(CharSequence) re-encoded} value of the
|
70 |
* {@linkplain #NORMAL normal} <a href="FormControl.html#OutputElement">output element's</a> <code>value</code> attribute.
|
71 |
* <dt>{@link FormControlType#TEXTAREA TEXTAREA}
|
72 |
* <dd>The content of the <a href="#DisplayValueElement">display value element</a> is the content of the <code>TEXTAREA</code> element
|
73 |
* re-encoded {@linkplain CharacterReference#encodeWithWhiteSpaceFormatting(CharSequence) with white space formatting}.
|
74 |
* <dt>{@link FormControlType#CHECKBOX CHECKBOX}, {@link FormControlType#RADIO RADIO}
|
75 |
* <dd>The {@linkplain #NORMAL normal} <a href="FormControl.html#OutputElement">output element</a> is replaced with the
|
76 |
* un-encoded content specified in the {@link ConfigDisplayValue#CheckedHTML ConfigDisplayValue.CheckedHTML} or
|
77 |
* {@link ConfigDisplayValue#UncheckedHTML ConfigDisplayValue.UncheckedHTML} static property, depending on
|
78 |
* whether the {@linkplain #NORMAL normal} <a href="FormControl.html#OutputElement">output element</a> contains a
|
79 |
* <code>checked</code> attribute.
|
80 |
* If the relevant static property has a value of <code>null</code> (the default), the
|
81 |
* <a href="FormControl.html#OutputElement">output element</a> is simply a {@linkplain FormControl#setDisabled(boolean) disabled}
|
82 |
* version of the form control.
|
83 |
* Attempting to determine which labels might apply to which checkbox or radio button, allowing only the
|
84 |
* selected controls to be displayed, would require a very complex and inexact algorithm, so is best left to the developer
|
85 |
* to implement if required.
|
86 |
* <dt>{@link FormControlType#SELECT_SINGLE SELECT_SINGLE}, {@link FormControlType#SELECT_MULTIPLE SELECT_MULTIPLE}
|
87 |
* <dd>The content of the <a href="#DisplayValueElement">display value element</a> is the
|
88 |
* {@linkplain CharacterReference#reencode(CharSequence) re-encoded} label of the currently selected option.
|
89 |
* In the case of a {@link FormControlType#SELECT_MULTIPLE SELECT_MULTIPLE} control, all labels of selected options
|
90 |
* are listed, separated by the text specified in the static
|
91 |
* {@link ConfigDisplayValue#MultipleValueSeparator ConfigDisplayValue.MultipleValueSeparator} property
|
92 |
* ("<code>, </code>" by default).
|
93 |
* <dt>{@link FormControlType#PASSWORD PASSWORD}
|
94 |
* <dd>The content of the <a href="#DisplayValueElement">display value element</a> is the
|
95 |
* {@linkplain CharacterReference#encode(CharSequence) encoded} character specified in the
|
96 |
* {@link ConfigDisplayValue#PasswordChar ConfigDisplayValue.PasswordChar} static property ('<code>*</code>' by default),
|
97 |
* repeated <i>n</i> times, where <i>n</i> is the number of characters in the control's
|
98 |
* <a href="FormControl.html#SubmissionValue">submission value</a>.
|
99 |
* <dt>{@link FormControlType#HIDDEN HIDDEN}
|
100 |
* <dd>The <a href="FormControl.html#OutputElement">output element</a> is {@linkplain #REMOVE removed} completely.
|
101 |
* <dt>{@link FormControlType#BUTTON BUTTON}, {@link FormControlType#SUBMIT SUBMIT}, {@link FormControlType#IMAGE IMAGE}
|
102 |
* <dd>The <a href="FormControl.html#OutputElement">output element</a>
|
103 |
* is a {@linkplain FormControl#setDisabled(boolean) disabled} version of the original form control.
|
104 |
* </dl>
|
105 |
* <p>
|
106 |
* If the <a href="FormControl.html#SubmissionValue">submission value</a> of the control is <code>null</code> or an empty string,
|
107 |
* the <a href="#DisplayValueElement">display value element</a> is given the un-encoded content specified in the
|
108 |
* {@link ConfigDisplayValue#EmptyHTML ConfigDisplayValue.EmptyHTML} static property.
|
109 |
*/
|
110 |
DISPLAY_VALUE;
|
111 |
|
112 |
/**
|
113 |
* Returns a string representation of this object useful for debugging purposes.
|
114 |
* <p>
|
115 |
* This is equivalent to {@link #toString()}.
|
116 |
*
|
117 |
* @return a string representation of this object useful for debugging purposes.
|
118 |
*/
|
119 |
public String getDebugInfo() {
|
120 |
return toString();
|
121 |
}
|
122 |
|
123 |
/**
|
124 |
* Contains static properties that configure the {@link #DISPLAY_VALUE} form control output style.
|
125 |
* <p>
|
126 |
* None of the properties should be assigned a <code>null</code> value.
|
127 |
* <p>
|
128 |
* See the documentation of the {@link #DISPLAY_VALUE} output style for details on how these properties are used.
|
129 |
*/
|
130 |
public static final class ConfigDisplayValue {
|
131 |
|
132 |
/**
|
133 |
* Defines the text that is used to separate multiple values in a
|
134 |
* <a href="FormControlOutputStyle.html#DisplayValueElement">display value element</a>.
|
135 |
* <p>
|
136 |
* This property is only relevant to {@link FormControlType#SELECT_MULTIPLE SELECT_MULTIPLE} form controls, and is only used
|
137 |
* if multiple items in the control are selected.
|
138 |
* <p>
|
139 |
* The default value is "<code>, </code>".
|
140 |
*/
|
141 |
public static volatile String MultipleValueSeparator=", ";
|
142 |
|
143 |
/**
|
144 |
* Defines the {@linkplain Element#getName() name} of
|
145 |
* <a href="FormControlOutputStyle.html#DisplayValueElement">display value elements</a>.
|
146 |
* <p>
|
147 |
* The default value is "<code>div</code>".
|
148 |
* <p>
|
149 |
* Although all form control {@linkplain FormControl#getElement() elements} are
|
150 |
* {@linkplain HTMLElements#getInlineLevelElementNames() inline-level} elements, the default replacement is the
|
151 |
* {@linkplain HTMLElements#getBlockLevelElementNames() block-level} {@link HTMLElementName#DIV DIV} element, which allows
|
152 |
* richer stylesheet formatting than the most common alternative, the {@link HTMLElementName#SPAN SPAN} element,
|
153 |
* such as the ability to set its <code>width</code> and <code>height</code>.
|
154 |
* <p>
|
155 |
* This has the undesired effect in some cases of displaying the value on a new line, whereas the original form control
|
156 |
* was not on a new line. In practical use however, many form controls are placed inside table cells for better control
|
157 |
* over their positioning. In this case replacing the original inline form control with the block <code>DIV</code>
|
158 |
* element does not alter its position.
|
159 |
*/
|
160 |
public static volatile String ElementName=HTMLElementName.DIV;
|
161 |
|
162 |
/**
|
163 |
* Defines the names of the {@linkplain Attributes attributes} that are copied from the normal form control
|
164 |
* <a href="FormControl.html#OutputElement">output element</a> to a
|
165 |
* <a href="FormControlOutputStyle.html#DisplayValueElement">display value element</a>.
|
166 |
* <p>
|
167 |
* The names included in the list by default are "<code>id</code>", "<code>class</code>" and "<code>style</code>".
|
168 |
* <p>
|
169 |
* These attributes are usually all that is needed to identify the elements in style sheets or specify the styles directly.
|
170 |
* <p>
|
171 |
* The default list is modifiable.
|
172 |
*/
|
173 |
public static volatile List<String> AttributeNames=new ArrayList<String>(Arrays.asList(new String[] {Attribute.ID,Attribute.CLASS,Attribute.STYLE}));
|
174 |
|
175 |
/**
|
176 |
* Defines the content of a <a href="FormControlOutputStyle.html#DisplayValueElement">display value element</a>
|
177 |
* if the <a href="FormControl.html#SubmissionValue">submission value</a> of the control is <code>null</code> or an empty string.
|
178 |
* <p>
|
179 |
* The content is not {@linkplain CharacterReference#encode(CharSequence) encoded} before output.
|
180 |
* <p>
|
181 |
* The default content is "<code>&nbsp;</code>".
|
182 |
*/
|
183 |
public static volatile String EmptyHTML=" ";
|
184 |
|
185 |
/**
|
186 |
* Defines the character used to represent the value of a {@link FormControlType#PASSWORD PASSWORD} form control
|
187 |
* in a <a href="#DisplayValueElement">display value element</a>.
|
188 |
* <p>
|
189 |
* The character is repeated <i>n</i> times, where <i>n</i> is the number of characters in the control's
|
190 |
* <a href="FormControl.html#SubmissionValue">submission value</a>.
|
191 |
* <p>
|
192 |
* The resulting string is {@linkplain CharacterReference#encode(CharSequence) encoded} before output.
|
193 |
* <p>
|
194 |
* The default password character is '<code>*</code>'.
|
195 |
*/
|
196 |
public static volatile char PasswordChar='*';
|
197 |
|
198 |
/**
|
199 |
* Defines the HTML which replaces the {@linkplain #NORMAL normal} <a href="FormControl.html#OutputElement">output element</a>
|
200 |
* of a {@link FormControlType#CHECKBOX CHECKBOX} or {@link FormControlType#RADIO RADIO} form control if it contains a
|
201 |
* <code>checked</code> attribute.
|
202 |
* <p>
|
203 |
* If this property is <code>null</code>, the <a href="FormControl.html#OutputElement">output element</a> is simply a
|
204 |
* {@linkplain FormControl#setDisabled(boolean) disabled} version of the form control.
|
205 |
* <p>
|
206 |
* The HTML is not {@linkplain CharacterReference#encode(CharSequence) encoded} before output.
|
207 |
* <p>
|
208 |
* The default value is <code>null</code>.
|
209 |
*/
|
210 |
public static volatile String CheckedHTML=null;
|
211 |
|
212 |
/**
|
213 |
* Defines the HTML which replaces the {@linkplain #NORMAL normal} <a href="FormControl.html#OutputElement">output element</a>
|
214 |
* of a {@link FormControlType#CHECKBOX CHECKBOX} or {@link FormControlType#RADIO RADIO} form control if it does not contain a
|
215 |
* <code>checked</code> attribute.
|
216 |
* <p>
|
217 |
* If this property is <code>null</code>, the <a href="FormControl.html#OutputElement">output element</a> is simply a
|
218 |
* {@linkplain FormControl#setDisabled(boolean) disabled} version of the form control.
|
219 |
* <p>
|
220 |
* The HTML is not {@linkplain CharacterReference#encode(CharSequence) encoded} before output.
|
221 |
* <p>
|
222 |
* The default value is <code>null</code>.
|
223 |
*/
|
224 |
public static volatile String UncheckedHTML=null;
|
225 |
|
226 |
private ConfigDisplayValue() {}
|
227 |
}
|
228 |
}
|