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

import static Torello.Java.C.*;

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

import Torello.Java.FileRW;
import Torello.Java.StringParse;
import Torello.Java.StrCSV;
import Torello.Java.StrIndexOf;

import Torello.Java.Additional.Ret2;
import Torello.Java.Additional.Ret3;

import Torello.JDUInternal.GeneralPurpose.Messager;
import Torello.JDUInternal.GeneralPurpose.GetHeaderTags;

import Torello.JDUInternal.DataClasses.UserUpgradeFilesConfig.PkgSort;
import Torello.JDUInternal.DataClasses.ClassUpgradeData.PathsAndTypes;
import Torello.JDUInternal.DataClasses.ClassUpgradeData.UpgradeSettings;

import Torello.JDUInternal.HTMLProcessors.Rearrange.RearrangePkgSummaryFile;
import Torello.JDUInternal.HTMLProcessors.Rearrange.RearrangePkgFrameFile;

import Torello.JDUInternal.HTMLProcessors.CleanerFixer.CleanPackageSummaryFile;

import Torello.JDUInternal.HTMLProcessors.HiLiteSource.HiLiteDividers;

import Torello.JDUInternal.ParseHTML.PackageSummary;
import Torello.JDUInternal.UserConfigReaders.RetrievePkgSortConfigClass;

import java.io.File;
import java.io.IOException;
import java.io.Serializable;

import Torello.Java.ReadOnly.ReadOnlyVector;
import Torello.Java.ReadOnly.ROTreeSetBuilder;
import Torello.Java.ReadOnly.ReadOnlyTreeSet;

import java.util.*;

import java.util.function.Consumer;

/**
 * A class that parses and encapsulates the contents of a <B>{@code 'package-summary.html'}</B>
 * File.
 */
public class PackageSummaryHTML implements Serializable
{
    // ********************************************************************************************
    // ********************************************************************************************
    // Static-Final Constant Fields
    // ********************************************************************************************
    // ********************************************************************************************


    /** <EMBED CLASS='external-html' DATA-FILE-ID=SVUID> */
    protected static final long serialVersionUID = 1;

    /** Deprecated, but useful API Error-Message */
    public static final String JD_FRAMES_WARNING_MESSAGE =
        "javadoc: warning - You have specified to generate frames, by using the --frames " +
            "option.\n" +
        "The default is currently to not generate frames and the support for \n" +
        "frames will be removed in a future release.\n" +
        "To suppress this warning, remove the --frames option and avoid the use of frames.\n";

    /*
    sb.append(
        "<UL CLASS=\"blockList\">\n" +
        "<LI CLASS=\"blockList\">\n" +
        "<TABLE CLASS=\"typeSummary\" BORDER=\"0\" cellpadding=\"3\" cellspacing=\"0\" " +
        "summary=\"Summary table, listing Classes, Interfaces and Enums, etc...\">\n"
    );
    */

    private static final Vector<HTMLNode> TABLE_START = HTMLPage.getPageTokens(
        "<UL CLASS=blockList>\n" +
        "<LI CLASS=blockList>\n" +
        "<TABLE CLASS=typeSummary BORDER=0 CELLPADDING=3 CELLSPACING=0 " +
        "summary=\"Summary table, listing Classes, Interfaces and Enums, etc...\">\n",
        false
    );

    private static final Vector<HTMLNode> TABLE_END =
        HTMLPage.getPageTokens("</UL>\n</LI>\n</TABLE>\n", false);

    private static final char FSEP = File.separator.charAt(0);

    private static final String PKG_SUMM_HTML = "Package Summary HTML";

    private static final TagNode BODY_WITH_CSS_CLASS_TN = new TagNode("<BODY CLASS=C30>");


    // ********************************************************************************************
    // ********************************************************************************************
    // final Class-Data Fields
    // ********************************************************************************************
    // ********************************************************************************************


    /** The name of the Java Package represented by this instance. */
    public final String packageName;

