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 | package Torello.HTML; import java.util.*; import Torello.HTML.NodeSearch.*; /** * A simple, demonstrative set of functions for retrieving {@code HTMLNode's} from a web-page * (a 'Workbook Class'). * * <BR /><BR /><EMBED CLASS="external-html" DATA-FILE-ID=ELEMENTS> */ @Torello.JavaDoc.StaticFunctional public class Elements { private Elements() { } /** * Retrieves the start and end points of the web-page body in the underlying HTML * page-{@code Vector}. * All nodes between {@code <BODY> ... </BODY>} will be included. * * @param html <EMBED CLASS="external-html" DATA-FILE-ID="HTMLVEC"> * * @return The start and end index pointers, as a {@code DotPair}, of the HTML requested * HTML sublist. * * @see InnerTagFindInclusive */ public static DotPair findBody(Vector<? extends HTMLNode> html) { return InnerTagFindInclusive.first(html, "body"); } /** * Gets the nodes of the web-page body. * All nodes between {@code <BODY> ... </BODY>} will be included. * * @param html <EMBED CLASS="external-html" DATA-FILE-ID="HTMLVEC"> * * @return The requested HTML sublist, as a {@code Vector}. * * @see InnerTagGetInclusive */ public static Vector<HTMLNode> getBody(Vector<? extends HTMLNode> html) { return InnerTagGetInclusive.first(html, "body"); } /** * Retrieves the start and end points of the web-page header in the underlying HTML * page-{@code Vector}. * All nodes between {@code <HEAD> ... </HEAD>} will be included. * * @param html <EMBED CLASS="external-html" DATA-FILE-ID="HTMLVEC"> * * @return The start and end index pointers, as a {@code DotPair}, of the HTML requested * HTML sublist. * * @see InnerTagFindInclusive */ public static DotPair findHead(Vector<? extends HTMLNode> html) { return InnerTagFindInclusive.first(html, "head"); } /** * Gets the nodes of the web-page header. * All nodes between {@code <HEAD> ... </HEAD>} will be included. * * @param html <EMBED CLASS="external-html" DATA-FILE-ID="HTMLVEC"> * * @return The requested HTML sublist, as a {@code Vector}. * * @see InnerTagGetInclusive */ public static Vector<HTMLNode> getHead(Vector<? extends HTMLNode> html) { return InnerTagGetInclusive.first(html, "head"); } /** * Gets all {@code <META NAME="..." CONTENT="...">} (or {@code <META CHARSET="...">} * and {@code <META HTTP-EQUIV="...">}) elements in a web-page header - returned via * their position in the page-{@code Vector}. * * @param html <EMBED CLASS="external-html" DATA-FILE-ID="HTMLVEC"> * * @return The requested HTML Elements, as an integer-array list of index-pointers to * the underlying {@code Vector}. * * @see TagNodeFind */ public static int[] findMeta(Vector<? extends HTMLNode> html) { return TagNodeFind.all(html, TC.OpeningTags, "meta"); } /** * Gets all {@code <META NAME="..." CONTENT="...">} (or {@code <META CHARSET="...">} * and {@code <META HTTP-EQUIV="...">}) elements in a web-page header. * * @param html <EMBED CLASS="external-html" DATA-FILE-ID="HTMLVEC"> * * @return The requested HTML Elements, as {@code TagNode's}, in a return {@code Vector}. * * @see TagNodeGet */ public static Vector<TagNode> getMeta(Vector<? extends HTMLNode> html) { return TagNodeGet.all(html, TC.OpeningTags, "meta"); } /** * Gets all {@code <LINK REL="..." HREF="...">} elements in a web-page header - returned * via their position in the page-{@code Vector}. * * @param html <EMBED CLASS="external-html" DATA-FILE-ID="HTMLVEC"> * * @return The requested HTML Elements, as an integer-array list of index-pointers to * the underlying {@code Vector}. * * @see TagNodeFind */ public static int[] findLink(Vector<? extends HTMLNode> html) { return TagNodeFind.all(html, TC.OpeningTags, "link"); } /** * Gets all {@code <LINK REL="..." HREF="...">} elements in a web-page header. * * @param html <EMBED CLASS="external-html" DATA-FILE-ID="HTMLVEC"> * * @return The requested HTML Elements, as {@code TagNode's}, in a return {@code Vector}. * * @see TagNodeGet */ public static Vector<TagNode> getLink(Vector<? extends HTMLNode> html) { return TagNodeGet.all(html, TC.OpeningTags, "link"); } /** * Returns the start and end positions in the page-{@code Vector} of the HTML * {@code <TITLE>...</TITLE>} elements. * * @param html <EMBED CLASS="external-html" DATA-FILE-ID="HTMLVEC"> * * @return The start and end index pointers, as a {@code DotPair}, of the HTML * requested HTML sublist. * * @see InnerTagFindInclusive */ public static DotPair findTitle(Vector<? extends HTMLNode> html) { return TagNodeFindInclusive.first(html, "title"); } /** * Returns the {@code <TITLE>...</TITLE>} elements sub-list from the HTML page-{@code Vector}. * * @param html <EMBED CLASS="external-html" DATA-FILE-ID="HTMLVEC"> * * @return The requested HTML sublist, as a {@code Vector}. * * @see InnerTagGetInclusive */ public static Vector<HTMLNode> getTitle(Vector<? extends HTMLNode> html) { return TagNodeGetInclusive.first(html, "title"); } /** * Returns the {@code String} encapsulated by the HTML {@code 'HEAD'}-section's * {@code "<TITLE>...</TITLE>"} element, if there such an element. If there is no such * element, null is returned. If there is a {@code 'TITLE'} element, but it has the * empty-{@code String} (zero-length-string) an empty {@code String} is returned. * * @param html <EMBED CLASS="external-html" DATA-FILE-ID="HTMLVEC"> * Retrieves the {@code 'TITLE'} of an HTML page - by getting the {@code String}-text between * the {@code 'TITLE'} elements. * * @return The title string */ public static String titleString(Vector<? extends HTMLNode> html) { Vector<HTMLNode> title = getTitle(html); if (title == null) return null; return Util.textNodesString(title); } /** * This method will find the very first HTML {@code 'TABLE'} * (<CODE><TABLE> <TH>...</TH> <TR> <TD>..</TD> ... * </TR> ... </TABLE></CODE>) element set. This returns the {@code Vector} * Position starting and ending boundaries {@code DotPair.start, DotPair.end} rather than * pointer-references to the nodes. This is what the <B>{@code 'FIND'}</B> keyword usually * means in this HTML-Scrape package. * * @param html <EMBED CLASS="external-html" DATA-FILE-ID="HTMLVEC"> * * @return The start and end index pointers, as a {@code DotPair}, of the HTML requested HTML * sublist. * * @see TagNodeFindInclusive */ public static DotPair findTable(Vector<? extends HTMLNode> html) { return TagNodeFindInclusive.first(html, "table"); } /** * This method will find the very first HTML {@code 'TABLE'} * (<CODE><TABLE> <TH>...</TH> <TR> <TD>..</TD> ... * </TR> ... </TABLE></CODE>) element set. This returns the {@code Vector} Position * starting and ending boundaries {@code DotPair.start, DotPair.end} rather than * pointer-references to the nodes. This is what the <B>{@code 'FIND'}</B> keyword usually * means in this HTML-Scrape package. * * @param html <EMBED CLASS="external-html" DATA-FILE-ID="HTMLVEC"> * @param sPos <EMBED CLASS="external-html" DATA-FILE-ID="SPOSVEC"> * @param ePos <EMBED CLASS="external-html" DATA-FILE-ID="EPOSVEC"> * * @return The start and end index pointers, as a {@code DotPair}, of the HTML requested HTML * sublist. * * @throws IndexOutOfBoundsException <EMBED CLASS="external-html" DATA-FILE-ID="VIOOBEX"> * * @see TagNodeFindInclusive */ public static DotPair findTable(Vector<? extends HTMLNode> html, int sPos, int ePos) { return TagNodeFindInclusive.first(html, sPos, ePos, "table"); } /** * This method will get the very first HTML {@code 'TABLE'} * (<CODE><TABLE> <TR> <TH>...</TH> </TR> <TR> * <TD>..</TD> ... </TR> ... </TABLE></CODE>) element set. This * returns a sub-{@code Vector} (an actual {@code Vector<HTMLNode>} object, not a {@code Vector * / array} starting and ending indices pair). This is what the <B>{@code 'GET'}</B> keyword * usually means in this HTML-Scrape package. * * @param html <EMBED CLASS="external-html" DATA-FILE-ID="HTMLVEC"> * * @return The requested HTML sublist, as a {@code Vector}. * * @see TagNodeGetInclusive */ public static Vector<HTMLNode> getTable(Vector<? extends HTMLNode> html) { return TagNodeGetInclusive.first(html, "table"); } /** * This method will get the very first HTML {@code 'TABLE'} * (<CODE><TABLE> <TH>...</TH> <TR> <TD>..</TD> ... * </TR> ... </TABLE></CODE>) element set. This returns a sub-vector (an actual * {@code Vector<HTMLNode>} object, not a {@code Vector / array} starting and ending indices * pair). This is what the <B>{@code 'GET'}</B> keyword usually means in this HTML-Scrape * package. * * @param html <EMBED CLASS="external-html" DATA-FILE-ID="HTMLVEC"> * @param sPos <EMBED CLASS="external-html" DATA-FILE-ID="SPOSVEC"> * @param ePos <EMBED CLASS="external-html" DATA-FILE-ID="EPOSVEC"> * * @return The requested HTML sublist, as a {@code Vector}. * * @throws IndexOutOfBoundsException <EMBED CLASS="external-html" DATA-FILE-ID="VIOOBEX"> * * @see TagNodeGetInclusive */ public static Vector<HTMLNode> getTable(Vector<? extends HTMLNode> html, int sPos, int ePos) { return TagNodeGetInclusive.first(html, sPos, ePos, "table"); } /** * This method will find the very first first HTML {@code 'SELECT-OPTION'} set. * (<CODE><SELECT> ... <OPTION> ... </OPTION> .. </SELECT></CODE>) * element set. This returns the {@code Vector} Position starting and ending boundaries * {@code DotPair.start, DotPair.end} rather than pointer-references to the nodes. This is * what the <B>{@code 'FIND'}</B> keyword usually means in this HTML-Scrape package. * * @param html <EMBED CLASS="external-html" DATA-FILE-ID="HTMLVEC"> * * @return The start and end index pointers, as a {@code DotPair}, of the HTML requested * HTML sublist. * * @see TagNodeFindInclusive */ public static DotPair findSelect(Vector<? extends HTMLNode> html) { return TagNodeFindInclusive.first(html, "select"); } /** * This method will find the very first first HTML {@code 'SELECT-OPTION'} set. * (<CODE><SELECT> ... <OPTION> ... </OPTION> .. </SELECT></CODE>) * element set. This returns the {@code Vector} Position starting and ending boundaries * {@code DotPair.start, DotPair.end} rather than pointer-references to the nodes. This is * what the <B>{@code 'FIND'}</B> keyword usually means in this HTML-Scrape package. * * @param html <EMBED CLASS="external-html" DATA-FILE-ID="HTMLVEC"> * @param sPos <EMBED CLASS="external-html" DATA-FILE-ID="SPOSVEC"> * @param ePos <EMBED CLASS="external-html" DATA-FILE-ID="EPOSVEC"> * * @return The start and end index pointers, as a {@code DotPair}, of the HTML requested * HTML sublist. * * @throws IndexOutOfBoundsException <EMBED CLASS="external-html" DATA-FILE-ID="VIOOBEX"> * * @see TagNodeFindInclusive */ public static DotPair findSelect(Vector<? extends HTMLNode> html, int sPos, int ePos) { return TagNodeFindInclusive.first(html, sPos, ePos, "select"); } /** * This method will find the very first first HTML {@code 'SELECT-OPTION'} set. * (<CODE><SELECT> ... <OPTION> ... </OPTION> .. </SELECT></CODE>) * element set. This returns a sub-vector (an actual {@code Vector<HTMLNode>} object, not * a {@code Vector / array} starting and ending indices pair.) This is what the * <B>{@code 'GET'}</B> keyword usually means in this HTML-Scrape package. * * @param html <EMBED CLASS="external-html" DATA-FILE-ID="HTMLVEC"> * * @return The requested HTML sublist, as a {@code Vector}. * * @see TagNodeGetInclusive */ public static Vector<HTMLNode> getSelect(Vector<? extends HTMLNode> html) { return TagNodeGetInclusive.first(html, "select"); } /** * This method will find the very first first HTML {@code 'SELECT-OPTION'} set. * (<CODE><SELECT> ... <OPTION> ... </OPTION> .. </SELECT></CODE>) * element set. This returns a sub-vector (an actual {@code Vector<HTMLNode>} object, not * a {@code Vector / array} starting and ending indices pair). This is what the * <B>{@code 'GET'}</B> keyword usually means in this HTML-Scrape package. * * @param html <EMBED CLASS="external-html" DATA-FILE-ID="HTMLVEC"> * @param sPos <EMBED CLASS="external-html" DATA-FILE-ID="SPOSVEC"> * @param ePos <EMBED CLASS="external-html" DATA-FILE-ID="EPOSVEC"> * * @return The requested HTML sublist, as a {@code Vector}. * * @throws IndexOutOfBoundsException <EMBED CLASS="external-html" DATA-FILE-ID="VIOOBEX"> * * @see TagNodeGetInclusive */ public static Vector<HTMLNode> getSelect(Vector<? extends HTMLNode> html, int sPos, int ePos) { return TagNodeGetInclusive.first(html, sPos, ePos, "select"); } /** * This method will find the very first HTML Un-Ordered List * (<CODE><UL> ..<LI>...</LI> ... </UL></CODE>) element set. * This returns the {@code Vector} Position starting and ending boundaries * {@code DotPair.start, DotPair.end} rather than pointer-references to the nodes. This is * what the <B>{@code 'FIND'}</B> keyword usually means in this HTML-Scrape package. * * @param html <EMBED CLASS="external-html" DATA-FILE-ID="HTMLVEC"> * * @return The start and end index pointers, as a {@code DotPair}, of the HTML requested * HTML sublist. * * @see TagNodeFindInclusive */ public static DotPair findUL(Vector<? extends HTMLNode> html) { return TagNodeFindInclusive.first(html, "ul"); } /** * This method will find the very first HTML Un-Ordered List * (<CODE><UL> ..<LI>...</LI> ... </UL></CODE>) element set. * This returns the {@code Vector} Position starting and ending boundaries * {@code DotPair.start, DotPair.end} rather than pointer-references to the nodes. This is * what the <B>{@code 'FIND'}</B> keyword usually means in this HTML-Scrape package. * * @param html <EMBED CLASS="external-html" DATA-FILE-ID="HTMLVEC"> * @param sPos <EMBED CLASS="external-html" DATA-FILE-ID="SPOSVEC"> * @param ePos <EMBED CLASS="external-html" DATA-FILE-ID="EPOSVEC"> * * @return The start and end index pointers, as a {@code DotPair}, of the HTML requested HTML * sublist. * * @throws IndexOutOfBoundsException <EMBED CLASS="external-html" DATA-FILE-ID="VIOOBEX"> * * @see TagNodeFindInclusive */ public static DotPair findUL(Vector<? extends HTMLNode> html, int sPos, int ePos) { return TagNodeFindInclusive.first(html, sPos, ePos, "ul"); } /** * This method will find the very first HTML Un-Ordered List * (<CODE><UL> ..<LI>...</LI> ... </UL></CODE>) element set. * This returns a sub-vector (an actual {@code Vector<HTMLNode>} object, not a * {@code Vector / array} starting and ending indices pair). * This is what the <B>{@code 'GET'}</B> keyword usually means in this HTML-Scrape package. * * @param html <EMBED CLASS="external-html" DATA-FILE-ID="HTMLVEC"> * * @return The requested HTML sublist, as a {@code Vector}. * * @see TagNodeGetInclusive */ public static Vector<HTMLNode> getUL(Vector<? extends HTMLNode> html) { return TagNodeGetInclusive.first(html, "ul"); } /** * This method will find the very first HTML Un-Ordered List * (<CODE><UL> ..<LI>...</LI> ... </UL></CODE>) element set. * This returns a sub-vector (an actual {@code Vector<HTMLNode>} object, not a * {@code Vector / array} starting and ending indices pair). * This is what the <B>{@code 'GET'}</B> keyword usually means in this HTML-Scrape package. * * @param html <EMBED CLASS="external-html" DATA-FILE-ID="HTMLVEC"> * @param sPos <EMBED CLASS="external-html" DATA-FILE-ID="SPOSVEC"> * @param ePos <EMBED CLASS="external-html" DATA-FILE-ID="EPOSVEC"> * * @return The requested HTML sublist, as a {@code Vector}. * * @throws IndexOutOfBoundsException <EMBED CLASS="external-html" DATA-FILE-ID="VIOOBEX"> * * @see TagNodeGetInclusive */ public static Vector<HTMLNode> getUL(Vector<? extends HTMLNode> html, int sPos, int ePos) { return TagNodeGetInclusive.first(html, sPos, ePos, "ul"); } /** * This method will find the very first HTML Un-Ordered List * (<CODE><OL> ..<LI>...</LI> ... </OL></CODE>) element set. * This returns the {@code Vector} Position starting and ending boundaries * {@code DotPair.start, DotPair.end} rather than pointer-references to the nodes. This is * what the <B>{@code 'FIND'}</B> keyword usually means in this HTML-Scrape package. * * @param html <EMBED CLASS="external-html" DATA-FILE-ID="HTMLVEC"> * * @return The start and end index pointers, as a {@code DotPair}, of the HTML requested * HTML sublist. * * @see TagNodeFindInclusive */ public static DotPair findOL(Vector<? extends HTMLNode> html) { return TagNodeFindInclusive.first(html, "ol"); } /** * This method will find the very first HTML Un-Ordered List * (<CODE><OL> ..<LI>...</LI> ... </OL></CODE>) element set. * This returns the {@code Vector} Position starting and ending boundaries * {@code DotPair.start, DotPair.end} rather than pointer-references to the nodes. This * is what the <B>{@code 'FIND'}</B> keyword usually means in this HTML-Scrape package. * * @param html <EMBED CLASS="external-html" DATA-FILE-ID="HTMLVEC"> * @param sPos <EMBED CLASS="external-html" DATA-FILE-ID="SPOSVEC"> * @param ePos <EMBED CLASS="external-html" DATA-FILE-ID="EPOSVEC"> * * @return The start and end index pointers, as a {@code DotPair}, of the HTML requested * HTML sublist. * * @throws IndexOutOfBoundsException <EMBED CLASS="external-html" DATA-FILE-ID="VIOOBEX"> * * @see TagNodeFindInclusive */ public static DotPair findOL(Vector<? extends HTMLNode> html, int sPos, int ePos) { return TagNodeFindInclusive.first(html, sPos, ePos, "ol"); } /** * This method will find the very first HTML Un-Ordered List * (<CODE><OL> ..<LI>...</LI> ... </OL></CODE>) element set. * This returns a sub-vector (an actual {@code Vector<HTMLNode>} object, not a * {@code Vector / array} starting and ending indices pair). * This is what the <B>{@code 'GET'}</B> keyword usually means in this HTML-Scrape package. * * @param html <EMBED CLASS="external-html" DATA-FILE-ID="HTMLVEC"> * * @return The requested HTML sublist, as a {@code Vector}. * * @see TagNodeGetInclusive */ public static Vector<HTMLNode> getOL(Vector<? extends HTMLNode> html) { return TagNodeGetInclusive.first(html, "ol"); } /** * This method will find the very first HTML Un-Ordered List * (<CODE><OL> ..<LI>...</LI> ... </OL></CODE>) element set. * This returns a sub-vector (an actual {@code Vector<HTMLNode>} object, not a * {@code Vector / array} starting and ending indices pair). * This is what the <B>{@code 'GET'}</B> keyword usually means in this HTML-Scrape package. * * @param html <EMBED CLASS="external-html" DATA-FILE-ID="HTMLVEC"> * @param sPos <EMBED CLASS="external-html" DATA-FILE-ID="SPOSVEC"> * @param ePos <EMBED CLASS="external-html" DATA-FILE-ID="EPOSVEC"> * * @return The requested HTML sublist, as a {@code Vector}. * * @throws IndexOutOfBoundsException <EMBED CLASS="external-html" DATA-FILE-ID="VIOOBEX"> * * @see TagNodeGetInclusive */ public static Vector<HTMLNode> getOL(Vector<? extends HTMLNode> html, int sPos, int ePos) { return TagNodeGetInclusive.first(html, sPos, ePos, "ol"); } /** * This will use the "L1 Inclusive" concept defined in this HTML package to provide a list * (returned using the type: {@code java.util.Vector<DotPair>}) of each element that fits the * <CODE><OPTION> ... </OPTION></CODE> HTML "select-option element" structure. * * @param selectList An HTML list of {@code TagNode's} and {@code TextNode's} that constitute * an selection-option drop-down menu. This list cannot contain extraneous {@code TagNode's} * or {@code TextNode's}, but rather, must begin and end with the open and close "select" * HTML drop-down menu Tags. * * @return A <I>"list of lists"</I> - specifically, a list of <B>{@code Torello.HTML.DotPair * }</B>, each of which delineate a complete {@code <OPTION> ... </OPTION>} sub-list that are * present within this HTML "select" drop-down-menu structure. * * @throws MalformedHTMLException This method in no way performs a complete evaluation of the * HTML structure provided by the user in the <B>{@code Vector<? extends HTMLNode> list} * parameter </B> that is passed. However rules that are related to the HTML * elements "Select Option" {@code <SELECT>...<OPTION> ... </OPTION> ... </SELECT>} are * inspected. * * <BR /><BR /><UL CLASS="JDUL"> * <LI> If the <B>passed list parameter</B> <I>does not start and end with the <B> exact HTML * elements</B> - {@code <SELECT>, </SELECT>} </I>, then this exception is thrown. * </LI> * <LI> If the <B>passed list parameter</B> contains "extraneous HTML tags" or "extraneous text" * in between the {@code <OPTION> ... </OPTION> or <SELECT> ... </SELECT>} list-start * and list-end demarcated HTML TagNodes, then the * {@code Torello.HTML.MalformedHTMLException } will, again, be thrown * </LI> * </UL> * * @see #checkEndPoints(Vector, String[]) * @see #checkL1(Vector, Vector) * @see TagNodeFindL1Inclusive */ public static Vector<DotPair> findAllOption (Vector<? extends HTMLNode> selectList) throws MalformedHTMLException { checkEndPoints(selectList, "select"); Vector<DotPair> ret = TagNodeFindL1Inclusive.all(selectList, "option"); checkL1(selectList, ret); return ret; } /** * This does the exact same thing as {@code findAllOption(Vector)} but the returned value is * converted from "sublist endpoints" (a vector of start/end pairs), and into a "List of * Sub-Lists", which is specifically a list {@code (java.util.Vector<>)} containing sub-lists * (also: {@code java.util.Vector<HTMLNode>}) * * <BR /><BR /><B>NOTE:</B> All of the rules and conditions explained in the comments for * method <B>{@code findAllOption(Vector)}</B> apply to this method as well. * * @param selectList An HTML list of {@code TagNode's} and {@code TextNode's} that constitute * an selection-option drop-down menu. * This list cannot contain extraneous {@code TagNode's} or {@code TextNode's}, but rather, * must begin and end with the open and close "select" HTML drop-down menu Tags. * * @return A <I>"list of lists"</I> - specifically, a list of * <B>{@code java.util.Vector<HTMLNode>} (sublists)</B>, each of which delineate * a complete {@code <OPTION> ... </OPTION>} sub-list that are present within this HTML * "select" drop-down-menu structure. * * @throws MalformedHTMLException This method in no way performs a complete evaluation of the * HTML structure provided by the user in the <B>{@code Vector<? extends HTMLNode> list} * parameter </B> that is passed. However rules that are related to the HTML * elements "Select Option" {@code <SELECT>...<OPTION> ... </OPTION> ... </SELECT>} are * inspected. * * <BR ><BR /><UL CLASS="JDUL"> * <LI> If the <B>passed list parameter</B> <I>does not start and end with the <B> exact HTML * elements</B> - {@code <SELECT>, </SELECT>}</I>, then this exception is thrown. * </LI> * <LI> If the <B>passed list parameter</B> contains "extraneous HTML tags" or "extraneous * text" in between the {@code <OPTION> ... </OPTION> or <SELECT> ... </SELECT>} * list-start and list-end demarcated HTML TagNodes, then the * {@code Torello.HTML.MalformedHTMLException } will, again, be thrown * </LI> * </UL> * * @see DotPair#toVectors(Vector, Iterable) */ public static Vector<Vector<HTMLNode>> getAllOption (Vector<? extends HTMLNode> selectList) throws MalformedHTMLException { return DotPair.toVectors(selectList, findAllOption(selectList)); } /** * This will use the "L1 Inclusive" concept defined in this HTML package to provide a list * (returned using the type: * {@code java.util.Vector<DotPair>}) of each element that fits the * <CODE><LI> ... </LI></CODE> HTML "list element" structure. * * @param list An HTML list of {@code TagNode's} and {@code TextNode's} that constitute an * ordered or unordered list. This list cannot contain * extraneous {@code TagNode's} or {@code TextNode's}, but rather, must begin and end with * the open and close list Tags. * * @return A <I>"list of lists"</I> - specifically, a list of * <B>{@code Torello.HTML.DotPair}</B>, each of which delineate a complete {@code <LI> ... * </LI>} sub-list that are present within this HTML list structure. * * @throws MalformedHTMLException This method in no way performs a complete evaluation of the * HTML structure provided by the user in the <B>{@code Vector<? extends HTMLNode> list} * parameter </B> that is passed. However rules that are related to the HTML elements * "Ordered List" {@code <OL>...</OL>} and "unordered list" {@code <UL>...</UL>} are * inspected. * * <BR /><BR /><UL CLASS="JDUL"> * <LI> If the <B>passed list parameter</B> <I>does not start and end with the <B>same HTML * elements</B> - specifically {@code <OL>, <UL>} </I>, then this exception is thrown. * </LI> * <LI> If the <B>passed list parameter</B> contains "extraneous HTML tags" or "extraneous text" * in between the {@code <OL> or <UL> ... </OL> or </UL>} list-start and list-end * demarcated HTML TagNodes, then the {@code Torello.HTML.MalformedHTMLException } * will, again, be thrown * </LI> * </UL> * * @see #checkEndPoints(Vector, String[]) * @see #checkL1(Vector, Vector) * @see TagNodeFindL1Inclusive */ public static Vector<DotPair> findAllLI(Vector<? extends HTMLNode> list) throws MalformedHTMLException { checkEndPoints(list, "ol", "ul"); Vector<DotPair> ret = TagNodeFindL1Inclusive.all(list, "li"); checkL1(list, ret); return ret; } /** * This does the exact same thing as {@code findAllLI(Vector)} but the returned value is * converted from "sublist endpoints" (a vector of start/end pairs), and into a "List of * Sub-Lists", which is specifically a list {@code (java.util.Vector<>)} containing sub-lists * (also: {@code java.util.Vector<HTMLNode>}) * * <BR /><BR /><B>NOTE:</B> All of the rules and conditions explained in the comments for * method <B>{@code findAllLI(Vector)}</B> apply to this method as well. * * @param list An HTML list of {@code TagNode's} and {@code TextNode's} that constitute an * ordered or unordered list. This list cannot contain extraneous {@code TagNode's} or * {@code TextNode's}, but rather, must begin and end with the open and close list Tags. * * @return A <I>"list of lists"</I> - specifically, a list of * <B>{@code java.util.Vector<HTMLNode>} (sublists)</B>, each of which delineate * a complete <UL>...</UL> sub-list that are present within this HTML list * structure. * * @throws MalformedHTMLException This method in no way performs a complete evaluation of the * HTML structure provided by the * user in the <B>{@code Vector<? extends HTMLNode> list} parameter </B> that is passed. * However rules that are related to the HTML elements "Ordered List" * (<CODE><OL>...</OL></CODE>) and "unordered list" * (<CODE><UL>...</UL></CODE>) are inspected. * * <BR /><BR /><UL CLASS="JDUL"> * <LI> If the <B>passed list parameter</B> <I>does not start and end with the <B>same HTML * elements</B> - specifically {@code <OL>, <UL>} </I>, then this exception is thrown. * </LI> * <LI> If the <B>passed list parameter</B> contains "extraneous HTML tags" or "extraneous text" * in between the {@code <OL> or <UL> ... </OL> or </UL>} list-start and list-end * demarcated HTML {@code TagNode's}, then the {@code Torello.HTML.MalformedHTMLException} * will, again, be thrown. * </LI> * </UL> * * @see DotPair#toVectors(Vector, Iterable) */ public static Vector<Vector<HTMLNode>> getAllLI (Vector<? extends HTMLNode> list) throws MalformedHTMLException { return DotPair.toVectors(list, findAllLI(list)); } /** * This method is used to guarantee precisely two conditions to the passed HTML Tag list. * * <BR /><BR /><UL CLASS="JDUL"> * <LI> <B>Condition 1:</B> The {@code Vector<HTMLNode> list } parameter begins and ends with * the <I>exact same HTML Tag</I>, (for instance: {@code <H1> ... </H1>}, or perhaps * {@code <LI> ... </LI> }) * </LI> * <LI> <B>Condition 2:</B> The HTML-Tag that is found at the start and end of this list is one * contained within the {@code 'tokList'} variable-length {@code String-array} parameter. * (if the {@code 'tokList'} parameter was a {@code java.lang.String[] tokList = { "th", * "tr" }}, then the passed "HTMLNode list" ({@code Vector}) parameter would have to begin * and end with either: {@code <TH> ... </TH> } or with {@code <TR> ... </TR> } * </LI> * </UL> * * <BR />Much of the java code in this method is used to provide some explanatory Exception * message information. * * @param list This is supposed to be a typical "open" and "close" HTML TagNode structure. It * may be anything including: * <SPAN STYLE="color: green;">{@code <DIV ID="..."> ... </DIV> }, or * {@code <TABLE ...> ... </TABLE> }, or even {@code <BODY> ... </BODY> } * </SPAN> * * @param tokList This is expected to be the possible set of tokens with which this HTML list * may begin or end with. * * @return If the passed list parameter passes both the conditions specified above, then the * token from the list of tokens that were provided is returned. * * <BR /><BR /><B>NOTE:</B> If the list does not meet these conditions, a * {@code Torello.HTML.MalformedHTMLException } will be thrown with an * explanatory exception-message (and, obviously, the method will not return anything!) * * @throws MalformedHTMLException Some explanatory information is provided to the coder for * what has failed with the input list. */ protected static String checkEndPoints (Vector<? extends HTMLNode> list, String... tokList) throws MalformedHTMLException { return checkEndPoints(list, 0, list.size()-1, tokList); } /** * This method, functionally, does the exact same thing as "checkEndPoints" - but with the * endpoints specified. It is being kept with <B><I>protected</I></B> access since it might * be unclear what endpoints are being checked. The previous method has many java exception * case strings laboriously typed out. Rather than retype this, this method is being * introduced. Functionally, it does the same thing as {@code checkEndPoints(Vector, String)} * - except it does not use {@code list.elementAt(0)} or * {@code list.elementAt(element.size()-1)} as the starting and ending points. * * @param sPos <EMBED CLASS="external-html" DATA-FILE-ID="SPOSVEC"> * @param ePos <EMBED CLASS="external-html" DATA-FILE-ID="EPOSVEC"> * @param tokList The list of valid HTML Element names (tokens). * * @see #checkEndPoints(Vector, String[]) */ protected static String checkEndPoints (Vector<? extends HTMLNode> list, int sPos, int ePos, String... tokList) throws MalformedHTMLException { HTMLNode n = null; String tok = null; if ((n = list.elementAt(sPos)).isTagNode()) tok = ((TagNode) n).tok; else throw new MalformedHTMLException( "This list does not begin an HTML TagNode, but rather a: " + n.getClass().getName() + "\n" + n.str ); if (! (n = list.elementAt(ePos)).isTagNode()) throw new MalformedHTMLException( "This list does not end with an HTML TagNode, but rather a : " + n.getClass().getName() + "\n" + n.str ); if (! ((TagNode) n).tok.equals(tok)) throw new MalformedHTMLException( "This list does not begin and end with the same HTML TagNode:\n" + "[OpeningTag: " + tok + "]\t[ClosingTag: " + ((TagNode) n).tok + "]" ); for (String t : tokList) if (t.equals(tok)) return tok; String expectedTokList = ""; for (String t: tokList) expectedTokList += " " + t; throw new MalformedHTMLException( "The opening and closing HTML Tag tokens for this list are not members of the " + "tokList parameter set...\n" + "Expected HTML Tag List: " + expectedTokList + "\nFound Tag: " + tok ); } /** * This checks that the sublists demarcated by the {@code Vector<DotPair> htmlSubLists } * parameter are properly formatted HTML. It would be easier to provide an example of * "proper HTML formatting" and "improper HTML formatting" here, rather that trying to explain * this using English. * * <BR /><BR /> * <B>PROPER HTML:</B> * * <DIV CLASS="HTML">{@code * <UL> * <LI> This is a list element.</LI> * <LI> This is another list element.</LI> * <LI> This list element contains <B><I> extra-tags</I></B> like "bold", "italics", and * even a <A HREF="http://Torello.Directory">link!</A></LI> * </UL> * }</DIV> * * <BR /><B>IMPROPER HTML:</B> * * <DIV CLASS="HTML">{@code * <UL> * This text should not be here, and constitutes "malformed HTML" * <LI> This LI element is just fine.</LI> * <A HREF="http://ChineseNewsBoard.com">This link</A> should be between LI elements * <LI> This LI element is also just fine!</LI> * </UL> * }</DIV> * <BR />In the above two lists, the latter would generate a MalformedHTMLException * * @throws MalformedHTMLException whenever improper HTML is presented to this function */ protected static void checkL1(Vector<? extends HTMLNode> list, Vector<DotPair> sublists) throws MalformedHTMLException { checkL1(list, 0, list.size()-1, sublists); } /** * This method, functionally, does the exact same thing as "checkEL1" - but with the endpoints * specified. It is being kept with <B><I>protected</I></B> access since it might be unclear * what endpoints are being checked. The previous method has many java exception case * {@code String's} laboriously typed out. Rather than retype this, this method is being * introduced. Functionally, it does the same thing as * {@code checkL1(Vector, String)} - except it does not use {@code list.elementAt(0)} * or {@code list.elementAt(element.size()-1) } as the starting and ending points. * * @param sPos <EMBED CLASS="external-html" DATA-FILE-ID="SPOSVEC"> * * @param ePos <EMBED CLASS="external-html" DATA-FILE-ID="EPOSVEC"> * * @see #checkL1(Vector, Vector) */ protected static void checkL1 (Vector<? extends HTMLNode> list, int sPos, int ePos, Vector<DotPair> sublists) throws MalformedHTMLException { int last = sPos; int t = ePos - 1; HTMLNode n = null; for (DotPair sublist : sublists) if (sublist.start == (last+1)) last = sublist.end; else { if ((sublist.start < (last+1)) || (sublist.start >= t)) throw new IllegalArgumentException( "The provided subLists parameter does not contain subLists that are in " + "order of the original list. The 'list of sublists' must contain " + "sublists that are in increasing sorted order.\n" + "Specifically, each sublist must contain start and end points that are " + "sequentially increasing. Also, they may not overlap." ); else { for (int i=(last+1); i < sublist.start; i++) if ((n = list.elementAt(i)).isTagNode()) throw new MalformedHTMLException( "There is a spurious HTML-Tag element at Vector position: " + i + "\n=>\t" + n.str ); else if (n.isTextNode() && (n.str.trim().length() > 0)) throw new MalformedHTMLException( "There is a spurious Text-Node element at Vector position: " + i + "\n=>\t" + n.str ); } } } } |