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 |
* Contains {@linkplain TagType tag types} representing Microsoft® <a target="_blank" href="http://en.wikipedia.org/wiki/Conditional_comment">conditional comments</a>.
|
27 |
* <p>
|
28 |
* Officially there are only two types of conditional comment,
|
29 |
* <a target="_blank" href="http://en.wikipedia.org/wiki/Conditional_comment#Downlevel-hidden_conditional_comment">downlevel-hidden</a> and
|
30 |
* <a target="_blank" href="http://en.wikipedia.org/wiki/Conditional_comment#Downlevel-revealed_conditional_comment">downlevel-revealed</a>,
|
31 |
* with each defining a start tag containing an "<code>if</code>" expression and an end tag containing the text "<code>endif</code>".
|
32 |
* <p>
|
33 |
* These four official tags are represented by the tag types
|
34 |
* {@link #DOWNLEVEL_HIDDEN_IF}, {@link #DOWNLEVEL_HIDDEN_ENDIF}, {@link #DOWNLEVEL_REVEALED_IF} and {@link #DOWNLEVEL_REVEALED_ENDIF}.
|
35 |
* <p>
|
36 |
* The conditional expression of an instance of any of the "<code>if</code>" tag types can be extracted using the {@link StartTag#getTagContent()} method.
|
37 |
* For example, if the variable <code>conditionalCommentIfTag</code> represents the tag <code><![if !IE]></code>, then the expression
|
38 |
* <code>conditionalCommentIfTag.getTagContent().toString().trim()</code> yields the string "<code>!IE</code>".
|
39 |
* <p>
|
40 |
* Conditional comments are only recognised by Internet Explorer. All other browsers recognise
|
41 |
* <a target="_blank" href="http://en.wikipedia.org/wiki/Conditional_comment#Downlevel-hidden_conditional_comment">downlevel-hidden</a> conditional comments as
|
42 |
* normal {@linkplain StartTagType#COMMENT comments}, and ignore
|
43 |
* <a target="_blank" href="http://en.wikipedia.org/wiki/Conditional_comment#Downlevel-revealed_conditional_comment">downlevel-revealed</a> conditional comment tags as
|
44 |
* unrecognised.
|
45 |
* <p>
|
46 |
* The use of <a target="_blank" href="http://en.wikipedia.org/wiki/Conditional_comment#Downlevel-revealed_conditional_comment">downlevel-revealed</a> conditional comments
|
47 |
* is generally avoided because they represent invalid HTML code. They can however be replaced by functionally equivalent syntactical constructs based on
|
48 |
* <a target="_blank" href="http://en.wikipedia.org/wiki/Conditional_comment#Downlevel-hidden_conditional_comment">downlevel-hidden</a> conditional comments
|
49 |
* so that the HTML remains valid.
|
50 |
* These composite constructs are represented by the tag types
|
51 |
* {@link #DOWNLEVEL_REVEALED_VALIDATING_IF}, {@link #DOWNLEVEL_REVEALED_VALIDATING_ENDIF} and {@link #DOWNLEVEL_REVEALED_VALIDATING_SIMPLIFIED_IF}.
|
52 |
* <p>
|
53 |
* Because none of the conditional comment end tags start with "<code></</code>", they are represented in this library as
|
54 |
* {@linkplain StartTagType start tag types}, and the parser makes no attempt to match if-endif tag pairs to form {@linkplain Element elements}.
|
55 |
* <p>
|
56 |
* The tag types defined in this class are not {@linkplain TagType#register() registered} by default.
|
57 |
*/
|
58 |
public final class MicrosoftConditionalCommentTagTypes {
|
59 |
|
60 |
/**
|
61 |
* The tag type given to a <a target="_blank" href="http://en.wikipedia.org/wiki/Conditional_comment#Downlevel-hidden_conditional_comment">downlevel-hidden conditional comment</a> <code>if</code> tag
|
62 |
* (<code><!--[if<var> ... </var>]></code>).
|
63 |
* <p>
|
64 |
* The corresponding end tag is represented by the tag type {@link #DOWNLEVEL_HIDDEN_ENDIF}.
|
65 |
* <p>
|
66 |
* <dl>
|
67 |
* <dt>Properties:</dt>
|
68 |
* <dd>
|
69 |
* <table class="bordered" style="margin: 15px" cellspacing="0">
|
70 |
* <tr><th>Property<th>Value
|
71 |
* <tr><td>{@link StartTagType#getDescription() Description}<td>Microsoft downlevel-hidden conditional comment IF
|
72 |
* <tr><td>{@link StartTagType#getStartDelimiter() StartDelimiter}<td><code><!--[if</code>
|
73 |
* <tr><td>{@link StartTagType#getClosingDelimiter() ClosingDelimiter}<td><code>]></code>
|
74 |
* <tr><td>{@link StartTagType#isServerTag() IsServerTag}<td><code>false</code>
|
75 |
* <tr><td>{@link StartTagType#getNamePrefix() NamePrefix}<td><code>!--[if</code>
|
76 |
* <tr><td>{@link StartTagType#getCorrespondingEndTagType() CorrespondingEndTagType}<td><code>null</code>
|
77 |
* <tr><td>{@link StartTagType#hasAttributes() HasAttributes}<td><code>false</code>
|
78 |
* <tr><td>{@link StartTagType#isNameAfterPrefixRequired() IsNameAfterPrefixRequired}<td><code>false</code>
|
79 |
* </table>
|
80 |
* <dt>Example:</dt>
|
81 |
* <dd><code><!--[if IE]></code></dd>
|
82 |
* </dl>
|
83 |
*/
|
84 |
public static final StartTagType DOWNLEVEL_HIDDEN_IF=StartTagTypeMicrosoftDownlevelHiddenConditionalCommentIf.INSTANCE;
|
85 |
|
86 |
/**
|
87 |
* The tag type given to a <a target="_blank" href="http://en.wikipedia.org/wiki/Conditional_comment#Downlevel-hidden_conditional_comment">downlevel-hidden conditional comment</a> <code>endif</code> tag
|
88 |
* (<code><![endif]--></code>).
|
89 |
* <p>
|
90 |
* The corresponding start tag is represented by the tag type {@link #DOWNLEVEL_HIDDEN_IF}.
|
91 |
* <p>
|
92 |
* Although this functions as an end tag, it is represented in this library as a {@linkplain StartTagType start tag type} because it does not start with the characters "<code></</code>".
|
93 |
* <p>
|
94 |
* <dl>
|
95 |
* <dt>Properties:</dt>
|
96 |
* <dd>
|
97 |
* <table class="bordered" style="margin: 15px" cellspacing="0">
|
98 |
* <tr><th>Property<th>Value
|
99 |
* <tr><td>{@link StartTagType#getDescription() Description}<td>Microsoft downlevel-hidden conditional comment ENDIF
|
100 |
* <tr><td>{@link StartTagType#getStartDelimiter() StartDelimiter}<td><code><![endif]--></code>
|
101 |
* <tr><td>{@link StartTagType#getClosingDelimiter() ClosingDelimiter}<td><i>(empty string)</i>
|
102 |
* <tr><td>{@link StartTagType#isServerTag() IsServerTag}<td><code>false</code>
|
103 |
* <tr><td>{@link StartTagType#getNamePrefix() NamePrefix}<td><code>![endif]--></code>
|
104 |
* <tr><td>{@link StartTagType#getCorrespondingEndTagType() CorrespondingEndTagType}<td><code>null</code>
|
105 |
* <tr><td>{@link StartTagType#hasAttributes() HasAttributes}<td><code>false</code>
|
106 |
* <tr><td>{@link StartTagType#isNameAfterPrefixRequired() IsNameAfterPrefixRequired}<td><code>false</code>
|
107 |
* </table>
|
108 |
* <dt>Example:</dt>
|
109 |
* <dd><code><![endif]></code></dd>
|
110 |
* </dl>
|
111 |
*/
|
112 |
public static final StartTagType DOWNLEVEL_HIDDEN_ENDIF=StartTagTypeMicrosoftDownlevelHiddenConditionalCommentEndif.INSTANCE;
|
113 |
|
114 |
/**
|
115 |
* The tag type given to a <a target="_blank" href="http://en.wikipedia.org/wiki/Conditional_comment#Downlevel-revealed_conditional_comment">downlevel-revealed conditional comment</a> <code>if</code> tag
|
116 |
* (<code><![if<var> ... </var>]></code>).
|
117 |
* <p>
|
118 |
* The corresponding end tag is represented by the tag type {@link #DOWNLEVEL_REVEALED_ENDIF}.
|
119 |
* <p>
|
120 |
* <dl>
|
121 |
* <dt>Properties:</dt>
|
122 |
* <dd>
|
123 |
* <table class="bordered" style="margin: 15px" cellspacing="0">
|
124 |
* <tr><th>Property<th>Value
|
125 |
* <tr><td>{@link StartTagType#getDescription() Description}<td>Microsoft downlevel-revealed conditional comment IF
|
126 |
* <tr><td>{@link StartTagType#getStartDelimiter() StartDelimiter}<td><code><![if</code>
|
127 |
* <tr><td>{@link StartTagType#getClosingDelimiter() ClosingDelimiter}<td><code>]></code>
|
128 |
* <tr><td>{@link StartTagType#isServerTag() IsServerTag}<td><code>false</code>
|
129 |
* <tr><td>{@link StartTagType#getNamePrefix() NamePrefix}<td><code>![if</code>
|
130 |
* <tr><td>{@link StartTagType#getCorrespondingEndTagType() CorrespondingEndTagType}<td><code>null</code>
|
131 |
* <tr><td>{@link StartTagType#hasAttributes() HasAttributes}<td><code>false</code>
|
132 |
* <tr><td>{@link StartTagType#isNameAfterPrefixRequired() IsNameAfterPrefixRequired}<td><code>false</code>
|
133 |
* </table>
|
134 |
* <dt>Example:</dt>
|
135 |
* <dd><code><![if !IE]></code></dd>
|
136 |
* </dl>
|
137 |
*/
|
138 |
public static final StartTagType DOWNLEVEL_REVEALED_IF=StartTagTypeMicrosoftDownlevelRevealedConditionalCommentIf.INSTANCE;
|
139 |
|
140 |
/**
|
141 |
* The tag type given to a <a target="_blank" href="http://en.wikipedia.org/wiki/Conditional_comment#Downlevel-revealed_conditional_comment">downlevel-revealed conditional comment</a> <code>endif</code> tag
|
142 |
* (<code><![endif]></code>).
|
143 |
* <p>
|
144 |
* The corresponding start tag is represented by the tag type {@link #DOWNLEVEL_REVEALED_IF}.
|
145 |
* <p>
|
146 |
* Although this functions as an end tag, it is represented in this library as a {@linkplain StartTagType start tag type} because it does not start with the characters "<code></</code>".
|
147 |
* <p>
|
148 |
* <dl>
|
149 |
* <dt>Properties:</dt>
|
150 |
* <dd>
|
151 |
* <table class="bordered" style="margin: 15px" cellspacing="0">
|
152 |
* <tr><th>Property<th>Value
|
153 |
* <tr><td>{@link StartTagType#getDescription() Description}<td>Microsoft downlevel-revealed conditional comment ENDIF
|
154 |
* <tr><td>{@link StartTagType#getStartDelimiter() StartDelimiter}<td><code><![endif]></code>
|
155 |
* <tr><td>{@link StartTagType#getClosingDelimiter() ClosingDelimiter}<td><i>(empty string)</i>
|
156 |
* <tr><td>{@link StartTagType#isServerTag() IsServerTag}<td><code>false</code>
|
157 |
* <tr><td>{@link StartTagType#getNamePrefix() NamePrefix}<td><code>![endif]></code>
|
158 |
* <tr><td>{@link StartTagType#getCorrespondingEndTagType() CorrespondingEndTagType}<td><code>null</code>
|
159 |
* <tr><td>{@link StartTagType#hasAttributes() HasAttributes}<td><code>false</code>
|
160 |
* <tr><td>{@link StartTagType#isNameAfterPrefixRequired() IsNameAfterPrefixRequired}<td><code>false</code>
|
161 |
* </table>
|
162 |
* <dt>Example:</dt>
|
163 |
* <dd><code><![endif]></code></dd>
|
164 |
* </dl>
|
165 |
*/
|
166 |
public static final StartTagType DOWNLEVEL_REVEALED_ENDIF=StartTagTypeMicrosoftDownlevelRevealedConditionalCommentEndif.INSTANCE;
|
167 |
|
168 |
/**
|
169 |
* The tag type given to a validating <a target="_blank" href="http://en.wikipedia.org/wiki/Conditional_comment#Downlevel-revealed_conditional_comment">downlevel-revealed conditional comment</a> <code>if</code> tag
|
170 |
* (<code><!--[if<var> ... </var>]><!--></code>).
|
171 |
* <p>
|
172 |
* The corresponding end tag is represented by the tag type {@link #DOWNLEVEL_REVEALED_VALIDATING_ENDIF}.
|
173 |
* <p>
|
174 |
* This tag is actually a composite syntactical construct containing a
|
175 |
* <a target="_blank" href="http://en.wikipedia.org/wiki/Conditional_comment#Downlevel-hidden_conditional_comment">downlevel-hidden conditional comment</a> <code>if</code> tag.
|
176 |
* <p>
|
177 |
* <dl>
|
178 |
* <dt>Properties:</dt>
|
179 |
* <dd>
|
180 |
* <table class="bordered" style="margin: 15px" cellspacing="0">
|
181 |
* <tr><th>Property<th>Value
|
182 |
* <tr><td>{@link StartTagType#getDescription() Description}<td>Microsoft downlevel-revealed validating conditional comment IF
|
183 |
* <tr><td>{@link StartTagType#getStartDelimiter() StartDelimiter}<td><code><!--[if</code>
|
184 |
* <tr><td>{@link StartTagType#getClosingDelimiter() ClosingDelimiter}<td><code>]><!--></code>
|
185 |
* <tr><td>{@link StartTagType#isServerTag() IsServerTag}<td><code>false</code>
|
186 |
* <tr><td>{@link StartTagType#getNamePrefix() NamePrefix}<td><code>!--[if</code>
|
187 |
* <tr><td>{@link StartTagType#getCorrespondingEndTagType() CorrespondingEndTagType}<td><code>null</code>
|
188 |
* <tr><td>{@link StartTagType#hasAttributes() HasAttributes}<td><code>false</code>
|
189 |
* <tr><td>{@link StartTagType#isNameAfterPrefixRequired() IsNameAfterPrefixRequired}<td><code>false</code>
|
190 |
* </table>
|
191 |
* <dt>Example:</dt>
|
192 |
* <dd><code><!--[if !(IE 5)]><!--></code></dd>
|
193 |
* </dl>
|
194 |
*/
|
195 |
public static final StartTagType DOWNLEVEL_REVEALED_VALIDATING_IF=StartTagTypeMicrosoftDownlevelRevealedValidatingConditionalCommentIf.INSTANCE;
|
196 |
|
197 |
/**
|
198 |
* The tag type given to a validating <a target="_blank" href="http://en.wikipedia.org/wiki/Conditional_comment#Downlevel-revealed_conditional_comment">downlevel-revealed conditional comment</a> <code>endif</code> tag
|
199 |
* (<code><!--<![endif]--></code>).
|
200 |
* <p>
|
201 |
* The corresponding start tag is represented by the tag type {@link #DOWNLEVEL_REVEALED_VALIDATING_IF}.
|
202 |
* <p>
|
203 |
* This tag is actually a composite syntactical construct containing a
|
204 |
* <a target="_blank" href="http://en.wikipedia.org/wiki/Conditional_comment#Downlevel-hidden_conditional_comment">downlevel-hidden conditional comment</a> <code>endif</code> tag.
|
205 |
* <p>
|
206 |
* Although this functions as an end tag, it is represented in this library as a {@linkplain StartTagType start tag type} because it does not start with the characters "<code></</code>".
|
207 |
* <p>
|
208 |
* <dl>
|
209 |
* <dt>Properties:</dt>
|
210 |
* <dd>
|
211 |
* <table class="bordered" style="margin: 15px" cellspacing="0">
|
212 |
* <tr><th>Property<th>Value
|
213 |
* <tr><td>{@link StartTagType#getDescription() Description}<td>Microsoft downlevel-revealed validating conditional comment ENDIF
|
214 |
* <tr><td>{@link StartTagType#getStartDelimiter() StartDelimiter}<td><code><!--<![endif]--></code>
|
215 |
* <tr><td>{@link StartTagType#getClosingDelimiter() ClosingDelimiter}<td><i>(empty string)</i>
|
216 |
* <tr><td>{@link StartTagType#isServerTag() IsServerTag}<td><code>false</code>
|
217 |
* <tr><td>{@link StartTagType#getNamePrefix() NamePrefix}<td><code>!--<![endif]--></code>
|
218 |
* <tr><td>{@link StartTagType#getCorrespondingEndTagType() CorrespondingEndTagType}<td><code>null</code>
|
219 |
* <tr><td>{@link StartTagType#hasAttributes() HasAttributes}<td><code>false</code>
|
220 |
* <tr><td>{@link StartTagType#isNameAfterPrefixRequired() IsNameAfterPrefixRequired}<td><code>false</code>
|
221 |
* </table>
|
222 |
* <dt>Example:</dt>
|
223 |
* <dd><code><!--<![endif]--></code></dd>
|
224 |
* </dl>
|
225 |
*/
|
226 |
public static final StartTagType DOWNLEVEL_REVEALED_VALIDATING_ENDIF=StartTagTypeMicrosoftDownlevelRevealedValidatingConditionalCommentEndif.INSTANCE;
|
227 |
|
228 |
/**
|
229 |
* The tag type given to a validating simplified <a target="_blank" href="http://en.wikipedia.org/wiki/Conditional_comment#Downlevel-revealed_conditional_comment">downlevel-revealed conditional comment</a> <code>if</code> tag
|
230 |
* (<code><!--[if<var> ... </var>]>--></code>).
|
231 |
* <p>
|
232 |
* This form of validating downlevel-revealed conditional comment must only be used when the condition always evaluated to false in Internet Explorer,
|
233 |
* which means the condition should be either "<code>false</code>" or "<code>!IE</code>".
|
234 |
* <p>
|
235 |
* The corresponding end tag is represented by the tag type {@link #DOWNLEVEL_REVEALED_VALIDATING_ENDIF}, which is identical to the corresponding end tag of {@link #DOWNLEVEL_REVEALED_VALIDATING_IF}.
|
236 |
* <p>
|
237 |
* This tag is actually a composite syntactical construct containing a
|
238 |
* <a target="_blank" href="http://en.wikipedia.org/wiki/Conditional_comment#Downlevel-hidden_conditional_comment">downlevel-hidden conditional comment</a> <code>if</code> tag.
|
239 |
* <p>
|
240 |
* <dl>
|
241 |
* <dt>Properties:</dt>
|
242 |
* <dd>
|
243 |
* <table class="bordered" style="margin: 15px" cellspacing="0">
|
244 |
* <tr><th>Property<th>Value
|
245 |
* <tr><td>{@link StartTagType#getDescription() Description}<td>Microsoft downlevel-revealed validating simplified conditional comment IF
|
246 |
* <tr><td>{@link StartTagType#getStartDelimiter() StartDelimiter}<td><code><!--[if</code>
|
247 |
* <tr><td>{@link StartTagType#getClosingDelimiter() ClosingDelimiter}<td><code>]>--></code>
|
248 |
* <tr><td>{@link StartTagType#isServerTag() IsServerTag}<td><code>false</code>
|
249 |
* <tr><td>{@link StartTagType#getNamePrefix() NamePrefix}<td><code>!--[if</code>
|
250 |
* <tr><td>{@link StartTagType#getCorrespondingEndTagType() CorrespondingEndTagType}<td><code>null</code>
|
251 |
* <tr><td>{@link StartTagType#hasAttributes() HasAttributes}<td><code>false</code>
|
252 |
* <tr><td>{@link StartTagType#isNameAfterPrefixRequired() IsNameAfterPrefixRequired}<td><code>false</code>
|
253 |
* </table>
|
254 |
* <dt>Example:</dt>
|
255 |
* <dd><code><!--[if !IE]>--></code></dd>
|
256 |
* </dl>
|
257 |
*/
|
258 |
public static final StartTagType DOWNLEVEL_REVEALED_VALIDATING_SIMPLIFIED_IF=StartTagTypeMicrosoftDownlevelRevealedValidatingSimplifiedConditionalCommentIf.INSTANCE;
|
259 |
|
260 |
private static final TagType[] TAG_TYPES={
|
261 |
DOWNLEVEL_HIDDEN_IF,
|
262 |
DOWNLEVEL_HIDDEN_ENDIF,
|
263 |
DOWNLEVEL_REVEALED_IF,
|
264 |
DOWNLEVEL_REVEALED_ENDIF,
|
265 |
DOWNLEVEL_REVEALED_VALIDATING_IF, // this must come after DOWNLEVEL_HIDDEN_IF so it has higher precedence
|
266 |
DOWNLEVEL_REVEALED_VALIDATING_SIMPLIFIED_IF, // this must come after DOWNLEVEL_HIDDEN_IF so it has higher precedence
|
267 |
DOWNLEVEL_REVEALED_VALIDATING_ENDIF
|
268 |
};
|
269 |
|
270 |
private MicrosoftConditionalCommentTagTypes() {}
|
271 |
|
272 |
/**
|
273 |
* {@linkplain TagType#register() Registers} all of the tag types defined in this class at once.
|
274 |
* <p>
|
275 |
* The tag types must be registered before the parser will recognise them.
|
276 |
*/
|
277 |
public static void register() {
|
278 |
for (TagType tagType : TAG_TYPES) tagType.register();
|
279 |
}
|
280 |
|
281 |
/**
|
282 |
* {@linkplain TagType#deregister() Deregisters} all of the tag types defined in this class at once.
|
283 |
*/
|
284 |
public static void deregister() {
|
285 |
for (TagType tagType : TAG_TYPES) tagType.deregister();
|
286 |
}
|
287 |
|
288 |
/**
|
289 |
* Indicates whether the specified tag type is defined in this class.
|
290 |
*
|
291 |
* @param tagType the {@link TagType} to test.
|
292 |
* @return <code>true</code> if the specified tag type is defined in this class, otherwise <code>false</code>.
|
293 |
*/
|
294 |
public static boolean defines(final TagType tagType) {
|
295 |
for (TagType definedTagType : TAG_TYPES) if (tagType==definedTagType) return true;
|
296 |
return false;
|
297 |
}
|
298 |
|
299 |
}
|
300 |
|