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 | package Torello.HTML; import java.util.*; import java.util.regex.*; import java.util.stream.*; import java.io.Serializable; import java.lang.reflect.*; import Torello.HTML.NodeSearch.*; import Torello.Java.*; /** * Computes miscellaneous statistics for a web-page, or sub-page. * * <BR /><BR /><EMBED CLASS='external-html' DATA-FILE-ID=PAGE_STATS> * * <STYLE TYPE="text/css"> * .PAGESTATS * { color: red; font-weight: bold; font-family: "Courier New", Courier, monospace; } * </STYLE> */ public class PageStats implements Serializable, Comparable<PageStats>, Cloneable { /** <EMBED CLASS='external-html' DATA-FILE-ID=SVUID> */ public static final long serialVersionUID = 1; /** * If a Vectorized HTML page were converted to a String, this would be the length of that * string. * * @see Util#strLength(Vector) * @see Util#strLength(Vector, int, int) */ public final int strLength; /** * The string hash-code of the vectorized-HTML webpage, as if it were being represented as one * single {@code java.lang.String.} * * @see Util#hashCode(Vector) * @see Util#hashCode(Vector, int, int) */ public final int hash; /** * The number of HTML {@code TagNode} elements that have a {@code 'class'} attribute, when * queried using {@code TagNode.AV("class")} */ public final short hasAVclass; /** * The number of HTML {@code TagNode} elements that have a {@code 'style'} attribute, when * queried using {@code TagNode.AV("style")} */ public final short hasAVstyle; /** * The number of HTML {@code TagNode} elements that have an {@code 'id'} attribute, when * queried using {@code TagNode.AV("id")} */ public final short hasAVid; /** * The number of HTML {@code TagNode} elements that have a {@code 'title'} attribute, when * queried using {@code TagNode.AV("title")} */ public final short hasAVtitle; /** * The number of HTML {@code TagNode} elements that have an {@code 'href'} attribute, when * queried using {@code TagNode.AV("href")} */ public final short hasAVhref; /** * The number of HTML {@code TagNode} elements that have a {@code 'hreflang'} attribute, when * queried using {@code TagNode.AV("hreflang")} */ public final short hasAVhreflang; /** * The number of HTML {@code TagNode} elements that have a {@code 'src'} attribute, when * queried using {@code TagNode.AV("src")} */ public final short hasAVsrc; /** * The number of HTML {@code TagNode} elements that have a {@code 'srcset'} attribute, when * queried using {@code TagNode.AV("srcset")} */ public final short hasAVsrcset; /** * The number of HTML {@code TagNode} elements that have a {@code 'srclang'} attribute, when * queried using {@code TagNode.AV("srclang")} */ public final short hasAVsrclang; /** * The number of HTML {@code TagNode} elements that have a {@code 'srcdoc'} attribute, when * queried using {@code TagNode.AV("srcdoc")} */ public final short hasAVsrcdoc; /** * The number of HTML {@code TagNode} elements that have an {@code 'alt'} attribute, when * queried using {@code TagNode.AV("alt")} */ public final short hasAValt; /** * The number of HTML {@code TagNode} elements that have a {@code 'target'} attribute, when * queried using {@code TagNode.AV("target")} */ public final short hasAVtarget; /** * The number of HTML {@code TagNode} elements that have a {@code 'width'} attribute, when * queried using {@code TagNode.AV("width")} */ public final short hasAVwidth; /** * The number of HTML {@code TagNode} elements that have a {@code 'height'} attribute, when * queried using {@code TagNode.AV("height")} */ public final short hasAVheight; /** * The number of HTML {@code TagNode} elements that have a {@code 'size'} attribute, when * queried using {@code TagNode.AV("size")} */ public final short hasAVsize; /** * The number of HTML {@code TagNode} elements that have a {@code 'sizes'} attribute, when * queried using {@code TagNode.AV("sizes")} */ public final short hasAVsizes; /** * The number of HTML {@code TagNode} elements that have a {@code 'cols'} attribute, when * queried using {@code TagNode.AV("cols")} */ public final short hasAVcols; /** * The number of HTML {@code TagNode} elements that have a {@code 'colspan'} attribute, when * queried using {@code TagNode.AV("colspan")} */ public final short hasAVcolspan; /** * The number of HTML {@code TagNode} elements that have a {@code 'rows'} attribute, when * queried using {@code TagNode.AV("rows")} */ public final short hasAVrows; /** * The number of HTML {@code TagNode} elements that have a {@code 'rowspan'} attribute, when * queried using {@code TagNode.AV("rowspan")} */ public final short hasAVrowspan; /** * The number of HTML {@code TagNode} elements that have a {@code 'wrap'} attribute, when * queried using {@code TagNode.AV("wrap")} */ public final short hasAVwrap; /** * The number of HTML {@code TagNode} elements that have a {@code 'value'} attribute, when * queried using {@code TagNode.AV("value")} */ public final short hasAVvalue; /** * The number of HTML {@code TagNode} elements that have a {@code 'type'} attribute, when * queried using {@code TagNode.AV("type")} */ public final short hasAVtype; /** * The number of HTML {@code TagNode} elements that have a {@code 'name'} attribute, when * queried using {@code TagNode.AV("name")} */ public final short hasAVname; /** * The number of HTML {@code TagNode} elements that have a {@code 'min'} attribute, when * queried using {@code TagNode.AV("min")} */ public final short hasAVmin; /** * The number of HTML {@code TagNode} elements that have a {@code 'max'} attribute, when * queried using {@code TagNode.AV("max")} */ public final short hasAVmax; /** * The number of HTML {@code TagNode} elements that have a {@code 'minlength'} attribute, when * queried using {@code TagNode.AV("minlength")} */ public final short hasAVminlength; /** * The number of HTML {@code TagNode} elements that have a {@code 'maxlength'} attribute, when * queried using {@code TagNode.AV("maxlength")} */ public final short hasAVmaxlength; /** * The number of HTML {@code TagNode} elements that have a {@code 'accept'} attribute, when * queried using {@code TagNode.AV("accept")} */ public final short hasAVaccept; /** This is identical to the value returned by: {@code pageVector.size()} */ public final int numNodes; /** * The number of {@code HTMLNode's} in the {@code Vector<HTMLNode>} that qualify as an * {@code "instanceof" TagNode}. * * @see Util.Count#tagNodes(Vector) * @see Util.Count#tagNodes(Vector, int, int) */ public final int numTagNodes; /** * The number of {@code HTMLNode's} in the {@code Vector<HTMLNode>} that qualify as an * {@code "instanceof" TextNode}. * * @see Util.Count#textNodes(Vector) * @see Util.Count#textNodes(Vector, int, int) */ public final int numTextNodes; /** * The number of {@code HTMLNode's} in the {@code Vector<HTMLNode>} that qualify as an * {@code "instanceof" CommentNode}. * * @see Util.Count#commentNodes(Vector) * @see Util.Count#commentNodes(Vector, int, int) */ public final int numCommentNodes; /** * This is the total number of new-line {@code '\n'} characters found inside any * {@code TextNode} present in the page-vector. * * @see Util.Count#newLines(Vector) * @see Util.Count#newLines(Vector, int, int) */ public final int numNewLines; /** * The total number of HTML <SPAN CLASS="PAGESTATS"><IMG ...></SPAN> {@code 'TagNode'} * elements found on the page. * * <BR /><BR /><B><SPAN STYLE='color: red;'>NOTE:</B></SPAN> This is considered an HTML-5 * {@code 'Singleton'} element, and thusly should only have an "Opening-Tag Version" of the * Element. If there are (accidentally) closing-versions of this tag, they will not be counted * by {@code class PageStats} */ public final short numImages; /** * The total number of HTML <SPAN CLASS="PAGESTATS"><META ...></SPAN> {@code 'TagNode'} * elements found on the page. * * <BR /><BR /><B><SPAN STYLE='color: red;'>NOTE:</B></SPAN> This is considered an HTML-5 * {@code 'Singleton'} element, and thusly should only have an "Opening-Tag Version" of the * Element. If there are (accidentally) closing-versions of this tag, they will not be counted * by {@code class PageStats} */ public final short numMeta; /** * The total number of HTML <SPAN CLASS="PAGESTATS"><LINK ...></SPAN> {@code 'TagNode'} * elements found on the page. * * <BR /><BR /><B><SPAN STYLE='color: red;'>NOTE:</B></SPAN> This is considered an HTML-5 * {@code 'Singleton'} element, and thusly should only have an "Opening-Tag Version" of the * Element. If there are (accidentally) closing-versions of this tag, they will not be counted * by {@code class PageStats} */ public final short numLink; /** * The total number of HTML <SPAN CLASS="PAGESTATS"><INPUT ...></SPAN> {@code 'TagNode'} * elements found on the page. * * <BR /><BR /><B><SPAN STYLE='color: red;'>NOTE:</B></SPAN> This is considered an HTML-5 * {@code 'Singleton'} element, and thusly should only have an "Opening-Tag Version" of the * Element. If there are (accidentally) closing-versions of this tag, they will not be counted * by {@code class PageStats} */ public final short numInput; /** * The total number of HTML <SPAN CLASS="PAGESTATS"><EMBED ...></SPAN> {@code 'TagNode'} * elements found on this page. * * <BR /><BR /><B><SPAN STYLE='color: red;'>NOTE:</B></SPAN> This is considered an HTML-5 * {@code 'Singleton'} element, and thusly should only have an "Opening-Tag Version" of the * Element. If there are (accidentally) closing-versions of this tag, they will not be counted * by {@code class PageStats} */ public final short numEmbed; /** * The total number of HTML <SPAN CLASS="PAGESTATS"><HR></SPAN> {@code 'TagNode'} * elements found on the page. * * <BR /><BR /><B><SPAN STYLE='color: red;'>NOTE:</B></SPAN> This is considered an HTML-5 * {@code 'Singleton'} element, and thusly should only have an "Opening-Tag Version" of the * Element. If there are (accidentally) closing-versions of this tag, they will not be counted * by {@code class PageStats} */ public final short numHR; /** * The total number of HTML <SPAN CLASS="PAGESTATS"><BR></SPAN> {@code 'TagNode'} * elements found on the page. * * <BR /><BR /><B><SPAN STYLE='color: red;'>NOTE:</B></SPAN> This is considered an HTML-5 * {@code 'Singleton'} element, and thusly should only have an "Opening-Tag Version" of the * Element. If there are (accidentally) closing-versions of this tag, they will not be counted * by {@code class PageStats} */ public final short numBR; /** * The total number of <SPAN CLASS="PAGESTATS"><TABLE>, TC.OpeningTags, TagNode</SPAN> * elements found on the page. Any element-internal attributes / inner-tags actually found * inside the HTML element will just be ignored for the purposes of this count. */ public final short numOpenTables; /** * The total number of <SPAN CLASS="PAGESTATS"></TABLE>, TC.ClosingTags, TagNode</SPAN> * elements found on the page. */ public final short numClosedTables; /** * The total number of <SPAN CLASS="PAGESTATS"><A> (Anchor), TC.OpeningTags, * TagNode</SPAN> elements found on the page. Any element-internal attributes / inner-tags * actually found inside the HTML element will just be ignored for the purposes of this count. */ public final short numOpenAnchors; /** * The total number of <SPAN CLASS="PAGESTATS"></A>, TC.ClosingTags, TagNode</SPAN> * elements found on the page. */ public final short numClosedAnchors; /** * The total number of <SPAN CLASS="PAGESTATS"><P> (Paragraph), TC.OpeningTags, * TagNode</SPAN> elements found on the page. Any element-internal attributes / inner-tags * actually found inside the HTML element will just be ignored for the purposes of this count. */ public final short numOpenParagraphs; /** * The total number of <SPAN CLASS="PAGESTATS"></P>, TC.ClosingTags, TagNode</SPAN> * elements found on the page. */ public final short numClosedParagraphs; /** * The total number of <SPAN CLASS="PAGESTATS"><DIV> (Divider), TC.OpeningTags, * TagNode</SPAN> elements found on the page. Any element-internal attributes / inner-tags * actually found inside the HTML element will just be ignored for the purposes of this count. */ public final short numOpenDivs; /** * The total number of <SPAN CLASS="PAGESTATS"></DIV>, TC.ClosingTags, TagNode</SPAN> * elements found on the page. */ public final short numClosedDivs; /** * The total number of <SPAN CLASS="PAGESTATS"><SPAN>, TC.OpeningTags, TagNode</SPAN> * elements found on the page. Any element-internal attributes / inner-tags actually found * inside the HTML element will just be ignored for the purposes of this count. */ public final short numOpenSpans; /** * The total number of <SPAN CLASS="PAGESTATS"></SPAN>, TC.ClosingTags, TagNode</SPAN> * elements found on the page. */ public final short numClosedSpans; /** * The total number of <SPAN CLASS="PAGESTATS"><SCRIPT>, TC.OpeningTags, TagNode</SPAN> * elements found on the page. Any element-internal attributes / inner-tags actually found * inside the HTML element will just be ignored for the purposes of this count. */ public final short numOpenScripts; /** * The total number of <SPAN CLASS="PAGESTATS"></SCRIPT>, TC.ClosingTags, TagNode</SPAN> * elements found on the page. */ public final short numClosedScripts; /** * The total number of <SPAN CLASS="PAGESTATS"><STYLE>, TC.OpeningTags, TagNode</SPAN> * elements found on the page. Any element-internal attributes / inner-tags actually found * inside the HTML element will just be ignored for the purposes of this count. */ public final short numOpenStyles; /** * The total number of <SPAN CLASS="PAGESTATS"></STYLE>, TC.ClosingTags, TagNode</SPAN> * elements found on the page. */ public final short numClosedStyles; /** * The total number of <SPAN CLASS="PAGESTATS"><FRAME>, TC.OpeningTags, TagNode</SPAN> * elements found on the page. Any element-internal attributes / inner-tags actually found * inside the HTML element will just be ignored for the purposes of this count. */ public final short numOpenFrames; /** * The total number of <SPAN CLASS="PAGESTATS"></FRAME>, TC.ClosingTags, TagNode</SPAN> * elements found on the page. */ public final short numClosedFrames; /** * The total number of <SPAN CLASS="PAGESTATS"><IFRAME>, TC.OpeningTags, TagNode</SPAN> * elements found on the page. Any element-internal attributes / inner-tags actually found * inside the HTML element will just be ignored for the purposes of this count. */ public final short numOpenIFrames; /** * The total number of <SPAN CLASS="PAGESTATS"></IFRAME>, TC.ClosingTags, TagNode</SPAN> * elements found on the page. */ public final short numClosedIFrames; /** * The total number of <SPAN CLASS="PAGESTATS"><FORM>, TC.OpeningTags, TagNode</SPAN> * elements found on the page. Any element-internal attributes / inner-tags actually found * inside the HTML element will just be ignored for the purposes of this count. */ public final short numOpenForms; /** * The total number of <SPAN CLASS="PAGESTATS"></FORM>, TC.ClosingTags, TagNode</SPAN> * elements found on the page. */ public final short numClosedForms; /** * Internally used by the 'clone' method. * * @param otherPageStats This is the instance of PageStats to be copied */ protected PageStats(PageStats otherPageStats) { this.hasAVclass = otherPageStats.hasAVclass; this.hasAVstyle = otherPageStats.hasAVstyle; this.hasAVid = otherPageStats.hasAVid; this.hasAVtitle = otherPageStats.hasAVtitle; this.hasAVhref = otherPageStats.hasAVhref; this.hasAVhreflang = otherPageStats.hasAVhreflang; this.hasAVsrc = otherPageStats.hasAVsrc; this.hasAVsrcset = otherPageStats.hasAVsrcset; this.hasAVsrclang = otherPageStats.hasAVsrclang; this.hasAVsrcdoc = otherPageStats.hasAVsrcdoc; this.hasAValt = otherPageStats.hasAValt; this.hasAVtarget = otherPageStats.hasAVtarget; this.hasAVwidth = otherPageStats.hasAVwidth; this.hasAVheight = otherPageStats.hasAVheight; this.hasAVsize = otherPageStats.hasAVsize; this.hasAVsizes = otherPageStats.hasAVsizes; this.hasAVcols = otherPageStats.hasAVcols; this.hasAVcolspan = otherPageStats.hasAVcolspan; this.hasAVrows = otherPageStats.hasAVrows; this.hasAVrowspan = otherPageStats.hasAVrowspan; this.hasAVwrap = otherPageStats.hasAVwrap; this.hasAVvalue = otherPageStats.hasAVvalue; this.hasAVtype = otherPageStats.hasAVtype; this.hasAVname = otherPageStats.hasAVname; this.hasAVmin = otherPageStats.hasAVmin; this.hasAVmax = otherPageStats.hasAVmax; this.hasAVminlength = otherPageStats.hasAVminlength; this.hasAVmaxlength = otherPageStats.hasAVmaxlength; this.hasAVaccept = otherPageStats.hasAVaccept; this.numImages = otherPageStats.numImages; this.numMeta = otherPageStats.numMeta; this.numLink = otherPageStats.numLink; this.numInput = otherPageStats.numInput; this.numEmbed = otherPageStats.numEmbed ; this.numHR = otherPageStats.numHR; this.numBR = otherPageStats.numBR; this.numOpenTables = otherPageStats.numOpenTables; this.numClosedTables = otherPageStats.numClosedTables; this.numOpenAnchors = otherPageStats.numOpenAnchors; this.numClosedAnchors = otherPageStats.numClosedAnchors; this.numOpenParagraphs = otherPageStats.numOpenParagraphs; this.numClosedParagraphs = otherPageStats.numClosedParagraphs; this.numOpenDivs = otherPageStats.numOpenDivs; this.numClosedDivs = otherPageStats.numClosedDivs; this.numOpenSpans = otherPageStats.numOpenSpans; this.numClosedSpans = otherPageStats.numClosedSpans; this.numOpenScripts = otherPageStats.numOpenScripts; this.numClosedScripts = otherPageStats.numClosedScripts; this.numOpenStyles = otherPageStats.numOpenStyles; this.numClosedStyles = otherPageStats.numClosedStyles; this.numOpenFrames = otherPageStats.numOpenFrames; this.numClosedFrames = otherPageStats.numClosedFrames; this.numOpenIFrames = otherPageStats.numOpenIFrames; this.numClosedIFrames = otherPageStats.numClosedIFrames; this.numOpenForms = otherPageStats.numOpenForms; this.numClosedForms = otherPageStats.numClosedForms; this.strLength = otherPageStats.strLength; this.hash = otherPageStats.hash; this.numNodes = otherPageStats.numNodes; this.numTagNodes = otherPageStats.numTagNodes; this.numTextNodes = otherPageStats.numTextNodes; this.numCommentNodes = otherPageStats.numCommentNodes; this.numNewLines = otherPageStats.numNewLines; } /** * Constructs a new instance of PageStats. Assigns values based on a vectorized-webpage to the * individual fields in this class. * * @param page Any HTML page or sub-page. * * @see Util#strLength(Vector) * @see Util#hashCode(Vector) * @see Util.Count#tagNodes(Vector) * @see Util.Count#textNodes(Vector) * @see Util.Count#commentNodes(Vector) * @see Util.Count#newLines(Vector) * @see TagNodeFindInclusive * @see TagNodeCount * @see TagNode#AV(String) */ public PageStats(Vector<HTMLNode> page) { this.strLength = Util.strLength(page); this.hash = Util.hashCode(page); this.numNodes = page.size(); this.numTagNodes = Util.Count.tagNodes(page); this.numTextNodes = Util.Count.textNodes(page); this.numCommentNodes = Util.Count.commentNodes(page); this.numNewLines = Util.Count.newLines(page); short numImages, numMeta, numLink, numInput, numEmbed, numHR, numBR; numImages = numMeta = numLink = numInput = numEmbed = numHR = numBR = 0; short hasAVclass, hasAVstyle, hasAVid, hasAVtitle, hasAVhref, hasAVhreflang, hasAVsrc; short hasAVsrcset, hasAVsrclang, hasAVsrcdoc, hasAValt, hasAVtarget, hasAVwidth; short hasAVheight, hasAVsize, hasAVsizes, hasAVcols, hasAVcolspan, hasAVrows, hasAVrowspan; short hasAVwrap, hasAVvalue, hasAVtype, hasAVname, hasAVmin, hasAVmax, hasAVminlength; short hasAVmaxlength, hasAVaccept; hasAVclass = hasAVstyle = hasAVid = hasAVtitle = hasAVhref = hasAVhreflang = hasAVsrc = hasAVsrcset = hasAVsrclang = hasAVsrcdoc = hasAValt = hasAVtarget = hasAVwidth = hasAVheight = hasAVsize = hasAVsizes = hasAVcols = hasAVcolspan = hasAVrows = hasAVrowspan = hasAVwrap = hasAVvalue = hasAVtype = hasAVname = hasAVmin = hasAVmax = hasAVminlength = hasAVmaxlength = hasAVaccept = 0; short numOpenTables, numClosedTables, numOpenAnchors, numClosedAnchors, numOpenParagraphs; short numClosedParagraphs, numOpenDivs, numClosedDivs, numOpenSpans, numClosedSpans; short numOpenScripts, numClosedScripts, numOpenStyles, numClosedStyles, numOpenFrames; short numClosedFrames, numOpenIFrames, numClosedIFrames, numOpenForms, numClosedForms; numOpenTables = numClosedTables = numOpenAnchors = numClosedAnchors = numOpenParagraphs = numClosedParagraphs = numOpenDivs = numClosedDivs = numOpenSpans = numClosedSpans = numOpenScripts = numClosedScripts = numOpenStyles = numClosedStyles = numOpenFrames = numClosedFrames = numOpenIFrames = numClosedIFrames = numOpenForms = numClosedForms = 0; for (HTMLNode n : page) if (n.isTagNode()) { TagNode tn = (TagNode) n; List<String> l = tn.allAN().collect(Collectors.toList()); if (l.size() > 0) { if (l.contains("class")) { l.remove("class"); hasAVclass++; } if (l.contains("style")) { l.remove("style"); hasAVstyle++; } if (l.contains("id")) { l.remove("id"); hasAVid++; } if (l.contains("title")) { l.remove("title"); hasAVtitle++; } if (l.contains("href")) { l.remove("href"); hasAVhref++; } if (l.contains("hreflang")) { l.remove("hreflang"); hasAVhreflang++; } if (l.contains("src")) { l.remove("src"); hasAVsrc++; } if (l.contains("srcset")) { l.remove("srcset"); hasAVsrcset++; } if (l.contains("srclang")) { l.remove("srclang"); hasAVsrclang++; } if (l.contains("srcdoc")) { l.remove("srcdoc"); hasAVsrcdoc++; } if (l.contains("alt")) { l.remove("alt"); hasAValt++; } if (l.contains("target")) { l.remove("target"); hasAVtarget++; } if (l.contains("width")) { l.remove("width"); hasAVwidth++; } if (l.contains("height")) { l.remove("height"); hasAVheight++; } if (l.contains("size")) { l.remove("size"); hasAVsize++; } if (l.contains("sizes")) { l.remove("sizes"); hasAVsizes++; } if (l.contains("cols")) { l.remove("cols"); hasAVcols++; } if (l.contains("colspan")) { l.remove("colspan"); hasAVcolspan++; } if (l.contains("rows")) { l.remove("rows"); hasAVrows++; } if (l.contains("rowspan")) { l.remove("rowspan"); hasAVrowspan++; } if (l.contains("wrap")) { l.remove("wrap"); hasAVwrap++; } if (l.contains("value")) { l.remove("value"); hasAVvalue++; } if (l.contains("type")) { l.remove("type"); hasAVtype++; } if (l.contains("name")) { l.remove("name"); hasAVname++; } if (l.contains("min")) { l.remove("min"); hasAVmin++; } if (l.contains("max")) { l.remove("max"); hasAVmax++; } if (l.contains("minlength")) { l.remove("minlength"); hasAVminlength++; } if (l.contains("maxlength")) { l.remove("maxlength"); hasAVmaxlength++; } if (l.contains("accept")) { l.remove("accept"); hasAVaccept++; } } if (tn.tok.equals("img")) numImages++; else if (tn.tok.equals("meta")) numMeta++; else if (tn.tok.equals("link")) numLink++; else if (tn.tok.equals("input")) numInput++; else if (tn.tok.equals("embed")) numEmbed++; else if (tn.tok.equals("hr")) numHR++; else if (tn.tok.equals("br")) numBR++; if (tn.tok.equals("table")) { if (tn.isClosing) numClosedTables++; else numOpenTables++; } else if (tn.tok.equals("a")) { if (tn.isClosing) numClosedAnchors++; else numOpenAnchors++; } else if (tn.tok.equals("p")) { if (tn.isClosing) numClosedParagraphs++; else numOpenParagraphs++; } else if (tn.tok.equals("div")) { if (tn.isClosing) numClosedDivs++; else numOpenDivs++; } else if (tn.tok.equals("span")) { if (tn.isClosing) numClosedSpans++; else numOpenSpans++; } else if (tn.tok.equals("script")) { if (tn.isClosing) numClosedScripts++; else numOpenScripts++; } else if (tn.tok.equals("style")) { if (tn.isClosing) numClosedStyles++; else numOpenStyles++; } else if (tn.tok.equals("frame")) { if (tn.isClosing) numClosedFrames++; else numOpenFrames++; } else if (tn.tok.equals("iframe")) { if (tn.isClosing) numClosedIFrames++; else numOpenIFrames++; } else if (tn.tok.equals("form")) { if (tn.isClosing) numClosedForms++; else numOpenForms++; } } this.numImages = numImages; this.numMeta = numMeta; this.numLink = numLink; this.numInput = numInput; this.numEmbed = numEmbed; this.numHR = numHR; this.numBR = numBR; this.hasAVclass = hasAVclass; this.hasAVstyle = hasAVstyle; this.hasAVid = hasAVid; this.hasAVtitle = hasAVtitle; this.hasAVhref = hasAVhref; this.hasAVhreflang = hasAVhreflang; this.hasAVsrc = hasAVsrc; this.hasAVsrcset = hasAVsrcset; this.hasAVsrclang = hasAVsrclang; this.hasAVsrcdoc = hasAVsrcdoc; this.hasAValt = hasAValt; this.hasAVtarget = hasAVtarget; this.hasAVwidth = hasAVwidth; this.hasAVheight = hasAVheight; this.hasAVsize = hasAVsize; this.hasAVsizes = hasAVsizes; this.hasAVcols = hasAVcols; this.hasAVcolspan = hasAVcolspan; this.hasAVrows = hasAVrows; this.hasAVrowspan = hasAVrowspan; this.hasAVwrap = hasAVwrap; this.hasAVvalue = hasAVvalue; this.hasAVtype = hasAVtype; this.hasAVname = hasAVname; this.hasAVmin = hasAVmin; this.hasAVmax = hasAVmax; this.hasAVminlength = hasAVminlength; this.hasAVmaxlength = hasAVmaxlength; this.hasAVaccept = hasAVaccept; this.numOpenTables = numOpenTables; this.numClosedTables = numClosedTables; this.numOpenAnchors = numOpenAnchors; this.numClosedAnchors = numClosedAnchors; this.numOpenParagraphs = numOpenParagraphs; this.numClosedParagraphs = numClosedParagraphs; this.numOpenDivs = numOpenDivs; this.numClosedDivs = numClosedDivs; this.numOpenSpans = numOpenSpans; this.numClosedSpans = numClosedSpans; this.numOpenScripts = numOpenScripts; this.numClosedScripts = numClosedScripts; this.numOpenStyles = numOpenStyles; this.numClosedStyles = numClosedStyles; this.numOpenFrames = numOpenFrames; this.numClosedFrames = numClosedFrames; this.numOpenIFrames = numOpenIFrames; this.numClosedIFrames = numClosedIFrames; this.numOpenForms = numOpenForms; this.numClosedForms = numClosedForms; } /** * Java's {@code public boolean equals(Object o)} requirements. * * @param o This may be any Java Object, but only ones of {@code 'this'} type whose * internal-values are identical will cause this method to return {@code TRUE}. * * @return {@code TRUE} if {@code 'this'} instance of {@code PageStats} is identical to * parameter {@code 'o'.} */ public boolean equals(Object o) { if (! (o instanceof PageStats)) return false; PageStats otherPageStats = (PageStats) o; return (this.strLength == otherPageStats.strLength) && (this.hash == otherPageStats.hash) && (this.numNodes == otherPageStats.numNodes) && (this.numTagNodes == otherPageStats.numTagNodes) && (this.numTextNodes == otherPageStats.numTextNodes) && (this.numCommentNodes == otherPageStats.numCommentNodes) && (this.numNewLines == otherPageStats.numNewLines) && (this.hasAVclass == otherPageStats.hasAVclass) && (this.hasAVstyle == otherPageStats.hasAVstyle) && (this.hasAVid == otherPageStats.hasAVid) && (this.hasAVtitle == otherPageStats.hasAVtitle) && (this.hasAVhref == otherPageStats.hasAVhref) && (this.hasAVhreflang == otherPageStats.hasAVhreflang) && (this.hasAVsrc == otherPageStats.hasAVsrc) && (this.hasAVsrcset == otherPageStats.hasAVsrcset) && (this.hasAVsrclang == otherPageStats.hasAVsrclang) && (this.hasAVsrcdoc == otherPageStats.hasAVsrcdoc) && (this.hasAValt == otherPageStats.hasAValt) && (this.hasAVtarget == otherPageStats.hasAVtarget) && (this.hasAVwidth == otherPageStats.hasAVwidth) && (this.hasAVheight == otherPageStats.hasAVheight) && (this.hasAVsize == otherPageStats.hasAVsize) && (this.hasAVsizes == otherPageStats.hasAVsizes) && (this.hasAVcols == otherPageStats.hasAVcols) && (this.hasAVcolspan == otherPageStats.hasAVcolspan) && (this.hasAVrows == otherPageStats.hasAVrows) && (this.hasAVrowspan == otherPageStats.hasAVrowspan) && (this.hasAVwrap == otherPageStats.hasAVwrap) && (this.hasAVvalue == otherPageStats.hasAVvalue) && (this.hasAVtype == otherPageStats.hasAVtype) && (this.hasAVname == otherPageStats.hasAVname) && (this.hasAVmin == otherPageStats.hasAVmin) && (this.hasAVmax == otherPageStats.hasAVmax) && (this.hasAVminlength == otherPageStats.hasAVminlength) && (this.hasAVmaxlength == otherPageStats.hasAVmaxlength) && (this.hasAVaccept == otherPageStats.hasAVaccept) && (this.numImages == otherPageStats.numImages) && (this.numMeta == otherPageStats.numMeta) && (this.numLink == otherPageStats.numLink) && (this.numInput == otherPageStats.numInput) && (this.numEmbed == otherPageStats.numEmbed) && (this.numHR == otherPageStats.numHR) && (this.numBR == otherPageStats.numBR) && (this.numOpenTables == otherPageStats.numOpenTables) && (this.numClosedTables == otherPageStats.numClosedTables) && (this.numOpenAnchors == otherPageStats.numOpenAnchors) && (this.numClosedAnchors == otherPageStats.numClosedAnchors) && (this.numOpenParagraphs == otherPageStats.numOpenParagraphs) && (this.numClosedParagraphs == otherPageStats.numClosedParagraphs) && (this.numOpenDivs == otherPageStats.numOpenDivs) && (this.numClosedDivs == otherPageStats.numClosedDivs) && (this.numOpenSpans == otherPageStats.numOpenSpans) && (this.numClosedSpans == otherPageStats.numClosedSpans) && (this.numOpenScripts == otherPageStats.numOpenScripts) && (this.numClosedScripts == otherPageStats.numClosedScripts) && (this.numOpenStyles == otherPageStats.numOpenStyles) && (this.numClosedStyles == otherPageStats.numClosedStyles) && (this.numOpenFrames == otherPageStats.numOpenFrames) && (this.numClosedFrames == otherPageStats.numClosedFrames) && (this.numOpenIFrames == otherPageStats.numOpenIFrames) && (this.numClosedIFrames == otherPageStats.numClosedIFrames) && (this.numOpenForms == otherPageStats.numOpenForms) && (this.numClosedForms == otherPageStats.numClosedForms); } /** * Java's hash-code requirement. Notice that this method is not static, and provides the * hashCode that was computed for the vectorized-webpage when this instance of * {@code PageStats} was created. Perhaps the subtlety is noticeable - <I>there is also a * {@code public static} version of method {@code int hashCode(); }</I> Both of them will * return the same number, but only one of them actually computes a hash-code (the * static-method). This non-static merely retrieves the hash that was created when this * instance was built by the constructor. * * @return A hash-code that may be used when storing this node in a java sorted-collection. */ public int hashCode() { return this.hash; } /** * Java's {@code interface Comparable<T>} requirements. This does a very simple comparison * using the underlying field {@code final String str} that all HTMLNode's contain. * * @param other Any other {@code PageStats} to be compared to {@code 'this' PageStats} * * @return An integer that fulfills Java's {@code interface Comparable<T> public boolean * compareTo(T t)} method requirements. */ public int compareTo(PageStats other) { int compare1 = this.numNodes - other.numNodes; if (compare1 != 0) return compare1; return this.strLength - other.strLength; } /** * This converts a {@code PageStats} object to a simple-string (Base64 Encoded) object that may * be passed and transmitted as a String. * * @return Zipped, Serialized, Base-64 Encoded String version of this object. * * @see StringParse#objToB64Str(Object) */ public String toB64String() { try { return StringParse.objToB64Str(this); } catch (Exception e) { return null; } } /** * Convets a Base65 Encoded {@code String} into an instance of {@code PageStats} * * @param minimized A previously minimized, compressed, Serialized version of this object * ({@code PageStats}). * * @return An instance of this class. * * @see StringParse#b64StrToObj(String) */ public static PageStats fromB64String(String minimized) { try { return (PageStats) StringParse.b64StrToObj(minimized); } catch (Exception e) { return null; } } /** * Generates a carbon copy of passed reference instance {@code 'PageStats'} * * @return Returns a 'clone' of this vector. Utilizes {@code 'this' class, protected * constructor}. */ public PageStats clone() { return new PageStats(this); } /** * Generates a java string representation of {@code 'this' instance} of {@code class PageStats} * * @return a java string of all the details encapsulated by a {@code PageStats} object * reference. */ public String toString() { return "strLength = " + strLength + '\n' + "hash = " + hash + '\n' + "numNodes = " + numNodes + '\n' + "numTagNodes = " + numTagNodes + '\n' + "numTextNodes = " + numTextNodes + '\n' + "numCommentNodes = " + numCommentNodes + '\n' + "numNewLines = " + numNewLines + '\n' + "\n" + "hasAVclass = " + hasAVclass + "\n" + "hasAVstyle = " + hasAVstyle + "\n" + "hasAVid = " + hasAVid + "\n" + "hasAVtitle = " + hasAVtitle + "\n" + "hasAVhref = " + hasAVhref + "\n" + "hasAVhreflang = " + hasAVhreflang + "\n" + "hasAVsrc = " + hasAVsrc + "\n" + "hasAVsrcset = " + hasAVsrcset + "\n" + "hasAVsrclang = " + hasAVsrclang + "\n" + "hasAVsrcdoc = " + hasAVsrcdoc + "\n" + "hasAValt = " + hasAValt + "\n" + "hasAVtarget = " + hasAVtarget + "\n" + "hasAVwidth = " + hasAVwidth + "\n" + "hasAVheight = " + hasAVheight + "\n" + "hasAVsize = " + hasAVsize + "\n" + "hasAVsizes = " + hasAVsizes + "\n" + "hasAVcols = " + hasAVcols + "\n" + "hasAVcolspan = " + hasAVcolspan + "\n" + "hasAVrows = " + hasAVrows + "\n" + "hasAVrowspan = " + hasAVrowspan + "\n" + "hasAVwrap = " + hasAVwrap + "\n" + "hasAVvalue = " + hasAVvalue + "\n" + "hasAVtype = " + hasAVtype + "\n" + "hasAVname = " + hasAVname + "\n" + "hasAVmin = " + hasAVmin + "\n" + "hasAVmax = " + hasAVmax + "\n" + "hasAVminlength = " + hasAVminlength + "\n" + "hasAVmaxlength = " + hasAVmaxlength + "\n" + "hasAVaccept = " + hasAVaccept + "\n" + "\n" + "numImages = " + numImages + '\n' + "numMeta = " + numMeta + '\n' + "numLink = " + numLink + '\n' + "numInput = " + numInput + '\n' + "numEmbed = " + numEmbed + '\n' + "numHR = " + numHR + '\n' + "numBR = " + numBR + '\n' + "\n" + "numOpenTables = " + numOpenTables + '\n' + "numClosedTables = " + numClosedTables + '\n' + "numOpenAnchors = " + numOpenAnchors + '\n' + "numClosedAnchors = " + numClosedAnchors + '\n' + "numOpenParagraphs = " + numOpenParagraphs + '\n' + "numClosedParagraphs = " + numClosedParagraphs + '\n' + "numOpenDivs = " + numOpenDivs + '\n' + "numClosedDivs = " + numClosedDivs + '\n' + "numOpenSpans = " + numOpenSpans + '\n' + "numClosedSpans = " + numClosedSpans + '\n' + "numOpenScripts = " + numOpenScripts + '\n' + "numClosedScripts = " + numClosedScripts + '\n' + "numOpenStyles = " + numOpenStyles + '\n' + "numClosedStyles = " + numClosedStyles + '\n' + "numOpenFrames = " + numOpenFrames + '\n' + "numClosedFrames = " + numClosedFrames + '\n' + "numOpenIFrames = " + numOpenIFrames + '\n' + "numClosedIFrames = " + numClosedIFrames + '\n' + "numOpenForms = " + numOpenForms + '\n' + "numClosedForms = " + numClosedForms + '\n'; } } |