1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 4906 4907 4908 4909 4910 4911 4912 4913 4914 4915 4916 4917 4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 4929 4930 4931 4932 4933 4934 4935 4936 4937 4938 4939 4940 4941 4942 4943 4944 4945 4946 4947 4948 4949 4950 4951 4952 4953 4954 4955 4956 4957 4958 4959 4960 4961 4962 4963 4964 4965 4966 4967 4968 4969 4970 4971 4972 4973 4974 4975 4976 4977 4978 4979 4980 4981 4982 4983 4984 4985 4986 4987 4988 4989 4990 4991 4992 4993 4994 4995 4996 4997 4998 4999 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 5034 5035 5036 5037 5038 5039 5040 5041 5042 5043 5044 5045 5046 5047 5048 5049 5050 5051 5052 5053 5054 5055 5056 5057 5058 5059 5060 5061 5062 5063 5064 5065 5066 5067 5068 5069 5070 5071 5072 5073 5074 5075 5076 5077 5078 5079 5080 5081 5082 5083 5084 5085 5086 5087 5088 5089 5090 5091 5092 5093 5094 5095 5096 5097 5098 5099 5100 5101 5102 5103 5104 5105 5106 5107 5108 5109 5110 5111 5112 5113 5114 5115 5116 5117 5118 5119 5120 5121 5122 5123 5124 5125 5126 5127 5128 5129 5130 5131 5132 5133 5134 5135 5136 5137 5138 5139 5140 5141 5142 5143 5144 5145 5146 5147 5148 5149 5150 5151 5152 5153 5154 5155 5156 5157 5158 5159 5160 5161 5162 5163 5164 5165 5166 5167 5168 5169 5170 5171 5172 5173 5174 5175 5176 5177 5178 5179 5180 5181 5182 5183 5184 5185 5186 5187 5188 5189 5190 5191 5192 5193 5194 5195 5196 5197 5198 5199 5200 5201 5202 5203 5204 5205 5206 5207 5208 5209 5210 5211 5212 5213 5214 5215 5216 5217 5218 5219 5220 5221 5222 5223 5224 5225 5226 5227 5228 5229 5230 5231 5232 5233 5234 5235 5236 5237 5238 5239 5240 5241 5242 5243 5244 5245 5246 5247 5248 5249 5250 5251 5252 5253 5254 5255 5256 5257 5258 5259 5260 5261 5262 5263 5264 5265 5266 5267 5268 5269 5270 5271 5272 5273 5274 5275 5276 5277 5278 5279 5280 5281 5282 5283 5284 5285 5286 5287 5288 5289 5290 5291 5292 5293 5294 5295 5296 5297 5298 5299 5300 5301 5302 5303 5304 5305 5306 5307 5308 5309 5310 5311 5312 5313 5314 5315 5316 5317 5318 5319 5320 5321 5322 5323 5324 5325 5326 5327 5328 5329 5330 5331 5332 5333 5334 5335 5336 5337 5338 5339 5340 5341 5342 5343 5344 5345 5346 5347 5348 5349 5350 5351 5352 5353 5354 5355 5356 5357 5358 5359 5360 5361 5362 5363 5364 5365 5366 5367 5368 5369 5370 5371 5372 5373 5374 5375 5376 5377 5378 5379 5380 5381 5382 5383 5384 5385 5386 5387 5388 5389 5390 5391 5392 5393 5394 5395 5396 5397 5398 5399 5400 5401 5402 5403 5404 5405 5406 5407 5408 5409 5410 5411 5412 5413 5414 5415 5416 5417 5418 5419 5420 5421 5422 5423 5424 5425 5426 5427 5428 5429 5430 5431 5432 5433 5434 5435 5436 5437 5438 5439 5440 5441 5442 5443 5444 5445 5446 5447 5448 5449 5450 5451 5452 5453 5454 5455 5456 5457 5458 5459 5460 5461 5462 5463 5464 5465 5466 5467 5468 5469 5470 5471 5472 5473 5474 5475 5476 5477 5478 5479 5480 5481 5482 5483 5484 5485 5486 5487 5488 5489 5490 5491 5492 5493 5494 5495 5496 5497 5498 5499 5500 5501 5502 5503 5504 5505 5506 5507 5508 5509 5510 5511 5512 5513 5514 5515 5516 5517 5518 5519 5520 5521 5522 5523 5524 5525 5526 5527 5528 5529 5530 5531 5532 5533 5534 5535 5536 5537 5538 5539 5540 5541 5542 5543 5544 5545 5546 5547 5548 5549 5550 5551 5552 5553 5554 5555 5556 5557 5558 5559 5560 5561 5562 5563 5564 5565 5566 5567 5568 5569 5570 5571 5572 5573 5574 5575 5576 5577 5578 5579 5580 5581 5582 5583 5584 5585 5586 5587 5588 5589 5590 5591 5592 5593 5594 5595 5596 5597 5598 5599 5600 5601 5602 5603 5604 5605 5606 5607 5608 5609 5610 5611 5612 5613 5614 5615 5616 5617 5618 5619 5620 5621 5622 5623 5624 5625 5626 5627 5628 5629 5630 5631 5632 5633 5634 5635 5636 5637 5638 5639 5640 5641 5642 5643 5644 5645 5646 5647 5648 5649 5650 5651 5652 5653 5654 5655 5656 5657 5658 5659 5660 5661 5662 5663 5664 5665 5666 5667 5668 5669 5670 5671 5672 5673 5674 5675 5676 5677 5678 5679 5680 5681 5682 5683 5684 5685 5686 5687 5688 5689 5690 5691 5692 5693 5694 5695 5696 5697 5698 5699 5700 5701 5702 5703 5704 5705 5706 5707 5708 5709 5710 5711 5712 5713 5714 5715 5716 5717 5718 5719 5720 5721 5722 5723 5724 5725 5726 5727 5728 5729 5730 5731 5732 5733 5734 5735 5736 5737 5738 5739 5740 5741 5742 5743 5744 5745 5746 5747 5748 5749 5750 5751 5752 5753 5754 5755 5756 5757 5758 5759 5760 5761 5762 5763 5764 5765 5766 5767 5768 5769 5770 5771 5772 5773 5774 5775 5776 5777 5778 5779 5780 5781 5782 5783 5784 5785 5786 5787 5788 5789 5790 5791 5792 5793 5794 5795 5796 5797 5798 5799 5800 5801 5802 5803 5804 5805 5806 5807 5808 5809 5810 5811 5812 5813 5814 5815 5816 5817 5818 5819 5820 5821 5822 5823 5824 5825 5826 5827 5828 5829 5830 5831 5832 5833 5834 5835 5836 5837 5838 5839 5840 5841 5842 5843 5844 5845 5846 5847 5848 5849 5850 5851 5852 5853 5854 5855 5856 5857 5858 5859 5860 5861 5862 5863 5864 5865 5866 5867 5868 5869 5870 5871 5872 5873 5874 5875 5876 5877 5878 5879 5880 5881 5882 5883 5884 5885 5886 5887 5888 5889 5890 5891 5892 5893 5894 5895 5896 5897 5898 5899 5900 5901 5902 5903 5904 5905 5906 5907 5908 5909 5910 5911 5912 5913 5914 5915 5916 5917 5918 5919 5920 5921 5922 5923 5924 5925 5926 5927 5928 5929 5930 5931 5932 5933 5934 5935 5936 5937 5938 5939 5940 5941 5942 5943 5944 5945 5946 5947 5948 5949 5950 5951 5952 5953 5954 5955 5956 5957 5958 5959 5960 5961 5962 5963 5964 5965 5966 5967 5968 5969 5970 5971 5972 5973 5974 5975 5976 5977 5978 5979 5980 5981 5982 5983 5984 5985 5986 5987 5988 5989 5990 5991 5992 5993 5994 5995 5996 5997 5998 5999 6000 6001 6002 6003 6004 6005 6006 6007 6008 6009 6010 6011 6012 6013 6014 6015 6016 6017 6018 6019 6020 6021 6022 6023 6024 6025 6026 6027 6028 6029 6030 6031 6032 6033 6034 6035 6036 6037 6038 6039 6040 6041 6042 6043 6044 6045 6046 6047 6048 6049 6050 6051 6052 6053 6054 6055 6056 6057 6058 6059 6060 6061 6062 6063 6064 6065 6066 6067 6068 6069 6070 6071 6072 6073 6074 6075 6076 6077 6078 6079 6080 6081 6082 6083 6084 6085 6086 6087 6088 6089 6090 6091 6092 6093 6094 6095 6096 6097 6098 6099 6100 6101 6102 6103 6104 6105 6106 6107 6108 6109 6110 6111 6112 6113 6114 6115 6116 6117 6118 6119 6120 6121 6122 6123 6124 6125 6126 6127 6128 6129 6130 6131 6132 6133 6134 6135 6136 6137 6138 6139 6140 6141 6142 6143 6144 6145 6146 6147 6148 6149 6150 6151 6152 6153 6154 6155 6156 6157 6158 6159 6160 6161 6162 6163 6164 6165 6166 6167 6168 6169 6170 6171 6172 6173 6174 6175 6176 6177 6178 6179 6180 6181 6182 6183 6184 6185 6186 6187 6188 6189 6190 6191 6192 6193 6194 6195 6196 6197 6198 6199 6200 6201 6202 6203 6204 6205 6206 6207 6208 6209 6210 6211 6212 6213 6214 6215 6216 6217 6218 6219 6220 6221 6222 6223 6224 6225 6226 6227 6228 6229 6230 6231 6232 6233 6234 6235 6236 6237 6238 6239 6240 6241 6242 6243 6244 6245 6246 6247 6248 6249 6250 6251 6252 6253 6254 6255 6256 6257 6258 6259 6260 6261 6262 6263 6264 6265 6266 6267 6268 6269 6270 6271 6272 6273 6274 6275 6276 6277 6278 6279 6280 6281 6282 6283 6284 6285 6286 6287 6288 6289 6290 6291 6292 6293 6294 6295 6296 6297 6298 6299 6300 6301 6302 6303 6304 6305 6306 6307 6308 6309 6310 6311 6312 6313 6314 6315 6316 6317 6318 6319 6320 6321 6322 6323 6324 6325 6326 6327 6328 6329 6330 6331 6332 6333 6334 6335 6336 6337 6338 6339 6340 6341 6342 6343 6344 6345 6346 6347 6348 6349 6350 6351 6352 6353 6354 6355 6356 6357 6358 6359 6360 6361 6362 6363 6364 6365 6366 6367 6368 6369 6370 6371 6372 6373 6374 6375 6376 6377 6378 6379 6380 6381 6382 6383 6384 6385 6386 6387 6388 6389 6390 6391 6392 6393 6394 6395 6396 6397 6398 6399 6400 6401 6402 6403 6404 6405 6406 6407 6408 6409 6410 6411 6412 6413 6414 6415 6416 6417 6418 6419 6420 6421 6422 6423 6424 6425 6426 6427 6428 6429 6430 6431 6432 6433 6434 6435 6436 6437 6438 6439 6440 6441 6442 6443 6444 6445 6446 6447 6448 6449 6450 6451 6452 6453 6454 6455 6456 6457 6458 6459 6460 6461 6462 6463 6464 6465 6466 6467 6468 6469 6470 6471 6472 6473 6474 6475 6476 6477 6478 6479 6480 6481 6482 6483 6484 6485 6486 6487 6488 6489 6490 6491 6492 6493 6494 6495 6496 6497 6498 6499 6500 6501 6502 6503 6504 6505 6506 6507 6508 6509 6510 6511 6512 6513 6514 6515 6516 6517 6518 6519 6520 6521 6522 6523 6524 6525 6526 6527 6528 6529 6530 6531 6532 6533 6534 6535 6536 6537 6538 6539 6540 6541 6542 6543 6544 6545 6546 6547 6548 6549 6550
|
/*
* Copyright (c) 2007 Henri Sivonen
* Copyright (c) 2007-2017 Mozilla Foundation
* Portions of comments Copyright 2004-2008 Apple Computer, Inc., Mozilla
* Foundation, and Opera Software ASA.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
/*
* The comments following this one that use the same comment syntax as this
* comment are quotes from the WHATWG HTML 5 spec as of 27 June 2007
* amended as of June 28 2007.
* That document came with this statement:
* "© Copyright 2004-2007 Apple Computer, Inc., Mozilla Foundation, and
* Opera Software ASA. You are granted a license to use, reproduce and
* create derivative works of this document."
*/
package nu.validator.htmlparser.impl;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.xml.sax.ErrorHandler;
import org.xml.sax.Locator;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
import nu.validator.htmlparser.annotation.Auto;
import nu.validator.htmlparser.annotation.Const;
import nu.validator.htmlparser.annotation.IdType;
import nu.validator.htmlparser.annotation.Inline;
import nu.validator.htmlparser.annotation.Literal;
import nu.validator.htmlparser.annotation.Local;
import nu.validator.htmlparser.annotation.NoLength;
import nu.validator.htmlparser.annotation.NsUri;
import nu.validator.htmlparser.common.DocumentMode;
import nu.validator.htmlparser.common.DocumentModeHandler;
import nu.validator.htmlparser.common.Interner;
import nu.validator.htmlparser.common.TokenHandler;
import nu.validator.htmlparser.common.XmlViolationPolicy;
public abstract class TreeBuilder<T> implements TokenHandler,
TreeBuilderState<T> {
/**
* Array version of U+FFFD.
*/
private static final @NoLength char[] REPLACEMENT_CHARACTER = { '\uFFFD' };
// Start dispatch groups
final static int OTHER = 0;
final static int A = 1;
final static int BASE = 2;
final static int BODY = 3;
final static int BR = 4;
final static int BUTTON = 5;
final static int CAPTION = 6;
final static int COL = 7;
final static int COLGROUP = 8;
final static int FORM = 9;
final static int FRAME = 10;
final static int FRAMESET = 11;
final static int IMAGE = 12;
final static int INPUT = 13;
final static int RT_OR_RP = 14;
final static int LI = 15;
final static int LINK_OR_BASEFONT_OR_BGSOUND = 16;
final static int MATH = 17;
final static int META = 18;
final static int SVG = 19;
final static int HEAD = 20;
final static int HR = 22;
final static int HTML = 23;
final static int NOBR = 24;
final static int NOFRAMES = 25;
final static int NOSCRIPT = 26;
final static int OPTGROUP = 27;
final static int OPTION = 28;
final static int P = 29;
final static int PLAINTEXT = 30;
final static int SCRIPT = 31;
final static int SELECT = 32;
final static int STYLE = 33;
final static int TABLE = 34;
final static int TEXTAREA = 35;
final static int TITLE = 36;
final static int TR = 37;
final static int XMP = 38;
final static int TBODY_OR_THEAD_OR_TFOOT = 39;
final static int TD_OR_TH = 40;
final static int DD_OR_DT = 41;
final static int H1_OR_H2_OR_H3_OR_H4_OR_H5_OR_H6 = 42;
final static int MARQUEE_OR_APPLET = 43;
final static int PRE_OR_LISTING = 44;
final static int B_OR_BIG_OR_CODE_OR_EM_OR_I_OR_S_OR_SMALL_OR_STRIKE_OR_STRONG_OR_TT_OR_U = 45;
final static int UL_OR_OL_OR_DL = 46;
final static int IFRAME = 47;
final static int EMBED = 48;
final static int AREA_OR_WBR = 49;
final static int DIV_OR_BLOCKQUOTE_OR_CENTER_OR_MENU = 50;
final static int ADDRESS_OR_ARTICLE_OR_ASIDE_OR_DETAILS_OR_DIALOG_OR_DIR_OR_FIGCAPTION_OR_FIGURE_OR_FOOTER_OR_HEADER_OR_HGROUP_OR_MAIN_OR_NAV_OR_SECTION_OR_SUMMARY = 51;
final static int RUBY_OR_SPAN_OR_SUB_OR_SUP_OR_VAR = 52;
final static int RB_OR_RTC = 53;
final static int PARAM_OR_SOURCE_OR_TRACK = 55;
final static int MGLYPH_OR_MALIGNMARK = 56;
final static int MI_MO_MN_MS_MTEXT = 57;
final static int ANNOTATION_XML = 58;
final static int FOREIGNOBJECT_OR_DESC = 59;
final static int NOEMBED = 60;
final static int FIELDSET = 61;
final static int OUTPUT = 62;
final static int OBJECT = 63;
final static int FONT = 64;
final static int KEYGEN = 65;
final static int TEMPLATE = 66;
final static int IMG = 67;
// start insertion modes
private static final int IN_ROW = 0;
private static final int IN_TABLE_BODY = 1;
private static final int IN_TABLE = 2;
private static final int IN_CAPTION = 3;
private static final int IN_CELL = 4;
private static final int FRAMESET_OK = 5;
private static final int IN_BODY = 6;
private static final int IN_HEAD = 7;
private static final int IN_HEAD_NOSCRIPT = 8;
// no fall-through
private static final int IN_COLUMN_GROUP = 9;
// no fall-through
private static final int IN_SELECT_IN_TABLE = 10;
private static final int IN_SELECT = 11;
// no fall-through
private static final int AFTER_BODY = 12;
// no fall-through
private static final int IN_FRAMESET = 13;
private static final int AFTER_FRAMESET = 14;
// no fall-through
private static final int INITIAL = 15;
// could add fall-through
private static final int BEFORE_HTML = 16;
// could add fall-through
private static final int BEFORE_HEAD = 17;
// no fall-through
private static final int AFTER_HEAD = 18;
// no fall-through
private static final int AFTER_AFTER_BODY = 19;
// no fall-through
private static final int AFTER_AFTER_FRAMESET = 20;
// no fall-through
private static final int TEXT = 21;
private static final int IN_TEMPLATE = 22;
// start charset states
private static final int CHARSET_INITIAL = 0;
private static final int CHARSET_C = 1;
private static final int CHARSET_H = 2;
private static final int CHARSET_A = 3;
private static final int CHARSET_R = 4;
private static final int CHARSET_S = 5;
private static final int CHARSET_E = 6;
private static final int CHARSET_T = 7;
private static final int CHARSET_EQUALS = 8;
private static final int CHARSET_SINGLE_QUOTED = 9;
private static final int CHARSET_DOUBLE_QUOTED = 10;
private static final int CHARSET_UNQUOTED = 11;
// end pseudo enums
@Literal private final static String[] QUIRKY_PUBLIC_IDS = {
"+//silmaril//dtd html pro v0r11 19970101//",
"-//advasoft ltd//dtd html 3.0 aswedit + extensions//",
"-//as//dtd html 3.0 aswedit + extensions//",
"-//ietf//dtd html 2.0 level 1//",
"-//ietf//dtd html 2.0 level 2//",
"-//ietf//dtd html 2.0 strict level 1//",
"-//ietf//dtd html 2.0 strict level 2//",
"-//ietf//dtd html 2.0 strict//",
"-//ietf//dtd html 2.0//",
"-//ietf//dtd html 2.1e//",
"-//ietf//dtd html 3.0//",
"-//ietf//dtd html 3.2 final//",
"-//ietf//dtd html 3.2//",
"-//ietf//dtd html 3//",
"-//ietf//dtd html level 0//",
"-//ietf//dtd html level 1//",
"-//ietf//dtd html level 2//",
"-//ietf//dtd html level 3//",
"-//ietf//dtd html strict level 0//",
"-//ietf//dtd html strict level 1//",
"-//ietf//dtd html strict level 2//",
"-//ietf//dtd html strict level 3//",
"-//ietf//dtd html strict//",
"-//ietf//dtd html//",
"-//metrius//dtd metrius presentational//",
"-//microsoft//dtd internet explorer 2.0 html strict//",
"-//microsoft//dtd internet explorer 2.0 html//",
"-//microsoft//dtd internet explorer 2.0 tables//",
"-//microsoft//dtd internet explorer 3.0 html strict//",
"-//microsoft//dtd internet explorer 3.0 html//",
"-//microsoft//dtd internet explorer 3.0 tables//",
"-//netscape comm. corp.//dtd html//",
"-//netscape comm. corp.//dtd strict html//",
"-//o'reilly and associates//dtd html 2.0//",
"-//o'reilly and associates//dtd html extended 1.0//",
"-//o'reilly and associates//dtd html extended relaxed 1.0//",
"-//softquad software//dtd hotmetal pro 6.0::19990601::extensions to html 4.0//",
"-//softquad//dtd hotmetal pro 4.0::19971010::extensions to html 4.0//",
"-//spyglass//dtd html 2.0 extended//",
"-//sq//dtd html 2.0 hotmetal + extensions//",
"-//sun microsystems corp.//dtd hotjava html//",
"-//sun microsystems corp.//dtd hotjava strict html//",
"-//w3c//dtd html 3 1995-03-24//", "-//w3c//dtd html 3.2 draft//",
"-//w3c//dtd html 3.2 final//", "-//w3c//dtd html 3.2//",
"-//w3c//dtd html 3.2s draft//", "-//w3c//dtd html 4.0 frameset//",
"-//w3c//dtd html 4.0 transitional//",
"-//w3c//dtd html experimental 19960712//",
"-//w3c//dtd html experimental 970421//", "-//w3c//dtd w3 html//",
"-//w3o//dtd w3 html 3.0//", "-//webtechs//dtd mozilla html 2.0//",
"-//webtechs//dtd mozilla html//" };
private static final int NOT_FOUND_ON_STACK = Integer.MAX_VALUE;
// [NOCPP[
private static final @Local String HTML_LOCAL = "html";
// ]NOCPP]
private int mode = INITIAL;
private int originalMode = INITIAL;
/**
* Used only when moving back to IN_BODY.
*/
private boolean framesetOk = true;
protected Tokenizer tokenizer;
// [NOCPP[
protected ErrorHandler errorHandler;
private DocumentModeHandler documentModeHandler;
// ]NOCPP]
private boolean scriptingEnabled = false;
private boolean needToDropLF;
// [NOCPP[
private boolean wantingComments;
// ]NOCPP]
private boolean fragment;
private @Local String contextName;
private @NsUri String contextNamespace;
private T contextNode;
/**
* Stack of template insertion modes
*/
private @Auto int[] templateModeStack;
/**
* Current template mode stack pointer.
*/
private int templateModePtr = -1;
private @Auto StackNode<T>[] stackNodes;
/**
* Index of the earliest possible unused or empty element in stackNodes.
*/
private int stackNodesIdx = -1;
private int numStackNodes = 0;
private @Auto StackNode<T>[] stack;
private int currentPtr = -1;
private @Auto StackNode<T>[] listOfActiveFormattingElements;
private int listPtr = -1;
private T formPointer;
private T headPointer;
protected @Auto char[] charBuffer;
protected int charBufferLen = 0;
private boolean quirks = false;
private boolean forceNoQuirks = false;
// [NOCPP[
private boolean reportingDoctype = true;
private XmlViolationPolicy namePolicy = XmlViolationPolicy.ALTER_INFOSET;
private final Map<String, LocatorImpl> idLocations = new HashMap<String, LocatorImpl>();
// ]NOCPP]
protected TreeBuilder() {
fragment = false;
}
/**
* Reports an condition that would make the infoset incompatible with XML
* 1.0 as fatal.
*
* @throws SAXException
* @throws SAXParseException
*/
protected void fatal() throws SAXException {
}
// CPPONLY: @Inline private @Creator Object htmlCreator(@HtmlCreator Object htmlCreator) {
// CPPONLY: @Creator Object creator;
// CPPONLY: creator.html = htmlCreator;
// CPPONLY: return creator;
// CPPONLY: }
// CPPONLY:
// CPPONLY: @Inline private @Creator Object svgCreator(@SvgCreator Object svgCreator) {
// CPPONLY: @Creator Object creator;
// CPPONLY: creator.svg = svgCreator;
// CPPONLY: return creator;
// CPPONLY: }
// [NOCPP[
protected final void fatal(Exception e) throws SAXException {
SAXParseException spe = new SAXParseException(e.getMessage(),
tokenizer, e);
if (errorHandler != null) {
errorHandler.fatalError(spe);
}
throw spe;
}
final void fatal(String s) throws SAXException {
SAXParseException spe = new SAXParseException(s, tokenizer);
if (errorHandler != null) {
errorHandler.fatalError(spe);
}
throw spe;
}
/**
* Reports a Parse Error.
*
* @param message
* the message
* @throws SAXException
*/
final void err(String message) throws SAXException {
if (errorHandler == null) {
return;
}
errNoCheck(message);
}
/**
* Reports a Parse Error without checking if an error handler is present.
*
* @param message
* the message
* @throws SAXException
*/
final void errNoCheck(String message) throws SAXException {
SAXParseException spe = new SAXParseException(message, tokenizer);
errorHandler.error(spe);
}
private void errListUnclosedStartTags(int eltPos) throws SAXException {
if (currentPtr != -1) {
for (int i = currentPtr; i > eltPos; i--) {
reportUnclosedElementNameAndLocation(i);
}
}
}
/**
* Reports the name and location of an unclosed element.
*
* @throws SAXException
*/
private final void reportUnclosedElementNameAndLocation(int pos) throws SAXException {
StackNode<T> node = stack[pos];
if (node.isOptionalEndTag()) {
return;
}
TaintableLocatorImpl locator = node.getLocator();
if (locator.isTainted()) {
return;
}
locator.markTainted();
SAXParseException spe = new SAXParseException(
"Unclosed element \u201C" + node.popName + "\u201D.", locator);
errorHandler.error(spe);
}
/**
* Reports a warning
*
* @param message
* the message
* @throws SAXException
*/
final void warn(String message) throws SAXException {
if (errorHandler == null) {
return;
}
SAXParseException spe = new SAXParseException(message, tokenizer);
errorHandler.warning(spe);
}
/**
* Reports a warning with an explicit locator
*
* @param message
* the message
* @throws SAXException
*/
final void warn(String message, Locator locator) throws SAXException {
if (errorHandler == null) {
return;
}
SAXParseException spe = new SAXParseException(message, locator);
errorHandler.warning(spe);
}
// ]NOCPP]
@SuppressWarnings("unchecked") public final void startTokenization(Tokenizer self) throws SAXException {
tokenizer = self;
stackNodes = new StackNode[64];
stack = new StackNode[64];
templateModeStack = new int[64];
listOfActiveFormattingElements = new StackNode[64];
needToDropLF = false;
originalMode = INITIAL;
templateModePtr = -1;
stackNodesIdx = 0;
numStackNodes = 0;
currentPtr = -1;
listPtr = -1;
formPointer = null;
headPointer = null;
// [NOCPP[
idLocations.clear();
wantingComments = wantsComments();
// ]NOCPP]
start(fragment);
charBufferLen = 0;
charBuffer = null;
framesetOk = true;
if (fragment) {
T elt;
if (contextNode != null) {
elt = contextNode;
} else {
elt = createHtmlElementSetAsRoot(tokenizer.emptyAttributes());
}
// When the context node is not in the HTML namespace, contrary
// to the spec, the first node on the stack is not set to "html"
// in the HTML namespace. Instead, it is set to a node that has
// the characteristics of the appropriate "adjusted current node".
// This way, there is no need to perform "adjusted current node"
// checks during tree construction. Instead, it's sufficient to
// just look at the current node. However, this also means that it
// is not safe to treat "html" in the HTML namespace as a sentinel
// that ends stack popping. Instead, stack popping loops that are
// meant not to pop the first element on the stack need to check
// for currentPos becoming zero.
if (contextNamespace == "http://www.w3.org/2000/svg") {
ElementName elementName = ElementName.SVG;
if ("title" == contextName || "desc" == contextName
|| "foreignObject" == contextName) {
// These elements are all alike and we don't care about
// the exact name.
elementName = ElementName.FOREIGNOBJECT;
}
// This is the SVG variant of the StackNode constructor.
StackNode<T> node = createStackNode(elementName,
elementName.getCamelCaseName(), elt
// [NOCPP[
, errorHandler == null ? null
: new TaintableLocatorImpl(tokenizer)
// ]NOCPP]
);
currentPtr++;
stack[currentPtr] = node;
tokenizer.setState(Tokenizer.DATA);
// The frameset-ok flag is set even though <frameset> never
// ends up being allowed as HTML frameset in the fragment case.
mode = FRAMESET_OK;
} else if (contextNamespace == "http://www.w3.org/1998/Math/MathML") {
ElementName elementName = ElementName.MATH;
if ("mi" == contextName || "mo" == contextName
|| "mn" == contextName || "ms" == contextName
|| "mtext" == contextName) {
// These elements are all alike and we don't care about
// the exact name.
elementName = ElementName.MTEXT;
} else if ("annotation-xml" == contextName) {
elementName = ElementName.ANNOTATION_XML;
// Blink does not check the encoding attribute of the
// annotation-xml element innerHTML is being set on.
// Let's do the same at least until
// https://www.w3.org/Bugs/Public/show_bug.cgi?id=26783
// is resolved.
}
// This is the MathML variant of the StackNode constructor.
StackNode<T> node = createStackNode(elementName, elt,
elementName.getName(), false
// [NOCPP[
, errorHandler == null ? null
: new TaintableLocatorImpl(tokenizer)
// ]NOCPP]
);
currentPtr++;
stack[currentPtr] = node;
tokenizer.setState(Tokenizer.DATA);
// The frameset-ok flag is set even though <frameset> never
// ends up being allowed as HTML frameset in the fragment case.
mode = FRAMESET_OK;
} else { // html
StackNode<T> node = createStackNode(ElementName.HTML, elt
// [NOCPP[
, errorHandler == null ? null
: new TaintableLocatorImpl(tokenizer)
// ]NOCPP]
);
currentPtr++;
stack[currentPtr] = node;
if ("template" == contextName) {
pushTemplateMode(IN_TEMPLATE);
}
resetTheInsertionMode();
formPointer = getFormPointerForContext(contextNode);
if ("title" == contextName || "textarea" == contextName) {
tokenizer.setState(Tokenizer.RCDATA);
} else if ("style" == contextName || "xmp" == contextName
|| "iframe" == contextName || "noembed" == contextName
|| "noframes" == contextName
|| (scriptingEnabled && "noscript" == contextName)) {
tokenizer.setState(Tokenizer.RAWTEXT);
} else if ("plaintext" == contextName) {
tokenizer.setState(Tokenizer.PLAINTEXT);
} else if ("script" == contextName) {
tokenizer.setState(Tokenizer.SCRIPT_DATA);
} else {
tokenizer.setState(Tokenizer.DATA);
}
}
} else {
mode = INITIAL;
// If we are viewing XML source, put a foreign element permanently
// on the stack so that cdataSectionAllowed() returns true.
// CPPONLY: if (tokenizer.isViewingXmlSource()) {
// CPPONLY: T elt = createElement("http://www.w3.org/2000/svg",
// CPPONLY: "svg",
// CPPONLY: tokenizer.emptyAttributes(), null,
// CPPONLY: svgCreator(NS_NewSVGSVGElement));
// CPPONLY: StackNode<T> node = createStackNode(ElementName.SVG,
// CPPONLY: "svg",
// CPPONLY: elt);
// CPPONLY: currentPtr++;
// CPPONLY: stack[currentPtr] = node;
// CPPONLY: }
}
}
public final void doctype(@Local String name, String publicIdentifier,
String systemIdentifier, boolean forceQuirks) throws SAXException {
needToDropLF = false;
if (!isInForeign() && mode == INITIAL) {
// [NOCPP[
if (reportingDoctype) {
// ]NOCPP]
String emptyString = Portability.newEmptyString();
appendDoctypeToDocument(name == null ? "" : name,
publicIdentifier == null ? emptyString
: publicIdentifier,
systemIdentifier == null ? emptyString
: systemIdentifier);
Portability.releaseString(emptyString);
// [NOCPP[
}
// ]NOCPP]
if (isQuirky(name, publicIdentifier, systemIdentifier,
forceQuirks)) {
errQuirkyDoctype();
documentModeInternal(DocumentMode.QUIRKS_MODE,
publicIdentifier, systemIdentifier);
} else if (isAlmostStandards(publicIdentifier,
systemIdentifier)) {
errAlmostStandardsDoctype();
documentModeInternal(
DocumentMode.ALMOST_STANDARDS_MODE,
publicIdentifier, systemIdentifier);
} else {
// [NOCPP[
if ((Portability.literalEqualsString(
"-//W3C//DTD HTML 4.0//EN", publicIdentifier) && (systemIdentifier == null || Portability.literalEqualsString(
"http://www.w3.org/TR/REC-html40/strict.dtd",
systemIdentifier)))
|| (Portability.literalEqualsString(
"-//W3C//DTD HTML 4.01//EN",
publicIdentifier) && (systemIdentifier == null || Portability.literalEqualsString(
"http://www.w3.org/TR/html4/strict.dtd",
systemIdentifier)))
|| (Portability.literalEqualsString(
"-//W3C//DTD XHTML 1.0 Strict//EN",
publicIdentifier) && Portability.literalEqualsString(
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd",
systemIdentifier))
|| (Portability.literalEqualsString(
"-//W3C//DTD XHTML 1.1//EN",
publicIdentifier) && Portability.literalEqualsString(
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd",
systemIdentifier))
) {
err("Obsolete doctype. Expected \u201C<!DOCTYPE html>\u201D.");
} else if (!((systemIdentifier == null || Portability.literalEqualsString(
"about:legacy-compat", systemIdentifier)) && publicIdentifier == null)) {
err("Legacy doctype. Expected \u201C<!DOCTYPE html>\u201D.");
}
// ]NOCPP]
documentModeInternal(DocumentMode.STANDARDS_MODE,
publicIdentifier, systemIdentifier);
}
/*
*
* Then, switch to the root element mode of the tree construction
* stage.
*/
mode = BEFORE_HTML;
return;
}
/*
* A DOCTYPE token Parse error.
*/
errStrayDoctype();
/*
* Ignore the token.
*/
return;
}
public final void comment(@NoLength char[] buf, int start, int length)
throws SAXException {
needToDropLF = false;
// [NOCPP[
if (!wantingComments) {
return;
}
// ]NOCPP]
if (!isInForeign()) {
switch (mode) {
case INITIAL:
case BEFORE_HTML:
case AFTER_AFTER_BODY:
case AFTER_AFTER_FRAMESET:
/*
* A comment token Append a Comment node to the Document
* object with the data attribute set to the data given in
* the comment token.
*/
appendCommentToDocument(buf, start, length);
return;
case AFTER_BODY:
/*
* A comment token Append a Comment node to the first
* element in the stack of open elements (the html element),
* with the data attribute set to the data given in the
* comment token.
*/
flushCharacters();
appendComment(stack[0].node, buf, start, length);
return;
default:
break;
}
}
/*
* A comment token Append a Comment node to the current node with the
* data attribute set to the data given in the comment token.
*/
flushCharacters();
appendComment(stack[currentPtr].node, buf, start, length);
return;
}
/**
* @see nu.validator.htmlparser.common.TokenHandler#characters(char[], int,
* int)
*/
public final void characters(@Const @NoLength char[] buf, int start, int length)
throws SAXException {
// Note: Can't attach error messages to EOF in C++ yet
// CPPONLY: if (tokenizer.isViewingXmlSource()) {
// CPPONLY: return;
// CPPONLY: }
if (needToDropLF) {
needToDropLF = false;
if (buf[start] == '\n') {
start++;
length--;
if (length == 0) {
return;
}
}
}
// optimize the most common case
switch (mode) {
case IN_BODY:
case IN_CELL:
case IN_CAPTION:
if (!isInForeignButNotHtmlOrMathTextIntegrationPoint()) {
reconstructTheActiveFormattingElements();
}
// CPPONLY: MOZ_FALLTHROUGH;
case TEXT:
accumulateCharacters(buf, start, length);
return;
case IN_TABLE:
case IN_TABLE_BODY:
case IN_ROW:
accumulateCharactersForced(buf, start, length);
return;
default:
int end = start + length;
charactersloop: for (int i = start; i < end; i++) {
switch (buf[i]) {
case ' ':
case '\t':
case '\n':
case '\r':
case '\u000C':
/*
* A character token that is one of one of U+0009
* CHARACTER TABULATION, U+000A LINE FEED (LF),
* U+000C FORM FEED (FF), or U+0020 SPACE
*/
switch (mode) {
case INITIAL:
case BEFORE_HTML:
case BEFORE_HEAD:
/*
* Ignore the token.
*/
start = i + 1;
continue;
case IN_HEAD:
case IN_HEAD_NOSCRIPT:
case AFTER_HEAD:
case IN_COLUMN_GROUP:
case IN_FRAMESET:
case AFTER_FRAMESET:
/*
* Append the character to the current node.
*/
continue;
case FRAMESET_OK:
case IN_TEMPLATE:
case IN_BODY:
case IN_CELL:
case IN_CAPTION:
if (start < i) {
accumulateCharacters(buf, start, i
- start);
start = i;
}
/*
* Reconstruct the active formatting
* elements, if any.
*/
if (!isInForeignButNotHtmlOrMathTextIntegrationPoint()) {
flushCharacters();
reconstructTheActiveFormattingElements();
}
/*
* Append the token's character to the
* current node.
*/
break charactersloop;
case IN_SELECT:
case IN_SELECT_IN_TABLE:
break charactersloop;
case IN_TABLE:
case IN_TABLE_BODY:
case IN_ROW:
accumulateCharactersForced(buf, i, 1);
start = i + 1;
continue;
case AFTER_BODY:
case AFTER_AFTER_BODY:
case AFTER_AFTER_FRAMESET:
if (start < i) {
accumulateCharacters(buf, start, i
- start);
start = i;
}
/*
* Reconstruct the active formatting
* elements, if any.
*/
flushCharacters();
reconstructTheActiveFormattingElements();
/*
* Append the token's character to the
* current node.
*/
continue;
}
// CPPONLY: MOZ_FALLTHROUGH_ASSERT();
default:
/*
* A character token that is not one of one of
* U+0009 CHARACTER TABULATION, U+000A LINE FEED
* (LF), U+000C FORM FEED (FF), or U+0020 SPACE
*/
switch (mode) {
case INITIAL:
/*
* Parse error.
*/
// [NOCPP[
// XXX figure out a way to report this in the Gecko View Source case
err("Non-space characters found without seeing a doctype first. Expected \u201C<!DOCTYPE html>\u201D.");
// ]NOCPP]
/*
*
* Set the document to quirks mode.
*/
documentModeInternal(
DocumentMode.QUIRKS_MODE, null,
null);
/*
* Then, switch to the root element mode of
* the tree construction stage
*/
mode = BEFORE_HTML;
/*
* and reprocess the current token.
*/
i--;
continue;
case BEFORE_HTML:
/*
* Create an HTMLElement node with the tag
* name html, in the HTML namespace. Append
* it to the Document object.
*/
// No need to flush characters here,
// because there's nothing to flush.
appendHtmlElementToDocumentAndPush();
/* Switch to the main mode */
mode = BEFORE_HEAD;
/*
* reprocess the current token.
*/
i--;
continue;
case BEFORE_HEAD:
if (start < i) {
accumulateCharacters(buf, start, i
- start);
start = i;
}
/*
* /Act as if a start tag token with the tag
* name "head" and no attributes had been
* seen,
*/
flushCharacters();
appendToCurrentNodeAndPushHeadElement(HtmlAttributes.EMPTY_ATTRIBUTES);
mode = IN_HEAD;
/*
* then reprocess the current token.
*
* This will result in an empty head element
* being generated, with the current token
* being reprocessed in the "after head"
* insertion mode.
*/
i--;
continue;
case IN_HEAD:
if (start < i) {
accumulateCharacters(buf, start, i
- start);
start = i;
}
/*
* Act as if an end tag token with the tag
* name "head" had been seen,
*/
flushCharacters();
pop();
mode = AFTER_HEAD;
/*
* and reprocess the current token.
*/
i--;
continue;
case IN_HEAD_NOSCRIPT:
if (start < i) {
accumulateCharacters(buf, start, i
- start);
start = i;
}
/*
* Parse error. Act as if an end tag with
* the tag name "noscript" had been seen
*/
errNonSpaceInNoscriptInHead();
flushCharacters();
pop();
mode = IN_HEAD;
/*
* and reprocess the current token.
*/
i--;
continue;
case AFTER_HEAD:
if (start < i) {
accumulateCharacters(buf, start, i
- start);
start = i;
}
/*
* Act as if a start tag token with the tag
* name "body" and no attributes had been
* seen,
*/
flushCharacters();
appendToCurrentNodeAndPushBodyElement();
mode = FRAMESET_OK;
/*
* and then reprocess the current token.
*/
i--;
continue;
case FRAMESET_OK:
framesetOk = false;
mode = IN_BODY;
i--;
continue;
case IN_TEMPLATE:
case IN_BODY:
case IN_CELL:
case IN_CAPTION:
if (start < i) {
accumulateCharacters(buf, start, i
- start);
start = i;
}
/*
* Reconstruct the active formatting
* elements, if any.
*/
if (!isInForeignButNotHtmlOrMathTextIntegrationPoint()) {
flushCharacters();
reconstructTheActiveFormattingElements();
}
/*
* Append the token's character to the
* current node.
*/
break charactersloop;
case IN_TABLE:
case IN_TABLE_BODY:
case IN_ROW:
accumulateCharactersForced(buf, i, 1);
start = i + 1;
continue;
case IN_COLUMN_GROUP:
if (start < i) {
accumulateCharacters(buf, start, i
- start);
start = i;
}
/*
* Act as if an end tag with the tag name
* "colgroup" had been seen, and then, if
* that token wasn't ignored, reprocess the
* current token.
*/
if (currentPtr == 0 || stack[currentPtr].getGroup() ==
TreeBuilder.TEMPLATE) {
errNonSpaceInColgroupInFragment();
start = i + 1;
continue;
}
flushCharacters();
pop();
mode = IN_TABLE;
i--;
continue;
case IN_SELECT:
case IN_SELECT_IN_TABLE:
break charactersloop;
case AFTER_BODY:
errNonSpaceAfterBody();
fatal();
mode = framesetOk ? FRAMESET_OK : IN_BODY;
i--;
continue;
case IN_FRAMESET:
if (start < i) {
accumulateCharacters(buf, start, i
- start);
// start index is adjusted below.
}
/*
* Parse error.
*/
errNonSpaceInFrameset();
/*
* Ignore the token.
*/
start = i + 1;
continue;
case AFTER_FRAMESET:
if (start < i) {
accumulateCharacters(buf, start, i
- start);
// start index is adjusted below.
}
/*
* Parse error.
*/
errNonSpaceAfterFrameset();
/*
* Ignore the token.
*/
start = i + 1;
continue;
case AFTER_AFTER_BODY:
/*
* Parse error.
*/
errNonSpaceInTrailer();
/*
* Switch back to the main mode and
* reprocess the token.
*/
mode = framesetOk ? FRAMESET_OK : IN_BODY;
i--;
continue;
case AFTER_AFTER_FRAMESET:
if (start < i) {
accumulateCharacters(buf, start, i
- start);
// start index is adjusted below.
}
/*
* Parse error.
*/
errNonSpaceInTrailer();
/*
* Ignore the token.
*/
start = i + 1;
continue;
}
}
}
if (start < end) {
accumulateCharacters(buf, start, end - start);
}
}
}
/**
* @see nu.validator.htmlparser.common.TokenHandler#zeroOriginatingReplacementCharacter()
*/
public void zeroOriginatingReplacementCharacter() throws SAXException {
if (mode == TEXT) {
accumulateCharacters(REPLACEMENT_CHARACTER, 0, 1);
return;
}
if (currentPtr >= 0) {
if (isSpecialParentInForeign(stack[currentPtr])) {
return;
}
accumulateCharacters(REPLACEMENT_CHARACTER, 0, 1);
}
}
/**
* @see nu.validator.htmlparser.common.TokenHandler#zeroOrReplacementCharacter()
*/
public void zeroOrReplacementCharacter() throws SAXException {
zeroOriginatingReplacementCharacter();
}
public final void eof() throws SAXException {
flushCharacters();
// Note: Can't attach error messages to EOF in C++ yet
eofloop: for (;;) {
switch (mode) {
case INITIAL:
/*
* Parse error.
*/
// [NOCPP[
err("End of file seen without seeing a doctype first. Expected \u201C<!DOCTYPE html>\u201D.");
// ]NOCPP]
/*
*
* Set the document to quirks mode.
*/
documentModeInternal(DocumentMode.QUIRKS_MODE, null, null);
/*
* Then, switch to the root element mode of the tree
* construction stage
*/
mode = BEFORE_HTML;
/*
* and reprocess the current token.
*/
continue;
case BEFORE_HTML:
/*
* Create an HTMLElement node with the tag name html, in the
* HTML namespace. Append it to the Document object.
*/
appendHtmlElementToDocumentAndPush();
// XXX application cache manifest
/* Switch to the main mode */
mode = BEFORE_HEAD;
/*
* reprocess the current token.
*/
continue;
case BEFORE_HEAD:
appendToCurrentNodeAndPushHeadElement(HtmlAttributes.EMPTY_ATTRIBUTES);
mode = IN_HEAD;
continue;
case IN_HEAD:
// [NOCPP[
if (errorHandler != null && currentPtr > 1) {
errEofWithUnclosedElements();
}
// ]NOCPP]
while (currentPtr > 0) {
popOnEof();
}
mode = AFTER_HEAD;
continue;
case IN_HEAD_NOSCRIPT:
// [NOCPP[
errEofWithUnclosedElements();
// ]NOCPP]
while (currentPtr > 1) {
popOnEof();
}
mode = IN_HEAD;
continue;
case AFTER_HEAD:
appendToCurrentNodeAndPushBodyElement();
mode = IN_BODY;
continue;
case IN_TABLE_BODY:
case IN_ROW:
case IN_TABLE:
case IN_SELECT_IN_TABLE:
case IN_SELECT:
case IN_COLUMN_GROUP:
case FRAMESET_OK:
case IN_CAPTION:
case IN_CELL:
case IN_BODY:
// [NOCPP[
// i > 0 to stop in time in the foreign fragment case.
openelementloop: for (int i = currentPtr; i > 0; i--) {
int group = stack[i].getGroup();
switch (group) {
case DD_OR_DT:
case LI:
case P:
case TBODY_OR_THEAD_OR_TFOOT:
case TD_OR_TH:
case BODY:
case HTML:
break;
default:
errEofWithUnclosedElements();
break openelementloop;
}
}
// ]NOCPP]
if (isTemplateModeStackEmpty()) {
break eofloop;
}
// fall through to IN_TEMPLATE
// CPPONLY: MOZ_FALLTHROUGH;
case IN_TEMPLATE:
int eltPos = findLast("template");
if (eltPos == TreeBuilder.NOT_FOUND_ON_STACK) {
assert fragment;
break eofloop;
}
if (errorHandler != null) {
errListUnclosedStartTags(0);
}
while (currentPtr >= eltPos) {
pop();
}
clearTheListOfActiveFormattingElementsUpToTheLastMarker();
popTemplateMode();
resetTheInsertionMode();
// Reprocess token.
continue;
case TEXT:
// [NOCPP[
if (errorHandler != null) {
errNoCheck("End of file seen when expecting text or an end tag.");
errListUnclosedStartTags(0);
}
// ]NOCPP]
// XXX mark script as already executed
if (originalMode == AFTER_HEAD) {
popOnEof();
}
popOnEof();
mode = originalMode;
continue;
case IN_FRAMESET:
// [NOCPP[
if (errorHandler != null && currentPtr > 0) {
errEofWithUnclosedElements();
}
// ]NOCPP]
break eofloop;
case AFTER_BODY:
case AFTER_FRAMESET:
case AFTER_AFTER_BODY:
case AFTER_AFTER_FRAMESET:
default:
// [NOCPP[
if (currentPtr == 0) { // This silliness is here to poison
// buggy compiler optimizations in
// GWT
System.currentTimeMillis();
}
// ]NOCPP]
break eofloop;
}
}
while (currentPtr > 0) {
popOnEof();
}
if (!fragment) {
popOnEof();
}
/* Stop parsing. */
}
/**
* @see nu.validator.htmlparser.common.TokenHandler#endTokenization()
*/
public final void endTokenization() throws SAXException {
formPointer = null;
headPointer = null;
contextName = null;
contextNode = null;
templateModeStack = null;
if (stack != null) {
while (currentPtr > -1) {
stack[currentPtr].release(this);
currentPtr--;
}
stack = null;
}
if (listOfActiveFormattingElements != null) {
while (listPtr > -1) {
if (listOfActiveFormattingElements[listPtr] != null) {
listOfActiveFormattingElements[listPtr].release(this);
}
listPtr--;
}
listOfActiveFormattingElements = null;
}
if (stackNodes != null) {
for (int i = 0; i < numStackNodes; i++) {
assert stackNodes[i].isUnused();
Portability.delete(stackNodes[i]);
}
numStackNodes = 0;
stackNodesIdx = 0;
stackNodes = null;
}
// [NOCPP[
idLocations.clear();
// ]NOCPP]
charBuffer = null;
end();
}
public final void startTag(ElementName elementName,
HtmlAttributes attributes, boolean selfClosing) throws SAXException {
flushCharacters();
// [NOCPP[
if (errorHandler != null) {
// ID uniqueness
@IdType String id = attributes.getId();
if (id != null) {
LocatorImpl oldLoc = idLocations.get(id);
if (oldLoc != null) {
err("Duplicate ID \u201C" + id + "\u201D.");
errorHandler.warning(new SAXParseException(
"The first occurrence of ID \u201C" + id
+ "\u201D was here.", oldLoc));
} else {
idLocations.put(id, new LocatorImpl(tokenizer));
}
}
}
// ]NOCPP]
int eltPos;
needToDropLF = false;
starttagloop: for (;;) {
int group = elementName.getGroup();
@Local String name = elementName.getName();
if (isInForeign()) {
StackNode<T> currentNode = stack[currentPtr];
@NsUri String currNs = currentNode.ns;
if (!(currentNode.isHtmlIntegrationPoint() || (currNs == "http://www.w3.org/1998/Math/MathML" && ((currentNode.getGroup() == MI_MO_MN_MS_MTEXT && group != MGLYPH_OR_MALIGNMARK) || (currentNode.getGroup() == ANNOTATION_XML && group == SVG))))) {
switch (group) {
case B_OR_BIG_OR_CODE_OR_EM_OR_I_OR_S_OR_SMALL_OR_STRIKE_OR_STRONG_OR_TT_OR_U:
case DIV_OR_BLOCKQUOTE_OR_CENTER_OR_MENU:
case BODY:
case BR:
case RUBY_OR_SPAN_OR_SUB_OR_SUP_OR_VAR:
case DD_OR_DT:
case UL_OR_OL_OR_DL:
case EMBED:
case IMG:
case H1_OR_H2_OR_H3_OR_H4_OR_H5_OR_H6:
case HEAD:
case HR:
case LI:
case META:
case NOBR:
case P:
case PRE_OR_LISTING:
case TABLE:
case FONT:
// re-check FONT to deal with the special case
if (!(group == FONT && !(attributes.contains(AttributeName.COLOR)
|| attributes.contains(AttributeName.FACE) || attributes.contains(AttributeName.SIZE)))) {
errHtmlStartTagInForeignContext(name);
if (!fragment) {
while (!isSpecialParentInForeign(stack[currentPtr])) {
popForeign(-1, -1);
}
continue starttagloop;
} // else fall thru
}
// CPPONLY: MOZ_FALLTHROUGH;
default:
if ("http://www.w3.org/2000/svg" == currNs) {
attributes.adjustForSvg();
if (selfClosing) {
appendVoidElementToCurrentMayFosterSVG(
elementName, attributes);
selfClosing = false;
} else {
appendToCurrentNodeAndPushElementMayFosterSVG(
elementName, attributes);
}
attributes = null; // CPP
break starttagloop;
} else {
attributes.adjustForMath();
if (selfClosing) {
appendVoidElementToCurrentMayFosterMathML(
elementName, attributes);
selfClosing = false;
} else {
appendToCurrentNodeAndPushElementMayFosterMathML(
elementName, attributes);
}
attributes = null; // CPP
break starttagloop;
}
} // switch
} // foreignObject / annotation-xml
}
switch (mode) {
case IN_TEMPLATE:
switch (group) {
case COL:
popTemplateMode();
pushTemplateMode(IN_COLUMN_GROUP);
mode = IN_COLUMN_GROUP;
// Reprocess token.
continue;
case CAPTION:
case COLGROUP:
case TBODY_OR_THEAD_OR_TFOOT:
popTemplateMode();
pushTemplateMode(IN_TABLE);
mode = IN_TABLE;
// Reprocess token.
continue;
case TR:
popTemplateMode();
pushTemplateMode(IN_TABLE_BODY);
mode = IN_TABLE_BODY;
// Reprocess token.
continue;
case TD_OR_TH:
popTemplateMode();
pushTemplateMode(IN_ROW);
mode = IN_ROW;
// Reprocess token.
continue;
case META:
checkMetaCharset(attributes);
appendVoidElementToCurrentMayFoster(
elementName,
attributes);
selfClosing = false;
attributes = null; // CPP
break starttagloop;
case TITLE:
startTagTitleInHead(elementName, attributes);
attributes = null; // CPP
break starttagloop;
case BASE:
case LINK_OR_BASEFONT_OR_BGSOUND:
appendVoidElementToCurrentMayFoster(
elementName,
attributes);
selfClosing = false;
attributes = null; // CPP
break starttagloop;
case SCRIPT:
startTagScriptInHead(elementName, attributes);
attributes = null; // CPP
break starttagloop;
case NOFRAMES:
case STYLE:
startTagGenericRawText(elementName, attributes);
attributes = null; // CPP
break starttagloop;
case TEMPLATE:
startTagTemplateInHead(elementName, attributes);
attributes = null; // CPP
break starttagloop;
default:
popTemplateMode();
pushTemplateMode(IN_BODY);
mode = IN_BODY;
// Reprocess token.
continue;
}
case IN_ROW:
switch (group) {
case TD_OR_TH:
clearStackBackTo(findLastOrRoot(TreeBuilder.TR));
appendToCurrentNodeAndPushElement(
elementName,
attributes);
mode = IN_CELL;
insertMarker();
attributes = null; // CPP
break starttagloop;
case CAPTION:
case COL:
case COLGROUP:
case TBODY_OR_THEAD_OR_TFOOT:
case TR:
eltPos = findLastOrRoot(TreeBuilder.TR);
if (eltPos == 0) {
assert fragment || isTemplateContents();
errNoTableRowToClose();
break starttagloop;
}
clearStackBackTo(eltPos);
pop();
mode = IN_TABLE_BODY;
continue;
default:
// fall through to IN_TABLE
}
// CPPONLY: MOZ_FALLTHROUGH;
case IN_TABLE_BODY:
switch (group) {
case TR:
clearStackBackTo(findLastInTableScopeOrRootTemplateTbodyTheadTfoot());
appendToCurrentNodeAndPushElement(
elementName,
attributes);
mode = IN_ROW;
attributes = null; // CPP
break starttagloop;
case TD_OR_TH:
errStartTagInTableBody(name);
clearStackBackTo(findLastInTableScopeOrRootTemplateTbodyTheadTfoot());
appendToCurrentNodeAndPushElement(
ElementName.TR,
HtmlAttributes.EMPTY_ATTRIBUTES);
mode = IN_ROW;
continue;
case CAPTION:
case COL:
case COLGROUP:
case TBODY_OR_THEAD_OR_TFOOT:
eltPos = findLastInTableScopeOrRootTemplateTbodyTheadTfoot();
if (eltPos == 0 || stack[eltPos].getGroup() == TEMPLATE) {
assert fragment || isTemplateContents();
errStrayStartTag(name);
break starttagloop;
} else {
clearStackBackTo(eltPos);
pop();
mode = IN_TABLE;
continue;
}
default:
// fall through to IN_TABLE
}
// CPPONLY: MOZ_FALLTHROUGH;
case IN_TABLE:
intableloop: for (;;) {
switch (group) {
case CAPTION:
clearStackBackTo(findLastOrRoot(TreeBuilder.TABLE));
insertMarker();
appendToCurrentNodeAndPushElement(
elementName,
attributes);
mode = IN_CAPTION;
attributes = null; // CPP
break starttagloop;
case COLGROUP:
clearStackBackTo(findLastOrRoot(TreeBuilder.TABLE));
appendToCurrentNodeAndPushElement(
elementName,
attributes);
mode = IN_COLUMN_GROUP;
attributes = null; // CPP
break starttagloop;
case COL:
clearStackBackTo(findLastOrRoot(TreeBuilder.TABLE));
appendToCurrentNodeAndPushElement(
ElementName.COLGROUP,
HtmlAttributes.EMPTY_ATTRIBUTES);
mode = IN_COLUMN_GROUP;
continue starttagloop;
case TBODY_OR_THEAD_OR_TFOOT:
clearStackBackTo(findLastOrRoot(TreeBuilder.TABLE));
appendToCurrentNodeAndPushElement(
elementName,
attributes);
mode = IN_TABLE_BODY;
attributes = null; // CPP
break starttagloop;
case TR:
case TD_OR_TH:
clearStackBackTo(findLastOrRoot(TreeBuilder.TABLE));
appendToCurrentNodeAndPushElement(
ElementName.TBODY,
HtmlAttributes.EMPTY_ATTRIBUTES);
mode = IN_TABLE_BODY;
continue starttagloop;
case TEMPLATE:
// fall through to IN_HEAD
break intableloop;
case TABLE:
errTableSeenWhileTableOpen();
eltPos = findLastInTableScope(name);
if (eltPos == TreeBuilder.NOT_FOUND_ON_STACK) {
assert fragment || isTemplateContents();
break starttagloop;
}
generateImpliedEndTags();
if (errorHandler != null && !isCurrent("table")) {
errNoCheckUnclosedElementsOnStack();
}
while (currentPtr >= eltPos) {
pop();
}
resetTheInsertionMode();
continue starttagloop;
case SCRIPT:
// XXX need to manage much more stuff
// here if
// supporting
// document.write()
appendToCurrentNodeAndPushElement(
elementName,
attributes);
originalMode = mode;
mode = TEXT;
tokenizer.setStateAndEndTagExpectation(
Tokenizer.SCRIPT_DATA, elementName);
attributes = null; // CPP
break starttagloop;
case STYLE:
appendToCurrentNodeAndPushElement(
elementName,
attributes);
originalMode = mode;
mode = TEXT;
tokenizer.setStateAndEndTagExpectation(
Tokenizer.RAWTEXT, elementName);
attributes = null; // CPP
break starttagloop;
case INPUT:
errStartTagInTable(name);
if (!Portability.lowerCaseLiteralEqualsIgnoreAsciiCaseString(
"hidden",
attributes.getValue(AttributeName.TYPE))) {
break intableloop;
}
appendVoidInputToCurrent(
attributes,
formPointer);
selfClosing = false;
attributes = null; // CPP
break starttagloop;
case FORM:
if (formPointer != null || isTemplateContents()) {
errFormWhenFormOpen();
break starttagloop;
} else {
errStartTagInTable(name);
appendVoidFormToCurrent(attributes);
attributes = null; // CPP
break starttagloop;
}
default:
errStartTagInTable(name);
// fall through to IN_BODY
break intableloop;
}
}
// CPPONLY: MOZ_FALLTHROUGH;
case IN_CAPTION:
switch (group) {
case CAPTION:
case COL:
case COLGROUP:
case TBODY_OR_THEAD_OR_TFOOT:
case TR:
case TD_OR_TH:
eltPos = findLastInTableScope("caption");
if (eltPos == TreeBuilder.NOT_FOUND_ON_STACK) {
assert fragment || isTemplateContents();
errStrayStartTag(name);
break starttagloop;
}
generateImpliedEndTags();
if (errorHandler != null && currentPtr != eltPos) {
errNoCheckUnclosedElementsOnStack();
}
while (currentPtr >= eltPos) {
pop();
}
clearTheListOfActiveFormattingElementsUpToTheLastMarker();
mode = IN_TABLE;
continue;
default:
// fall through to IN_BODY
}
// CPPONLY: MOZ_FALLTHROUGH;
case IN_CELL:
switch (group) {
case CAPTION:
case COL:
case COLGROUP:
case TBODY_OR_THEAD_OR_TFOOT:
case TR:
case TD_OR_TH:
eltPos = findLastInTableScopeTdTh();
if (eltPos == TreeBuilder.NOT_FOUND_ON_STACK) {
errNoCellToClose();
break starttagloop;
} else {
closeTheCell(eltPos);
continue;
}
default:
// fall through to IN_BODY
}
// CPPONLY: MOZ_FALLTHROUGH;
case FRAMESET_OK:
switch (group) {
case FRAMESET:
if (mode == FRAMESET_OK) {
if (currentPtr == 0 || stack[1].getGroup() != BODY) {
assert fragment || isTemplateContents();
errStrayStartTag(name);
break starttagloop;
} else {
errFramesetStart();
detachFromParent(stack[1].node);
while (currentPtr > 0) {
pop();
}
appendToCurrentNodeAndPushElement(
elementName,
attributes);
mode = IN_FRAMESET;
attributes = null; // CPP
break starttagloop;
}
} else {
errStrayStartTag(name);
break starttagloop;
}
// NOT falling through!
case PRE_OR_LISTING:
case LI:
case DD_OR_DT:
case BUTTON:
case MARQUEE_OR_APPLET:
case OBJECT:
case TABLE:
case AREA_OR_WBR:
case KEYGEN:
case BR:
case EMBED:
case IMG:
case INPUT:
case HR:
case TEXTAREA:
case XMP:
case IFRAME:
case SELECT:
if (mode == FRAMESET_OK
&& !(group == INPUT && Portability.lowerCaseLiteralEqualsIgnoreAsciiCaseString(
"hidden",
attributes.getValue(AttributeName.TYPE)))) {
framesetOk = false;
mode = IN_BODY;
}
// CPPONLY: MOZ_FALLTHROUGH;
default:
// fall through to IN_BODY
}
// CPPONLY: MOZ_FALLTHROUGH;
case IN_BODY:
inbodyloop: for (;;) {
switch (group) {
case HTML:
errStrayStartTag(name);
if (!fragment && !isTemplateContents()) {
addAttributesToHtml(attributes);
attributes = null; // CPP
}
break starttagloop;
case BASE:
case LINK_OR_BASEFONT_OR_BGSOUND:
case META:
case STYLE:
case SCRIPT:
case TITLE:
case TEMPLATE:
// Fall through to IN_HEAD
break inbodyloop;
case BODY:
if (currentPtr == 0 || stack[1].getGroup() != BODY || isTemplateContents()) {
assert fragment || isTemplateContents();
errStrayStartTag(name);
break starttagloop;
}
errFooSeenWhenFooOpen(name);
framesetOk = false;
if (mode == FRAMESET_OK) {
mode = IN_BODY;
}
if (addAttributesToBody(attributes)) {
attributes = null; // CPP
}
break starttagloop;
case P:
case DIV_OR_BLOCKQUOTE_OR_CENTER_OR_MENU:
case UL_OR_OL_OR_DL:
case ADDRESS_OR_ARTICLE_OR_ASIDE_OR_DETAILS_OR_DIALOG_OR_DIR_OR_FIGCAPTION_OR_FIGURE_OR_FOOTER_OR_HEADER_OR_HGROUP_OR_MAIN_OR_NAV_OR_SECTION_OR_SUMMARY:
implicitlyCloseP();
appendToCurrentNodeAndPushElementMayFoster(
elementName,
attributes);
attributes = null; // CPP
break starttagloop;
case H1_OR_H2_OR_H3_OR_H4_OR_H5_OR_H6:
implicitlyCloseP();
if (stack[currentPtr].getGroup() == H1_OR_H2_OR_H3_OR_H4_OR_H5_OR_H6) {
errHeadingWhenHeadingOpen();
pop();
}
appendToCurrentNodeAndPushElementMayFoster(
elementName,
attributes);
attributes = null; // CPP
break starttagloop;
case FIELDSET:
implicitlyCloseP();
appendToCurrentNodeAndPushElementMayFoster(
elementName,
attributes, formPointer);
attributes = null; // CPP
break starttagloop;
case PRE_OR_LISTING:
implicitlyCloseP();
appendToCurrentNodeAndPushElementMayFoster(
elementName,
attributes);
needToDropLF = true;
attributes = null; // CPP
break starttagloop;
case FORM:
if (formPointer != null && !isTemplateContents()) {
errFormWhenFormOpen();
break starttagloop;
} else {
implicitlyCloseP();
appendToCurrentNodeAndPushFormElementMayFoster(attributes);
attributes = null; // CPP
break starttagloop;
}
case LI:
case DD_OR_DT:
eltPos = currentPtr;
for (;;) {
StackNode<T> node = stack[eltPos]; // weak
// ref
if (node.getGroup() == group) { // LI or
// DD_OR_DT
generateImpliedEndTagsExceptFor(node.name);
if (errorHandler != null
&& eltPos != currentPtr) {
errUnclosedElementsImplied(eltPos, name);
}
while (currentPtr >= eltPos) {
pop();
}
break;
} else if (eltPos == 0 || (node.isSpecial()
&& (node.ns != "http://www.w3.org/1999/xhtml"
|| (node.name != "p"
&& node.name != "address"
&& node.name != "div")))) {
break;
}
eltPos--;
}
implicitlyCloseP();
appendToCurrentNodeAndPushElementMayFoster(
elementName,
attributes);
attributes = null; // CPP
break starttagloop;
case PLAINTEXT:
implicitlyCloseP();
appendToCurrentNodeAndPushElementMayFoster(
elementName,
attributes);
tokenizer.setStateAndEndTagExpectation(
Tokenizer.PLAINTEXT, elementName);
attributes = null; // CPP
break starttagloop;
case A:
int activeAPos = findInListOfActiveFormattingElementsContainsBetweenEndAndLastMarker("a");
if (activeAPos != -1) {
errFooSeenWhenFooOpen(name);
StackNode<T> activeA = listOfActiveFormattingElements[activeAPos];
activeA.retain();
adoptionAgencyEndTag("a");
removeFromStack(activeA);
activeAPos = findInListOfActiveFormattingElements(activeA);
if (activeAPos != -1) {
removeFromListOfActiveFormattingElements(activeAPos);
}
activeA.release(this);
}
reconstructTheActiveFormattingElements();
appendToCurrentNodeAndPushFormattingElementMayFoster(
elementName,
attributes);
attributes = null; // CPP
break starttagloop;
case B_OR_BIG_OR_CODE_OR_EM_OR_I_OR_S_OR_SMALL_OR_STRIKE_OR_STRONG_OR_TT_OR_U:
case FONT:
reconstructTheActiveFormattingElements();
maybeForgetEarlierDuplicateFormattingElement(elementName.getName(), attributes);
appendToCurrentNodeAndPushFormattingElementMayFoster(
elementName,
attributes);
attributes = null; // CPP
break starttagloop;
case NOBR:
reconstructTheActiveFormattingElements();
if (TreeBuilder.NOT_FOUND_ON_STACK != findLastInScope("nobr")) {
errFooSeenWhenFooOpen(name);
adoptionAgencyEndTag("nobr");
reconstructTheActiveFormattingElements();
}
appendToCurrentNodeAndPushFormattingElementMayFoster(
elementName,
attributes);
attributes = null; // CPP
break starttagloop;
case BUTTON:
eltPos = findLastInScope(name);
if (eltPos != TreeBuilder.NOT_FOUND_ON_STACK) {
errFooSeenWhenFooOpen(name);
generateImpliedEndTags();
if (errorHandler != null
&& !isCurrent(name)) {
errUnclosedElementsImplied(eltPos, name);
}
while (currentPtr >= eltPos) {
pop();
}
continue starttagloop;
} else {
reconstructTheActiveFormattingElements();
appendToCurrentNodeAndPushElementMayFoster(
elementName,
attributes, formPointer);
attributes = null; // CPP
break starttagloop;
}
case OBJECT:
reconstructTheActiveFormattingElements();
appendToCurrentNodeAndPushElementMayFoster(
elementName,
attributes, formPointer);
insertMarker();
attributes = null; // CPP
break starttagloop;
case MARQUEE_OR_APPLET:
reconstructTheActiveFormattingElements();
appendToCurrentNodeAndPushElementMayFoster(
elementName,
attributes);
insertMarker();
attributes = null; // CPP
break starttagloop;
case TABLE:
// The only quirk. Blame Hixie and
// Acid2.
if (!quirks) {
implicitlyCloseP();
}
appendToCurrentNodeAndPushElementMayFoster(
elementName,
attributes);
mode = IN_TABLE;
attributes = null; // CPP
break starttagloop;
case BR:
case EMBED:
case AREA_OR_WBR:
case KEYGEN:
reconstructTheActiveFormattingElements();
// FALL THROUGH to PARAM_OR_SOURCE_OR_TRACK
// CPPONLY: MOZ_FALLTHROUGH;
case PARAM_OR_SOURCE_OR_TRACK:
appendVoidElementToCurrentMayFoster(
elementName,
attributes);
selfClosing = false;
attributes = null; // CPP
break starttagloop;
case HR:
implicitlyCloseP();
appendVoidElementToCurrentMayFoster(
elementName,
attributes);
selfClosing = false;
attributes = null; // CPP
break starttagloop;
case IMAGE:
errImage();
elementName = ElementName.IMG;
continue starttagloop;
case IMG:
case INPUT:
reconstructTheActiveFormattingElements();
appendVoidElementToCurrentMayFoster(
elementName, attributes,
formPointer);
selfClosing = false;
attributes = null; // CPP
break starttagloop;
case TEXTAREA:
appendToCurrentNodeAndPushElementMayFoster(
elementName,
attributes, formPointer);
tokenizer.setStateAndEndTagExpectation(
Tokenizer.RCDATA, elementName);
originalMode = mode;
mode = TEXT;
needToDropLF = true;
attributes = null; // CPP
break starttagloop;
case XMP:
implicitlyCloseP();
reconstructTheActiveFormattingElements();
appendToCurrentNodeAndPushElementMayFoster(
elementName,
attributes);
originalMode = mode;
mode = TEXT;
tokenizer.setStateAndEndTagExpectation(
Tokenizer.RAWTEXT, elementName);
attributes = null; // CPP
break starttagloop;
case NOSCRIPT:
if (!scriptingEnabled) {
reconstructTheActiveFormattingElements();
appendToCurrentNodeAndPushElementMayFoster(
elementName,
attributes);
attributes = null; // CPP
break starttagloop;
}
// CPPONLY: MOZ_FALLTHROUGH;
case NOFRAMES:
case IFRAME:
case NOEMBED:
startTagGenericRawText(elementName, attributes);
attributes = null; // CPP
break starttagloop;
case SELECT:
reconstructTheActiveFormattingElements();
appendToCurrentNodeAndPushElementMayFoster(
elementName,
attributes, formPointer);
switch (mode) {
case IN_TABLE:
case IN_CAPTION:
case IN_COLUMN_GROUP:
case IN_TABLE_BODY:
case IN_ROW:
case IN_CELL:
mode = IN_SELECT_IN_TABLE;
break;
default:
mode = IN_SELECT;
break;
}
attributes = null; // CPP
break starttagloop;
case OPTGROUP:
case OPTION:
if (isCurrent("option")) {
pop();
}
reconstructTheActiveFormattingElements();
appendToCurrentNodeAndPushElementMayFoster(
elementName,
attributes);
attributes = null; // CPP
break starttagloop;
case RB_OR_RTC:
eltPos = findLastInScope("ruby");
if (eltPos != NOT_FOUND_ON_STACK) {
generateImpliedEndTags();
}
if (eltPos != currentPtr) {
if (eltPos == NOT_FOUND_ON_STACK) {
errStartTagSeenWithoutRuby(name);
} else {
errUnclosedChildrenInRuby();
}
}
appendToCurrentNodeAndPushElementMayFoster(
elementName,
attributes);
attributes = null; // CPP
break starttagloop;
case RT_OR_RP:
eltPos = findLastInScope("ruby");
if (eltPos != NOT_FOUND_ON_STACK) {
generateImpliedEndTagsExceptFor("rtc");
}
if (eltPos != currentPtr) {
if (!isCurrent("rtc")) {
if (eltPos == NOT_FOUND_ON_STACK) {
errStartTagSeenWithoutRuby(name);
} else {
errUnclosedChildrenInRuby();
}
}
}
appendToCurrentNodeAndPushElementMayFoster(
elementName,
attributes);
attributes = null; // CPP
break starttagloop;
case MATH:
reconstructTheActiveFormattingElements();
attributes.adjustForMath();
if (selfClosing) {
appendVoidElementToCurrentMayFosterMathML(
elementName, attributes);
selfClosing = false;
} else {
appendToCurrentNodeAndPushElementMayFosterMathML(
elementName, attributes);
}
attributes = null; // CPP
break starttagloop;
case SVG:
reconstructTheActiveFormattingElements();
attributes.adjustForSvg();
if (selfClosing) {
appendVoidElementToCurrentMayFosterSVG(
elementName,
attributes);
selfClosing = false;
} else {
appendToCurrentNodeAndPushElementMayFosterSVG(
elementName, attributes);
}
attributes = null; // CPP
break starttagloop;
case CAPTION:
case COL:
case COLGROUP:
case TBODY_OR_THEAD_OR_TFOOT:
case TR:
case TD_OR_TH:
case FRAME:
case FRAMESET:
case HEAD:
errStrayStartTag(name);
break starttagloop;
case OUTPUT:
reconstructTheActiveFormattingElements();
appendToCurrentNodeAndPushElementMayFoster(
elementName,
attributes, formPointer);
attributes = null; // CPP
break starttagloop;
default:
reconstructTheActiveFormattingElements();
appendToCurrentNodeAndPushElementMayFoster(
elementName,
attributes);
attributes = null; // CPP
break starttagloop;
}
}
// CPPONLY: MOZ_FALLTHROUGH;
case IN_HEAD:
inheadloop: for (;;) {
switch (group) {
case HTML:
errStrayStartTag(name);
if (!fragment && !isTemplateContents()) {
addAttributesToHtml(attributes);
attributes = null; // CPP
}
break starttagloop;
case BASE:
case LINK_OR_BASEFONT_OR_BGSOUND:
appendVoidElementToCurrentMayFoster(
elementName,
attributes);
selfClosing = false;
attributes = null; // CPP
break starttagloop;
case META:
// Fall through to IN_HEAD_NOSCRIPT
break inheadloop;
case TITLE:
startTagTitleInHead(elementName, attributes);
attributes = null; // CPP
break starttagloop;
case NOSCRIPT:
if (scriptingEnabled) {
appendToCurrentNodeAndPushElement(
elementName,
attributes);
originalMode = mode;
mode = TEXT;
tokenizer.setStateAndEndTagExpectation(
Tokenizer.RAWTEXT, elementName);
} else {
appendToCurrentNodeAndPushElementMayFoster(
elementName,
attributes);
mode = IN_HEAD_NOSCRIPT;
}
attributes = null; // CPP
break starttagloop;
case SCRIPT:
startTagScriptInHead(elementName, attributes);
attributes = null; // CPP
break starttagloop;
case STYLE:
case NOFRAMES:
startTagGenericRawText(elementName, attributes);
attributes = null; // CPP
break starttagloop;
case HEAD:
/* Parse error. */
errFooSeenWhenFooOpen(name);
/* Ignore the token. */
break starttagloop;
case TEMPLATE:
startTagTemplateInHead(elementName, attributes);
attributes = null; // CPP
break starttagloop;
default:
pop();
mode = AFTER_HEAD;
continue starttagloop;
}
}
// CPPONLY: MOZ_FALLTHROUGH;
case IN_HEAD_NOSCRIPT:
switch (group) {
case HTML:
// XXX did Hixie really mean to omit "base"
// here?
errStrayStartTag(name);
if (!fragment && !isTemplateContents()) {
addAttributesToHtml(attributes);
attributes = null; // CPP
}
break starttagloop;
case LINK_OR_BASEFONT_OR_BGSOUND:
appendVoidElementToCurrentMayFoster(
elementName,
attributes);
selfClosing = false;
attributes = null; // CPP
break starttagloop;
case META:
checkMetaCharset(attributes);
appendVoidElementToCurrentMayFoster(
elementName,
attributes);
selfClosing = false;
attributes = null; // CPP
break starttagloop;
case STYLE:
case NOFRAMES:
appendToCurrentNodeAndPushElement(
elementName,
attributes);
originalMode = mode;
mode = TEXT;
tokenizer.setStateAndEndTagExpectation(
Tokenizer.RAWTEXT, elementName);
attributes = null; // CPP
break starttagloop;
case HEAD:
errFooSeenWhenFooOpen(name);
break starttagloop;
case NOSCRIPT:
errFooSeenWhenFooOpen(name);
break starttagloop;
default:
errBadStartTagInNoscriptInHead(name);
pop();
mode = IN_HEAD;
continue;
}
case IN_COLUMN_GROUP:
switch (group) {
case HTML:
errStrayStartTag(name);
if (!fragment && !isTemplateContents()) {
addAttributesToHtml(attributes);
attributes = null; // CPP
}
break starttagloop;
case COL:
appendVoidElementToCurrentMayFoster(
elementName,
attributes);
selfClosing = false;
attributes = null; // CPP
break starttagloop;
case TEMPLATE:
startTagTemplateInHead(elementName, attributes);
attributes = null; // CPP
break starttagloop;
default:
if (currentPtr == 0 || stack[currentPtr].getGroup() == TEMPLATE) {
assert fragment || isTemplateContents();
errGarbageInColgroup();
break starttagloop;
}
pop();
mode = IN_TABLE;
continue;
}
case IN_SELECT_IN_TABLE:
switch (group) {
case CAPTION:
case TBODY_OR_THEAD_OR_TFOOT:
case TR:
case TD_OR_TH:
case TABLE:
errStartTagWithSelectOpen(name);
eltPos = findLastInTableScope("select");
if (eltPos == TreeBuilder.NOT_FOUND_ON_STACK) {
assert fragment;
break starttagloop; // http://www.w3.org/Bugs/Public/show_bug.cgi?id=8375
}
while (currentPtr >= eltPos) {
pop();
}
resetTheInsertionMode();
continue;
default:
// fall through to IN_SELECT
}
// CPPONLY: MOZ_FALLTHROUGH;
case IN_SELECT:
switch (group) {
case HTML:
errStrayStartTag(name);
if (!fragment) {
addAttributesToHtml(attributes);
attributes = null; // CPP
}
break starttagloop;
case OPTION:
if (isCurrent("option")) {
pop();
}
appendToCurrentNodeAndPushElement(
elementName,
attributes);
attributes = null; // CPP
break starttagloop;
case OPTGROUP:
if (isCurrent("option")) {
pop();
}
if (isCurrent("optgroup")) {
pop();
}
appendToCurrentNodeAndPushElement(
elementName,
attributes);
attributes = null; // CPP
break starttagloop;
case SELECT:
errStartSelectWhereEndSelectExpected();
eltPos = findLastInTableScope(name);
if (eltPos == TreeBuilder.NOT_FOUND_ON_STACK) {
assert fragment;
errNoSelectInTableScope();
break starttagloop;
} else {
while (currentPtr >= eltPos) {
pop();
}
resetTheInsertionMode();
break starttagloop;
}
case INPUT:
case TEXTAREA:
errStartTagWithSelectOpen(name);
eltPos = findLastInTableScope("select");
if (eltPos == TreeBuilder.NOT_FOUND_ON_STACK) {
assert fragment;
break starttagloop;
}
while (currentPtr >= eltPos) {
pop();
}
resetTheInsertionMode();
continue;
case SCRIPT:
startTagScriptInHead(elementName, attributes);
attributes = null; // CPP
break starttagloop;
case TEMPLATE:
startTagTemplateInHead(elementName, attributes);
attributes = null; // CPP
break starttagloop;
default:
errStrayStartTag(name);
break starttagloop;
}
case AFTER_BODY:
switch (group) {
case HTML:
errStrayStartTag(name);
if (!fragment && !isTemplateContents()) {
addAttributesToHtml(attributes);
attributes = null; // CPP
}
break starttagloop;
default:
errStrayStartTag(name);
mode = framesetOk ? FRAMESET_OK : IN_BODY;
continue;
}
case IN_FRAMESET:
switch (group) {
case FRAMESET:
appendToCurrentNodeAndPushElement(
elementName,
attributes);
attributes = null; // CPP
break starttagloop;
case FRAME:
appendVoidElementToCurrentMayFoster(
elementName,
attributes);
selfClosing = false;
attributes = null; // CPP
break starttagloop;
default:
// fall through to AFTER_FRAMESET
}
// CPPONLY: MOZ_FALLTHROUGH;
case AFTER_FRAMESET:
switch (group) {
case HTML:
errStrayStartTag(name);
if (!fragment && !isTemplateContents()) {
addAttributesToHtml(attributes);
attributes = null; // CPP
}
break starttagloop;
case NOFRAMES:
appendToCurrentNodeAndPushElement(
elementName,
attributes);
originalMode = mode;
mode = TEXT;
tokenizer.setStateAndEndTagExpectation(
Tokenizer.RAWTEXT, elementName);
attributes = null; // CPP
break starttagloop;
default:
errStrayStartTag(name);
break starttagloop;
}
case INITIAL:
/*
* Parse error.
*/
errStartTagWithoutDoctype();
/*
*
* Set the document to quirks mode.
*/
documentModeInternal(DocumentMode.QUIRKS_MODE, null, null);
/*
* Then, switch to the root element mode of the tree
* construction stage
*/
mode = BEFORE_HTML;
/*
* and reprocess the current token.
*/
continue;
case BEFORE_HTML:
switch (group) {
case HTML:
// optimize error check and streaming SAX by
// hoisting
// "html" handling here.
if (attributes == HtmlAttributes.EMPTY_ATTRIBUTES) {
// This has the right magic side effect
// that
// it
// makes attributes in SAX Tree mutable.
appendHtmlElementToDocumentAndPush();
} else {
appendHtmlElementToDocumentAndPush(attributes);
}
// XXX application cache should fire here
mode = BEFORE_HEAD;
attributes = null; // CPP
break starttagloop;
default:
/*
* Create an HTMLElement node with the tag name
* html, in the HTML namespace. Append it to the
* Document object.
*/
appendHtmlElementToDocumentAndPush();
/* Switch to the main mode */
mode = BEFORE_HEAD;
/*
* reprocess the current token.
*/
continue;
}
case BEFORE_HEAD:
switch (group) {
case HTML:
errStrayStartTag(name);
if (!fragment && !isTemplateContents()) {
addAttributesToHtml(attributes);
attributes = null; // CPP
}
break starttagloop;
case HEAD:
/*
* A start tag whose tag name is "head"
*
* Create an element for the token.
*
* Set the head element pointer to this new element
* node.
*
* Append the new element to the current node and
* push it onto the stack of open elements.
*/
appendToCurrentNodeAndPushHeadElement(attributes);
/*
* Change the insertion mode to "in head".
*/
mode = IN_HEAD;
attributes = null; // CPP
break starttagloop;
default:
/*
* Any other start tag token
*
* Act as if a start tag token with the tag name
* "head" and no attributes had been seen,
*/
appendToCurrentNodeAndPushHeadElement(HtmlAttributes.EMPTY_ATTRIBUTES);
mode = IN_HEAD;
/*
* then reprocess the current token.
*
* This will result in an empty head element being
* generated, with the current token being
* reprocessed in the "after head" insertion mode.
*/
continue;
}
case AFTER_HEAD:
switch (group) {
case HTML:
errStrayStartTag(name);
if (!fragment && !isTemplateContents()) {
addAttributesToHtml(attributes);
attributes = null; // CPP
}
break starttagloop;
case BODY:
if (attributes.getLength() == 0) {
// This has the right magic side effect
// that
// it
// makes attributes in SAX Tree mutable.
appendToCurrentNodeAndPushBodyElement();
} else {
appendToCurrentNodeAndPushBodyElement(attributes);
}
framesetOk = false;
mode = IN_BODY;
attributes = null; // CPP
break starttagloop;
case FRAMESET:
appendToCurrentNodeAndPushElement(
elementName,
attributes);
mode = IN_FRAMESET;
attributes = null; // CPP
break starttagloop;
case TEMPLATE:
errFooBetweenHeadAndBody(name);
pushHeadPointerOntoStack();
StackNode<T> headOnStack = stack[currentPtr];
startTagTemplateInHead(elementName, attributes);
removeFromStack(headOnStack);
attributes = null; // CPP
break starttagloop;
case BASE:
case LINK_OR_BASEFONT_OR_BGSOUND:
errFooBetweenHeadAndBody(name);
pushHeadPointerOntoStack();
appendVoidElementToCurrentMayFoster(
elementName,
attributes);
selfClosing = false;
pop(); // head
attributes = null; // CPP
break starttagloop;
case META:
errFooBetweenHeadAndBody(name);
checkMetaCharset(attributes);
pushHeadPointerOntoStack();
appendVoidElementToCurrentMayFoster(
elementName,
attributes);
selfClosing = false;
pop(); // head
attributes = null; // CPP
break starttagloop;
case SCRIPT:
errFooBetweenHeadAndBody(name);
pushHeadPointerOntoStack();
appendToCurrentNodeAndPushElement(
elementName,
attributes);
originalMode = mode;
mode = TEXT;
tokenizer.setStateAndEndTagExpectation(
Tokenizer.SCRIPT_DATA, elementName);
attributes = null; // CPP
break starttagloop;
case STYLE:
case NOFRAMES:
errFooBetweenHeadAndBody(name);
pushHeadPointerOntoStack();
appendToCurrentNodeAndPushElement(
elementName,
attributes);
originalMode = mode;
mode = TEXT;
tokenizer.setStateAndEndTagExpectation(
Tokenizer.RAWTEXT, elementName);
attributes = null; // CPP
break starttagloop;
case TITLE:
errFooBetweenHeadAndBody(name);
pushHeadPointerOntoStack();
appendToCurrentNodeAndPushElement(
elementName,
attributes);
originalMode = mode;
mode = TEXT;
tokenizer.setStateAndEndTagExpectation(
Tokenizer.RCDATA, elementName);
attributes = null; // CPP
break starttagloop;
case HEAD:
errStrayStartTag(name);
break starttagloop;
default:
appendToCurrentNodeAndPushBodyElement();
mode = FRAMESET_OK;
continue;
}
case AFTER_AFTER_BODY:
switch (group) {
case HTML:
errStrayStartTag(name);
if (!fragment && !isTemplateContents()) {
addAttributesToHtml(attributes);
attributes = null; // CPP
}
break starttagloop;
default:
errStrayStartTag(name);
fatal();
mode = framesetOk ? FRAMESET_OK : IN_BODY;
continue;
}
case AFTER_AFTER_FRAMESET:
switch (group) {
case HTML:
errStrayStartTag(name);
if (!fragment && !isTemplateContents()) {
addAttributesToHtml(attributes);
attributes = null; // CPP
}
break starttagloop;
case NOFRAMES:
startTagGenericRawText(elementName, attributes);
attributes = null; // CPP
break starttagloop;
default:
errStrayStartTag(name);
break starttagloop;
}
case TEXT:
assert false;
break starttagloop; // Avoid infinite loop if the assertion
// fails
}
}
if (selfClosing) {
errSelfClosing();
}
// CPPONLY: if (mBuilder == null && attributes != HtmlAttributes.EMPTY_ATTRIBUTES) {
// CPPONLY: Portability.delete(attributes);
// CPPONLY: }
}
private void startTagTitleInHead(ElementName elementName, HtmlAttributes attributes) throws SAXException {
appendToCurrentNodeAndPushElementMayFoster(elementName, attributes);
originalMode = mode;
mode = TEXT;
tokenizer.setStateAndEndTagExpectation(Tokenizer.RCDATA, elementName);
}
private void startTagGenericRawText(ElementName elementName, HtmlAttributes attributes) throws SAXException {
appendToCurrentNodeAndPushElementMayFoster(elementName, attributes);
originalMode = mode;
mode = TEXT;
tokenizer.setStateAndEndTagExpectation(Tokenizer.RAWTEXT, elementName);
}
private void startTagScriptInHead(ElementName elementName, HtmlAttributes attributes) throws SAXException {
// XXX need to manage much more stuff here if supporting document.write()
appendToCurrentNodeAndPushElementMayFoster(elementName, attributes);
originalMode = mode;
mode = TEXT;
tokenizer.setStateAndEndTagExpectation(Tokenizer.SCRIPT_DATA, elementName);
}
private void startTagTemplateInHead(ElementName elementName, HtmlAttributes attributes) throws SAXException {
appendToCurrentNodeAndPushElement(elementName, attributes);
insertMarker();
framesetOk = false;
originalMode = mode;
mode = IN_TEMPLATE;
pushTemplateMode(IN_TEMPLATE);
}
private boolean isTemplateContents() {
return TreeBuilder.NOT_FOUND_ON_STACK != findLast("template");
}
private boolean isTemplateModeStackEmpty() {
return templateModePtr == -1;
}
private boolean isSpecialParentInForeign(StackNode<T> stackNode) {
@NsUri String ns = stackNode.ns;
return ("http://www.w3.org/1999/xhtml" == ns)
|| (stackNode.isHtmlIntegrationPoint())
|| (("http://www.w3.org/1998/Math/MathML" == ns) && (stackNode.getGroup() == MI_MO_MN_MS_MTEXT));
}
/**
*
* <p>
* C++ memory note: The return value must be released.
*
* @return
* @throws SAXException
* @throws StopSniffingException
*/
public static String extractCharsetFromContent(String attributeValue
// CPPONLY: , TreeBuilder tb
) {
// This is a bit ugly. Converting the string to char array in order to
// make the portability layer smaller.
int charsetState = CHARSET_INITIAL;
int start = -1;
int end = -1;
@Auto char[] buffer = Portability.newCharArrayFromString(attributeValue);
charsetloop: for (int i = 0; i < buffer.length; i++) {
char c = buffer[i];
switch (charsetState) {
case CHARSET_INITIAL:
switch (c) {
case 'c':
case 'C':
charsetState = CHARSET_C;
continue;
default:
continue;
}
case CHARSET_C:
switch (c) {
case 'h':
case 'H':
charsetState = CHARSET_H;
continue;
default:
charsetState = CHARSET_INITIAL;
continue;
}
case CHARSET_H:
switch (c) {
case 'a':
case 'A':
charsetState = CHARSET_A;
continue;
default:
charsetState = CHARSET_INITIAL;
continue;
}
case CHARSET_A:
switch (c) {
case 'r':
case 'R':
charsetState = CHARSET_R;
continue;
default:
charsetState = CHARSET_INITIAL;
continue;
}
case CHARSET_R:
switch (c) {
case 's':
case 'S':
charsetState = CHARSET_S;
continue;
default:
charsetState = CHARSET_INITIAL;
continue;
}
case CHARSET_S:
switch (c) {
case 'e':
case 'E':
charsetState = CHARSET_E;
continue;
default:
charsetState = CHARSET_INITIAL;
continue;
}
case CHARSET_E:
switch (c) {
case 't':
case 'T':
charsetState = CHARSET_T;
continue;
default:
charsetState = CHARSET_INITIAL;
continue;
}
case CHARSET_T:
switch (c) {
case '\t':
case '\n':
case '\u000C':
case '\r':
case ' ':
continue;
case '=':
charsetState = CHARSET_EQUALS;
continue;
default:
return null;
}
case CHARSET_EQUALS:
switch (c) {
case '\t':
case '\n':
case '\u000C':
case '\r':
case ' ':
continue;
case '\'':
start = i + 1;
charsetState = CHARSET_SINGLE_QUOTED;
continue;
case '\"':
start = i + 1;
charsetState = CHARSET_DOUBLE_QUOTED;
continue;
default:
start = i;
charsetState = CHARSET_UNQUOTED;
continue;
}
case CHARSET_SINGLE_QUOTED:
switch (c) {
case '\'':
end = i;
break charsetloop;
default:
continue;
}
case CHARSET_DOUBLE_QUOTED:
switch (c) {
case '\"':
end = i;
break charsetloop;
default:
continue;
}
case CHARSET_UNQUOTED:
switch (c) {
case '\t':
case '\n':
case '\u000C':
case '\r':
case ' ':
case ';':
end = i;
break charsetloop;
default:
continue;
}
}
}
if (start != -1) {
if (end == -1) {
if (charsetState == CHARSET_UNQUOTED) {
end = buffer.length;
} else {
return null;
}
}
return Portability.newStringFromBuffer(buffer, start, end
- start
// CPPONLY: , tb, false
);
}
return null;
}
private void checkMetaCharset(HtmlAttributes attributes)
throws SAXException {
String charset = attributes.getValue(AttributeName.CHARSET);
if (charset != null) {
if (tokenizer.internalEncodingDeclaration(charset)) {
requestSuspension();
return;
}
return;
}
if (!Portability.lowerCaseLiteralEqualsIgnoreAsciiCaseString(
"content-type",
attributes.getValue(AttributeName.HTTP_EQUIV))) {
return;
}
String content = attributes.getValue(AttributeName.CONTENT);
if (content != null) {
String extract = TreeBuilder.extractCharsetFromContent(content
// CPPONLY: , this
);
// remember not to return early without releasing the string
if (extract != null) {
if (tokenizer.internalEncodingDeclaration(extract)) {
requestSuspension();
}
}
Portability.releaseString(extract);
}
}
public final void endTag(ElementName elementName) throws SAXException {
flushCharacters();
needToDropLF = false;
int eltPos;
int group = elementName.getGroup();
@Local String name = elementName.getName();
endtagloop: for (;;) {
if (isInForeign()) {
if (stack[currentPtr].name != name) {
if (currentPtr == 0) {
errStrayEndTag(name);
} else {
errEndTagDidNotMatchCurrentOpenElement(name, stack[currentPtr].popName);
}
}
eltPos = currentPtr;
int origPos = currentPtr;
for (;;) {
if (eltPos == 0) {
assert fragment: "We can get this close to the root of the stack in foreign content only in the fragment case.";
break endtagloop;
}
if (stack[eltPos].name == name) {
while (currentPtr >= eltPos) {
popForeign(origPos, eltPos);
}
break endtagloop;
}
if (stack[--eltPos].ns == "http://www.w3.org/1999/xhtml") {
break;
}
}
}
switch (mode) {
case IN_TEMPLATE:
switch (group) {
case TEMPLATE:
// fall through to IN_HEAD
break;
default:
errStrayEndTag(name);
break endtagloop;
}
// CPPONLY: MOZ_FALLTHROUGH;
case IN_ROW:
switch (group) {
case TR:
eltPos = findLastOrRoot(TreeBuilder.TR);
if (eltPos == 0) {
assert fragment || isTemplateContents();
errNoTableRowToClose();
break endtagloop;
}
clearStackBackTo(eltPos);
pop();
mode = IN_TABLE_BODY;
break endtagloop;
case TABLE:
eltPos = findLastOrRoot(TreeBuilder.TR);
if (eltPos == 0) {
assert fragment || isTemplateContents();
errNoTableRowToClose();
break endtagloop;
}
clearStackBackTo(eltPos);
pop();
mode = IN_TABLE_BODY;
continue;
case TBODY_OR_THEAD_OR_TFOOT:
if (findLastInTableScope(name) == TreeBuilder.NOT_FOUND_ON_STACK) {
errStrayEndTag(name);
break endtagloop;
}
eltPos = findLastOrRoot(TreeBuilder.TR);
if (eltPos == 0) {
assert fragment || isTemplateContents();
errNoTableRowToClose();
break endtagloop;
}
clearStackBackTo(eltPos);
pop();
mode = IN_TABLE_BODY;
continue;
case BODY:
case CAPTION:
case COL:
case COLGROUP:
case HTML:
case TD_OR_TH:
errStrayEndTag(name);
break endtagloop;
default:
// fall through to IN_TABLE
}
// CPPONLY: MOZ_FALLTHROUGH;
case IN_TABLE_BODY:
switch (group) {
case TBODY_OR_THEAD_OR_TFOOT:
eltPos = findLastOrRoot(name);
if (eltPos == 0) {
errStrayEndTag(name);
break endtagloop;
}
clearStackBackTo(eltPos);
pop();
mode = IN_TABLE;
break endtagloop;
case TABLE:
eltPos = findLastInTableScopeOrRootTemplateTbodyTheadTfoot();
if (eltPos == 0 || stack[eltPos].getGroup() == TEMPLATE) {
assert fragment || isTemplateContents();
errStrayEndTag(name);
break endtagloop;
}
clearStackBackTo(eltPos);
pop();
mode = IN_TABLE;
continue;
case BODY:
case CAPTION:
case COL:
case COLGROUP:
case HTML:
case TD_OR_TH:
case TR:
errStrayEndTag(name);
break endtagloop;
default:
// fall through to IN_TABLE
}
// CPPONLY: MOZ_FALLTHROUGH;
case IN_TABLE:
switch (group) {
case TABLE:
eltPos = findLast("table");
if (eltPos == TreeBuilder.NOT_FOUND_ON_STACK) {
assert fragment || isTemplateContents();
errStrayEndTag(name);
break endtagloop;
}
while (currentPtr >= eltPos) {
pop();
}
resetTheInsertionMode();
break endtagloop;
case BODY:
case CAPTION:
case COL:
case COLGROUP:
case HTML:
case TBODY_OR_THEAD_OR_TFOOT:
case TD_OR_TH:
case TR:
errStrayEndTag(name);
break endtagloop;
case TEMPLATE:
// fall through to IN_HEAD
break;
default:
errStrayEndTag(name);
// fall through to IN_BODY
}
// CPPONLY: MOZ_FALLTHROUGH;
case IN_CAPTION:
switch (group) {
case CAPTION:
eltPos = findLastInTableScope("caption");
if (eltPos == TreeBuilder.NOT_FOUND_ON_STACK) {
break endtagloop;
}
generateImpliedEndTags();
if (errorHandler != null && currentPtr != eltPos) {
errUnclosedElements(eltPos, name);
}
while (currentPtr >= eltPos) {
pop();
}
clearTheListOfActiveFormattingElementsUpToTheLastMarker();
mode = IN_TABLE;
break endtagloop;
case TABLE:
eltPos = findLastInTableScope("caption");
if (eltPos == TreeBuilder.NOT_FOUND_ON_STACK) {
assert fragment || isTemplateContents();
errStrayEndTag(name);
break endtagloop;
}
generateImpliedEndTags();
if (errorHandler != null && currentPtr != eltPos) {
errUnclosedElements(eltPos, name);
}
while (currentPtr >= eltPos) {
pop();
}
clearTheListOfActiveFormattingElementsUpToTheLastMarker();
mode = IN_TABLE;
continue;
case BODY:
case COL:
case COLGROUP:
case HTML:
case TBODY_OR_THEAD_OR_TFOOT:
case TD_OR_TH:
case TR:
errStrayEndTag(name);
break endtagloop;
default:
// fall through to IN_BODY
}
// CPPONLY: MOZ_FALLTHROUGH;
case IN_CELL:
switch (group) {
case TD_OR_TH:
eltPos = findLastInTableScope(name);
if (eltPos == TreeBuilder.NOT_FOUND_ON_STACK) {
errStrayEndTag(name);
break endtagloop;
}
generateImpliedEndTags();
if (errorHandler != null && !isCurrent(name)) {
errUnclosedElements(eltPos, name);
}
while (currentPtr >= eltPos) {
pop();
}
clearTheListOfActiveFormattingElementsUpToTheLastMarker();
mode = IN_ROW;
break endtagloop;
case TABLE:
case TBODY_OR_THEAD_OR_TFOOT:
case TR:
if (findLastInTableScope(name) == TreeBuilder.NOT_FOUND_ON_STACK) {
assert name == "tbody" || name == "tfoot" || name == "thead" || fragment || isTemplateContents();
errStrayEndTag(name);
break endtagloop;
}
closeTheCell(findLastInTableScopeTdTh());
continue;
case BODY:
case CAPTION:
case COL:
case COLGROUP:
case HTML:
errStrayEndTag(name);
break endtagloop;
default:
// fall through to IN_BODY
}
// CPPONLY: MOZ_FALLTHROUGH;
case FRAMESET_OK:
case IN_BODY:
switch (group) {
case BODY:
if (!isSecondOnStackBody()) {
assert fragment || isTemplateContents();
errStrayEndTag(name);
break endtagloop;
}
assert currentPtr >= 1;
if (errorHandler != null) {
uncloseloop1: for (int i = 2; i <= currentPtr; i++) {
switch (stack[i].getGroup()) {
case DD_OR_DT:
case LI:
case OPTGROUP:
case OPTION: // is this possible?
case P:
case RB_OR_RTC:
case RT_OR_RP:
case TD_OR_TH:
case TBODY_OR_THEAD_OR_TFOOT:
break;
default:
errEndWithUnclosedElements(name);
break uncloseloop1;
}
}
}
mode = AFTER_BODY;
break endtagloop;
case HTML:
if (!isSecondOnStackBody()) {
assert fragment || isTemplateContents();
errStrayEndTag(name);
break endtagloop;
}
if (errorHandler != null) {
uncloseloop2: for (int i = 0; i <= currentPtr; i++) {
switch (stack[i].getGroup()) {
case DD_OR_DT:
case LI:
case P:
case RB_OR_RTC:
case RT_OR_RP:
case TBODY_OR_THEAD_OR_TFOOT:
case TD_OR_TH:
case BODY:
case HTML:
break;
default:
errEndWithUnclosedElements(name);
break uncloseloop2;
}
}
}
mode = AFTER_BODY;
continue;
case DIV_OR_BLOCKQUOTE_OR_CENTER_OR_MENU:
case UL_OR_OL_OR_DL:
case PRE_OR_LISTING:
case FIELDSET:
case BUTTON:
case ADDRESS_OR_ARTICLE_OR_ASIDE_OR_DETAILS_OR_DIALOG_OR_DIR_OR_FIGCAPTION_OR_FIGURE_OR_FOOTER_OR_HEADER_OR_HGROUP_OR_MAIN_OR_NAV_OR_SECTION_OR_SUMMARY:
eltPos = findLastInScope(name);
if (eltPos == TreeBuilder.NOT_FOUND_ON_STACK) {
errStrayEndTag(name);
} else {
generateImpliedEndTags();
if (errorHandler != null && !isCurrent(name)) {
errUnclosedElements(eltPos, name);
}
while (currentPtr >= eltPos) {
pop();
}
}
break endtagloop;
case FORM:
if (!isTemplateContents()) {
if (formPointer == null) {
errStrayEndTag(name);
break endtagloop;
}
formPointer = null;
eltPos = findLastInScope(name);
if (eltPos == TreeBuilder.NOT_FOUND_ON_STACK) {
errStrayEndTag(name);
break endtagloop;
}
generateImpliedEndTags();
if (errorHandler != null && !isCurrent(name)) {
errUnclosedElements(eltPos, name);
}
removeFromStack(eltPos);
break endtagloop;
} else {
eltPos = findLastInScope(name);
if (eltPos == TreeBuilder.NOT_FOUND_ON_STACK) {
errStrayEndTag(name);
break endtagloop;
}
generateImpliedEndTags();
if (errorHandler != null && !isCurrent(name)) {
errUnclosedElements(eltPos, name);
}
while (currentPtr >= eltPos) {
pop();
}
break endtagloop;
}
case P:
eltPos = findLastInButtonScope("p");
if (eltPos == TreeBuilder.NOT_FOUND_ON_STACK) {
errNoElementToCloseButEndTagSeen("p");
// XXX Can the 'in foreign' case happen anymore?
if (isInForeign()) {
errHtmlStartTagInForeignContext(name);
// Check for currentPtr for the fragment
// case.
while (currentPtr >= 0 && stack[currentPtr].ns != "http://www.w3.org/1999/xhtml") {
pop();
}
}
appendVoidElementToCurrentMayFoster(
elementName,
HtmlAttributes.EMPTY_ATTRIBUTES);
break endtagloop;
}
generateImpliedEndTagsExceptFor("p");
assert eltPos != TreeBuilder.NOT_FOUND_ON_STACK;
if (errorHandler != null && eltPos != currentPtr) {
errUnclosedElements(eltPos, name);
}
while (currentPtr >= eltPos) {
pop();
}
break endtagloop;
case LI:
eltPos = findLastInListScope(name);
if (eltPos == TreeBuilder.NOT_FOUND_ON_STACK) {
errNoElementToCloseButEndTagSeen(name);
} else {
generateImpliedEndTagsExceptFor(name);
if (errorHandler != null
&& eltPos != currentPtr) {
errUnclosedElements(eltPos, name);
}
while (currentPtr >= eltPos) {
pop();
}
}
break endtagloop;
case DD_OR_DT:
eltPos = findLastInScope(name);
if (eltPos == TreeBuilder.NOT_FOUND_ON_STACK) {
errNoElementToCloseButEndTagSeen(name);
} else {
generateImpliedEndTagsExceptFor(name);
if (errorHandler != null
&& eltPos != currentPtr) {
errUnclosedElements(eltPos, name);
}
while (currentPtr >= eltPos) {
pop();
}
}
break endtagloop;
case H1_OR_H2_OR_H3_OR_H4_OR_H5_OR_H6:
eltPos = findLastInScopeHn();
if (eltPos == TreeBuilder.NOT_FOUND_ON_STACK) {
errStrayEndTag(name);
} else {
generateImpliedEndTags();
if (errorHandler != null && !isCurrent(name)) {
errUnclosedElements(eltPos, name);
}
while (currentPtr >= eltPos) {
pop();
}
}
break endtagloop;
case OBJECT:
case MARQUEE_OR_APPLET:
eltPos = findLastInScope(name);
if (eltPos == TreeBuilder.NOT_FOUND_ON_STACK) {
errStrayEndTag(name);
} else {
generateImpliedEndTags();
if (errorHandler != null && !isCurrent(name)) {
errUnclosedElements(eltPos, name);
}
while (currentPtr >= eltPos) {
pop();
}
clearTheListOfActiveFormattingElementsUpToTheLastMarker();
}
break endtagloop;
case BR:
errEndTagBr();
if (isInForeign()) {
// XXX can this happen anymore?
errHtmlStartTagInForeignContext(name);
// Check for currentPtr for the fragment
// case.
while (currentPtr >= 0 && stack[currentPtr].ns != "http://www.w3.org/1999/xhtml") {
pop();
}
}
reconstructTheActiveFormattingElements();
appendVoidElementToCurrentMayFoster(
elementName,
HtmlAttributes.EMPTY_ATTRIBUTES);
break endtagloop;
case TEMPLATE:
// fall through to IN_HEAD;
break;
case AREA_OR_WBR:
case KEYGEN: // XXX??
case PARAM_OR_SOURCE_OR_TRACK:
case EMBED:
case IMG:
case IMAGE:
case INPUT:
case HR:
case IFRAME:
case NOEMBED: // XXX???
case NOFRAMES: // XXX??
case SELECT:
case TABLE:
case TEXTAREA: // XXX??
errStrayEndTag(name);
break endtagloop;
case NOSCRIPT:
if (scriptingEnabled) {
errStrayEndTag(name);
break endtagloop;
}
// CPPONLY: MOZ_FALLTHROUGH;
case A:
case B_OR_BIG_OR_CODE_OR_EM_OR_I_OR_S_OR_SMALL_OR_STRIKE_OR_STRONG_OR_TT_OR_U:
case FONT:
case NOBR:
if (adoptionAgencyEndTag(name)) {
break endtagloop;
}
// else handle like any other tag
// CPPONLY: MOZ_FALLTHROUGH;
default:
if (isCurrent(name)) {
pop();
break endtagloop;
}
eltPos = currentPtr;
for (;;) {
StackNode<T> node = stack[eltPos];
if (node.ns == "http://www.w3.org/1999/xhtml" && node.name == name) {
generateImpliedEndTags();
if (errorHandler != null
&& !isCurrent(name)) {
errUnclosedElements(eltPos, name);
}
while (currentPtr >= eltPos) {
pop();
}
break endtagloop;
} else if (eltPos == 0 || node.isSpecial()) {
errStrayEndTag(name);
break endtagloop;
}
eltPos--;
}
}
// CPPONLY: MOZ_FALLTHROUGH;
case IN_HEAD:
switch (group) {
case HEAD:
pop();
mode = AFTER_HEAD;
break endtagloop;
case BR:
case HTML:
case BODY:
pop();
mode = AFTER_HEAD;
continue;
case TEMPLATE:
endTagTemplateInHead();
break endtagloop;
default:
errStrayEndTag(name);
break endtagloop;
}
case IN_HEAD_NOSCRIPT:
switch (group) {
case NOSCRIPT:
pop();
mode = IN_HEAD;
break endtagloop;
case BR:
errStrayEndTag(name);
pop();
mode = IN_HEAD;
continue;
default:
errStrayEndTag(name);
break endtagloop;
}
case IN_COLUMN_GROUP:
switch (group) {
case COLGROUP:
if (currentPtr == 0 || stack[currentPtr].getGroup() ==
TreeBuilder.TEMPLATE) {
assert fragment || isTemplateContents();
errGarbageInColgroup();
break endtagloop;
}
pop();
mode = IN_TABLE;
break endtagloop;
case COL:
errStrayEndTag(name);
break endtagloop;
case TEMPLATE:
endTagTemplateInHead();
break endtagloop;
default:
if (currentPtr == 0 || stack[currentPtr].getGroup() ==
TreeBuilder.TEMPLATE) {
assert fragment || isTemplateContents();
errGarbageInColgroup();
break endtagloop;
}
pop();
mode = IN_TABLE;
continue;
}
case IN_SELECT_IN_TABLE:
switch (group) {
case CAPTION:
case TABLE:
case TBODY_OR_THEAD_OR_TFOOT:
case TR:
case TD_OR_TH:
errEndTagSeenWithSelectOpen(name);
if (findLastInTableScope(name) != TreeBuilder.NOT_FOUND_ON_STACK) {
eltPos = findLastInTableScope("select");
if (eltPos == TreeBuilder.NOT_FOUND_ON_STACK) {
assert fragment;
break endtagloop; // http://www.w3.org/Bugs/Public/show_bug.cgi?id=8375
}
while (currentPtr >= eltPos) {
pop();
}
resetTheInsertionMode();
continue;
} else {
break endtagloop;
}
default:
// fall through to IN_SELECT
}
// CPPONLY: MOZ_FALLTHROUGH;
case IN_SELECT:
switch (group) {
case OPTION:
if (isCurrent("option")) {
pop();
break endtagloop;
} else {
errStrayEndTag(name);
break endtagloop;
}
case OPTGROUP:
if (isCurrent("option")
&& "optgroup" == stack[currentPtr - 1].name) {
pop();
}
if (isCurrent("optgroup")) {
pop();
} else {
errStrayEndTag(name);
}
break endtagloop;
case SELECT:
eltPos = findLastInTableScope("select");
if (eltPos == TreeBuilder.NOT_FOUND_ON_STACK) {
assert fragment;
errStrayEndTag(name);
break endtagloop;
}
while (currentPtr >= eltPos) {
pop();
}
resetTheInsertionMode();
break endtagloop;
case TEMPLATE:
endTagTemplateInHead();
break endtagloop;
default:
errStrayEndTag(name);
break endtagloop;
}
case AFTER_BODY:
switch (group) {
case HTML:
if (fragment) {
errStrayEndTag(name);
break endtagloop;
} else {
mode = AFTER_AFTER_BODY;
break endtagloop;
}
default:
errEndTagAfterBody();
mode = framesetOk ? FRAMESET_OK : IN_BODY;
continue;
}
case IN_FRAMESET:
switch (group) {
case FRAMESET:
if (currentPtr == 0) {
assert fragment;
errStrayEndTag(name);
break endtagloop;
}
pop();
if ((!fragment) && !isCurrent("frameset")) {
mode = AFTER_FRAMESET;
}
break endtagloop;
default:
errStrayEndTag(name);
break endtagloop;
}
case AFTER_FRAMESET:
switch (group) {
case HTML:
mode = AFTER_AFTER_FRAMESET;
break endtagloop;
default:
errStrayEndTag(name);
break endtagloop;
}
case INITIAL:
/*
* Parse error.
*/
errEndTagSeenWithoutDoctype();
/*
*
* Set the document to quirks mode.
*/
documentModeInternal(DocumentMode.QUIRKS_MODE, null, null);
/*
* Then, switch to the root element mode of the tree
* construction stage
*/
mode = BEFORE_HTML;
/*
* and reprocess the current token.
*/
continue;
case BEFORE_HTML:
switch (group) {
case HEAD:
case BR:
case HTML:
case BODY:
/*
* Create an HTMLElement node with the tag name
* html, in the HTML namespace. Append it to the
* Document object.
*/
appendHtmlElementToDocumentAndPush();
/* Switch to the main mode */
mode = BEFORE_HEAD;
/*
* reprocess the current token.
*/
continue;
default:
errStrayEndTag(name);
break endtagloop;
}
case BEFORE_HEAD:
switch (group) {
case HEAD:
case BR:
case HTML:
case BODY:
appendToCurrentNodeAndPushHeadElement(HtmlAttributes.EMPTY_ATTRIBUTES);
mode = IN_HEAD;
continue;
default:
errStrayEndTag(name);
break endtagloop;
}
case AFTER_HEAD:
switch (group) {
case TEMPLATE:
endTagTemplateInHead();
break endtagloop;
case HTML:
case BODY:
case BR:
appendToCurrentNodeAndPushBodyElement();
mode = FRAMESET_OK;
continue;
default:
errStrayEndTag(name);
break endtagloop;
}
case AFTER_AFTER_BODY:
errStrayEndTag(name);
mode = framesetOk ? FRAMESET_OK : IN_BODY;
continue;
case AFTER_AFTER_FRAMESET:
errStrayEndTag(name);
break endtagloop;
case TEXT:
// XXX need to manage insertion point here
pop();
if (originalMode == AFTER_HEAD) {
silentPop();
}
mode = originalMode;
break endtagloop;
}
} // endtagloop
}
private void endTagTemplateInHead() throws SAXException {
int eltPos = findLast("template");
if (eltPos == TreeBuilder.NOT_FOUND_ON_STACK) {
errStrayEndTag("template");
return;
}
generateImpliedEndTagsThoroughly();
if (errorHandler != null && !isCurrent("template")) {
errUnclosedElements(eltPos, "template");
}
while (currentPtr >= eltPos) {
pop();
}
clearTheListOfActiveFormattingElementsUpToTheLastMarker();
popTemplateMode();
resetTheInsertionMode();
}
private int findLastInTableScopeOrRootTemplateTbodyTheadTfoot() {
for (int i = currentPtr; i > 0; i--) {
if (stack[i].ns == "http://www.w3.org/1999/xhtml"
&& (stack[i].getGroup() == TreeBuilder.TBODY_OR_THEAD_OR_TFOOT
|| stack[i].getGroup() == TreeBuilder.TEMPLATE)) {
return i;
}
}
return 0;
}
private int findLast(@Local String name) {
for (int i = currentPtr; i > 0; i--) {
if (stack[i].ns == "http://www.w3.org/1999/xhtml" && stack[i].name == name) {
return i;
}
}
return TreeBuilder.NOT_FOUND_ON_STACK;
}
private int findLastInTableScope(@Local String name) {
for (int i = currentPtr; i > 0; i--) {
if (stack[i].ns == "http://www.w3.org/1999/xhtml") {
if (stack[i].name == name) {
return i;
} else if (stack[i].name == "table" || stack[i].name == "template") {
return TreeBuilder.NOT_FOUND_ON_STACK;
}
}
}
return TreeBuilder.NOT_FOUND_ON_STACK;
}
private int findLastInButtonScope(@Local String name) {
for (int i = currentPtr; i > 0; i--) {
if (stack[i].ns == "http://www.w3.org/1999/xhtml") {
if (stack[i].name == name) {
return i;
} else if (stack[i].name == "button") {
return TreeBuilder.NOT_FOUND_ON_STACK;
}
}
if (stack[i].isScoping()) {
return TreeBuilder.NOT_FOUND_ON_STACK;
}
}
return TreeBuilder.NOT_FOUND_ON_STACK;
}
private int findLastInScope(@Local String name) {
for (int i = currentPtr; i > 0; i--) {
if (stack[i].ns == "http://www.w3.org/1999/xhtml" && stack[i].name == name) {
return i;
} else if (stack[i].isScoping()) {
return TreeBuilder.NOT_FOUND_ON_STACK;
}
}
return TreeBuilder.NOT_FOUND_ON_STACK;
}
private int findLastInListScope(@Local String name) {
for (int i = currentPtr; i > 0; i--) {
if (stack[i].ns == "http://www.w3.org/1999/xhtml") {
if (stack[i].name == name) {
return i;
} else if (stack[i].name == "ul" || stack[i].name == "ol") {
return TreeBuilder.NOT_FOUND_ON_STACK;
}
}
if (stack[i].isScoping()) {
return TreeBuilder.NOT_FOUND_ON_STACK;
}
}
return TreeBuilder.NOT_FOUND_ON_STACK;
}
private int findLastInScopeHn() {
for (int i = currentPtr; i > 0; i--) {
if (stack[i].getGroup() == TreeBuilder.H1_OR_H2_OR_H3_OR_H4_OR_H5_OR_H6) {
return i;
} else if (stack[i].isScoping()) {
return TreeBuilder.NOT_FOUND_ON_STACK;
}
}
return TreeBuilder.NOT_FOUND_ON_STACK;
}
private void generateImpliedEndTagsExceptFor(@Local String name)
throws SAXException {
for (;;) {
StackNode<T> node = stack[currentPtr];
switch (node.getGroup()) {
case P:
case LI:
case DD_OR_DT:
case OPTION:
case OPTGROUP:
case RB_OR_RTC:
case RT_OR_RP:
if (node.ns == "http://www.w3.org/1999/xhtml" && node.name == name) {
return;
}
pop();
continue;
default:
return;
}
}
}
private void generateImpliedEndTags() throws SAXException {
for (;;) {
switch (stack[currentPtr].getGroup()) {
case P:
case LI:
case DD_OR_DT:
case OPTION:
case OPTGROUP:
case RB_OR_RTC:
case RT_OR_RP:
pop();
continue;
default:
return;
}
}
}
private void generateImpliedEndTagsThoroughly() throws SAXException {
for (;;) {
switch (stack[currentPtr].getGroup()) {
case CAPTION:
case COLGROUP:
case DD_OR_DT:
case LI:
case OPTGROUP:
case OPTION:
case P:
case RB_OR_RTC:
case RT_OR_RP:
case TBODY_OR_THEAD_OR_TFOOT:
case TD_OR_TH:
case TR:
pop();
continue;
default:
return;
}
}
}
private boolean isSecondOnStackBody() {
return currentPtr >= 1 && stack[1].getGroup() == TreeBuilder.BODY;
}
private void documentModeInternal(DocumentMode m, String publicIdentifier,
String systemIdentifier)
throws SAXException {
if (forceNoQuirks) {
// Srcdoc documents are always rendered in standards mode.
quirks = false;
if (documentModeHandler != null) {
documentModeHandler.documentMode(
DocumentMode.STANDARDS_MODE
// [NOCPP[
, null, null
// ]NOCPP]
);
}
return;
}
quirks = (m == DocumentMode.QUIRKS_MODE);
if (documentModeHandler != null) {
documentModeHandler.documentMode(
m
// [NOCPP[
, publicIdentifier, systemIdentifier
// ]NOCPP]
);
}
// [NOCPP[
documentMode(m, publicIdentifier, systemIdentifier);
// ]NOCPP]
}
private boolean isAlmostStandards(String publicIdentifier,
String systemIdentifier) {
if (Portability.lowerCaseLiteralIsPrefixOfIgnoreAsciiCaseString(
"-//w3c//dtd xhtml 1.0 transitional//", publicIdentifier)) {
return true;
}
if (Portability.lowerCaseLiteralIsPrefixOfIgnoreAsciiCaseString(
"-//w3c//dtd xhtml 1.0 frameset//", publicIdentifier)) {
return true;
}
if (systemIdentifier != null) {
if (Portability.lowerCaseLiteralIsPrefixOfIgnoreAsciiCaseString(
"-//w3c//dtd html 4.01 transitional//", publicIdentifier)) {
return true;
}
if (Portability.lowerCaseLiteralIsPrefixOfIgnoreAsciiCaseString(
"-//w3c//dtd html 4.01 frameset//", publicIdentifier)) {
return true;
}
}
return false;
}
private boolean isQuirky(@Local String name, String publicIdentifier,
String systemIdentifier, boolean forceQuirks) {
if (forceQuirks) {
return true;
}
if (name != HTML_LOCAL) {
return true;
}
if (publicIdentifier != null) {
for (int i = 0; i < TreeBuilder.QUIRKY_PUBLIC_IDS.length; i++) {
if (Portability.lowerCaseLiteralIsPrefixOfIgnoreAsciiCaseString(
TreeBuilder.QUIRKY_PUBLIC_IDS[i], publicIdentifier)) {
return true;
}
}
if (Portability.lowerCaseLiteralEqualsIgnoreAsciiCaseString(
"-//w3o//dtd w3 html strict 3.0//en//", publicIdentifier)
|| Portability.lowerCaseLiteralEqualsIgnoreAsciiCaseString(
"-/w3c/dtd html 4.0 transitional/en",
publicIdentifier)
|| Portability.lowerCaseLiteralEqualsIgnoreAsciiCaseString(
"html", publicIdentifier)) {
return true;
}
}
if (systemIdentifier == null) {
if (Portability.lowerCaseLiteralIsPrefixOfIgnoreAsciiCaseString(
"-//w3c//dtd html 4.01 transitional//", publicIdentifier)) {
return true;
} else if (Portability.lowerCaseLiteralIsPrefixOfIgnoreAsciiCaseString(
"-//w3c//dtd html 4.01 frameset//", publicIdentifier)) {
return true;
}
} else if (Portability.lowerCaseLiteralEqualsIgnoreAsciiCaseString(
"http://www.ibm.com/data/dtd/v11/ibmxhtml1-transitional.dtd",
systemIdentifier)) {
return true;
}
return false;
}
private void closeTheCell(int eltPos) throws SAXException {
generateImpliedEndTags();
if (errorHandler != null && eltPos != currentPtr) {
errUnclosedElementsCell(eltPos);
}
while (currentPtr >= eltPos) {
pop();
}
clearTheListOfActiveFormattingElementsUpToTheLastMarker();
mode = IN_ROW;
return;
}
private int findLastInTableScopeTdTh() {
for (int i = currentPtr; i > 0; i--) {
@Local String name = stack[i].name;
if (stack[i].ns == "http://www.w3.org/1999/xhtml") {
if ("td" == name || "th" == name) {
return i;
} else if (name == "table" || name == "template") {
return TreeBuilder.NOT_FOUND_ON_STACK;
}
}
}
return TreeBuilder.NOT_FOUND_ON_STACK;
}
private void clearStackBackTo(int eltPos) throws SAXException {
int eltGroup = stack[eltPos].getGroup();
while (currentPtr > eltPos) { // > not >= intentional
if (stack[currentPtr].ns == "http://www.w3.org/1999/xhtml"
&& stack[currentPtr].getGroup() == TEMPLATE
&& (eltGroup == TABLE || eltGroup == TBODY_OR_THEAD_OR_TFOOT|| eltGroup == TR || eltPos == 0)) {
return;
}
pop();
}
}
private void resetTheInsertionMode() {
StackNode<T> node;
@Local String name;
@NsUri String ns;
for (int i = currentPtr; i >= 0; i--) {
node = stack[i];
name = node.name;
ns = node.ns;
if (i == 0) {
if (!(contextNamespace == "http://www.w3.org/1999/xhtml" && (contextName == "td" || contextName == "th"))) {
if (fragment) {
// Make sure we are parsing a fragment otherwise the context element doesn't make sense.
name = contextName;
ns = contextNamespace;
}
} else {
mode = framesetOk ? FRAMESET_OK : IN_BODY; // XXX from Hixie's email
return;
}
}
if ("select" == name) {
int ancestorIndex = i;
while (ancestorIndex > 0) {
StackNode<T> ancestor = stack[ancestorIndex--];
if ("http://www.w3.org/1999/xhtml" == ancestor.ns) {
if ("template" == ancestor.name) {
break;
}
if ("table" == ancestor.name) {
mode = IN_SELECT_IN_TABLE;
return;
}
}
}
mode = IN_SELECT;
return;
} else if ("td" == name || "th" == name) {
mode = IN_CELL;
return;
} else if ("tr" == name) {
mode = IN_ROW;
return;
} else if ("tbody" == name || "thead" == name || "tfoot" == name) {
mode = IN_TABLE_BODY;
return;
} else if ("caption" == name) {
mode = IN_CAPTION;
return;
} else if ("colgroup" == name) {
mode = IN_COLUMN_GROUP;
return;
} else if ("table" == name) {
mode = IN_TABLE;
return;
} else if ("http://www.w3.org/1999/xhtml" != ns) {
mode = framesetOk ? FRAMESET_OK : IN_BODY;
return;
} else if ("template" == name) {
assert templateModePtr >= 0;
mode = templateModeStack[templateModePtr];
return;
} else if ("head" == name) {
if (name == contextName) {
mode = framesetOk ? FRAMESET_OK : IN_BODY; // really
} else {
mode = IN_HEAD;
}
return;
} else if ("body" == name) {
mode = framesetOk ? FRAMESET_OK : IN_BODY;
return;
} else if ("frameset" == name) {
// TODO: Fragment case. Add error reporting.
mode = IN_FRAMESET;
return;
} else if ("html" == name) {
if (headPointer == null) {
// TODO: Fragment case. Add error reporting.
mode = BEFORE_HEAD;
} else {
mode = AFTER_HEAD;
}
return;
} else if (i == 0) {
mode = framesetOk ? FRAMESET_OK : IN_BODY;
return;
}
}
}
/**
* @throws SAXException
*
*/
private void implicitlyCloseP() throws SAXException {
int eltPos = findLastInButtonScope("p");
if (eltPos == TreeBuilder.NOT_FOUND_ON_STACK) {
return;
}
generateImpliedEndTagsExceptFor("p");
if (errorHandler != null && eltPos != currentPtr) {
errUnclosedElementsImplied(eltPos, "p");
}
while (currentPtr >= eltPos) {
pop();
}
}
private boolean debugOnlyClearLastStackSlot() {
stack[currentPtr] = null;
return true;
}
private boolean debugOnlyClearLastListSlot() {
listOfActiveFormattingElements[listPtr] = null;
return true;
}
private void pushTemplateMode(int mode) {
templateModePtr++;
if (templateModePtr == templateModeStack.length) {
int[] newStack = new int[templateModeStack.length + 64];
System.arraycopy(templateModeStack, 0, newStack, 0, templateModeStack.length);
templateModeStack = newStack;
}
templateModeStack[templateModePtr] = mode;
}
@SuppressWarnings("unchecked") private void push(StackNode<T> node) throws SAXException {
currentPtr++;
if (currentPtr == stack.length) {
StackNode<T>[] newStack = new StackNode[stack.length + 64];
System.arraycopy(stack, 0, newStack, 0, stack.length);
stack = newStack;
}
stack[currentPtr] = node;
elementPushed(node.ns, node.popName, node.node);
}
@SuppressWarnings("unchecked") private void silentPush(StackNode<T> node) throws SAXException {
currentPtr++;
if (currentPtr == stack.length) {
StackNode<T>[] newStack = new StackNode[stack.length + 64];
System.arraycopy(stack, 0, newStack, 0, stack.length);
stack = newStack;
}
stack[currentPtr] = node;
}
@SuppressWarnings("unchecked") private void append(StackNode<T> node) {
listPtr++;
if (listPtr == listOfActiveFormattingElements.length) {
StackNode<T>[] newList = new StackNode[listOfActiveFormattingElements.length + 64];
System.arraycopy(listOfActiveFormattingElements, 0, newList, 0,
listOfActiveFormattingElements.length);
listOfActiveFormattingElements = newList;
}
listOfActiveFormattingElements[listPtr] = node;
}
@Inline private void insertMarker() {
append(null);
}
private void clearTheListOfActiveFormattingElementsUpToTheLastMarker() {
while (listPtr > -1) {
if (listOfActiveFormattingElements[listPtr] == null) {
--listPtr;
return;
}
listOfActiveFormattingElements[listPtr].release(this);
--listPtr;
}
}
@Inline private boolean isCurrent(@Local String name) {
return stack[currentPtr].ns == "http://www.w3.org/1999/xhtml" &&
name == stack[currentPtr].name;
}
private void removeFromStack(int pos) throws SAXException {
if (currentPtr == pos) {
pop();
} else {
fatal();
stack[pos].release(this);
System.arraycopy(stack, pos + 1, stack, pos, currentPtr - pos);
assert debugOnlyClearLastStackSlot();
currentPtr--;
}
}
private void removeFromStack(StackNode<T> node) throws SAXException {
if (stack[currentPtr] == node) {
pop();
} else {
int pos = currentPtr - 1;
while (pos >= 0 && stack[pos] != node) {
pos--;
}
if (pos == -1) {
// dead code?
return;
}
fatal();
node.release(this);
System.arraycopy(stack, pos + 1, stack, pos, currentPtr - pos);
currentPtr--;
}
}
private void removeFromListOfActiveFormattingElements(int pos) {
assert listOfActiveFormattingElements[pos] != null;
listOfActiveFormattingElements[pos].release(this);
if (pos == listPtr) {
assert debugOnlyClearLastListSlot();
listPtr--;
return;
}
assert pos < listPtr;
System.arraycopy(listOfActiveFormattingElements, pos + 1,
listOfActiveFormattingElements, pos, listPtr - pos);
assert debugOnlyClearLastListSlot();
listPtr--;
}
/**
* Adoption agency algorithm.
*
* @param name subject as described in the specified algorithm.
* @return Returns true if the algorithm has completed and there is nothing remaining to
* be done. Returns false if the algorithm needs to "act as described in the 'any other
* end tag' entry" as described in the specified algorithm.
* @throws SAXException
*/
private boolean adoptionAgencyEndTag(@Local String name) throws SAXException {
// This check intends to ensure that for properly nested tags, closing tags will match
// against the stack instead of the listOfActiveFormattingElements.
if (stack[currentPtr].ns == "http://www.w3.org/1999/xhtml" &&
stack[currentPtr].name == name &&
findInListOfActiveFormattingElements(stack[currentPtr]) == -1) {
// If the current element matches the name but isn't on the list of active
// formatting elements, then it is possible that the list was mangled by the Noah's Ark
// clause. In this case, we want to match the end tag against the stack instead of
// proceeding with the AAA algorithm that may match against the list of
// active formatting elements (and possibly mangle the tree in unexpected ways).
pop();
return true;
}
// If you crash around here, perhaps some stack node variable claimed to
// be a weak ref isn't.
for (int i = 0; i < 8; ++i) {
int formattingEltListPos = listPtr;
while (formattingEltListPos > -1) {
StackNode<T> listNode = listOfActiveFormattingElements[formattingEltListPos]; // weak ref
if (listNode == null) {
formattingEltListPos = -1;
break;
} else if (listNode.name == name) {
break;
}
formattingEltListPos--;
}
if (formattingEltListPos == -1) {
return false;
}
// this *looks* like a weak ref to the list of formatting elements
StackNode<T> formattingElt = listOfActiveFormattingElements[formattingEltListPos];
int formattingEltStackPos = currentPtr;
boolean inScope = true;
while (formattingEltStackPos > -1) {
StackNode<T> node = stack[formattingEltStackPos]; // weak ref
if (node == formattingElt) {
break;
} else if (node.isScoping()) {
inScope = false;
}
formattingEltStackPos--;
}
if (formattingEltStackPos == -1) {
errNoElementToCloseButEndTagSeen(name);
removeFromListOfActiveFormattingElements(formattingEltListPos);
return true;
}
if (!inScope) {
errNoElementToCloseButEndTagSeen(name);
return true;
}
// stackPos now points to the formatting element and it is in scope
if (formattingEltStackPos != currentPtr) {
errEndTagViolatesNestingRules(name);
}
int furthestBlockPos = formattingEltStackPos + 1;
while (furthestBlockPos <= currentPtr) {
StackNode<T> node = stack[furthestBlockPos]; // weak ref
assert furthestBlockPos > 0: "How is formattingEltStackPos + 1 not > 0?";
if (node.isSpecial()) {
break;
}
furthestBlockPos++;
}
if (furthestBlockPos > currentPtr) {
// no furthest block
while (currentPtr >= formattingEltStackPos) {
pop();
}
removeFromListOfActiveFormattingElements(formattingEltListPos);
return true;
}
// commonAncestor is used for running the algorithm and
// insertionCommonAncestor is used for the actual insertions to
// keep them depth-limited.
StackNode<T> commonAncestor = stack[formattingEltStackPos - 1]; // weak ref
T insertionCommonAncestor = nodeFromStackWithBlinkCompat(formattingEltStackPos - 1); // weak ref
StackNode<T> furthestBlock = stack[furthestBlockPos]; // weak ref
// detachFromParent(furthestBlock.node); XXX AAA CHANGE
int bookmark = formattingEltListPos;
int nodePos = furthestBlockPos;
StackNode<T> lastNode = furthestBlock; // weak ref
int j = 0;
for (;;) {
++j;
nodePos--;
if (nodePos == formattingEltStackPos) {
break;
}
StackNode<T> node = stack[nodePos]; // weak ref
int nodeListPos = findInListOfActiveFormattingElements(node);
if (j > 3 && nodeListPos != -1) {
removeFromListOfActiveFormattingElements(nodeListPos);
// Adjust the indices into the list to account
// for the removal of nodeListPos.
if (nodeListPos <= formattingEltListPos) {
formattingEltListPos--;
}
if (nodeListPos <= bookmark) {
bookmark--;
}
// Update position to reflect removal from list.
nodeListPos = -1;
}
if (nodeListPos == -1) {
assert formattingEltStackPos < nodePos;
assert bookmark < nodePos;
assert furthestBlockPos > nodePos;
removeFromStack(nodePos); // node is now a bad pointer in C++
furthestBlockPos--;
continue;
}
// now node is both on stack and in the list
if (nodePos == furthestBlockPos) {
bookmark = nodeListPos + 1;
}
// if (hasChildren(node.node)) { XXX AAA CHANGE
assert node == listOfActiveFormattingElements[nodeListPos];
assert node == stack[nodePos];
T clone = createElement("http://www.w3.org/1999/xhtml",
node.name, node.attributes.cloneAttributes(), insertionCommonAncestor
// CPPONLY: , htmlCreator(node.getHtmlCreator())
);
StackNode<T> newNode = createStackNode(node.getFlags(), node.ns,
node.name, clone, node.popName, node.attributes
// CPPONLY: , node.getHtmlCreator()
// [NOCPP[
, node.getLocator()
// ]NOCPP]
); // creation ownership goes to stack
node.dropAttributes(); // adopt ownership to newNode
stack[nodePos] = newNode;
newNode.retain(); // retain for list
listOfActiveFormattingElements[nodeListPos] = newNode;
node.release(this); // release from stack
node.release(this); // release from list
node = newNode;
// } XXX AAA CHANGE
detachFromParent(lastNode.node);
appendElement(lastNode.node, nodeFromStackWithBlinkCompat(nodePos));
lastNode = node;
}
// If we insert into a foster parent, for simplicity, we insert
// accoding to the spec without Blink's depth limit.
if (commonAncestor.isFosterParenting()) {
fatal();
detachFromParent(lastNode.node);
insertIntoFosterParent(lastNode.node);
} else {
detachFromParent(lastNode.node);
appendElement(lastNode.node, insertionCommonAncestor);
}
T clone = createElement("http://www.w3.org/1999/xhtml",
formattingElt.name,
formattingElt.attributes.cloneAttributes(), furthestBlock.node
// CPPONLY: , htmlCreator(formattingElt.getHtmlCreator())
);
StackNode<T> formattingClone = createStackNode(
formattingElt.getFlags(), formattingElt.ns,
formattingElt.name, clone, formattingElt.popName,
formattingElt.attributes
// CPPONLY: , formattingElt.getHtmlCreator()
// [NOCPP[
, errorHandler == null ? null : new TaintableLocatorImpl(tokenizer)
// ]NOCPP]
); // Ownership transfers to stack below
formattingElt.dropAttributes(); // transfer ownership to
// formattingClone
appendChildrenToNewParent(furthestBlock.node, clone);
appendElement(clone, furthestBlock.node);
removeFromListOfActiveFormattingElements(formattingEltListPos);
insertIntoListOfActiveFormattingElements(formattingClone, bookmark);
assert formattingEltStackPos < furthestBlockPos;
removeFromStack(formattingEltStackPos);
// furthestBlockPos is now off by one and points to the slot after
// it
insertIntoStack(formattingClone, furthestBlockPos);
}
return true;
}
private void insertIntoStack(StackNode<T> node, int position)
throws SAXException {
assert currentPtr + 1 < stack.length;
assert position <= currentPtr + 1;
if (position == currentPtr + 1) {
push(node);
} else {
System.arraycopy(stack, position, stack, position + 1,
(currentPtr - position) + 1);
currentPtr++;
stack[position] = node;
}
}
private void insertIntoListOfActiveFormattingElements(
StackNode<T> formattingClone, int bookmark) {
formattingClone.retain();
assert listPtr + 1 < listOfActiveFormattingElements.length;
if (bookmark <= listPtr) {
System.arraycopy(listOfActiveFormattingElements, bookmark,
listOfActiveFormattingElements, bookmark + 1,
(listPtr - bookmark) + 1);
}
listPtr++;
listOfActiveFormattingElements[bookmark] = formattingClone;
}
private int findInListOfActiveFormattingElements(StackNode<T> node) {
for (int i = listPtr; i >= 0; i--) {
if (node == listOfActiveFormattingElements[i]) {
return i;
}
}
return -1;
}
private int findInListOfActiveFormattingElementsContainsBetweenEndAndLastMarker(
@Local String name) {
for (int i = listPtr; i >= 0; i--) {
StackNode<T> node = listOfActiveFormattingElements[i];
if (node == null) {
return -1;
} else if (node.name == name) {
return i;
}
}
return -1;
}
private void maybeForgetEarlierDuplicateFormattingElement(
@Local String name, HtmlAttributes attributes) throws SAXException {
int candidate = -1;
int count = 0;
for (int i = listPtr; i >= 0; i--) {
StackNode<T> node = listOfActiveFormattingElements[i];
if (node == null) {
break;
}
if (node.name == name && node.attributes.equalsAnother(attributes)) {
candidate = i;
++count;
}
}
if (count >= 3) {
removeFromListOfActiveFormattingElements(candidate);
}
}
private int findLastOrRoot(@Local String name) {
for (int i = currentPtr; i > 0; i--) {
if (stack[i].ns == "http://www.w3.org/1999/xhtml" && stack[i].name == name) {
return i;
}
}
return 0;
}
private int findLastOrRoot(int group) {
for (int i = currentPtr; i > 0; i--) {
if (stack[i].ns == "http://www.w3.org/1999/xhtml" && stack[i].getGroup() == group) {
return i;
}
}
return 0;
}
/**
* Attempt to add attribute to the body element.
* @param attributes the attributes
* @return <code>true</code> iff the attributes were added
* @throws SAXException
*/
private boolean addAttributesToBody(HtmlAttributes attributes)
throws SAXException {
// [NOCPP[
checkAttributes(attributes, "http://www.w3.org/1999/xhtml");
// ]NOCPP]
if (currentPtr >= 1) {
StackNode<T> body = stack[1];
if (body.getGroup() == TreeBuilder.BODY) {
addAttributesToElement(body.node, attributes);
return true;
}
}
return false;
}
private void addAttributesToHtml(HtmlAttributes attributes)
throws SAXException {
// [NOCPP[
checkAttributes(attributes, "http://www.w3.org/1999/xhtml");
// ]NOCPP]
addAttributesToElement(stack[0].node, attributes);
}
private void pushHeadPointerOntoStack() throws SAXException {
assert headPointer != null;
assert mode == AFTER_HEAD;
fatal();
silentPush(createStackNode(ElementName.HEAD, headPointer
// [NOCPP[
, errorHandler == null ? null : new TaintableLocatorImpl(tokenizer)
// ]NOCPP]
));
}
/**
* @throws SAXException
*
*/
private void reconstructTheActiveFormattingElements() throws SAXException {
if (listPtr == -1) {
return;
}
StackNode<T> mostRecent = listOfActiveFormattingElements[listPtr];
if (mostRecent == null || isInStack(mostRecent)) {
return;
}
int entryPos = listPtr;
for (;;) {
entryPos--;
if (entryPos == -1) {
break;
}
if (listOfActiveFormattingElements[entryPos] == null) {
break;
}
if (isInStack(listOfActiveFormattingElements[entryPos])) {
break;
}
}
while (entryPos < listPtr) {
entryPos++;
StackNode<T> entry = listOfActiveFormattingElements[entryPos];
StackNode<T> current = stack[currentPtr];
T clone;
if (current.isFosterParenting()) {
clone = createAndInsertFosterParentedElement("http://www.w3.org/1999/xhtml", entry.name,
entry.attributes.cloneAttributes()
// CPPONLY: , htmlCreator(entry.getHtmlCreator())
);
} else {
T currentNode = nodeFromStackWithBlinkCompat(currentPtr);
clone = createElement("http://www.w3.org/1999/xhtml", entry.name,
entry.attributes.cloneAttributes(), currentNode
// CPPONLY: , htmlCreator(entry.getHtmlCreator())
);
appendElement(clone, currentNode);
}
StackNode<T> entryClone = createStackNode(entry.getFlags(),
entry.ns, entry.name, clone, entry.popName,
entry.attributes
// CPPONLY: , entry.getHtmlCreator()
// [NOCPP[
, entry.getLocator()
// ]NOCPP]
);
entry.dropAttributes(); // transfer ownership to entryClone
push(entryClone);
// stack takes ownership of the local variable
listOfActiveFormattingElements[entryPos] = entryClone;
// overwriting the old entry on the list, so release & retain
entry.release(this);
entryClone.retain();
}
}
void notifyUnusedStackNode(int idxInStackNodes) {
// stackNodesIdx is the earliest possible index of a stack node that might be unused,
// so update the index if necessary.
if (idxInStackNodes < stackNodesIdx) {
stackNodesIdx = idxInStackNodes;
}
}
@SuppressWarnings("unchecked") private StackNode<T> getUnusedStackNode() {
// Search for an unused stack node.
while (stackNodesIdx < numStackNodes) {
if (stackNodes[stackNodesIdx].isUnused()) {
return stackNodes[stackNodesIdx++];
}
stackNodesIdx++;
}
if (stackNodesIdx < stackNodes.length) {
// No unused stack nodes, but there is still space in the storage array.
stackNodes[stackNodesIdx] = new StackNode<T>(stackNodesIdx);
numStackNodes++;
return stackNodes[stackNodesIdx++];
}
// Could not find an unused stack node and storage array is full.
StackNode<T>[] newStack = new StackNode[stackNodes.length + 64];
System.arraycopy(stackNodes, 0, newStack, 0, stackNodes.length);
stackNodes = newStack;
// Create a new stack node and return it.
stackNodes[stackNodesIdx] = new StackNode<T>(stackNodesIdx);
numStackNodes++;
return stackNodes[stackNodesIdx++];
}
private StackNode<T> createStackNode(int flags, @NsUri String ns, @Local String name, T node,
@Local String popName, HtmlAttributes attributes
// CPPONLY: , @HtmlCreator Object htmlCreator
// [NOCPP[
, TaintableLocatorImpl locator
// ]NOCPP]
) {
StackNode<T> instance = getUnusedStackNode();
instance.setValues(flags, ns, name, node, popName, attributes
// CPPONLY: , htmlCreator
// [NOCPP[
, locator
// ]NOCPP]
);
return instance;
}
private StackNode<T> createStackNode(ElementName elementName, T node
// [NOCPP[
, TaintableLocatorImpl locator
// ]NOCPP]
) {
StackNode<T> instance = getUnusedStackNode();
instance.setValues(elementName, node
// [NOCPP[
, locator
// ]NOCPP]
);
return instance;
}
private StackNode<T> createStackNode(ElementName elementName, T node, HtmlAttributes attributes
// [NOCPP[
, TaintableLocatorImpl locator
// ]NOCPP]
) {
StackNode<T> instance = getUnusedStackNode();
instance.setValues(elementName, node, attributes
// [NOCPP[
, locator
// ]NOCPP]
);
return instance;
}
private StackNode<T> createStackNode(ElementName elementName, T node, @Local String popName
// [NOCPP[
, TaintableLocatorImpl locator
// ]NOCPP]
) {
StackNode<T> instance = getUnusedStackNode();
instance.setValues(elementName, node, popName
// [NOCPP[
, locator
// ]NOCPP]
);
return instance;
}
private StackNode<T> createStackNode(ElementName elementName, @Local String popName, T node
// [NOCPP[
, TaintableLocatorImpl locator
// ]NOCPP]
) {
StackNode<T> instance = getUnusedStackNode();
instance.setValues(elementName, popName, node
// [NOCPP[
, locator
// ]NOCPP]
);
return instance;
}
private StackNode<T> createStackNode(ElementName elementName, T node, @Local String popName,
boolean markAsIntegrationPoint
// [NOCPP[
, TaintableLocatorImpl locator
// ]NOCPP]
) {
StackNode<T> instance = getUnusedStackNode();
instance.setValues(elementName, node, popName, markAsIntegrationPoint
// [NOCPP[
, locator
// ]NOCPP]
);
return instance;
}
private void insertIntoFosterParent(T child) throws SAXException {
int tablePos = findLastOrRoot(TreeBuilder.TABLE);
int templatePos = findLastOrRoot(TreeBuilder.TEMPLATE);
if (templatePos >= tablePos) {
appendElement(child, stack[templatePos].node);
return;
}
StackNode<T> node = stack[tablePos];
insertFosterParentedChild(child, node.node, stack[tablePos - 1].node);
}
private T createAndInsertFosterParentedElement(@NsUri String ns, @Local String name,
HtmlAttributes attributes
// CPPONLY: , @Creator Object creator
) throws SAXException {
return createAndInsertFosterParentedElement(ns, name, attributes, null
// CPPONLY: , creator
);
}
private T createAndInsertFosterParentedElement(@NsUri String ns, @Local String name,
HtmlAttributes attributes, T form
// CPPONLY: , @Creator Object creator
) throws SAXException {
int tablePos = findLastOrRoot(TreeBuilder.TABLE);
int templatePos = findLastOrRoot(TreeBuilder.TEMPLATE);
if (templatePos >= tablePos) {
T child = createElement(ns, name, attributes, form, stack[templatePos].node
// CPPONLY: , creator
);
appendElement(child, stack[templatePos].node);
return child;
}
StackNode<T> node = stack[tablePos];
return createAndInsertFosterParentedElement(ns, name, attributes, form, node.node, stack[tablePos - 1].node
// CPPONLY: , creator
);
}
private boolean isInStack(StackNode<T> node) {
for (int i = currentPtr; i >= 0; i--) {
if (stack[i] == node) {
return true;
}
}
return false;
}
private void popTemplateMode() {
templateModePtr--;
}
private void pop() throws SAXException {
StackNode<T> node = stack[currentPtr];
assert debugOnlyClearLastStackSlot();
currentPtr--;
elementPopped(node.ns, node.popName, node.node);
node.release(this);
}
private void popForeign(int origPos, int eltPos) throws SAXException {
StackNode<T> node = stack[currentPtr];
if (origPos != currentPtr || eltPos != currentPtr) {
markMalformedIfScript(node.node);
}
assert debugOnlyClearLastStackSlot();
currentPtr--;
elementPopped(node.ns, node.popName, node.node);
node.release(this);
}
private void silentPop() throws SAXException {
StackNode<T> node = stack[currentPtr];
assert debugOnlyClearLastStackSlot();
currentPtr--;
node.release(this);
}
private void popOnEof() throws SAXException {
StackNode<T> node = stack[currentPtr];
assert debugOnlyClearLastStackSlot();
currentPtr--;
markMalformedIfScript(node.node);
elementPopped(node.ns, node.popName, node.node);
node.release(this);
}
// [NOCPP[
private void checkAttributes(HtmlAttributes attributes, @NsUri String ns)
throws SAXException {
if (errorHandler != null) {
int len = attributes.getXmlnsLength();
for (int i = 0; i < len; i++) {
AttributeName name = attributes.getXmlnsAttributeName(i);
if (name == AttributeName.XMLNS) {
String xmlns = attributes.getXmlnsValue(i);
if (!ns.equals(xmlns)) {
err("Bad value \u201C"
+ xmlns
+ "\u201D for the attribute \u201Cxmlns\u201D (only \u201C"
+ ns + "\u201D permitted here).");
switch (namePolicy) {
case ALTER_INFOSET:
// fall through
case ALLOW:
warn("Attribute \u201Cxmlns\u201D is not serializable as XML 1.0.");
break;
case FATAL:
fatal("Attribute \u201Cxmlns\u201D is not serializable as XML 1.0.");
break;
}
}
} else if (ns != "http://www.w3.org/1999/xhtml"
&& name == AttributeName.XMLNS_XLINK) {
String xmlns = attributes.getXmlnsValue(i);
if (!"http://www.w3.org/1999/xlink".equals(xmlns)) {
err("Bad value \u201C"
+ xmlns
+ "\u201D for the attribute \u201Cxmlns:link\u201D (only \u201Chttp://www.w3.org/1999/xlink\u201D permitted here).");
switch (namePolicy) {
case ALTER_INFOSET:
// fall through
case ALLOW:
warn("Attribute \u201Cxmlns:xlink\u201D with a value other than \u201Chttp://www.w3.org/1999/xlink\u201D is not serializable as XML 1.0 without changing document semantics.");
break;
case FATAL:
fatal("Attribute \u201Cxmlns:xlink\u201D with a value other than \u201Chttp://www.w3.org/1999/xlink\u201D is not serializable as XML 1.0 without changing document semantics.");
break;
}
}
} else {
err("Attribute \u201C" + attributes.getXmlnsLocalName(i)
+ "\u201D not allowed here.");
switch (namePolicy) {
case ALTER_INFOSET:
// fall through
case ALLOW:
warn("Attribute with the local name \u201C"
+ attributes.getXmlnsLocalName(i)
+ "\u201D is not serializable as XML 1.0.");
break;
case FATAL:
fatal("Attribute with the local name \u201C"
+ attributes.getXmlnsLocalName(i)
+ "\u201D is not serializable as XML 1.0.");
break;
}
}
}
}
attributes.processNonNcNames(this, namePolicy);
}
private String checkPopName(@Local String name) throws SAXException {
if (NCName.isNCName(name)) {
return name;
} else {
switch (namePolicy) {
case ALLOW:
warn("Element name \u201C" + name
+ "\u201D cannot be represented as XML 1.0.");
return name;
case ALTER_INFOSET:
warn("Element name \u201C" + name
+ "\u201D cannot be represented as XML 1.0.");
return NCName.escapeName(name);
case FATAL:
fatal("Element name \u201C" + name
+ "\u201D cannot be represented as XML 1.0.");
}
}
return null; // keep compiler happy
}
// ]NOCPP]
private void appendHtmlElementToDocumentAndPush(HtmlAttributes attributes)
throws SAXException {
// [NOCPP[
checkAttributes(attributes, "http://www.w3.org/1999/xhtml");
// ]NOCPP]
T elt = createHtmlElementSetAsRoot(attributes);
StackNode<T> node = createStackNode(ElementName.HTML,
elt
// [NOCPP[
, errorHandler == null ? null : new TaintableLocatorImpl(tokenizer)
// ]NOCPP]
);
push(node);
}
private void appendHtmlElementToDocumentAndPush() throws SAXException {
appendHtmlElementToDocumentAndPush(tokenizer.emptyAttributes());
}
private void appendToCurrentNodeAndPushHeadElement(HtmlAttributes attributes)
throws SAXException {
// [NOCPP[
checkAttributes(attributes, "http://www.w3.org/1999/xhtml");
// ]NOCPP]
T currentNode = nodeFromStackWithBlinkCompat(currentPtr);
T elt = createElement("http://www.w3.org/1999/xhtml", "head", attributes, currentNode
/*
* head uses NS_NewHTMLSharedElement creator
*/
// CPPONLY: , htmlCreator(NS_NewHTMLSharedElement)
);
appendElement(elt, currentNode);
headPointer = elt;
StackNode<T> node = createStackNode(ElementName.HEAD,
elt
// [NOCPP[
, errorHandler == null ? null : new TaintableLocatorImpl(tokenizer)
// ]NOCPP]
);
push(node);
}
private void appendToCurrentNodeAndPushBodyElement(HtmlAttributes attributes)
throws SAXException {
appendToCurrentNodeAndPushElement(ElementName.BODY,
attributes);
}
private void appendToCurrentNodeAndPushBodyElement() throws SAXException {
appendToCurrentNodeAndPushBodyElement(tokenizer.emptyAttributes());
}
private void appendToCurrentNodeAndPushFormElementMayFoster(
HtmlAttributes attributes) throws SAXException {
// [NOCPP[
checkAttributes(attributes, "http://www.w3.org/1999/xhtml");
// ]NOCPP]
T elt;
StackNode<T> current = stack[currentPtr];
if (current.isFosterParenting()) {
fatal();
elt = createAndInsertFosterParentedElement("http://www.w3.org/1999/xhtml", "form", attributes
// CPPONLY: , htmlCreator(NS_NewHTMLFormElement)
);
} else {
T currentNode = nodeFromStackWithBlinkCompat(currentPtr);
elt = createElement("http://www.w3.org/1999/xhtml", "form", attributes, currentNode
// CPPONLY: , htmlCreator(NS_NewHTMLFormElement)
);
appendElement(elt, currentNode);
}
if (!isTemplateContents()) {
formPointer = elt;
}
StackNode<T> node = createStackNode(ElementName.FORM,
elt
// [NOCPP[
, errorHandler == null ? null : new TaintableLocatorImpl(tokenizer)
// ]NOCPP]
);
push(node);
}
private void appendToCurrentNodeAndPushFormattingElementMayFoster(
ElementName elementName, HtmlAttributes attributes)
throws SAXException {
// [NOCPP[
checkAttributes(attributes, "http://www.w3.org/1999/xhtml");
// ]NOCPP]
// This method can't be called for custom elements
HtmlAttributes clone = attributes.cloneAttributes();
// Attributes must not be read after calling createElement, because
// createElement may delete attributes in C++.
T elt;
StackNode<T> current = stack[currentPtr];
if (current.isFosterParenting()) {
fatal();
elt = createAndInsertFosterParentedElement("http://www.w3.org/1999/xhtml", elementName.getName(), attributes
// CPPONLY: , htmlCreator(elementName.getHtmlCreator())
);
} else {
T currentNode = nodeFromStackWithBlinkCompat(currentPtr);
elt = createElement("http://www.w3.org/1999/xhtml", elementName.getName(), attributes, currentNode
// CPPONLY: , htmlCreator(elementName.getHtmlCreator())
);
appendElement(elt, currentNode);
}
StackNode<T> node = createStackNode(elementName, elt, clone
// [NOCPP[
, errorHandler == null ? null : new TaintableLocatorImpl(tokenizer)
// ]NOCPP]
);
push(node);
append(node);
node.retain(); // append doesn't retain itself
}
private void appendToCurrentNodeAndPushElement(ElementName elementName,
HtmlAttributes attributes)
throws SAXException {
// [NOCPP[
checkAttributes(attributes, "http://www.w3.org/1999/xhtml");
// ]NOCPP]
// This method can't be called for custom elements
T currentNode = nodeFromStackWithBlinkCompat(currentPtr);
T elt = createElement("http://www.w3.org/1999/xhtml", elementName.getName(), attributes, currentNode
// CPPONLY: , htmlCreator(elementName.getHtmlCreator())
);
appendElement(elt, currentNode);
if (ElementName.TEMPLATE == elementName) {
elt = getDocumentFragmentForTemplate(elt);
}
StackNode<T> node = createStackNode(elementName, elt
// [NOCPP[
, errorHandler == null ? null : new TaintableLocatorImpl(tokenizer)
// ]NOCPP]
);
push(node);
}
private void appendToCurrentNodeAndPushElementMayFoster(ElementName elementName,
HtmlAttributes attributes)
throws SAXException {
@Local String popName = elementName.getName();
// [NOCPP[
checkAttributes(attributes, "http://www.w3.org/1999/xhtml");
if (!elementName.isInterned()) {
popName = checkPopName(popName);
}
// ]NOCPP]
T elt;
StackNode<T> current = stack[currentPtr];
if (current.isFosterParenting()) {
fatal();
elt = createAndInsertFosterParentedElement("http://www.w3.org/1999/xhtml", popName, attributes
// CPPONLY: , htmlCreator(elementName.getHtmlCreator())
);
} else {
T currentNode = nodeFromStackWithBlinkCompat(currentPtr);
elt = createElement("http://www.w3.org/1999/xhtml", popName, attributes, currentNode
// CPPONLY: , htmlCreator(elementName.getHtmlCreator())
);
appendElement(elt, currentNode);
}
StackNode<T> node = createStackNode(elementName, elt, popName
// [NOCPP[
, errorHandler == null ? null : new TaintableLocatorImpl(tokenizer)
// ]NOCPP]
);
push(node);
}
private void appendToCurrentNodeAndPushElementMayFosterMathML(
ElementName elementName, HtmlAttributes attributes)
throws SAXException {
@Local String popName = elementName.getName();
// [NOCPP[
checkAttributes(attributes, "http://www.w3.org/1998/Math/MathML");
if (!elementName.isInterned()) {
popName = checkPopName(popName);
}
// ]NOCPP]
boolean markAsHtmlIntegrationPoint = false;
if (ElementName.ANNOTATION_XML == elementName
&& annotationXmlEncodingPermitsHtml(attributes)) {
markAsHtmlIntegrationPoint = true;
}
// Attributes must not be read after calling createElement(), since
// createElement may delete the object in C++.
T elt;
StackNode<T> current = stack[currentPtr];
if (current.isFosterParenting()) {
fatal();
elt = createAndInsertFosterParentedElement("http://www.w3.org/1998/Math/MathML", popName, attributes
// CPPONLY: , htmlCreator(null)
);
} else {
T currentNode = nodeFromStackWithBlinkCompat(currentPtr);
elt = createElement("http://www.w3.org/1998/Math/MathML", popName, attributes, currentNode
// CPPONLY: , htmlCreator(null)
);
appendElement(elt, currentNode);
}
StackNode<T> node = createStackNode(elementName, elt, popName,
markAsHtmlIntegrationPoint
// [NOCPP[
, errorHandler == null ? null : new TaintableLocatorImpl(tokenizer)
// ]NOCPP]
);
push(node);
}
// [NOCPP[
T getDocumentFragmentForTemplate(T template) {
return template;
}
T getFormPointerForContext(T context) {
return null;
}
// ]NOCPP]
private boolean annotationXmlEncodingPermitsHtml(HtmlAttributes attributes) {
String encoding = attributes.getValue(AttributeName.ENCODING);
if (encoding == null) {
return false;
}
return Portability.lowerCaseLiteralEqualsIgnoreAsciiCaseString(
"application/xhtml+xml", encoding)
|| Portability.lowerCaseLiteralEqualsIgnoreAsciiCaseString(
"text/html", encoding);
}
private void appendToCurrentNodeAndPushElementMayFosterSVG(
ElementName elementName, HtmlAttributes attributes)
throws SAXException {
@Local String popName = elementName.getCamelCaseName();
// [NOCPP[
checkAttributes(attributes, "http://www.w3.org/2000/svg");
if (!elementName.isInterned()) {
popName = checkPopName(popName);
}
// ]NOCPP]
T elt;
StackNode<T> current = stack[currentPtr];
if (current.isFosterParenting()) {
fatal();
elt = createAndInsertFosterParentedElement("http://www.w3.org/2000/svg", popName, attributes
// CPPONLY: , svgCreator(elementName.getSvgCreator())
);
} else {
T currentNode = nodeFromStackWithBlinkCompat(currentPtr);
elt = createElement("http://www.w3.org/2000/svg", popName, attributes, currentNode
// CPPONLY: , svgCreator(elementName.getSvgCreator())
);
appendElement(elt, currentNode);
}
StackNode<T> node = createStackNode(elementName, popName, elt
// [NOCPP[
, errorHandler == null ? null : new TaintableLocatorImpl(tokenizer)
// ]NOCPP]
);
push(node);
}
private void appendToCurrentNodeAndPushElementMayFoster(ElementName elementName,
HtmlAttributes attributes, T form)
throws SAXException {
// [NOCPP[
checkAttributes(attributes, "http://www.w3.org/1999/xhtml");
// ]NOCPP]
// Can't be called for custom elements
T elt;
T formOwner = form == null || fragment || isTemplateContents() ? null : form;
StackNode<T> current = stack[currentPtr];
if (current.isFosterParenting()) {
fatal();
elt = createAndInsertFosterParentedElement("http://www.w3.org/1999/xhtml", elementName.getName(),
attributes, formOwner
// CPPONLY: , htmlCreator(elementName.getHtmlCreator())
);
} else {
T currentNode = nodeFromStackWithBlinkCompat(currentPtr);
elt = createElement("http://www.w3.org/1999/xhtml", elementName.getName(),
attributes, formOwner, currentNode
// CPPONLY: , htmlCreator(elementName.getHtmlCreator())
);
appendElement(elt, currentNode);
}
StackNode<T> node = createStackNode(elementName, elt
// [NOCPP[
, errorHandler == null ? null : new TaintableLocatorImpl(tokenizer)
// ]NOCPP]
);
push(node);
}
private void appendVoidElementToCurrentMayFoster(
ElementName elementName, HtmlAttributes attributes, T form) throws SAXException {
@Local String name = elementName.getName();
// [NOCPP[
checkAttributes(attributes, "http://www.w3.org/1999/xhtml");
// ]NOCPP]
// Can't be called for custom elements
T elt;
T formOwner = form == null || fragment || isTemplateContents() ? null : form;
StackNode<T> current = stack[currentPtr];
if (current.isFosterParenting()) {
fatal();
elt = createAndInsertFosterParentedElement("http://www.w3.org/1999/xhtml", name,
attributes, formOwner
// CPPONLY: , htmlCreator(elementName.getHtmlCreator())
);
} else {
T currentNode = nodeFromStackWithBlinkCompat(currentPtr);
elt = createElement("http://www.w3.org/1999/xhtml", name,
attributes, formOwner, currentNode
// CPPONLY: , htmlCreator(elementName.getHtmlCreator())
);
appendElement(elt, currentNode);
}
elementPushed("http://www.w3.org/1999/xhtml", name, elt);
elementPopped("http://www.w3.org/1999/xhtml", name, elt);
}
private void appendVoidElementToCurrentMayFoster(
ElementName elementName, HtmlAttributes attributes)
throws SAXException {
@Local String popName = elementName.getName();
// [NOCPP[
checkAttributes(attributes, "http://www.w3.org/1999/xhtml");
if (!elementName.isInterned()) {
popName = checkPopName(popName);
}
// ]NOCPP]
T elt;
StackNode<T> current = stack[currentPtr];
if (current.isFosterParenting()) {
fatal();
elt = createAndInsertFosterParentedElement("http://www.w3.org/1999/xhtml", popName, attributes
// CPPONLY: , htmlCreator(elementName.getHtmlCreator())
);
} else {
T currentNode = nodeFromStackWithBlinkCompat(currentPtr);
elt = createElement("http://www.w3.org/1999/xhtml", popName, attributes, currentNode
// CPPONLY: , htmlCreator(elementName.getHtmlCreator())
);
appendElement(elt, currentNode);
}
elementPushed("http://www.w3.org/1999/xhtml", popName, elt);
elementPopped("http://www.w3.org/1999/xhtml", popName, elt);
}
private void appendVoidElementToCurrentMayFosterSVG(
ElementName elementName, HtmlAttributes attributes)
throws SAXException {
@Local String popName = elementName.getCamelCaseName();
// [NOCPP[
checkAttributes(attributes, "http://www.w3.org/2000/svg");
if (!elementName.isInterned()) {
popName = checkPopName(popName);
}
// ]NOCPP]
T elt;
StackNode<T> current = stack[currentPtr];
if (current.isFosterParenting()) {
fatal();
elt = createAndInsertFosterParentedElement("http://www.w3.org/2000/svg", popName, attributes
// CPPONLY: , svgCreator(elementName.getSvgCreator())
);
} else {
T currentNode = nodeFromStackWithBlinkCompat(currentPtr);
elt = createElement("http://www.w3.org/2000/svg", popName, attributes, currentNode
// CPPONLY: , svgCreator(elementName.getSvgCreator())
);
appendElement(elt, currentNode);
}
elementPushed("http://www.w3.org/2000/svg", popName, elt);
elementPopped("http://www.w3.org/2000/svg", popName, elt);
}
private void appendVoidElementToCurrentMayFosterMathML(
ElementName elementName, HtmlAttributes attributes)
throws SAXException {
@Local String popName = elementName.getName();
// [NOCPP[
checkAttributes(attributes, "http://www.w3.org/1998/Math/MathML");
if (!elementName.isInterned()) {
popName = checkPopName(popName);
}
// ]NOCPP]
T elt;
StackNode<T> current = stack[currentPtr];
if (current.isFosterParenting()) {
fatal();
elt = createAndInsertFosterParentedElement("http://www.w3.org/1998/Math/MathML", popName, attributes
// CPPONLY: , htmlCreator(null)
);
} else {
T currentNode = nodeFromStackWithBlinkCompat(currentPtr);
elt = createElement("http://www.w3.org/1998/Math/MathML", popName, attributes, currentNode
// CPPONLY: , htmlCreator(null)
);
appendElement(elt, currentNode);
}
elementPushed("http://www.w3.org/1998/Math/MathML", popName, elt);
elementPopped("http://www.w3.org/1998/Math/MathML", popName, elt);
}
private void appendVoidInputToCurrent(HtmlAttributes attributes, T form) throws SAXException {
// [NOCPP[
checkAttributes(attributes, "http://www.w3.org/1999/xhtml");
// ]NOCPP]
// Can't be called for custom elements
T currentNode = nodeFromStackWithBlinkCompat(currentPtr);
T elt = createElement("http://www.w3.org/1999/xhtml", "input", attributes,
form == null || fragment || isTemplateContents() ? null : form, currentNode
// CPPONLY: , htmlCreator(NS_NewHTMLInputElement)
);
appendElement(elt, currentNode);
elementPushed("http://www.w3.org/1999/xhtml", "input", elt);
elementPopped("http://www.w3.org/1999/xhtml", "input", elt);
}
private void appendVoidFormToCurrent(HtmlAttributes attributes) throws SAXException {
// [NOCPP[
checkAttributes(attributes, "http://www.w3.org/1999/xhtml");
// ]NOCPP]
T currentNode = nodeFromStackWithBlinkCompat(currentPtr);
T elt = createElement("http://www.w3.org/1999/xhtml", "form",
attributes, currentNode
// CPPONLY: , htmlCreator(NS_NewHTMLFormElement)
);
formPointer = elt;
// ownership transferred to form pointer
appendElement(elt, currentNode);
elementPushed("http://www.w3.org/1999/xhtml", "form", elt);
elementPopped("http://www.w3.org/1999/xhtml", "form", elt);
}
// [NOCPP[
private final void accumulateCharactersForced(@Const @NoLength char[] buf,
int start, int length) throws SAXException {
System.arraycopy(buf, start, charBuffer, charBufferLen, length);
charBufferLen += length;
}
@Override public void ensureBufferSpace(int inputLength)
throws SAXException {
// TODO: Unify Tokenizer.strBuf and TreeBuilder.charBuffer so that
// this method becomes unnecessary.
int worstCase = charBufferLen + inputLength;
if (charBuffer == null) {
// Add an arbitrary small value to avoid immediate reallocation
// once there are a few characters in the buffer.
charBuffer = new char[worstCase + 128];
} else if (worstCase > charBuffer.length) {
// HotSpot reportedly allocates memory with 8-byte accuracy, so
// there's no point in trying to do math here to avoid slop.
// Maybe we should add some small constant to worstCase here
// but not doing that without profiling. In C++ with jemalloc,
// the corresponding method should do math to round up here
// to avoid slop.
char[] newBuf = new char[worstCase];
System.arraycopy(charBuffer, 0, newBuf, 0, charBufferLen);
charBuffer = newBuf;
}
}
// ]NOCPP]
protected void accumulateCharacters(@Const @NoLength char[] buf, int start,
int length) throws SAXException {
appendCharacters(stack[currentPtr].node, buf, start, length);
}
// ------------------------------- //
protected final void requestSuspension() {
tokenizer.requestSuspension();
}
protected abstract T createElement(@NsUri String ns, @Local String name,
HtmlAttributes attributes, T intendedParent
// CPPONLY: , @Creator Object creator
) throws SAXException;
protected T createElement(@NsUri String ns, @Local String name,
HtmlAttributes attributes, T form, T intendedParent
// CPPONLY: , @Creator Object creator
) throws SAXException {
return createElement("http://www.w3.org/1999/xhtml", name, attributes, intendedParent
// CPPONLY: , creator
);
}
protected abstract T createHtmlElementSetAsRoot(HtmlAttributes attributes)
throws SAXException;
protected abstract void detachFromParent(T element) throws SAXException;
protected abstract boolean hasChildren(T element) throws SAXException;
protected abstract void appendElement(T child, T newParent)
throws SAXException;
protected abstract void appendChildrenToNewParent(T oldParent, T newParent)
throws SAXException;
protected abstract void insertFosterParentedChild(T child, T table,
T stackParent) throws SAXException;
// We don't generate CPP code for this method because it is not used in generated CPP
// code. Instead, the form owner version of this method is called with a null form owner.
// [NOCPP[
protected abstract T createAndInsertFosterParentedElement(@NsUri String ns, @Local String name,
HtmlAttributes attributes, T table, T stackParent) throws SAXException;
// ]NOCPP]
protected T createAndInsertFosterParentedElement(@NsUri String ns, @Local String name,
HtmlAttributes attributes, T form, T table, T stackParent
// CPPONLY: , @Creator Object creator
) throws SAXException {
return createAndInsertFosterParentedElement(ns, name, attributes, table, stackParent);
};
protected abstract void insertFosterParentedCharacters(
@NoLength char[] buf, int start, int length, T table, T stackParent)
throws SAXException;
protected abstract void appendCharacters(T parent, @NoLength char[] buf,
int start, int length) throws SAXException;
protected abstract void appendComment(T parent, @NoLength char[] buf,
int start, int length) throws SAXException;
protected abstract void appendCommentToDocument(@NoLength char[] buf,
int start, int length) throws SAXException;
protected abstract void addAttributesToElement(T element,
HtmlAttributes attributes) throws SAXException;
protected void markMalformedIfScript(T elt) throws SAXException {
}
protected void start(boolean fragmentMode) throws SAXException {
}
protected void end() throws SAXException {
}
protected void appendDoctypeToDocument(@Local String name,
String publicIdentifier, String systemIdentifier)
throws SAXException {
}
protected void elementPushed(@NsUri String ns, @Local String name, T node)
throws SAXException {
}
protected void elementPopped(@NsUri String ns, @Local String name, T node)
throws SAXException {
}
// [NOCPP[
protected void documentMode(DocumentMode m, String publicIdentifier,
String systemIdentifier)
throws SAXException {
}
/**
* @see nu.validator.htmlparser.common.TokenHandler#wantsComments()
*/
public boolean wantsComments() {
return wantingComments;
}
public void setIgnoringComments(boolean ignoreComments) {
wantingComments = !ignoreComments;
}
/**
* Sets the errorHandler.
*
* @param errorHandler
* the errorHandler to set
*/
public final void setErrorHandler(ErrorHandler errorHandler) {
this.errorHandler = errorHandler;
}
/**
* Returns the errorHandler.
*
* @return the errorHandler
*/
public ErrorHandler getErrorHandler() {
return errorHandler;
}
/**
* The argument MUST be an interned string or <code>null</code>.
*
* @param context
*/
public final void setFragmentContext(@Local String context) {
this.contextName = context;
this.contextNamespace = "http://www.w3.org/1999/xhtml";
this.contextNode = null;
this.fragment = (contextName != null);
this.quirks = false;
}
// ]NOCPP]
/**
* @see nu.validator.htmlparser.common.TokenHandler#cdataSectionAllowed()
*/
@Inline public boolean cdataSectionAllowed() throws SAXException {
return isInForeign();
}
private boolean isInForeign() {
return currentPtr >= 0
&& stack[currentPtr].ns != "http://www.w3.org/1999/xhtml";
}
private boolean isInForeignButNotHtmlOrMathTextIntegrationPoint() {
if (currentPtr < 0) {
return false;
}
return !isSpecialParentInForeign(stack[currentPtr]);
}
/**
* The argument MUST be an interned string or <code>null</code>.
*
* @param context
*/
public final void setFragmentContext(@Local String context,
@NsUri String ns, T node, boolean quirks) {
// [NOCPP[
if (!((context == null && ns == null)
|| "http://www.w3.org/1999/xhtml" == ns
|| "http://www.w3.org/2000/svg" == ns || "http://www.w3.org/1998/Math/MathML" == ns)) {
throw new IllegalArgumentException(
"The namespace must be the HTML, SVG or MathML namespace (or null when the local name is null). Got: "
+ ns);
}
// ]NOCPP]
this.contextName = context;
this.contextNamespace = ns;
this.contextNode = node;
this.fragment = (contextName != null);
this.quirks = quirks;
}
protected final T currentNode() {
return stack[currentPtr].node;
}
/**
* Returns the scriptingEnabled.
*
* @return the scriptingEnabled
*/
public boolean isScriptingEnabled() {
return scriptingEnabled;
}
/**
* Sets the scriptingEnabled.
*
* @param scriptingEnabled
* the scriptingEnabled to set
*/
public void setScriptingEnabled(boolean scriptingEnabled) {
this.scriptingEnabled = scriptingEnabled;
}
public void setForceNoQuirks(boolean forceNoQuirks) {
this.forceNoQuirks = forceNoQuirks;
}
// Redundant method retained because previously public.
public void setIsSrcdocDocument(boolean isSrcdocDocument) {
this.setForceNoQuirks(isSrcdocDocument);
}
// [NOCPP[
public void setNamePolicy(XmlViolationPolicy namePolicy) {
this.namePolicy = namePolicy;
}
/**
* Sets the documentModeHandler.
*
* @param documentModeHandler
* the documentModeHandler to set
*/
public void setDocumentModeHandler(DocumentModeHandler documentModeHandler) {
this.documentModeHandler = documentModeHandler;
}
/**
* Sets the reportingDoctype.
*
* @param reportingDoctype
* the reportingDoctype to set
*/
public void setReportingDoctype(boolean reportingDoctype) {
this.reportingDoctype = reportingDoctype;
}
// ]NOCPP]
/**
* Flushes the pending characters. Public for document.write use cases only.
* @throws SAXException
*/
public final void flushCharacters() throws SAXException {
if (charBufferLen > 0) {
if ((mode == IN_TABLE || mode == IN_TABLE_BODY || mode == IN_ROW)
&& charBufferContainsNonWhitespace()) {
errNonSpaceInTable();
reconstructTheActiveFormattingElements();
if (!stack[currentPtr].isFosterParenting()) {
// reconstructing gave us a new current node
appendCharacters(currentNode(), charBuffer, 0,
charBufferLen);
charBufferLen = 0;
return;
}
int tablePos = findLastOrRoot(TreeBuilder.TABLE);
int templatePos = findLastOrRoot(TreeBuilder.TEMPLATE);
if (templatePos >= tablePos) {
appendCharacters(stack[templatePos].node, charBuffer, 0, charBufferLen);
charBufferLen = 0;
return;
}
StackNode<T> tableElt = stack[tablePos];
insertFosterParentedCharacters(charBuffer, 0, charBufferLen,
tableElt.node, stack[tablePos - 1].node);
charBufferLen = 0;
return;
}
appendCharacters(currentNode(), charBuffer, 0, charBufferLen);
charBufferLen = 0;
}
}
private boolean charBufferContainsNonWhitespace() {
for (int i = 0; i < charBufferLen; i++) {
switch (charBuffer[i]) {
case ' ':
case '\t':
case '\n':
case '\r':
case '\u000C':
continue;
default:
return true;
}
}
return false;
}
/**
* Creates a comparable snapshot of the tree builder state. Snapshot
* creation is only supported immediately after a script end tag has been
* processed. In C++ the caller is responsible for calling
* <code>delete</code> on the returned object.
*
* @return a snapshot.
* @throws SAXException
*/
@SuppressWarnings("unchecked") public TreeBuilderState<T> newSnapshot()
throws SAXException {
StackNode<T>[] listCopy = new StackNode[listPtr + 1];
for (int i = 0; i < listCopy.length; i++) {
StackNode<T> node = listOfActiveFormattingElements[i];
if (node != null) {
StackNode<T> newNode = new StackNode<T>(-1);
newNode.setValues(node.getFlags(), node.ns,
node.name, node.node, node.popName,
node.attributes.cloneAttributes()
// CPPONLY: , node.getHtmlCreator()
// [NOCPP[
, node.getLocator()
// ]NOCPP]
);
listCopy[i] = newNode;
} else {
listCopy[i] = null;
}
}
StackNode<T>[] stackCopy = new StackNode[currentPtr + 1];
for (int i = 0; i < stackCopy.length; i++) {
StackNode<T> node = stack[i];
int listIndex = findInListOfActiveFormattingElements(node);
if (listIndex == -1) {
StackNode<T> newNode = new StackNode<T>(-1);
newNode.setValues(node.getFlags(), node.ns,
node.name, node.node, node.popName,
null
// CPPONLY: , node.getHtmlCreator()
// [NOCPP[
, node.getLocator()
// ]NOCPP]
);
stackCopy[i] = newNode;
} else {
stackCopy[i] = listCopy[listIndex];
stackCopy[i].retain();
}
}
int[] templateModeStackCopy = new int[templateModePtr + 1];
System.arraycopy(templateModeStack, 0, templateModeStackCopy, 0,
templateModeStackCopy.length);
return new StateSnapshot<T>(stackCopy, listCopy, templateModeStackCopy, formPointer,
headPointer, mode, originalMode, framesetOk,
needToDropLF, quirks);
}
public boolean snapshotMatches(TreeBuilderState<T> snapshot) {
StackNode<T>[] stackCopy = snapshot.getStack();
int stackLen = snapshot.getStackLength();
StackNode<T>[] listCopy = snapshot.getListOfActiveFormattingElements();
int listLen = snapshot.getListOfActiveFormattingElementsLength();
int[] templateModeStackCopy = snapshot.getTemplateModeStack();
int templateModeStackLen = snapshot.getTemplateModeStackLength();
if (stackLen != currentPtr + 1
|| listLen != listPtr + 1
|| templateModeStackLen != templateModePtr + 1
|| formPointer != snapshot.getFormPointer()
|| headPointer != snapshot.getHeadPointer()
|| mode != snapshot.getMode()
|| originalMode != snapshot.getOriginalMode()
|| framesetOk != snapshot.isFramesetOk()
|| needToDropLF != snapshot.isNeedToDropLF()
|| quirks != snapshot.isQuirks()) { // maybe just assert quirks
return false;
}
for (int i = listLen - 1; i >= 0; i--) {
if (listCopy[i] == null
&& listOfActiveFormattingElements[i] == null) {
continue;
} else if (listCopy[i] == null
|| listOfActiveFormattingElements[i] == null) {
return false;
}
if (listCopy[i].node != listOfActiveFormattingElements[i].node) {
return false; // it's possible that this condition is overly
// strict
}
}
for (int i = stackLen - 1; i >= 0; i--) {
if (stackCopy[i].node != stack[i].node) {
return false;
}
}
for (int i = templateModeStackLen - 1; i >=0; i--) {
if (templateModeStackCopy[i] != templateModeStack[i]) {
return false;
}
}
return true;
}
@SuppressWarnings("unchecked") public void loadState(
TreeBuilderState<T> snapshot)
throws SAXException {
// CPPONLY: mCurrentHtmlScriptIsAsyncOrDefer = false;
StackNode<T>[] stackCopy = snapshot.getStack();
int stackLen = snapshot.getStackLength();
StackNode<T>[] listCopy = snapshot.getListOfActiveFormattingElements();
int listLen = snapshot.getListOfActiveFormattingElementsLength();
int[] templateModeStackCopy = snapshot.getTemplateModeStack();
int templateModeStackLen = snapshot.getTemplateModeStackLength();
for (int i = 0; i <= listPtr; i++) {
if (listOfActiveFormattingElements[i] != null) {
listOfActiveFormattingElements[i].release(this);
}
}
if (listOfActiveFormattingElements.length < listLen) {
listOfActiveFormattingElements = new StackNode[listLen];
}
listPtr = listLen - 1;
for (int i = 0; i <= currentPtr; i++) {
stack[i].release(this);
}
if (stack.length < stackLen) {
stack = new StackNode[stackLen];
}
currentPtr = stackLen - 1;
if (templateModeStack.length < templateModeStackLen) {
templateModeStack = new int[templateModeStackLen];
}
templateModePtr = templateModeStackLen - 1;
for (int i = 0; i < listLen; i++) {
StackNode<T> node = listCopy[i];
if (node != null) {
StackNode<T> newNode = createStackNode(node.getFlags(), node.ns,
node.name, node.node,
node.popName,
node.attributes.cloneAttributes()
// CPPONLY: , node.getHtmlCreator()
// [NOCPP[
, node.getLocator()
// ]NOCPP]
);
listOfActiveFormattingElements[i] = newNode;
} else {
listOfActiveFormattingElements[i] = null;
}
}
for (int i = 0; i < stackLen; i++) {
StackNode<T> node = stackCopy[i];
int listIndex = findInArray(node, listCopy);
if (listIndex == -1) {
StackNode<T> newNode = createStackNode(node.getFlags(), node.ns,
node.name, node.node,
node.popName,
null
// CPPONLY: , node.getHtmlCreator()
// [NOCPP[
, node.getLocator()
// ]NOCPP]
);
stack[i] = newNode;
} else {
stack[i] = listOfActiveFormattingElements[listIndex];
stack[i].retain();
}
}
System.arraycopy(templateModeStackCopy, 0, templateModeStack, 0, templateModeStackLen);
formPointer = snapshot.getFormPointer();
headPointer = snapshot.getHeadPointer();
mode = snapshot.getMode();
originalMode = snapshot.getOriginalMode();
framesetOk = snapshot.isFramesetOk();
needToDropLF = snapshot.isNeedToDropLF();
quirks = snapshot.isQuirks();
}
private int findInArray(StackNode<T> node, StackNode<T>[] arr) {
for (int i = listPtr; i >= 0; i--) {
if (node == arr[i]) {
return i;
}
}
return -1;
}
/**
* Returns <code>stack[stackPos].node</code> if <code>stackPos</code> is
* smaller than Blink's magic limit or the node at Blink's magic limit
* otherwise.
*
* In order to get Blink-compatible handling of excessive deeply-nested
* markup, this method must be used to obtain the node that is used as the
* parent node of an insertion.
*
* Blink's magic number is 512, but our counting is off by one compared to
* Blink's way of counting, so in order to get the same
* externally-observable outcome, we use 511 as our magic number.
*
* @param stackPos the stack position to attempt to read
* @return node at the position capped to Blink's magic number
* @throws SAXException
*/
private T nodeFromStackWithBlinkCompat(int stackPos) throws SAXException {
// Magic number if off by one relative to Blink's magic number, but the
// outcome is the same, because the counting is different by one.
if (stackPos > 511) {
errDeepTree();
return stack[511].node;
}
return stack[stackPos].node;
}
/**
* @see nu.validator.htmlparser.impl.TreeBuilderState#getFormPointer()
*/
@Override
public T getFormPointer() {
return formPointer;
}
/**
* Returns the headPointer.
*
* @return the headPointer
*/
@Override
public T getHeadPointer() {
return headPointer;
}
/**
* @see nu.validator.htmlparser.impl.TreeBuilderState#getListOfActiveFormattingElements()
*/
@Override
public StackNode<T>[] getListOfActiveFormattingElements() {
return listOfActiveFormattingElements;
}
/**
* @see nu.validator.htmlparser.impl.TreeBuilderState#getStack()
*/
@Override
public StackNode<T>[] getStack() {
return stack;
}
/**
* @see nu.validator.htmlparser.impl.TreeBuilderState#getTemplateModeStack()
*/
@Override
public int[] getTemplateModeStack() {
return templateModeStack;
}
/**
* Returns the mode.
*
* @return the mode
*/
@Override
public int getMode() {
return mode;
}
/**
* Returns the originalMode.
*
* @return the originalMode
*/
@Override
public int getOriginalMode() {
return originalMode;
}
/**
* Returns the framesetOk.
*
* @return the framesetOk
*/
@Override
public boolean isFramesetOk() {
return framesetOk;
}
/**
* Returns the needToDropLF.
*
* @return the needToDropLF
*/
@Override
public boolean isNeedToDropLF() {
return needToDropLF;
}
/**
* Returns the quirks.
*
* @return the quirks
*/
@Override
public boolean isQuirks() {
return quirks;
}
/**
* @see nu.validator.htmlparser.impl.TreeBuilderState#getListOfActiveFormattingElementsLength()
*/
@Override
public int getListOfActiveFormattingElementsLength() {
return listPtr + 1;
}
/**
* @see nu.validator.htmlparser.impl.TreeBuilderState#getStackLength()
*/
@Override
public int getStackLength() {
return currentPtr + 1;
}
/**
* @see nu.validator.htmlparser.impl.TreeBuilderState#getTemplateModeStackLength()
*/
@Override
public int getTemplateModeStackLength() {
return templateModePtr + 1;
}
/**
* Complains about an over-deep tree. Theoretically this should just be
* a warning, but in practice authors should take this as an error.
*
* @throws SAXException
*/
private void errDeepTree() throws SAXException {
err("The document tree is more than 513 elements deep, which causes Firefox and Chrome to flatten the tree.");
}
/**
* Reports a stray start tag.
* @param name the name of the stray tag
*
* @throws SAXException
*/
private void errStrayStartTag(@Local String name) throws SAXException {
err("Stray start tag \u201C" + name + "\u201D.");
}
/**
* Reports a stray end tag.
* @param name the name of the stray tag
*
* @throws SAXException
*/
private void errStrayEndTag(@Local String name) throws SAXException {
err("Stray end tag \u201C" + name + "\u201D.");
}
/**
* Reports a state when elements expected to be closed were not.
*
* @param eltPos the position of the start tag on the stack of the element
* being closed.
* @param name the name of the end tag
*
* @throws SAXException
*/
private void errUnclosedElements(int eltPos, @Local String name) throws SAXException {
errNoCheck("End tag \u201C" + name + "\u201D seen, but there were open elements.");
errListUnclosedStartTags(eltPos);
}
/**
* Reports a state when elements expected to be closed ahead of an implied
* end tag but were not.
*
* @param eltPos the position of the start tag on the stack of the element
* being closed.
* @param name the name of the end tag
*
* @throws SAXException
*/
private void errUnclosedElementsImplied(int eltPos, String name) throws SAXException {
errNoCheck("End tag \u201C" + name + "\u201D implied, but there were open elements.");
errListUnclosedStartTags(eltPos);
}
/**
* Reports a state when elements expected to be closed ahead of an implied
* table cell close.
*
* @param eltPos the position of the start tag on the stack of the element
* being closed.
* @throws SAXException
*/
private void errUnclosedElementsCell(int eltPos) throws SAXException {
errNoCheck("A table cell was implicitly closed, but there were open elements.");
errListUnclosedStartTags(eltPos);
}
private void errStrayDoctype() throws SAXException {
err("Stray doctype.");
}
private void errAlmostStandardsDoctype() throws SAXException {
if (!forceNoQuirks) {
err("Almost standards mode doctype. Expected \u201C<!DOCTYPE html>\u201D.");
}
}
private void errQuirkyDoctype() throws SAXException {
if (!forceNoQuirks) {
err("Quirky doctype. Expected \u201C<!DOCTYPE html>\u201D.");
}
}
private void errNonSpaceInTrailer() throws SAXException {
err("Non-space character in page trailer.");
}
private void errNonSpaceAfterFrameset() throws SAXException {
err("Non-space after \u201Cframeset\u201D.");
}
private void errNonSpaceInFrameset() throws SAXException {
err("Non-space in \u201Cframeset\u201D.");
}
private void errNonSpaceAfterBody() throws SAXException {
err("Non-space character after body.");
}
private void errNonSpaceInColgroupInFragment() throws SAXException {
err("Non-space in \u201Ccolgroup\u201D when parsing fragment.");
}
private void errNonSpaceInNoscriptInHead() throws SAXException {
err("Non-space character inside \u201Cnoscript\u201D inside \u201Chead\u201D.");
}
private void errFooBetweenHeadAndBody(@Local String name) throws SAXException {
if (errorHandler == null) {
return;
}
errNoCheck("\u201C" + name + "\u201D element between \u201Chead\u201D and \u201Cbody\u201D.");
}
private void errStartTagWithoutDoctype() throws SAXException {
if (!forceNoQuirks) {
err("Start tag seen without seeing a doctype first. Expected \u201C<!DOCTYPE html>\u201D.");
}
}
private void errNoSelectInTableScope() throws SAXException {
err("No \u201Cselect\u201D in table scope.");
}
private void errStartSelectWhereEndSelectExpected() throws SAXException {
err("\u201Cselect\u201D start tag where end tag expected.");
}
private void errStartTagWithSelectOpen(@Local String name)
throws SAXException {
if (errorHandler == null) {
return;
}
errNoCheck("\u201C" + name
+ "\u201D start tag with \u201Cselect\u201D open.");
}
private void errBadStartTagInNoscriptInHead(@Local String name) throws SAXException {
if (errorHandler == null) {
return;
}
errNoCheck("Bad start tag in \u201C" + name
+ "\u201D in \u201Cnoscript\u201D in \u201Chead\u201D.");
}
private void errImage() throws SAXException {
err("Saw a start tag \u201Cimage\u201D.");
}
private void errFooSeenWhenFooOpen(@Local String name) throws SAXException {
if (errorHandler == null) {
return;
}
errNoCheck("Start tag \u201C" + name + "\u201D seen but an element of the same type was already open.");
}
private void errHeadingWhenHeadingOpen() throws SAXException {
err("Heading cannot be a child of another heading.");
}
private void errFramesetStart() throws SAXException {
err("\u201Cframeset\u201D start tag seen.");
}
private void errNoCellToClose() throws SAXException {
err("No cell to close.");
}
private void errStartTagInTable(@Local String name) throws SAXException {
if (errorHandler == null) {
return;
}
errNoCheck("Start tag \u201C" + name
+ "\u201D seen in \u201Ctable\u201D.");
}
private void errFormWhenFormOpen() throws SAXException {
err("Saw a \u201Cform\u201D start tag, but there was already an active \u201Cform\u201D element. Nested forms are not allowed. Ignoring the tag.");
}
private void errTableSeenWhileTableOpen() throws SAXException {
err("Start tag for \u201Ctable\u201D seen but the previous \u201Ctable\u201D is still open.");
}
private void errStartTagInTableBody(@Local String name) throws SAXException {
if (errorHandler == null) {
return;
}
errNoCheck("\u201C" + name + "\u201D start tag in table body.");
}
private void errEndTagSeenWithoutDoctype() throws SAXException {
if (!forceNoQuirks) {
err("End tag seen without seeing a doctype first. Expected \u201C<!DOCTYPE html>\u201D.");
}
}
private void errEndTagAfterBody() throws SAXException {
err("Saw an end tag after \u201Cbody\u201D had been closed.");
}
private void errEndTagSeenWithSelectOpen(@Local String name) throws SAXException {
if (errorHandler == null) {
return;
}
errNoCheck("\u201C" + name
+ "\u201D end tag with \u201Cselect\u201D open.");
}
private void errGarbageInColgroup() throws SAXException {
err("Garbage in \u201Ccolgroup\u201D fragment.");
}
private void errEndTagBr() throws SAXException {
err("End tag \u201Cbr\u201D.");
}
private void errNoElementToCloseButEndTagSeen(@Local String name)
throws SAXException {
if (errorHandler == null) {
return;
}
errNoCheck("No \u201C" + name + "\u201D element in scope but a \u201C"
+ name + "\u201D end tag seen.");
}
private void errHtmlStartTagInForeignContext(@Local String name)
throws SAXException {
if (errorHandler == null) {
return;
}
errNoCheck("HTML start tag \u201C" + name
+ "\u201D in a foreign namespace context.");
}
private void errNoTableRowToClose() throws SAXException {
err("No table row to close.");
}
private void errNonSpaceInTable() throws SAXException {
err("Misplaced non-space characters inside a table.");
}
private void errUnclosedChildrenInRuby() throws SAXException {
if (errorHandler == null) {
return;
}
errNoCheck("Unclosed children in \u201Cruby\u201D.");
}
private void errStartTagSeenWithoutRuby(@Local String name) throws SAXException {
if (errorHandler == null) {
return;
}
errNoCheck("Start tag \u201C"
+ name
+ "\u201D seen without a \u201Cruby\u201D element being open.");
}
private void errSelfClosing() throws SAXException {
if (errorHandler == null) {
return;
}
errNoCheck("Self-closing syntax (\u201C/>\u201D) used on a non-void HTML element. Ignoring the slash and treating as a start tag.");
}
private void errNoCheckUnclosedElementsOnStack() throws SAXException {
errNoCheck("Unclosed elements on stack.");
}
private void errEndTagDidNotMatchCurrentOpenElement(@Local String name,
@Local String currOpenName) throws SAXException {
if (errorHandler == null) {
return;
}
errNoCheck("End tag \u201C"
+ name
+ "\u201D did not match the name of the current open element (\u201C"
+ currOpenName + "\u201D).");
}
private void errEndTagViolatesNestingRules(@Local String name) throws SAXException {
if (errorHandler == null) {
return;
}
errNoCheck("End tag \u201C" + name + "\u201D violates nesting rules.");
}
private void errEofWithUnclosedElements() throws SAXException {
if (errorHandler == null) {
return;
}
errNoCheck("End of file seen and there were open elements.");
// just report all remaining unclosed elements
errListUnclosedStartTags(0);
}
/**
* Reports arriving at/near end of document with unclosed elements remaining.
*
* @param message
* the message
* @throws SAXException
*/
private void errEndWithUnclosedElements(@Local String name) throws SAXException {
if (errorHandler == null) {
return;
}
errNoCheck("End tag for \u201C"
+ name
+ "\u201D seen, but there were unclosed elements.");
// just report all remaining unclosed elements
errListUnclosedStartTags(0);
}
}
|