src/share/classes/com/sun/tools/doclint/HtmlTag.java

Wed, 10 Jun 2015 14:22:04 -0700

author
mfang
date
Wed, 10 Jun 2015 14:22:04 -0700
changeset 2815
d4051d4f5daf
parent 2413
fe033d997ddf
child 2525
2eb010b6cb22
child 3315
6f0746b6de9f
permissions
-rw-r--r--

8083601: jdk8u60 l10n resource file translation update 2
Reviewed-by: ksrini, yhuang

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

mercurial