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
package Torello.HTML.Tools.JavaDoc;

import Torello.HTML.*;
import Torello.HTML.NodeSearch.*;
import Torello.Java.*;

import Torello.Java.Shell.C;

import java.util.*;
import java.io.*;

import java.util.function.Consumer;

/**
 * <B STYLE='color:darkred;'>Process Java Doc Web-Page:</B>
 * 
 * Simple utility for modifying Java Doc Package-Summary Files, using a user-provided
 * function-pointer or lamda.
 * 
 * <EMBED CLASS="external-html" DATA-FILE-ID=PKG_PRIVATE_MSG>
 * <EMBED CLASS="external-html" DATA-FILE-ID=CLEAN_PKG_SUMM>
 */
@StaticFunctional
public class CleanPackageSummaries
{
    private CleanPackageSummaries() { }

    private static final String[] searches = { ".", "<br/>", "\n" };

    static final void defaultCleaner(Vector<HTMLNode> cietSummary)
    {
        boolean VERBOSE = Messager.isVerbose();

        // System.out.println("INSIDE MY LAMBDA:\n" + Util.pageToString(cietSummary));

        int i=0, nodePos=-1;

        if (VERBOSE)
            Messager.println("cietSummary: " + C.BGREEN + Util.pageToString(cietSummary) + C.RESET);

        while ((nodePos == -1) && (i < searches.length))
            nodePos = TextNodeFind.first(cietSummary, TextComparitor.CN_CI, searches[i++]);

        if (nodePos == -1)
        {
            if (VERBOSE) Messager.println("No String Markers Found!  Exiting...");
            return;
        }

        String  s   = cietSummary.elementAt(nodePos).str;
        int     pos = StrIndexOf.first_CI(s, searches[--i]);

        if (VERBOSE) Messager.println("s: " + s);

        s = s.substring(0, pos);

        if (VERBOSE) Messager.println("s.substring: " + s);

        if (s.length() != 0)
            cietSummary.setElementAt(new TextNode(s), nodePos++);

        if (nodePos < cietSummary.size())
            Util.removeRange(cietSummary, nodePos, cietSummary.size());

        // Util.removeAllTagNodes(cietSummary);
        // CHANGED March 2nd 2022
        TagNodeRemove.allExcept(cietSummary, TC.Both, "a", "b", "i", "code", "span");

        if (VERBOSE) Messager.println(
            C.BCYAN + Util.pageToString(cietSummary) + C.RESET +
            "\n************************************************************\n"
        );
    }

    // MESSAGER: Messager.isVerbose, println only
    static void run(Vector<HTMLNode> jdPage, Consumer<Vector<HTMLNode>> summaryCleaner)
    {
        if (Messager.isVerbose()) Messager.println("CleanPackageSummaries.run(...):");

        int count = 0;

        HNLIInclusive iter = InnerTagInclusiveIterator.get
            (jdPage, "tr", "class", TextComparitor.C, "altColor", "rowColor");

        while (iter.hasNext())
        {
            DotPair dp = iter.nextDotPair();

            DotPair cLast = InnerTagFindInclusive.first
                (jdPage, dp.start, dp.end, "td", "class", TextComparitor.C, "colLast");

            if (cLast == null) continue;

            DotPair div = InnerTagFindInclusive.first
                (jdPage, cLast.start, cLast.end, "div", "class", TextComparitor.C, "block");

            if (div == null) continue;
            if (div.size() < 3) continue;

            DotPair divContentsDP = new DotPair(div.start+1, div.end-1);

            Vector<HTMLNode> divContents = Util.cloneRange(jdPage, divContentsDP);
            summaryCleaner.accept(divContents);
            iter.replaceRange(divContentsDP, divContents);

            count++;
        }

        if (Messager.isVerbose()) Messager.println(
            "    Cleaned " + C.BBLUE +  StringParse.zeroPad(count) + C.RESET +
            " '" + C.BCYAN + "package-summary.html" + C.RESET + "' CIETEE-Summary Dividers."
        );
    }
}