author | briangoetz |
Wed, 18 Dec 2013 16:05:18 -0500 | |
changeset 22163 | 3651128c74eb |
parent 22153 | f9f06fcca59d |
child 25452 | 581d57f5c7d8 |
permissions | -rw-r--r-- |
14952 | 1 |
/* |
15370 | 2 |
* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. |
14952 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. Oracle designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
|
10 |
* |
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
24 |
*/ |
|
25 |
||
26 |
package com.sun.tools.doclint; |
|
27 |
||
28 |
import java.util.Set; |
|
29 |
import java.util.Collections; |
|
30 |
import java.util.EnumMap; |
|
31 |
import java.util.EnumSet; |
|
32 |
import java.util.HashMap; |
|
19511
59a48a75fac7
8022080: javadoc generates invalid HTML in Turkish locale
jjg
parents:
18001
diff
changeset
|
33 |
import java.util.Locale; |
14952 | 34 |
import java.util.Map; |
35 |
||
36 |
import javax.lang.model.element.Name; |
|
37 |
||
38 |
import static com.sun.tools.doclint.HtmlTag.Attr.*; |
|
22153
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
20253
diff
changeset
|
39 |
import com.sun.tools.javac.util.StringUtils; |
14952 | 40 |
|
41 |
/** |
|
42 |
* Enum representing HTML tags. |
|
43 |
* |
|
44 |
* The intent of this class is to embody the semantics of W3C HTML 4.01 |
|
45 |
* to the extent supported/used by javadoc. |
|
19658 | 46 |
* In time, we may wish to transition javadoc and doclint to using HTML 5. |
14952 | 47 |
* |
48 |
* This is derivative of com.sun.tools.doclets.formats.html.markup.HtmlTag. |
|
49 |
* Eventually, these two should be merged back together, and possibly made |
|
50 |
* public. |
|
51 |
* |
|
52 |
* @see <a href="http://www.w3.org/TR/REC-html40/">HTML 4.01 Specification</a> |
|
19658 | 53 |
* @see <a href="http://www.w3.org/TR/html5/">HTML 5 Specification</a> |
14952 | 54 |
* @author Bhavesh Patel |
55 |
* @author Jonathan Gibbons (revised) |
|
56 |
*/ |
|
57 |
public enum HtmlTag { |
|
58 |
A(BlockType.INLINE, EndKind.REQUIRED, |
|
59 |
attrs(AttrKind.OK, HREF, TARGET, NAME)), |
|
60 |
||
61 |
B(BlockType.INLINE, EndKind.REQUIRED, |
|
62 |
EnumSet.of(Flag.EXPECT_CONTENT, Flag.NO_NEST)), |
|
63 |
||
15371
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
64 |
BIG(BlockType.INLINE, EndKind.REQUIRED, |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
65 |
EnumSet.of(Flag.EXPECT_CONTENT)), |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
66 |
|
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
67 |
BLOCKQUOTE(BlockType.BLOCK, EndKind.REQUIRED, |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
68 |
EnumSet.of(Flag.ACCEPTS_BLOCK, Flag.ACCEPTS_INLINE)), |
14952 | 69 |
|
70 |
BODY(BlockType.OTHER, EndKind.REQUIRED), |
|
71 |
||
72 |
BR(BlockType.INLINE, EndKind.NONE, |
|
73 |
attrs(AttrKind.USE_CSS, CLEAR)), |
|
74 |
||
15371
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
75 |
CAPTION(BlockType.TABLE_ITEM, EndKind.REQUIRED, |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
76 |
EnumSet.of(Flag.ACCEPTS_INLINE, Flag.EXPECT_CONTENT)), |
14952 | 77 |
|
15371
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
78 |
CENTER(BlockType.BLOCK, EndKind.REQUIRED, |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
79 |
EnumSet.of(Flag.ACCEPTS_BLOCK, Flag.ACCEPTS_INLINE)), |
14952 | 80 |
|
81 |
CITE(BlockType.INLINE, EndKind.REQUIRED, |
|
82 |
EnumSet.of(Flag.EXPECT_CONTENT, Flag.NO_NEST)), |
|
83 |
||
84 |
CODE(BlockType.INLINE, EndKind.REQUIRED, |
|
85 |
EnumSet.of(Flag.EXPECT_CONTENT, Flag.NO_NEST)), |
|
86 |
||
15371
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
87 |
DD(BlockType.LIST_ITEM, EndKind.OPTIONAL, |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
88 |
EnumSet.of(Flag.ACCEPTS_BLOCK, Flag.ACCEPTS_INLINE, Flag.EXPECT_CONTENT)), |
14952 | 89 |
|
20253 | 90 |
DFN(BlockType.INLINE, EndKind.REQUIRED, |
91 |
EnumSet.of(Flag.EXPECT_CONTENT, Flag.NO_NEST)), |
|
92 |
||
15371
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
93 |
DIV(BlockType.BLOCK, EndKind.REQUIRED, |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
94 |
EnumSet.of(Flag.ACCEPTS_BLOCK, Flag.ACCEPTS_INLINE)), |
14952 | 95 |
|
96 |
DL(BlockType.BLOCK, EndKind.REQUIRED, |
|
15371
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
97 |
EnumSet.of(Flag.EXPECT_CONTENT), |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
98 |
attrs(AttrKind.USE_CSS, COMPACT)) { |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
99 |
@Override |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
100 |
public boolean accepts(HtmlTag t) { |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
101 |
return (t == DT) || (t == DD); |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
102 |
} |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
103 |
}, |
14952 | 104 |
|
15371
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
105 |
DT(BlockType.LIST_ITEM, EndKind.OPTIONAL, |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
106 |
EnumSet.of(Flag.ACCEPTS_INLINE, Flag.EXPECT_CONTENT)), |
14952 | 107 |
|
108 |
EM(BlockType.INLINE, EndKind.REQUIRED, |
|
109 |
EnumSet.of(Flag.NO_NEST)), |
|
110 |
||
111 |
FONT(BlockType.INLINE, EndKind.REQUIRED, // tag itself is deprecated |
|
112 |
EnumSet.of(Flag.EXPECT_CONTENT), |
|
113 |
attrs(AttrKind.USE_CSS, SIZE, COLOR, FACE)), |
|
114 |
||
115 |
FRAME(BlockType.OTHER, EndKind.NONE), |
|
116 |
||
117 |
FRAMESET(BlockType.OTHER, EndKind.REQUIRED), |
|
118 |
||
15371
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
119 |
H1(BlockType.BLOCK, EndKind.REQUIRED), |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
120 |
H2(BlockType.BLOCK, EndKind.REQUIRED), |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
121 |
H3(BlockType.BLOCK, EndKind.REQUIRED), |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
122 |
H4(BlockType.BLOCK, EndKind.REQUIRED), |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
123 |
H5(BlockType.BLOCK, EndKind.REQUIRED), |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
124 |
H6(BlockType.BLOCK, EndKind.REQUIRED), |
14952 | 125 |
|
126 |
HEAD(BlockType.OTHER, EndKind.REQUIRED), |
|
127 |
||
19658 | 128 |
HR(BlockType.BLOCK, EndKind.NONE, |
129 |
attrs(AttrKind.OK, WIDTH)), // OK in 4.01; not allowed in 5 |
|
14952 | 130 |
|
131 |
HTML(BlockType.OTHER, EndKind.REQUIRED), |
|
132 |
||
133 |
I(BlockType.INLINE, EndKind.REQUIRED, |
|
134 |
EnumSet.of(Flag.EXPECT_CONTENT, Flag.NO_NEST)), |
|
135 |
||
136 |
IMG(BlockType.INLINE, EndKind.NONE, |
|
137 |
attrs(AttrKind.OK, SRC, ALT, HEIGHT, WIDTH), |
|
138 |
attrs(AttrKind.OBSOLETE, NAME), |
|
139 |
attrs(AttrKind.USE_CSS, ALIGN, HSPACE, VSPACE, BORDER)), |
|
140 |
||
15371
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
141 |
LI(BlockType.LIST_ITEM, EndKind.OPTIONAL, |
18001 | 142 |
EnumSet.of(Flag.ACCEPTS_BLOCK, Flag.ACCEPTS_INLINE), |
143 |
attrs(AttrKind.OK, VALUE)), |
|
14952 | 144 |
|
145 |
LINK(BlockType.OTHER, EndKind.NONE), |
|
146 |
||
15371
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
147 |
MENU(BlockType.BLOCK, EndKind.REQUIRED) { |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
148 |
@Override |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
149 |
public boolean accepts(HtmlTag t) { |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
150 |
return (t == LI); |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
151 |
} |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
152 |
}, |
14952 | 153 |
|
154 |
META(BlockType.OTHER, EndKind.NONE), |
|
155 |
||
156 |
NOFRAMES(BlockType.OTHER, EndKind.REQUIRED), |
|
157 |
||
15371
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
158 |
NOSCRIPT(BlockType.BLOCK, EndKind.REQUIRED), |
14952 | 159 |
|
160 |
OL(BlockType.BLOCK, EndKind.REQUIRED, |
|
15371
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
161 |
EnumSet.of(Flag.EXPECT_CONTENT), |
19658 | 162 |
attrs(AttrKind.OK, START, TYPE)) { |
15371
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
163 |
@Override |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
164 |
public boolean accepts(HtmlTag t) { |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
165 |
return (t == LI); |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
166 |
} |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
167 |
}, |
14952 | 168 |
|
169 |
P(BlockType.BLOCK, EndKind.OPTIONAL, |
|
170 |
EnumSet.of(Flag.EXPECT_CONTENT), |
|
171 |
attrs(AttrKind.USE_CSS, ALIGN)), |
|
172 |
||
15371
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
173 |
PRE(BlockType.BLOCK, EndKind.REQUIRED, |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
174 |
EnumSet.of(Flag.EXPECT_CONTENT)) { |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
175 |
@Override |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
176 |
public boolean accepts(HtmlTag t) { |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
177 |
switch (t) { |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
178 |
case IMG: case BIG: case SMALL: case SUB: case SUP: |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
179 |
return false; |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
180 |
default: |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
181 |
return (t.blockType == BlockType.INLINE); |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
182 |
} |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
183 |
} |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
184 |
}, |
14952 | 185 |
|
186 |
SCRIPT(BlockType.OTHER, EndKind.REQUIRED), |
|
187 |
||
15371
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
188 |
SMALL(BlockType.INLINE, EndKind.REQUIRED, |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
189 |
EnumSet.of(Flag.EXPECT_CONTENT)), |
14952 | 190 |
|
191 |
SPAN(BlockType.INLINE, EndKind.REQUIRED, |
|
192 |
EnumSet.of(Flag.EXPECT_CONTENT)), |
|
193 |
||
194 |
STRONG(BlockType.INLINE, EndKind.REQUIRED, |
|
195 |
EnumSet.of(Flag.EXPECT_CONTENT)), |
|
196 |
||
197 |
SUB(BlockType.INLINE, EndKind.REQUIRED, |
|
198 |
EnumSet.of(Flag.EXPECT_CONTENT, Flag.NO_NEST)), |
|
199 |
||
200 |
SUP(BlockType.INLINE, EndKind.REQUIRED, |
|
201 |
EnumSet.of(Flag.EXPECT_CONTENT, Flag.NO_NEST)), |
|
202 |
||
203 |
TABLE(BlockType.BLOCK, EndKind.REQUIRED, |
|
15371
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
204 |
EnumSet.of(Flag.EXPECT_CONTENT), |
14952 | 205 |
attrs(AttrKind.OK, SUMMARY, Attr.FRAME, RULES, BORDER, |
19658 | 206 |
CELLPADDING, CELLSPACING, WIDTH), // width OK in 4.01; not allowed in 5 |
207 |
attrs(AttrKind.USE_CSS, ALIGN, BGCOLOR)) { |
|
15371
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
208 |
@Override |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
209 |
public boolean accepts(HtmlTag t) { |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
210 |
switch (t) { |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
211 |
case CAPTION: |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
212 |
case THEAD: case TBODY: case TFOOT: |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
213 |
case TR: // HTML 3.2 |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
214 |
return true; |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
215 |
default: |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
216 |
return false; |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
217 |
} |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
218 |
} |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
219 |
}, |
14952 | 220 |
|
15371
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
221 |
TBODY(BlockType.TABLE_ITEM, EndKind.REQUIRED, |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
222 |
EnumSet.of(Flag.EXPECT_CONTENT), |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
223 |
attrs(AttrKind.OK, ALIGN, CHAR, CHAROFF, VALIGN)) { |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
224 |
@Override |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
225 |
public boolean accepts(HtmlTag t) { |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
226 |
return (t == TR); |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
227 |
} |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
228 |
}, |
14952 | 229 |
|
15371
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
230 |
TD(BlockType.TABLE_ITEM, EndKind.OPTIONAL, |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
231 |
EnumSet.of(Flag.ACCEPTS_BLOCK, Flag.ACCEPTS_INLINE), |
14952 | 232 |
attrs(AttrKind.OK, COLSPAN, ROWSPAN, HEADERS, SCOPE, ABBR, AXIS, |
233 |
ALIGN, CHAR, CHAROFF, VALIGN), |
|
234 |
attrs(AttrKind.USE_CSS, WIDTH, BGCOLOR, HEIGHT, NOWRAP)), |
|
235 |
||
15371
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
236 |
TFOOT(BlockType.TABLE_ITEM, EndKind.REQUIRED, |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
237 |
attrs(AttrKind.OK, ALIGN, CHAR, CHAROFF, VALIGN)) { |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
238 |
@Override |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
239 |
public boolean accepts(HtmlTag t) { |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
240 |
return (t == TR); |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
241 |
} |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
242 |
}, |
14952 | 243 |
|
15371
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
244 |
TH(BlockType.TABLE_ITEM, EndKind.OPTIONAL, |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
245 |
EnumSet.of(Flag.ACCEPTS_BLOCK, Flag.ACCEPTS_INLINE), |
14952 | 246 |
attrs(AttrKind.OK, COLSPAN, ROWSPAN, HEADERS, SCOPE, ABBR, AXIS, |
247 |
ALIGN, CHAR, CHAROFF, VALIGN), |
|
248 |
attrs(AttrKind.USE_CSS, WIDTH, BGCOLOR, HEIGHT, NOWRAP)), |
|
249 |
||
15371
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
250 |
THEAD(BlockType.TABLE_ITEM, EndKind.REQUIRED, |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
251 |
attrs(AttrKind.OK, ALIGN, CHAR, CHAROFF, VALIGN)) { |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
252 |
@Override |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
253 |
public boolean accepts(HtmlTag t) { |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
254 |
return (t == TR); |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
255 |
} |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
256 |
}, |
14952 | 257 |
|
258 |
TITLE(BlockType.OTHER, EndKind.REQUIRED), |
|
259 |
||
15371
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
260 |
TR(BlockType.TABLE_ITEM, EndKind.OPTIONAL, |
14952 | 261 |
attrs(AttrKind.OK, ALIGN, CHAR, CHAROFF, VALIGN), |
15371
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
262 |
attrs(AttrKind.USE_CSS, BGCOLOR)) { |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
263 |
@Override |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
264 |
public boolean accepts(HtmlTag t) { |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
265 |
return (t == TH) || (t == TD); |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
266 |
} |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
267 |
}, |
14952 | 268 |
|
269 |
TT(BlockType.INLINE, EndKind.REQUIRED, |
|
270 |
EnumSet.of(Flag.EXPECT_CONTENT, Flag.NO_NEST)), |
|
271 |
||
272 |
U(BlockType.INLINE, EndKind.REQUIRED, |
|
273 |
EnumSet.of(Flag.EXPECT_CONTENT, Flag.NO_NEST)), |
|
274 |
||
275 |
UL(BlockType.BLOCK, EndKind.REQUIRED, |
|
15371
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
276 |
EnumSet.of(Flag.EXPECT_CONTENT), |
19658 | 277 |
attrs(AttrKind.OK, COMPACT, TYPE)) { // OK in 4.01; not allowed in 5 |
15371
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
278 |
@Override |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
279 |
public boolean accepts(HtmlTag t) { |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
280 |
return (t == LI); |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
281 |
} |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
282 |
}, |
14952 | 283 |
|
284 |
VAR(BlockType.INLINE, EndKind.REQUIRED); |
|
285 |
||
286 |
/** |
|
287 |
* Enum representing the type of HTML element. |
|
288 |
*/ |
|
289 |
public static enum BlockType { |
|
290 |
BLOCK, |
|
291 |
INLINE, |
|
15371
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
292 |
LIST_ITEM, |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
293 |
TABLE_ITEM, |
22163 | 294 |
OTHER |
14952 | 295 |
} |
296 |
||
297 |
/** |
|
298 |
* Enum representing HTML end tag requirement. |
|
299 |
*/ |
|
300 |
public static enum EndKind { |
|
301 |
NONE, |
|
302 |
OPTIONAL, |
|
22163 | 303 |
REQUIRED |
14952 | 304 |
} |
305 |
||
306 |
public static enum Flag { |
|
15371
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
307 |
ACCEPTS_BLOCK, |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
308 |
ACCEPTS_INLINE, |
14952 | 309 |
EXPECT_CONTENT, |
15371
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
310 |
NO_NEST |
14952 | 311 |
} |
312 |
||
313 |
public static enum Attr { |
|
314 |
ABBR, |
|
315 |
ALIGN, |
|
316 |
ALT, |
|
317 |
AXIS, |
|
318 |
BGCOLOR, |
|
319 |
BORDER, |
|
320 |
CELLSPACING, |
|
321 |
CELLPADDING, |
|
322 |
CHAR, |
|
323 |
CHAROFF, |
|
324 |
CLEAR, |
|
325 |
CLASS, |
|
326 |
COLOR, |
|
327 |
COLSPAN, |
|
328 |
COMPACT, |
|
329 |
FACE, |
|
330 |
FRAME, |
|
331 |
HEADERS, |
|
332 |
HEIGHT, |
|
333 |
HREF, |
|
334 |
HSPACE, |
|
335 |
ID, |
|
336 |
NAME, |
|
337 |
NOWRAP, |
|
338 |
REVERSED, |
|
339 |
ROWSPAN, |
|
340 |
RULES, |
|
341 |
SCOPE, |
|
342 |
SIZE, |
|
343 |
SPACE, |
|
344 |
SRC, |
|
345 |
START, |
|
346 |
STYLE, |
|
347 |
SUMMARY, |
|
348 |
TARGET, |
|
349 |
TYPE, |
|
350 |
VALIGN, |
|
18001 | 351 |
VALUE, |
14952 | 352 |
VSPACE, |
353 |
WIDTH; |
|
354 |
||
355 |
public String getText() { |
|
22153
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
20253
diff
changeset
|
356 |
return StringUtils.toLowerCase(name()); |
14952 | 357 |
} |
358 |
||
22163 | 359 |
static final Map<String,Attr> index = new HashMap<>(); |
14952 | 360 |
static { |
361 |
for (Attr t: values()) { |
|
15370 | 362 |
index.put(t.getText(), t); |
14952 | 363 |
} |
364 |
} |
|
365 |
} |
|
366 |
||
367 |
public static enum AttrKind { |
|
368 |
INVALID, |
|
369 |
OBSOLETE, |
|
370 |
USE_CSS, |
|
371 |
OK |
|
372 |
} |
|
373 |
||
374 |
// This class exists to avoid warnings from using parameterized vararg type |
|
375 |
// Map<Attr,AttrKind> in signature of HtmlTag constructor. |
|
376 |
private static class AttrMap extends EnumMap<Attr,AttrKind> { |
|
377 |
private static final long serialVersionUID = 0; |
|
378 |
AttrMap() { |
|
379 |
super(Attr.class); |
|
380 |
} |
|
381 |
} |
|
382 |
||
383 |
||
384 |
public final BlockType blockType; |
|
385 |
public final EndKind endKind; |
|
386 |
public final Set<Flag> flags; |
|
387 |
private final Map<Attr,AttrKind> attrs; |
|
388 |
||
389 |
HtmlTag(BlockType blockType, EndKind endKind, AttrMap... attrMaps) { |
|
390 |
this(blockType, endKind, Collections.<Flag>emptySet(), attrMaps); |
|
391 |
} |
|
392 |
||
393 |
HtmlTag(BlockType blockType, EndKind endKind, Set<Flag> flags, AttrMap... attrMaps) { |
|
394 |
this.blockType = blockType; |
|
15371
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
395 |
this.endKind = endKind; |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
396 |
this.flags = flags; |
22163 | 397 |
this.attrs = new EnumMap<>(Attr.class); |
14952 | 398 |
for (Map<Attr,AttrKind> m: attrMaps) |
399 |
this.attrs.putAll(m); |
|
400 |
attrs.put(Attr.CLASS, AttrKind.OK); |
|
401 |
attrs.put(Attr.ID, AttrKind.OK); |
|
402 |
attrs.put(Attr.STYLE, AttrKind.OK); |
|
403 |
} |
|
404 |
||
15371
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
405 |
public boolean accepts(HtmlTag t) { |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
406 |
if (flags.contains(Flag.ACCEPTS_BLOCK) && flags.contains(Flag.ACCEPTS_INLINE)) { |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
407 |
return (t.blockType == BlockType.BLOCK) || (t.blockType == BlockType.INLINE); |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
408 |
} else if (flags.contains(Flag.ACCEPTS_BLOCK)) { |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
409 |
return (t.blockType == BlockType.BLOCK); |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
410 |
} else if (flags.contains(Flag.ACCEPTS_INLINE)) { |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
411 |
return (t.blockType == BlockType.INLINE); |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
412 |
} else |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
413 |
switch (blockType) { |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
414 |
case BLOCK: |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
415 |
case INLINE: |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
416 |
return (t.blockType == BlockType.INLINE); |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
417 |
case OTHER: |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
418 |
// OTHER tags are invalid in doc comments, and will be |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
419 |
// reported separately, so silently accept/ignore any content |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
420 |
return true; |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
421 |
default: |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
422 |
// any combination which could otherwise arrive here |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
423 |
// ought to have been handled in an overriding method |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
424 |
throw new AssertionError(this + ":" + t); |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
425 |
} |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
426 |
} |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
427 |
|
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
428 |
public boolean acceptsText() { |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
429 |
// generally, anywhere we can put text we can also put inline tag |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
430 |
// so check if a typical inline tag is allowed |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
431 |
return accepts(B); |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
432 |
} |
8f719dc43e1f
8006251: doclint: incorrect position for diagnostic for illegal text in tags
jjg
parents:
15370
diff
changeset
|
433 |
|
14952 | 434 |
public String getText() { |
22153
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
20253
diff
changeset
|
435 |
return StringUtils.toLowerCase(name()); |
14952 | 436 |
} |
437 |
||
438 |
public Attr getAttr(Name attrName) { |
|
22153
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
20253
diff
changeset
|
439 |
return Attr.index.get(StringUtils.toLowerCase(attrName.toString())); |
14952 | 440 |
} |
441 |
||
442 |
public AttrKind getAttrKind(Name attrName) { |
|
443 |
AttrKind k = attrs.get(getAttr(attrName)); // null-safe |
|
444 |
return (k == null) ? AttrKind.INVALID : k; |
|
445 |
} |
|
446 |
||
447 |
private static AttrMap attrs(AttrKind k, Attr... attrs) { |
|
448 |
AttrMap map = new AttrMap(); |
|
449 |
for (Attr a: attrs) map.put(a, k); |
|
450 |
return map; |
|
451 |
} |
|
452 |
||
22163 | 453 |
private static final Map<String,HtmlTag> index = new HashMap<>(); |
14952 | 454 |
static { |
455 |
for (HtmlTag t: values()) { |
|
15370 | 456 |
index.put(t.getText(), t); |
14952 | 457 |
} |
458 |
} |
|
459 |
||
460 |
static HtmlTag get(Name tagName) { |
|
22153
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
20253
diff
changeset
|
461 |
return index.get(StringUtils.toLowerCase(tagName.toString())); |
19511
59a48a75fac7
8022080: javadoc generates invalid HTML in Turkish locale
jjg
parents:
18001
diff
changeset
|
462 |
} |
59a48a75fac7
8022080: javadoc generates invalid HTML in Turkish locale
jjg
parents:
18001
diff
changeset
|
463 |
|
14952 | 464 |
} |