    // Contains the top Navigation Bar's HTML 
    // This, and all SubSection instances, must be private, because they are mutable

    private final SubSection head;

    // Contains the top Navigation Bar's HTML 
    private final SubSection topNavBar;

    // Contains the bottom Navigation Bar's HTML
    private final SubSection bottomNavBar;

    // THe Top-Description HTML/Text
    private final SubSection description;

    // The rows (which contain CIET/Types) of this 'package-summary.html' File
    private final Vector<Vector<HTMLNode>> cietRowHTML;

    private final Vector<String> cietRowSimpleNames;

    private final TreeMap<String, Vector<HTMLNode>> rowTM = new TreeMap<>();

    // This is needed for the "package-frame.html" file generation in later JavaDoc versions where
    // the "--frames" switch was deprecated.  This is only used internally.
    //
    // Note, this could theoretically be public - although "they" wouldn't have much use for it
    // that I can think of...  But mainly, the class "PkgSort" is not really accessible to the end
    // user.  Therefore it shall remain package-private

    final PkgSort sorter;


    // ********************************************************************************************
    // ********************************************************************************************
    // Simple Accessor Methods
    // ********************************************************************************************
    // ********************************************************************************************


    /**
     * Allows a User to both retrieve and to modify the contents of the
     * {@code 'package-summary.html'} {@code <HEAD>}-Section.
     * 
     * @return Vectorized-HTML of this Web-Page's {@code <HEAD>...</HEAD>} Section.
     */
    public Vector<HTMLNode> head() { return this.head.html; }

    /**
     * Allows a User to both retrieve and to modify the contents of the
     * {@code 'package-summary.html'} Nav-Bar.
     * 
     * @return Vectorized-HTML of this Web-Page's Upper Navigation Menu-Bar.
     */
    public Vector<HTMLNode> topNavBar()
    { return (this.topNavBar == null) ? null : this.topNavBar.html; }

    /**
     * Allows a User to both retrieve and to modify the contents of the
     * {@code 'package-summary.html'} Nav-Bar.
     * 
     * @return Vectorized-HTML of this Web-Page's Lower Navigation Menu-Bar.
     */
    public Vector<HTMLNode> bottomNavBar()
    { return (this.bottomNavBar == null) ? null : this.bottomNavBar.html; }

    /**
     * Allows a User to both retrieve and to modify the contents of the
     * {@code 'package-summary.html'} Description Text-Area.
     * 
     * @return Vectorized-HTML of this Web-Page's Main Description Box.
     */
    public Vector<HTMLNode> description() { return this.description.html; }


    // ********************************************************************************************
    // ********************************************************************************************
    // Default Package-Summary Cleaner
    // ********************************************************************************************
    // ********************************************************************************************


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

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

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

        int i=0, nodePos=-1;

        /*
        if (VERBOSE) MessagerVerbose.println
            ("cietSummary: " + BGREEN + Util.pageToString(cietSummary) + RESET);
        */

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

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

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

        /*
        if (VERBOSE) MessagerVerbose.println("s: " + s);
        */

        s = s.substring(0, pos);

        /*
        if (VERBOSE) MessagerVerbose.println("s.substring: " + s);
        */

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

        if (nodePos < cietSummary.size())
            Util.Remove.range(cietSummary, nodePos, cietSummary.size());

        // Util.removeAllTagNodes(cietSummary);
        // CHANGED March 2nd 2022

        TagNodeRemove.allExcept(cietSummary, TC.Both, "a", "b", "i", "code", "span");

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


    // ********************************************************************************************
    // ********************************************************************************************
    // This class Main-Builder (Constructor)
    // ********************************************************************************************
    // ********************************************************************************************


