1 7 8 package org.cyberneko.html; 9 10 17 public class HTMLElements { 18 19 23 25 29 public static final short A = 0; 30 public static final short ABBR = A+1; 31 public static final short ACRONYM = ABBR+1; 32 public static final short ADDRESS = ACRONYM+1; 33 public static final short APPLET = ADDRESS+1; 34 public static final short AREA = APPLET+1; 35 public static final short B = AREA+1; 36 public static final short BASE = B+1; 37 public static final short BASEFONT = BASE+1; 38 public static final short BDO = BASEFONT+1; 39 public static final short BGSOUND = BDO+1; 40 public static final short BIG = BGSOUND+1; 41 public static final short BLINK = BIG+1; 42 public static final short BLOCKQUOTE = BLINK+1; 43 public static final short BODY = BLOCKQUOTE+1; 44 public static final short BR = BODY+1; 45 public static final short BUTTON = BR+1; 46 public static final short CAPTION = BUTTON+1; 47 public static final short CENTER = CAPTION+1; 48 public static final short CITE = CENTER+1; 49 public static final short CODE = CITE+1; 50 public static final short COL = CODE+1; 51 public static final short COLGROUP = COL+1; 52 public static final short COMMENT = COLGROUP+1; 53 public static final short DEL = COMMENT+1; 54 public static final short DFN = DEL+1; 55 public static final short DIR = DFN+1; 56 public static final short DIV = DIR+1; 57 public static final short DD = DIV+1; 58 public static final short DL = DD+1; 59 public static final short DT = DL+1; 60 public static final short EM = DT+1; 61 public static final short EMBED = EM+1; 62 public static final short FIELDSET = EMBED+1; 63 public static final short FONT = FIELDSET+1; 64 public static final short FORM = FONT+1; 65 public static final short FRAME = FORM+1; 66 public static final short FRAMESET = FRAME+1; 67 public static final short H1 = FRAMESET+1; 68 public static final short H2 = H1+1; 69 public static final short H3 = H2+1; 70 public static final short H4 = H3+1; 71 public static final short H5 = H4+1; 72 public static final short H6 = H5+1; 73 public static final short HEAD = H6+1; 74 public static final short HR = HEAD+1; 75 public static final short HTML = HR+1; 76 public static final short I = HTML+1; 77 public static final short IFRAME = I+1; 78 public static final short ILAYER = IFRAME+1; 79 public static final short IMG = ILAYER+1; 80 public static final short INPUT = IMG+1; 81 public static final short INS = INPUT+1; 82 public static final short ISINDEX = INS+1; 83 public static final short KBD = ISINDEX+1; 84 public static final short KEYGEN = KBD+1; 85 public static final short LABEL = KEYGEN+1; 86 public static final short LAYER = LABEL+1; 87 public static final short LEGEND = LAYER+1; 88 public static final short LI = LEGEND+1; 89 public static final short LINK = LI+1; 90 public static final short LISTING = LINK+1; 91 public static final short MAP = LISTING+1; 92 public static final short MARQUEE = MAP+1; 93 public static final short MENU = MARQUEE+1; 94 public static final short META = MENU+1; 95 public static final short MULTICOL = META+1; 96 public static final short NEXTID = MULTICOL+1; 97 public static final short NOBR = NEXTID+1; 98 public static final short NOEMBED = NOBR+1; 99 public static final short NOFRAMES = NOEMBED+1; 100 public static final short NOLAYER = NOFRAMES+1; 101 public static final short NOSCRIPT = NOLAYER+1; 102 public static final short OBJECT = NOSCRIPT+1; 103 public static final short OL = OBJECT+1; 104 public static final short OPTION = OL+1; 105 public static final short OPTGROUP = OPTION+1; 106 public static final short P = OPTGROUP+1; 107 public static final short PARAM = P+1; 108 public static final short PLAINTEXT = PARAM+1; 109 public static final short PRE = PLAINTEXT+1; 110 public static final short Q = PRE+1; 111 public static final short RB = Q+1; 112 public static final short RBC = RB+1; 113 public static final short RP = RBC+1; 114 public static final short RT = RP+1; 115 public static final short RTC = RT+1; 116 public static final short RUBY = RTC+1; 117 public static final short S = RUBY+1; 118 public static final short SAMP = S+1; 119 public static final short SCRIPT = SAMP+1; 120 public static final short SELECT = SCRIPT+1; 121 public static final short SMALL = SELECT+1; 122 public static final short SOUND = SMALL+1; 123 public static final short SPACER = SOUND+1; 124 public static final short SPAN = SPACER+1; 125 public static final short STRIKE = SPAN+1; 126 public static final short STRONG = STRIKE+1; 127 public static final short STYLE = STRONG+1; 128 public static final short SUB = STYLE+1; 129 public static final short SUP = SUB+1; 130 public static final short TABLE = SUP+1; 131 public static final short TBODY = TABLE+1; 132 public static final short TD = TBODY+1; 133 public static final short TEXTAREA = TD+1; 134 public static final short TFOOT = TEXTAREA+1; 135 public static final short TH = TFOOT+1; 136 public static final short THEAD = TH+1; 137 public static final short TITLE = THEAD+1; 138 public static final short TR = TITLE+1; 139 public static final short TT = TR+1; 140 public static final short U = TT+1; 141 public static final short UL = U+1; 142 public static final short VAR = UL+1; 143 public static final short WBR = VAR+1; 144 public static final short XML = WBR+1; 145 public static final short XMP = XML+1; 146 public static final short UNKNOWN = XMP+1; 147 148 150 151 protected static final Element[][] ELEMENTS_ARRAY = new Element[26][]; 152 153 154 protected static final ElementList ELEMENTS = new ElementList(); 155 156 157 public static final Element NO_SUCH_ELEMENT = new Element(UNKNOWN, "", 0, new short[]{HEAD,BODY}, null); 158 159 163 171 static { 172 181 ELEMENTS_ARRAY['A'-'A'] = new Element[] { 183 new Element(A, "A", Element.INLINE, BODY, null), 185 new Element(ABBR, "ABBR", Element.INLINE, BODY, null), 187 new Element(ACRONYM, "ACRONYM", Element.INLINE, BODY, null), 189 new Element(ADDRESS, "ADDRESS", Element.BLOCK, BODY, null), 191 new Element(APPLET, "APPLET", 0, BODY, null), 193 new Element(AREA, "AREA", Element.EMPTY, MAP, null), 195 }; 196 ELEMENTS_ARRAY['B'-'A'] = new Element[] { 197 new Element(B, "B", Element.INLINE, BODY, null), 199 new Element(BASE, "BASE", Element.EMPTY, HEAD, null), 201 new Element(BASEFONT, "BASEFONT", 0, HEAD, null), 203 new Element(BDO, "BDO", Element.INLINE, BODY, null), 205 new Element(BGSOUND, "BGSOUND", Element.EMPTY, HEAD, null), 207 new Element(BIG, "BIG", Element.INLINE, BODY, null), 209 new Element(BLINK, "BLINK", Element.INLINE, BODY, null), 211 new Element(BLOCKQUOTE, "BLOCKQUOTE", Element.BLOCK, BODY, new short[]{P}), 213 new Element(BODY, "BODY", 0, HTML, new short[]{HEAD}), 215 new Element(BR, "BR", Element.EMPTY, BODY, null), 217 new Element(BUTTON, "BUTTON", 0, BODY, null), 219 }; 220 ELEMENTS_ARRAY['C'-'A'] = new Element[] { 221 new Element(CAPTION, "CAPTION", Element.INLINE, TABLE, null), 223 new Element(CENTER, "CENTER", 0, BODY, null), 225 new Element(CITE, "CITE", Element.INLINE, BODY, null), 227 new Element(CODE, "CODE", Element.INLINE, BODY, null), 229 new Element(COL, "COL", Element.EMPTY, TABLE, null), 231 new Element(COLGROUP, "COLGROUP", 0, TABLE, new short[]{COL,COLGROUP}), 233 new Element(COMMENT, "COMMENT", Element.SPECIAL, HTML, null), 235 }; 236 ELEMENTS_ARRAY['D'-'A'] = new Element[] { 237 new Element(DEL, "DEL", 0, BODY, null), 239 new Element(DFN, "DFN", Element.INLINE, BODY, null), 241 new Element(DIR, "DIR", 0, BODY, null), 243 new Element(DIV, "DIV", Element.BLOCK, BODY, null), 245 new Element(DD, "DD", 0, DL, new short[]{DT,DD}), 247 new Element(DL, "DL", Element.BLOCK, BODY, null), 249 new Element(DT, "DT", 0, DL, new short[]{DT,DD}), 251 }; 252 ELEMENTS_ARRAY['E'-'A'] = new Element[] { 253 new Element(EM, "EM", Element.INLINE, BODY, null), 255 new Element(EMBED, "EMBED", 0, BODY, null), 257 }; 258 ELEMENTS_ARRAY['F'-'A'] = new Element[] { 259 new Element(FIELDSET, "FIELDSET", 0, BODY, null), 261 new Element(FONT, "FONT", Element.CONTAINER, BODY, null), 263 new Element(FORM, "FORM", Element.CONTAINER, new short[]{BODY,TD,P,DIV}, new short[]{FORM,BUTTON}), 265 new Element(FRAME, "FRAME", Element.EMPTY, FRAMESET, null), 267 new Element(FRAMESET, "FRAMESET", 0, HTML, null), 269 }; 270 ELEMENTS_ARRAY['H'-'A'] = new Element[] { 271 new Element(H1, "H1", Element.BLOCK, new short[]{BODY,A}, new short[]{H1,H2,H3,H4,H5,H6,P}), 273 new Element(H2, "H2", Element.BLOCK, new short[]{BODY,A}, new short[]{H1,H2,H3,H4,H5,H6,P}), 274 new Element(H3, "H3", Element.BLOCK, new short[]{BODY,A}, new short[]{H1,H2,H3,H4,H5,H6,P}), 275 new Element(H4, "H4", Element.BLOCK, new short[]{BODY,A}, new short[]{H1,H2,H3,H4,H5,H6,P}), 276 new Element(H5, "H5", Element.BLOCK, new short[]{BODY,A}, new short[]{H1,H2,H3,H4,H5,H6,P}), 277 new Element(H6, "H6", Element.BLOCK, new short[]{BODY,A}, new short[]{H1,H2,H3,H4,H5,H6,P}), 278 new Element(HEAD, "HEAD", 0, HTML, null), 280 new Element(HR, "HR", Element.EMPTY, BODY, new short[]{P}), 282 new Element(HTML, "HTML", 0, null, null), 284 }; 285 ELEMENTS_ARRAY['I'-'A'] = new Element[] { 286 new Element(I, "I", Element.INLINE, BODY, null), 288 new Element(IFRAME, "IFRAME", Element.BLOCK, BODY, null), 290 new Element(ILAYER, "ILAYER", Element.BLOCK, BODY, null), 292 new Element(IMG, "IMG", Element.EMPTY, BODY, null), 294 new Element(INPUT, "INPUT", Element.EMPTY, BODY, null), 296 new Element(INS, "INS", 0, BODY, null), 298 new Element(ISINDEX, "ISINDEX", 0, HEAD, null), 300 }; 301 ELEMENTS_ARRAY['K'-'A'] = new Element[] { 302 new Element(KBD, "KBD", Element.INLINE, BODY, null), 304 new Element(KEYGEN, "KEYGEN", 0, BODY, null), 306 }; 307 ELEMENTS_ARRAY['L'-'A'] = new Element[] { 308 new Element(LABEL, "LABEL", 0, BODY, null), 310 new Element(LAYER, "LAYER", Element.BLOCK, BODY, null), 312 new Element(LEGEND, "LEGEND", Element.INLINE, FIELDSET, null), 314 new Element(LI, "LI", 0, new short[]{BODY,UL,OL}, new short[]{LI}), 316 new Element(LINK, "LINK", Element.EMPTY, HEAD, null), 318 new Element(LISTING, "LISTING", 0, BODY, null), 320 }; 321 ELEMENTS_ARRAY['M'-'A'] = new Element[] { 322 new Element(MAP, "MAP", Element.INLINE, BODY, null), 324 new Element(MARQUEE, "MARQUEE", 0, BODY, null), 326 new Element(MENU, "MENU", 0, BODY, null), 328 new Element(META, "META", Element.EMPTY, HEAD, new short[]{STYLE,TITLE}), 330 new Element(MULTICOL, "MULTICOL", 0, BODY, null), 332 }; 333 ELEMENTS_ARRAY['N'-'A'] = new Element[] { 334 new Element(NEXTID, "NEXTID", Element.EMPTY, BODY, null), 336 new Element(NOBR, "NOBR", Element.INLINE, BODY, null), 338 new Element(NOEMBED, "NOEMBED", 0, BODY, null), 340 new Element(NOFRAMES, "NOFRAMES", 0, FRAMESET, null), 342 new Element(NOLAYER, "NOLAYER", 0, BODY, null), 344 new Element(NOSCRIPT, "NOSCRIPT", 0, new short[]{HEAD,BODY}, null), 346 }; 347 ELEMENTS_ARRAY['O'-'A'] = new Element[] { 348 new Element(OBJECT, "OBJECT", 0, BODY, null), 350 new Element(OL, "OL", Element.BLOCK, BODY, null), 352 new Element(OPTGROUP, "OPTGROUP", 0, SELECT, new short[]{OPTION}), 354 new Element(OPTION, "OPTION", 0, SELECT, new short[]{OPTION}), 356 }; 357 ELEMENTS_ARRAY['P'-'A'] = new Element[] { 358 new Element(P, "P", 0, BODY, new short[]{P}), 360 new Element(PARAM, "PARAM", Element.EMPTY, new short[]{OBJECT,APPLET}, null), 362 new Element(PLAINTEXT, "PLAINTEXT", Element.SPECIAL, BODY, null), 364 new Element(PRE, "PRE", 0, BODY, null), 366 }; 367 ELEMENTS_ARRAY['Q'-'A'] = new Element[] { 368 new Element(Q, "Q", Element.INLINE, BODY, null), 370 }; 371 ELEMENTS_ARRAY['R'-'A'] = new Element[] { 372 new Element(RB, "RB", Element.INLINE, RUBY, new short[]{RB}), 374 new Element(RBC, "RBC", 0, RUBY, null), 376 new Element(RP, "RP", Element.INLINE, RUBY, new short[]{RB}), 378 new Element(RT, "RT", Element.INLINE, RUBY, new short[]{RB,RP}), 380 new Element(RTC, "RTC", 0, RUBY, new short[]{RBC}), 382 new Element(RUBY, "RUBY", 0, BODY, new short[]{RUBY}), 384 }; 385 ELEMENTS_ARRAY['S'-'A'] = new Element[] { 386 new Element(S, "S", 0, BODY, null), 388 new Element(SAMP, "SAMP", Element.INLINE, BODY, null), 390 new Element(SCRIPT, "SCRIPT", Element.SPECIAL, new short[]{HEAD,BODY}, null), 392 new Element(SELECT, "SELECT", 0, BODY, new short[]{SELECT}), 394 new Element(SMALL, "SMALL", Element.INLINE, BODY, null), 396 new Element(SOUND, "SOUND", Element.EMPTY, HEAD, null), 398 new Element(SPACER, "SPACER", Element.EMPTY, BODY, null), 400 new Element(SPAN, "SPAN", Element.CONTAINER, BODY, null), 402 new Element(STRIKE, "STRIKE", Element.INLINE, BODY, null), 404 new Element(STRONG, "STRONG", Element.INLINE, BODY, null), 406 new Element(STYLE, "STYLE", Element.SPECIAL, new short[]{HEAD,BODY}, new short[]{STYLE,TITLE,META}), 408 new Element(SUB, "SUB", Element.INLINE, BODY, null), 410 new Element(SUP, "SUP", Element.INLINE, BODY, null), 412 }; 413 ELEMENTS_ARRAY['T'-'A'] = new Element[] { 414 new Element(TABLE, "TABLE", Element.BLOCK|Element.CONTAINER, BODY, null), 416 new Element(TBODY, "TBODY", 0, TABLE, new short[]{THEAD,TD,TH,TR,COLGROUP}), 418 new Element(TD, "TD", 0, TR, TABLE, new short[]{TD,TH}), 420 new Element(TEXTAREA, "TEXTAREA", Element.SPECIAL, BODY, null), 422 new Element(TFOOT, "TFOOT", 0, TABLE, new short[]{THEAD,TBODY,TD,TH,TR}), 424 new Element(TH, "TH", 0, TR, TABLE, new short[]{TD,TH}), 426 new Element(THEAD, "THEAD", 0, TABLE, new short[]{COLGROUP}), 428 new Element(TITLE, "TITLE", 0, new short[]{HEAD,BODY}, null), 430 new Element(TR, "TR", Element.BLOCK, TABLE, new short[]{TD,TH,TR,COLGROUP}), 432 new Element(TT, "TT", Element.INLINE, BODY, null), 434 }; 435 ELEMENTS_ARRAY['U'-'A'] = new Element[] { 436 new Element(U, "U", Element.INLINE, BODY, null), 438 new Element(UL, "UL", Element.BLOCK, BODY, null), 440 }; 441 ELEMENTS_ARRAY['V'-'A'] = new Element[] { 442 new Element(VAR, "VAR", Element.INLINE, BODY, null), 444 }; 445 ELEMENTS_ARRAY['W'-'A'] = new Element[] { 446 new Element(WBR, "WBR", Element.EMPTY, BODY, null), 448 }; 449 ELEMENTS_ARRAY['X'-'A'] = new Element[] { 450 new Element(XML, "XML", 0, BODY, null), 452 new Element(XMP, "XMP", Element.SPECIAL, BODY, null), 454 }; 455 456 for (int i = 0; i < ELEMENTS_ARRAY.length; i++) { 458 Element[] elements = ELEMENTS_ARRAY[i]; 459 if (elements != null) { 460 for (int j = 0; j < elements.length; j++) { 461 Element element = elements[j]; 462 ELEMENTS.addElement(element); 463 } 464 } 465 } 466 ELEMENTS.addElement(NO_SUCH_ELEMENT); 467 468 for (int i = 0; i < ELEMENTS.size; i++) { 470 Element element = ELEMENTS.data[i]; 471 if (element.parentCodes != null) { 472 element.parent = new Element[element.parentCodes.length]; 473 for (int j = 0; j < element.parentCodes.length; j++) { 474 element.parent[j] = ELEMENTS.data[element.parentCodes[j]]; 475 } 476 element.parentCodes = null; 477 } 478 } 479 480 } 482 486 491 public static final Element getElement(short code) { 492 return ELEMENTS.data[code]; 493 } 495 500 public static final Element getElement(String ename) { 501 return getElement(ename, NO_SUCH_ELEMENT); 502 } 504 510 public static final Element getElement(String ename, Element element) { 511 512 if (ename.length() > 0) { 513 int c = ename.charAt(0); 514 if (c >= 'a' && c <= 'z') { 515 c = 'A' + c - 'a'; 516 } 517 if (c >= 'A' && c <= 'Z') { 518 Element[] elements = ELEMENTS_ARRAY[c - 'A']; 519 if (elements != null) { 520 for (int i = 0; i < elements.length; i++) { 521 Element elem = elements[i]; 522 if (elem.name.equalsIgnoreCase(ename)) { 523 return elem; 524 } 525 } 526 } 527 } 528 } 529 return element; 530 531 } 533 537 542 public static class Element { 543 544 548 549 public static final int INLINE = 0x01; 550 551 552 public static final int BLOCK = 0x02; 553 554 555 public static final int EMPTY = 0x04; 556 557 558 public static final int CONTAINER = 0x08; 559 560 561 public static final int SPECIAL = 0x10; 562 563 564 private static final short[] EMPTY_ARRAY = new short[0]; 565 566 570 571 public short code; 572 573 574 public String name; 575 576 577 public int flags; 578 579 580 public short[] parentCodes; 581 582 583 public Element[] parent; 584 585 586 public short bounds; 587 588 589 public short[] closes; 590 591 595 604 public Element(short code, String name, int flags, 605 short parent, short[] closes) { 606 this(code, name, flags, new short[]{parent}, (short)-1, closes); 607 } 609 618 public Element(short code, String name, int flags, 619 short parent, short bounds, short[] closes) { 620 this(code, name, flags, new short[]{parent}, bounds, closes); 621 } 623 632 public Element(short code, String name, int flags, 633 short[] parents, short[] closes) { 634 this(code, name, flags, parents, (short)-1, closes); 635 } 637 646 public Element(short code, String name, int flags, 647 short[] parents, short bounds, short[] closes) { 648 this.code = code; 649 this.name = name; 650 this.flags = flags; 651 this.parentCodes = parents; 652 this.parent = null; 653 this.bounds = bounds; 654 this.closes = closes; 655 } 657 661 662 public final boolean isInline() { 663 return (flags & INLINE) != 0; 664 } 666 667 public final boolean isBlock() { 668 return (flags & BLOCK) != 0; 669 } 671 672 public final boolean isEmpty() { 673 return (flags & EMPTY) != 0; 674 } 676 677 public final boolean isContainer() { 678 return (flags & CONTAINER) != 0; 679 } 681 685 public final boolean isSpecial() { 686 return (flags & SPECIAL) != 0; 687 } 689 694 public boolean closes(short tag) { 695 696 if (closes != null) { 697 for (int i = 0; i < closes.length; i++) { 698 if (closes[i] == tag) { 699 return true; 700 } 701 } 702 } 703 return false; 704 705 } 707 711 712 public int hashCode() { 713 return name.hashCode(); 714 } 716 717 public boolean equals(Object o) { 718 return name.equals(o); 719 } 721 } 723 724 public static class ElementList { 725 726 730 731 public int size; 732 733 734 public Element[] data = new Element[120]; 735 736 740 741 public void addElement(Element element) { 742 if (size == data.length) { 743 Element[] newarray = new Element[size + 20]; 744 System.arraycopy(data, 0, newarray, 0, size); 745 data = newarray; 746 } 747 data[size++] = element; 748 } 750 } 752 } | Popular Tags |