    public PackageSummaryHTML(
            final String                jdPkgSummFName,
            final PathsAndTypes.Builder pathsTypesBuilder,
            final UpgradeSettings       settings
        )
    {
        Messager.setCurrentFileName(jdPkgSummFName, "'package-summary.html' File");

        final String dotDotsFileSystem = StringParse.dotDots
            (jdPkgSummFName, pathsTypesBuilder.rootJavaDocDirectory, File.separatorChar);

        final String dotDotsUrls = (File.separatorChar == '/')
            ? dotDotsFileSystem
            : dotDotsFileSystem.replace(File.separatorChar, '/');

        final Consumer<Vector<HTMLNode>> packageSummaryCleaner = settings.packageSummaryCleaner;


        // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
        // Calculate the Package-Name.  This is the very first time this is done.
        // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***

        final String packageSubDir = jdPkgSummFName.substring(
            pathsTypesBuilder.rootJavaDocDirectory.length(),

            // "/package-summary.html" ==> String-Length = 21
            jdPkgSummFName.length() - 21
        );

        // As of February, 2024, this is now a public final String field
        packageName = packageSubDir.replace(FSEP, '.');

        // Read the file from disk and parse into Vectorized-HTML
        Vector<HTMLNode> fileVec =
            loadHTMLFile(jdPkgSummFName, "package-summary.html");


        // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
        // Check for a PackageSummarySort.class File - check all Class-Path Source-Code Dirs
        // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***

        final ArrayList<String> sorters = new ArrayList<>(4);

        for (String dir : pathsTypesBuilder.rootSourceFileDirectories)
        {
            String fileName = dir + packageSubDir + FSEP + "upgrade-files" + FSEP +
                "config-classes" + FSEP + "PackageSummarySort.class";

            File f = new File(fileName);

            if (f.exists() && f.isFile()) sorters.add(fileName);
        }

        if (sorters.size() > 1) Messager.userErrorHalt(
            "Multiple Package Sorters were found:\n" +
            StrCSV.toCSV(sorters, fName -> "    " + fName + '\n', true, null)
        );

        // This is an instance of "PkgSort"  As of February 2024, it must be retained as an 
        // instance-field of this class, in case the "package-frame.html" file must be built from
        // scratch.  (Thereby allowing for later javadoc versions, where `--frames` was deprecated
        // to continue to have a 'packge-frame.html' file anyway)

        sorter = (sorters.size() == 0)
            ? null
            : RetrievePkgSortConfigClass.readConfigurationClassFromDisk
                (sorters.get(0), packageName);


        // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
        // Sort **OR** just Clean-Up the CIET/Type List on this web-page
        // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***

        if (sorter != null)
        {
            // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
            // Read the File's Contents & Sort if needed.
            // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***

            // Used to build the Master CIET/Type List for registering with 'pathsTypes'
            ROTreeSetBuilder<String> cietSimpleNamesList = new ROTreeSetBuilder<>();

            // Builds a TreeMap of all of the table rows on the "Package Summary" JavaDoc HTML Page
            HNLIInclusive iter = PackageSummary.iteratorTypeRows(fileVec);

            // Save the rows by CIET-Name in a TreeMap
            // Map-Key:     CIET Simple-Name
            // Map-Value:   Table-Row of HTML <TR> ... </TR>

            final TreeMap<String, Vector<HTMLNode>> entries = new TreeMap<>();

            // Fill the TreeMap with all of the table-rows on the page.  These are going to be
            // completely rearranged in the next step.

            while (iter.hasNext())
            {
                Vector<HTMLNode>    cietHTML        = iter.next();
                int                 pos             = TagNodeFind.first(cietHTML, TC.OpeningTags, "a");
                String              cietSimpleName  = cietHTML.elementAt(pos + 1).str;

                entries.put(cietSimpleName, cietHTML);      // Saved for Sorting
                cietSimpleNamesList.add(cietSimpleName);    // Saved to PathsAndTypes
            }

            final Ret2<
                Vector<String>,
                Vector<Vector<HTMLNode>>
            > r2 = RearrangePkgSummaryFile.run(sorter.sections, sorter.types, entries);

            // If there were errors, then the above function might return null.  Halt the
            // constructor here, BUT do not throw so that all of the PackageSummaryHTML's can
            // execute, FIRST, before quitting.

            if (r2 == null)
            {
                // Prevent `javac` complaints: (final field may not have been initialized)
                this.cietRowHTML        = null;
                this.cietRowSimpleNames = null;

                // These are all SubSection instances
                this.head = this.topNavBar = this.bottomNavBar = this.description = null;

                return;
            };

            this.cietRowSimpleNames = r2.a;
            this.cietRowHTML        = r2.b;

            // Update the Global Package-Name ==> CIET/Type List TreeMap (Inside PathsAndTypes)
            pathsTypesBuilder.packageCIETLists.put(packageName, cietSimpleNamesList.build());
        }

        else
        {
            // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
            // Read the File's Contents & Clean-It
            // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***

            Ret3
            <
                Vector<String>,             // cietRowSimpleNames
                Vector<Vector<HTMLNode>>,   // cietRowHTML
                ReadOnlyTreeSet<String>     // cietSimpleNamesList
            >
            r3 = CleanPackageSummaryFile.run(fileVec);

            this.cietRowSimpleNames = r3.a;
            this.cietRowHTML        = r3.b;

            // Update the Global Package-Name ==> CIET/Type List TreeMap (Inside PathsAndTypes)
            pathsTypesBuilder.packageCIETLists.put(packageName, r3.c);
        }


        // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
        // Build the Updated 'package-summary.html' Page
        // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***

        // This DotPair contains the entire Summary-Table in a package-summary.html file
        DotPair dp = InnerTagFindInclusive.first
            (fileVec, "ul", "class", TextComparitor.C, "blockList");

        // Build the new Package-Summary CIET/Type Table
        final Vector<HTMLNode> newTable = new Vector<>();

        newTable.addAll(TABLE_START);

        for (Vector<HTMLNode> cietHTML : this.cietRowHTML) newTable.addAll(cietHTML);

        newTable.addAll(TABLE_END);

        // Insert the new Table into the same location where the old table had been placed
        ReplaceNodes.r(fileVec, dp, newTable);


        // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
        // Check if there is a User-Provided (or Default) "Package Summary Cleaner"
        // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***

        // MESSAGER: Messager.isVerbose, println only
        if (packageSummaryCleaner != null)
            CleanPackageSummaryFile.run(fileVec, packageSummaryCleaner);

        // MESSAGER:
        //  1) INVOKES:     assertFailGeneralPurpose, assertFailHTML
        //  2) INVOKED-BY:  ExtraFilesProcessor (once) MainFilesProcessor (once), method above
        //  3) RETURNS:     Number of HiLited <DIV>'s (maybe zero, if zero)
        //  4) THROWS:      asserFail ==> JavaDocHTMLParseException & UpgradeException

        HiLiteDividers.hiLite(fileVec, settings.hiLiter);


        // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
        // Retrieve the <HEAD>...</HEAD> Header
        // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***

        this.head = TagNodePeekInclusive.first(fileVec, "head");

        if (this.head == null) Messager.assertFailHTML(
            "This 'package-summary.html' page does not appear to have a <HEAD>...</HEAD> Element",
            PKG_SUMM_HTML
        );


        // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
        // The Top Navigation-Bar - There may be pages which do not have a NavBar
        // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
        //
        // NOTE: I just noticed that the Navigation-Bar is a series of <DIV>'s, and there is no
        //       surrounding HTML divider.  We have to find the first open-<DIV>, and the last
        //       closing </DIV>

        int sPos = CommentNodeFind.first
            (fileVec, head.location.end, -1, s -> s.contains("=== START OF TOP NAVBAR ==="));

        int ePos;

        if (sPos == -1)
        {
            this.topNavBar = null;
            ePos = head.location.end;
        }

        else
        {
            ePos = CommentNodeFind.first
                (fileVec, sPos, -1, s -> s.contains("=== END OF TOP NAVBAR ==="));

            sPos = TagNodeFind.first(fileVec, sPos, ePos, TC.OpeningTags, "div");
            ePos = TagNodeFind.last(fileVec, sPos, ePos, TC.ClosingTags, "div");

            dp = new DotPair(sPos, ePos);

            this.topNavBar = new SubSection(dp, Util.cloneRange(fileVec, dp));
        }


        // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
        // Package-Description
        // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***

        this.description = TagNodePeekInclusive.first(fileVec, ePos, -1, "section");

        if (this.description == null) Messager.assertFailHTML
            ("This Package returned a null Description", PKG_SUMM_HTML);


        // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
        // The Bottom Navigation-Bar, There may be pages which do not have a NavBar
        // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
        //
        // Searching through "CommentNode" instances is much faster since the
        // if (HTMLNode.isCommentNode()) is the fastest of the search-specifies...  There aren't
        // many comment's in a javadc page (much fewer than the number of TagNode's & TextNode's)
        //
        // ALSO: as explained in the "Top Navigation-Bar" getter-section (way above this part),
        //       The Bottom and Top Bar's are a series of "sibling" <DIV> Tags, and you have to
        //       get the first opening-<DIV> and the last closing-</DIV>

        sPos = CommentNodeFind.first(fileVec, s -> s.contains("== START OF BOTTOM NAVBAR =="));

        if (sPos == -1) this.bottomNavBar = null;

        else
        {
            ePos = CommentNodeFind.first
                (fileVec, sPos, -1, s -> s.contains("=== END OF BOTTOM NAVBAR ==="));

            if (ePos == -1) Messager.assertFailHTML("BOTTOM NAVBAR End-Marker not found", null);

            sPos = TagNodeFind.first(fileVec, sPos, ePos, TC.OpeningTags, "div");
            ePos = TagNodeFind.last(fileVec, sPos, ePos, TC.ClosingTags, "div");
    
            dp = new DotPair(sPos, ePos);

            this.bottomNavBar = new SubSection(dp, Util.cloneRange(fileVec, dp));
        }


        // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
        // Meta-Tags in Header, Stats Button in Navigation Bar
        // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***

        final List<HTMLNode> tags = GetHeaderTags.packageSummaryHTMLTags(
                ((settings.cssFiles == null) ? null : settings.cssFiles.customizedCSS),
                dotDotsUrls,
                settings.faviconImageFileName,
                settings.headerTags
            )
            .wrapToImmutableList();

        this.head.html.addAll(1, tags);

        Stats.addStatsButton(this.topNavBar(), this.bottomNavBar(), dotDotsUrls, packageName);


        // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
        // Re-Build the Page-Vector
        // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***

        Replaceable[] replaceables =
            { this.head, this.topNavBar, this.description, this.bottomNavBar };

        fileVec = ReplaceNodes.r(fileVec, Arrays.asList(replaceables), false).a;


        // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
        // Write the new 'package-summary.html' to Disk
        // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***

        try
            { FileRW.writeFile(Util.pageToString(fileVec), jdPkgSummFName); }

        catch (IOException ioe)
        {
            Messager.assertFailGeneralPurpose
                (ioe, "Failed Writing 'package-summary.html' File", null);
        }


        // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
        // Handle 'package-frame.html' - IF IT EXISTS
        // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
        //
        // Requirements:
        //      1) User has provided a Package-Sorter
        //      2) JavaDoc has created a package-frame.html file

        // "package-summary.html" ==> "summary.html" ==> length() is 12
        final String jdPkgFrameFName =
            jdPkgSummFName.substring(0, jdPkgSummFName.length() - 12) + "frame.html";

        final File f = new File(jdPkgFrameFName);

        // Now check that the package-frame.html file exists, and is an HTML-File
        if (f.exists() && f.isFile())
        {
            Messager.setCurrentFileName(jdPkgSummFName, "'package-frame.html' File");
    
            // Read the file from disk and parse into Vectorized-HTML
            fileVec =
                loadHTMLFile(jdPkgFrameFName, "package-summary.html");


            // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
            // Rearrange 'package-frame.html'
            // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***

            if (sorter != null)
                RearrangePkgFrameFile.run(fileVec, sorter.sections, sorter.types);


            // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
            // Original "Package-Frame Cleaner" - Moved Here from EFP, November 2023
            // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***

            fileVec.setElementAt(
                BODY_WITH_CSS_CLASS_TN,     /* <BODY CLASS=C30> */
                TagNodeFind.first(fileVec, TC.OpeningTags, "body")
            );

            /*
            // February 2024, EVEN-BETTER
            // Just do <BODY CLASS=C30> inside of a 'package-frame.html' file INSTEAD OF ALL OF
            // THESE STUPID "extra CSS Classses"
            // SEE ABOVE 3 LOC

            for (TagNodeIndex tni : TagNodePeek.all(fileVec, TC.OpeningTags, "h1", "h2", "ul"))

                if (tni.n.tok.equals("h1"))            
                    fileVec.setElementAt(
                        tni.n.appendCSSClass(CSSTags.CSS_CLASS_FOR_PKG_FRAME_H1, null),
                        tni.index
                    );

                else if (tni.n.tok.equals("h2"))
                    fileVec.setElementAt(
                        tni.n.appendCSSClass(CSSTags.CSS_CLASS_FOR_PKG_FRAME_H2, null),
                        tni.index
                    );

                else // if (tni.n.tok.equals("ul"))
                    fileVec.setElementAt(
                        tni.n.appendCSSClass(CSSTags.CSS_CLASS_FOR_PKG_FRAME_UL, null),
                        tni.index
                    );
            */


            // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
            // Meta-Tags in Header
            // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***

            final int pkgFrameHeaderPos = TagNodeFind.first(fileVec, TC.OpeningTags, "HEAD");

            fileVec.addAll(pkgFrameHeaderPos + 1, tags);


            // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
            // Write 'package-frame.html' back to disk
            // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***

            try
                { FileRW.writeFile(Util.pageToString(fileVec), jdPkgFrameFName); }

            catch (IOException ioe)
            {
                Messager.assertFailGeneralPurpose
                    (ioe, "Failed Writing 'package-summary.html' File", null);
            }
        }

    }


    // ********************************************************************************************
    // ********************************************************************************************
    // A Little Helper That Could
    // ********************************************************************************************
    // ********************************************************************************************


    private static Vector<HTMLNode> loadHTMLFile(final String fileName, final String fileKind)
    {
        // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
        // Load The Package-Summary HTML File from disk.
        // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***

        // Temp Variable, the file as a String
        final String fileAsStr;

        try
            { fileAsStr = FileRW.loadFileToString(fileName); }

        catch (Exception e)
        {
            throw (Error) /* Shut-Up Compiler */ Messager.assertFailGeneralPurpose(
                e,
                "I/O Exception throwm attempting to load " + fileKind + " file from disk",
                null
            );
        }


        // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
        // Parse The Summary HTML File from the raw-file text-string
        // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***

        // This portion of the code attempts to load the Package-Frame list of classes, 
        // interfaces enums, errors and exceptions into a Vectorized-HTML page.

        final Vector<HTMLNode> fileVec;

        try
            { fileVec = HTMLPage.getPageTokens(fileAsStr, false); }

        // It seems ridiculous to check for this exception, but oh well, this always does have
        // the upside that if class HTMLPage does break (for whatever reason), what has
        // happened would be much easier to identify

        catch (Exception e)
        {
            throw (Error) /* Shut-Up Compiler */ Messager.assertFailHTML(
                e,
                "Error Parsing HTML in file " + fileKind + " using class HTMLPage.parsePgeTokens",
                null
            );
        }

        return fileVec;
    }
}