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

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

import Torello.Java.Shell.C;
import Torello.Java.Additional.Ret3;
import Torello.Java.Additional.EffectivelyFinal;

import java.util.*;
import java.io.File;
import java.io.IOException;

/**
 * <B STYLE='color:darkred;'>Process Java Doc Web-Page:</B>
 * 
 * Inserts link to a complete <CODE>'&#46;java'</CODE> HiLited Source-File Page into a
 * Java Doc Page.
 * 
 * <EMBED CLASS="external-html" DATA-FILE-ID=PKG_PRIVATE_MSG>
 * <EMBED CLASS="external-html" DATA-FILE-ID=HILITE_SCFILE>
 */
@StaticFunctional
public class HiLiteSrcCodeFile
{
    private HiLiteSrcCodeFile() { }


    // ********************************************************************************************
    // ********************************************************************************************
    // A PACKAGE-VISIBLE inner-class to hold a single Source Code HiLiting Link.
    // ********************************************************************************************
    // ********************************************************************************************


    // This is a class for a single "LIST" filed 2-D String[][] Array Entry that contains a single
    // Extra HiLited Source-Code Link.  Each time an "Extra Source Code Link" is added, it will
    // have an actual File to be Hilited (javaSrcCodeFileName), a "Title-Bar" String, and also a
    // "Class Name Label" String.  To view one of these things, look at any of the Search Classes
    // in the Torello.HTML.NodeSearch Package.  Each of the Search-Loop Classes there have an
    // extra "Search-Loops" link, and a link to "ARGCHECK.java" file.

    static class ExtraSrcLink
    {
        public final String CIETName;
        public final String javaSrcCodeFileName;    // A '.java' file to be sent to the HiLiter
        public final String titleBarLabel;          // Title String explaining this extra file.
        public final String classNameLabel;         // Text-String used - in place of the Java
                                                    // Source FileName, because often that file
                                                    // name is JUST TOO LONG!

        ExtraSrcLink(String[] extraLinkArr)
        {
            this.CIETName               = extraLinkArr[0];
            this.titleBarLabel          = extraLinkArr[1];
            this.javaSrcCodeFileName    = extraLinkArr[2];
            this.classNameLabel         = extraLinkArr[3];
        }
    }


    // ********************************************************************************************
    // ********************************************************************************************
    // HiLited Source Code HTML-File Header & Footer (The LINKED HTML Page, NOT the Java-Doc Page)
    // ********************************************************************************************
    // ********************************************************************************************


    private static final Vector<HTMLNode> PAGE_HEADER = HTMLPage.getPageTokens(
        "<HTML>\n<HEAD>\n\n" + 
        "<TITLE>CIET_NAME</TITLE>\n\n" +
        "<!-- Java Documentation Upgrader, Torello.HTML.Tools.JavaDoc.Upgrader -->\n\n" +
        "<META charset=\"UTF-8\">\n\n" +
        "</HEAD>\n<BODY>\n",
        false
    );

    private static final Vector<HTMLNode> PAGE_FOOTER = HTMLPage.getPageTokens
        ("\n</BODY>\n</HTML>\n", false);

    private static final int titlePos =
        TextNodeFind.first(PAGE_HEADER, (String s) -> s.equals("CIET_NAME"));

    /**
     * Used in build library.
     * 
     * @param cietName The name of the class, interface or enumerated-type whose source-code file
     * is being hilited.  This name will be placed in the title portion of the HTML
     * {@code <HEAD>...</HEAD>} section.
     * 
     * @return A clone of the {@code Vector} which is placed at the top of a HiLited Source
     * Code {@code '.html'} File.
     */
    @SuppressWarnings("unchecked")
    public static Vector<HTMLNode> retrieveHEADER(String cietName)
    {
        Vector<HTMLNode> header = (Vector<HTMLNode>) PAGE_HEADER.clone();
        header.setElementAt(new TextNode(cietName), titlePos);
        return header;
    }

    /**
     * Used in build library.  Must be declared {@code public.}
     * 
     * @return a clone of the hilited source-code HTML-{@code Vector} page footer.
     */
    @SuppressWarnings("unchecked")
    public static Vector<HTMLNode> retrieveFOOTER()
    { return (Vector<HTMLNode>) PAGE_FOOTER.clone(); }


    // ********************************************************************************************
    // ********************************************************************************************
    // Page  URL Links (The LINKS inserted into the JAVA-DOC PAGE, **NOT** the linked-pages)
    // ********************************************************************************************
    // ********************************************************************************************


    /** This is the HTML Inserted into the Page. */
    protected static final Vector<HTMLNode> SRCCODE_ANCHOR = HTMLPage.getPageTokens(
        "\n" +
        "<BR />\n" +
        "<DIV ID=SRCCODELINK>\n" +
        "<SPAN CLASS=srcCodeLabel>Hi-Lited Source-Code:</SPAN>\n" +
        "<DIV CLASS=JDTopIndent>\n" +
        "<UL CLASS=JDUL>\n" +
        "<LI><SPAN STYLE='white-space: pre; font-family: monospace'>" +
        "View Here:              </SPAN><A>SRCCODE_FILE_NAME</A></LI>\n" +
        "<LI><SPAN STYLE='white-space: pre; font-family: monospace'>" +
        "Open New Browser-Tab:   </SPAN><A TARGET='_blank'>SRCCODE_FILE_NAME</A></LI>\n" +
        "</UL>\n" +
        "<SPAN STYLE='white-space: pre; font-family: monospace;'>" +
        "File Size:     FS Bytes\n" +
        "Line Count:    LC \'\\n\' Characters Found\n" +
        "</SPAN>\n" +
        "</DIV> <!-- DIV CLASS=JDTopIndent -->\n" +
        "</DIV> <!-- DIV ID=SRCCODELINK -->\n" +
        "<BR />\n\n",
        false
    );

    private static final int[] ANCHOR_POS_ARR = 
        TagNodeFind.all(SRCCODE_ANCHOR, TC.OpeningTags, "A");

    private static final int[] FILENAME_POS_ARR =
        TextNodeFind.all(SRCCODE_ANCHOR, TextComparitor.EQ, "SRCCODE_FILE_NAME");

    private static final int TXTNODE_COUNT_POS =
        TextNodeFind.first(SRCCODE_ANCHOR, TextComparitor.CN, "File Size");

    private static final String[] replaceArr = { "FS", "LC" };


    // ********************************************************************************************
    // ********************************************************************************************
    // EXTRA & ADDITIONAL HiLited-Source Links - By Request
    // ********************************************************************************************
    // ********************************************************************************************


    private static final int INSERT_FIRST_DESCRIPTION_POS =
        TagNodeFind.first(SRCCODE_ANCHOR, TC.OpeningTags, "ul");

    private static final Vector<HTMLNode> FIRST_DESCRIPTION = HTMLPage.getPageTokens
        ("<SPAN CLASS=SRCCODETITLE>DESCRIPTION</SPAN><BR />\n", false);

    private static final int FIRST_DESCIPTION_TXTNODE_POS = TextNodeFind.first
        (FIRST_DESCRIPTION, (String text) -> text.equals("DESCRIPTION"));

    // It should be inserted directly at/before the following line:
    // "</DIV> <!-- DIV CLASS=JDTopIndent -->\n"

    private static final int EXTRA_LINK_INSERTION_POS =
        TagNodeFind.first(SRCCODE_ANCHOR, TC.ClosingTags, "div");

    /**
     * Using a Lambda-Configuration with the Configuration-Class {@link Upgrade}, a user may
     * request that additional HiLited Source Code Links be added to this section / area on
     * Java Doc Class File Pages.
     * 
     * <BR /><BR />This is the HTML that is added to the page, upon request.
     */
    protected static final Vector<HTMLNode> EXTRA_SRCCODE_ANCHOR = HTMLPage.getPageTokens(
        "\n" +
        "<BR /><SPAN CLASS=SRCCODETITLE>DESCRIPTION</SPAN>\n" +
        "<BR />\n" +
        "<UL CLASS=JDUL>\n" +
        "<LI><SPAN STYLE='white-space: pre; font-family: monospace'>" +
        "View Here:              </SPAN><A>SRCCODE_FILE_NAME</A></LI>\n" +
        "<LI><SPAN STYLE='white-space: pre; font-family: monospace'>" +
        "Open New Browser-Tab:   </SPAN><A TARGET='_blank'>SRCCODE_FILE_NAME</A></LI>\n" +
        "</UL>\n" +
        "<SPAN STYLE='white-space: pre; font-family: monospace;'>" +
        "File Size:     FS Bytes\n" +
        "Line Count:    LC \'\\n\' Characters Found\n" +
        "</SPAN>\n",
        false
    );

    private static final int[] EXTRA_ANCHOR_POS_ARR = 
        TagNodeFind.all(EXTRA_SRCCODE_ANCHOR, TC.OpeningTags, "A");

    private static final int[] EXTRA_FILENAME_POS_ARR =
        TextNodeFind.all(EXTRA_SRCCODE_ANCHOR, TextComparitor.EQ, "SRCCODE_FILE_NAME");

    private static final int EXTRA_TXTNODE_COUNT_POS =
        TextNodeFind.first(EXTRA_SRCCODE_ANCHOR, TextComparitor.CN, "File Size");

    private static final int SECOND_DESCRIPTION_TXTNODE_POS = TextNodeFind.first
        (EXTRA_SRCCODE_ANCHOR, (String text) -> text.equals("DESCRIPTION"));


    // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
    // FIX ME!!! THIS SHOULD BE MOVED TO CLASS Upgrade.  Static-Member Fields with State is
    // cheating and ugly-to-look-at
    // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***

    private static final HashSet<String> alreadyHiLitedList = new HashSet<>();


    // ********************************************************************************************
    // ********************************************************************************************
    // Methods
    // ********************************************************************************************
    // ********************************************************************************************


    // This is package-private.
    //
    // The inline comments may be read by clicking the "View HiLited Source Code Button"
    // If there are errors, this method throws JDE
    //
    // MESSAGER:
    //  1) SETS:        processorName to 'HiLiteSrcCodeFile' on entry
    //  2) INVOKES:     'errorThrowJDE' for errors, also has 'errorContinue'
    //  3) RETURNS:     boolean indicating whether or not the src-file was hilited
    //  4) INVOKED-BY:  Only once in MainFilesProcessor, main-loop
    //  5) EXPECTS:     FileName to already be set
    //  6) THROWS:      JavaDocError

    @SuppressWarnings({"unchecked", "rawtypes"})
    static boolean hiLite(
            Upgrade u, JavaDocHTMLFile jdhf, String srcCodeAsStr, String dotDots,
            String srcCodeFileName, ArrayList<ExtraSrcLink> extraLinks
        )
    {
        Messager.setProcessorName("HiLiteSrcCodeFile");

        // Vector<HTMLNode> topOfHTMLPage = jdhf.pageTop();
        Vector<HTMLNode> pageDLs = jdhf.headerFooter.defListsBelowDesc();

        boolean hasExtra = (extraLinks != null) && (extraLinks.size() > 0);

        int numExtra = (hasExtra) ? extraLinks.size() : 0;

        // Since the addition of "hilited-files/" - this is now necessary
        // Remember, for URL's (as opposed to files) ALWAYS USE A FOWARD-SLASH!

        dotDots = dotDots + "../";

        /*
        System.out.println(
            "Class [" + jdhf.fullyQualifiedName + "] " +
            C.BGREEN + (hasExtra ? "*DOES*" : "**DOES NOT**") + C.RESET +
            " have extra Hilite Links!"
        );
        */

        // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
        // STEP A-ONE: Build '.html' Hi-Lited Source-Code File & Dir Names, Create Dir If Needed
        // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***

        // *** The Full-Path Diectory-Name of the output / save Directory used by this CIET
        String hiLitedSrcCodeDirectory = StringParse.beforeLastFileSeparatorPos
            (jdhf.fileName) + "hilite-files" + File.separator;

        // *** The Simple File-Name of the HiLited Source-Code File: Used for <TITLE>...</TITLE>
        //     jdhf.fileName is just that - the Full-Path Name of the Java Doc HTML File that is
        //     currently being processed.

        String simpleHiLitedFileName = StringParse.fromLastFileSeparatorPos(jdhf.fileName);

        // REMEMBER: Inner-Classes reuse their container classes hilited html-files ... and there
        //           is no need to hilite them twice!

        if (jdhf.isInner) simpleHiLitedFileName =
            simpleHiLitedFileName.substring(0, simpleHiLitedFileName.indexOf('.')) + ".java.html";
        else
            simpleHiLitedFileName = simpleHiLitedFileName.substring
                (0, simpleHiLitedFileName.length() - ".html".length()) + ".java.html";

        // *** The Full-Path File-Name of the HiLited Source-Code File: Used to write file to disk
        String hiLitedSrcCodeFileName = hiLitedSrcCodeDirectory + simpleHiLitedFileName;

        // *** The "Anchor Link HREF=..." URL
        // NEW-AND-IMPROVED: This will insert the Line-Number into the Anchor-URL when the class
        // that is being processed is an inner-class.  For "FileNode.RetTypeChoice" - for example -
        // this will skip all the way to the bottom of the source-file (which is where 
        // "RetTypeChoice" is defined).  It looks a lot better...

        String anchorURL = "hilite-files" + File.separator + simpleHiLitedFileName +
            (jdhf.isInner
                ? ("#L" +
                    ((jdhf.jdStartLineNumber != -1)
                        ? jdhf.jdStartLineNumber
                        : jdhf.startLineNumber))
                : "");


        // *** This will be the text used *BETWEEN* the Anchor-Elements <A HREF=...> TEXT-HERE </A>
        // *** You could call this the 'LINK-TEXT' ... it is the File-Name as it is PRINTED inside
        // *** the HTML Document itself!
        //
        // REMEMBER: Inner-Classes reuse their container classes hilited html-files ... and there
        //           is no need to hilite them twice!

        String printedFileName = jdhf.isInner

            ? (jdhf.packageName.replace('.', '/') + '/' +
                jdhf.simpleName.substring(0, jdhf.simpleName.indexOf('.')) + ".java")

            : (jdhf.fullyQualifiedName.replace('.', '/') + ".java");

        // *** Create the output directory, if it has not been created yet!
        File hiLiteDir = new File(hiLitedSrcCodeDirectory);

        try
            { if (! hiLiteDir.exists()) hiLiteDir.mkdirs(); }

        catch (Exception e)
        {
            Messager.assertFailGeneralPurpose(
                e,
                "An Exception was thrown while attempting to create the output directory for " +
                "saving HiLited Source Code Files.",
                null
            );
        }


        // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
        // B-ONE: Build the "EXTRA" Hi-Lited Source-Code File & Dir Names.
        // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***

        String[] extraSrcCodeAsStrs             = null; // HiLite.ME Send-String
        String[] extraSimpleHiLitedFileNames    = null; // Used for: <TITLE> ... </TITLE>
        String[] extraHiLitedSrcCodeFileNames   = null; // Used for: Writing File(s) to Disk
        String[] extraAnchorURLs                = null; // Used for: <A HREF=...> </A>

        if (hasExtra)
        {
            extraSrcCodeAsStrs              = new String[numExtra];
            extraSimpleHiLitedFileNames     = new String[numExtra];
            extraHiLitedSrcCodeFileNames    = new String[numExtra];
            extraAnchorURLs                 = new String[numExtra];

            for (int i=0; i < numExtra; i++)
            {
                // The data inside the inner-class "ExtraSrcLink" is the actual list of Strings
                // (a 2-D String[][] Array) the the user provided.  This includes three main
                // String-Fields: The Java-FileName, the "Title-Bar Label", and "Class-Name Label"

                ExtraSrcLink esl = extraLinks.get(i);

                try
                    { extraSrcCodeAsStrs[i] = FileRW.loadFileToString(esl.javaSrcCodeFileName); }

                catch (Exception e)
                {
                    // When they provide a bogus XTRA-SRC-FILE to be hilited, this is going to be
                    // called a non-fatal error....  The result will be that no hilited files will
                    // be inserted ANYWHERE - INCLUDING THE NORMAL SRC-HILITE-AND-INSERT..
                    Messager.errorContinue(
                        e,
                        "Inserting extra Hi-Lited Source-Code Files, User-Provided File-Name " +
                        "failed to load from disk: " +
                        "    [" + C.BCYAN + esl.javaSrcCodeFileName + C.RESET + "]\n" +
                        "Not inserting extra hi-lited source-code file links..."
                    );

                    // CALCULATE THE NORMAL RETURN VALUE - AND EXIT THIS METHOD
                    /// When an "Extra File" fails, just skip adding the HiLited Code, at all, for
                    // this class
                    //
                    // 'false' is that the file was not successfully hilited.  "NavButtons" needs
                    // to know

                    return false;
                }

                // *** The Simple File-Name of the HiLited Source-Code File: Used for <TITLE>
                // NOTE:    Slightly different than the main HiLited-Src File-Name Computation
                // THERE:   jdhf.fileName   ==> The JavaDoc '.html' File
                // HERE:    xtra.b[i]       ==> Some other '.java' Source-Code File
                extraSimpleHiLitedFileNames[i] = StringParse.fromLastFileSeparatorPos
                    (esl.javaSrcCodeFileName) + ".html";

                // *** The Full-Path File-Name of the HiLited Source-Code File: Used to write the
                //     file to disk
                extraHiLitedSrcCodeFileNames[i] = hiLitedSrcCodeDirectory + 
                    extraSimpleHiLitedFileNames[i];

                // *** The "Anchor Link HREF=..." URL (for the extra file(s) - if any)
                extraAnchorURLs[i] = "hilite-files" + File.separator +
                    extraSimpleHiLitedFileNames[i];
            }
        }


        // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
        // STEP TWO: Run the HiLiter
        // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***

        // This invokes the HiLiter, and saves the HTML File to Disk.  This now officially checks
        // for inner-classes, and makes sure not to hilite them twice.
        //
        // ARG-1: Upgrade-Instance (for the Messager)
        // ARG-2: <TITLE> ... <TITLE>
        // ARG-3: Full-Path File-Save Name
        // ARG-4: The '.java' File As a java.lang.String
        // ARG-5: Relative Path String to use for the <META> Tags, Favicon, etc...
        //
        // NOTE: On error, this uses Messager.errorThrowJDE()

        if (! alreadyHiLitedList.contains(hiLitedSrcCodeFileName))
        {
            hiLiteSrcCodeFile
                (u, simpleHiLitedFileName, hiLitedSrcCodeFileName, srcCodeAsStr, dotDots);

            alreadyHiLitedList.add(hiLitedSrcCodeFileName);
        }

        // Run the HiLiter for any / all "Extra HiLited Source Code Files"  This if-statement
        // should rarely be invoked.  It is only used if the user has provided the 
        // Configuration-Class File "ExtraHiLitedSrc.class" in the /upgrade-files/config-classes/
        // directory.

        if (hasExtra) for (int i=0; i < numExtra; i++)
        {
            // There is no need to continusously "Re-HiLite" and "Re-Save" any files, over and over
            // The primary example is the use of "ARGCHECK.java" in Node-Search, which is linked
            // in all of the HTML Files.
            //
            // This little HashMap "alreadyHiLitedList" just makes not of the on-disk file-name for
            // the output HiLited-HTML-Files, and returns "TRUE" if it looks like the same exact
            // file is about to be HiLited and written to disk again.

            if (! alreadyHiLitedList.contains(extraHiLitedSrcCodeFileNames[i]))
            {
                // Uses: Messager.errorThrowJDE, if problems happen
                hiLiteSrcCodeFile(
                    u, extraSimpleHiLitedFileNames[i], extraHiLitedSrcCodeFileNames[i], 
                    extraSrcCodeAsStrs[i], dotDots
                );

                alreadyHiLitedList.add(extraHiLitedSrcCodeFileNames[i]);
            }
        }


        // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
        // STEP THREE: Clone the HTML Vectors to insert & Set the HREF=... in all Anchors <A>
        // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***

        // Vector<HTMLNode> SRCCODE_ANCHOR = HTMLPage.getPageTokens(...)
        //
        // @SuppressWarnings("unchecked")

        Vector<HTMLNode> srcCodeAnchorHTMLVec = (Vector<HTMLNode>) SRCCODE_ANCHOR.clone();

        Attributes.update
            // int[] ANCHOR_POS_ARR = TagNodeFind.all(SRCCODE_ANCHOR, TC.OpeningTags, "A");
            (srcCodeAnchorHTMLVec, AUM.Set, ANCHOR_POS_ARR, "href", anchorURL, SD.SingleQuotes);

        // Vector<HTMLNode> EXTRA_SRCCODE_ANCHOR = HTMLPage.getPageTokens(...)
        //
        // @SuppressWarnings({"unchecked", "rawtypes"})
        Vector<HTMLNode>[] extraSrcCodeAnchorHTMLVecs = null;

        if (hasExtra)
        {
            extraSrcCodeAnchorHTMLVecs = new Vector[numExtra];

            for (int i=0; i < numExtra; i++)
            {
                extraSrcCodeAnchorHTMLVecs[i] = (Vector<HTMLNode>) EXTRA_SRCCODE_ANCHOR.clone();

                Attributes.update(
                    // int[] EXTRA_ANCHOR_POS_ARR =
                    //      TagNodeFind.all(EXTRA_SRCCODE_ANCHOR, TC.OpeningTags, "A");
                    extraSrcCodeAnchorHTMLVecs[i], AUM.Set, EXTRA_ANCHOR_POS_ARR, "href",
                    extraAnchorURLs[i], SD.SingleQuotes
                );
            }
        }


        // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
        // STEP FOUR: Insert / replace the correct the 'line-count' and 'file-size' TextNodes.
        // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***

        // int TXTNODE_COUNT_POS =
        //      TextNodeFind.first(SRCCODE_ANCHOR, TextComparitor.CN, "File Size");
        TextNode counts = (TextNode) srcCodeAnchorHTMLVec.elementAt(TXTNODE_COUNT_POS);

        String[] countsTextArr = new String[]
        { StringParse.commas(jdhf.typeSizeChars), StringParse.commas(jdhf.typeLineCount) };

        counts = new TextNode(StrReplace.r(counts.str, replaceArr, countsTextArr));

        // int TXTNODE_COUNT_POS =
        //      TextNodeFind.first(SRCCODE_ANCHOR, TextComparitor.CN, "File Size");
        srcCodeAnchorHTMLVec.setElementAt(counts, TXTNODE_COUNT_POS);

        if (hasExtra) for (int i=0; i < numExtra; i++)
        {
            // int EXTRA_TXTNODE_COUNT_POS =
            //      TextNodeFind.first(EXTRA_SRCCODE_ANCHOR, TextComparitor.CN, "File Size");
            counts = (TextNode) extraSrcCodeAnchorHTMLVecs[i].elementAt(EXTRA_TXTNODE_COUNT_POS);

            int fileSize = extraSrcCodeAsStrs[i].length();
            int newLines = StringParse.countCharacters(extraSrcCodeAsStrs[i], '\n');
    
            countsTextArr = new String[]
            { StringParse.commas(fileSize), StringParse.commas(newLines) };
    
            counts = new TextNode(StrReplace.r(counts.str, replaceArr, countsTextArr));

            // int EXTRA_TXTNODE_COUNT_POS =
            //      TextNodeFind.first(EXTRA_SRCCODE_ANCHOR, TextComparitor.CN, "File Size");
            extraSrcCodeAnchorHTMLVecs[i].setElementAt(counts, EXTRA_TXTNODE_COUNT_POS);
        }


        // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
        // STEP FIVE: Insert The file-name(s) themselves (as a TextNode)
        // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***

        // NOTE: If you try to get rid of the "EffectivelyFinal" Cheat-Hack Class, it isn't the
        //       "new TextNode" (since it is only one String, and only created twice) in the
        //       ReplaceNodes.r internal-loop...
        //
        // BUT-RATHER: It is the 'i' in the loop below that also needs the "EffectivelyFinal" hack.

        final EffectivelyFinal<TextNode> sourceFileNameTxN
            = new EffectivelyFinal<>(new TextNode(printedFileName));

        ReplaceNodes.r(
            // int[] FILENAME_POS_ARR =
            //      TextNodeFind.all(SRCCODE_ANCHOR, TextComparitor.EQ, "SRCCODE_FILE_NAME");
            srcCodeAnchorHTMLVec, FILENAME_POS_ARR,
            (HTMLNode n, int dummy1, int dummy2) -> sourceFileNameTxN.f
        );

        if (hasExtra) for (int i=0; i < numExtra; i++)
        {
            // The text that is used for between the <A HREF=...> TEXT </A> link is called the
            // "classNameLabel".  It is a final field inside the ExtraSrcLink inner-class at the
            // top of this class.  If this is hard to keep straight which label or text is being
            // placed where ==> The 'classNameLabel' would be "searchLoops/TxNFind.java" (if you
            // were talking about the extra-links in the NodeSearch Package).
            //
            // If you were talking about the GlassFish extra links from the java.json package, this
            // would be the one that reads "org/glassfish/Json.java"  text-string.

            sourceFileNameTxN.f = new TextNode(extraLinks.get(i).classNameLabel);

            ReplaceNodes.r(
                // int[] EXTRA_FILENAME_POS_ARR = TextNodeFind.all
                //      (EXTRA_SRCCODE_ANCHOR, TextComparitor.EQ, "SRCCODE_FILE_NAME");
                extraSrcCodeAnchorHTMLVecs[i], EXTRA_FILENAME_POS_ARR,
                (HTMLNode n, int dummy1, int dummy2) -> sourceFileNameTxN.f
            );
        }


        // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
        // STEP SIX: Add the "File-Title" <SPAN>'s.  This ONLY HAPPENS when there are Extra-Files
        // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***

        if (hasExtra)
        {
            // int EXTRA_LINK_INSERTION_POS =
            //      TagNodeFind.last(SRCCODE_ANCHOR, TC.ClosingTags, "div");
            int insertionPos = EXTRA_LINK_INSERTION_POS;

            // NOTE: ORDER IS KIND OF IMPORTANT BELOW... THE POINTERS GO STALE!
            // STALE VECTOR-INDICES: Always insert the stuff at the end *FIRST*.
            for (int i=0; i < numExtra; i++)
            {
                // int SECOND_DESCRIPTION_TXTNODE_POS = TextNodeFind.first
                //      (EXTRA_SRCCODE_ANCHOR, (String text) -> text.equals("DESCRIPTION"));
                extraSrcCodeAnchorHTMLVecs[i].setElementAt(
                    new TextNode(extraLinks.get(i).titleBarLabel),
                    SECOND_DESCRIPTION_TXTNODE_POS
                );

                // Do this after previous line!
                srcCodeAnchorHTMLVec.addAll(insertionPos, extraSrcCodeAnchorHTMLVecs[i]);

                // NOTE: move this forward...
                insertionPos += extraSrcCodeAnchorHTMLVecs[i].size();
            }

            // STALE-INDEX-MAIN-POINT: This is the part THAT HAS TO BE DONE LAST - because the
            // index-pointer "INSERT_FIRST_DESCRIPTION_POS" points to the beginning of the
            // "srcCodeAnchorHTMLVec" - and *THAT* Vector is the whole HiLited-Source-Code HTML
            // Vector.

            // Vector<HTMLNode> FIRST_DESCRIPTION = HTMLPage.getPageTokens
            //      ("<BR /><SPAN CLASS=SRCCODETITLE>DESCRIPTION</SPAN><BR />\n", false);
            @SuppressWarnings("unchecked")
            Vector<HTMLNode> firstDescription = (Vector<HTMLNode>) FIRST_DESCRIPTION.clone();

            // int FIRST_DESCIPTION_TXTNODE_POS = TextNodeFind.first
            //      (FIRST_DESCRIPTION, (String text) -> text.equals("DESCRIPTION"));
            firstDescription.setElementAt
                (new TextNode("This File's Source Code:"), FIRST_DESCIPTION_TXTNODE_POS);

            // int INSERT_FIRST_DESCRIPTION_POS =
            //      TagNodeFind.first(SRCCODE_ANCHOR, TC.OpeningTags, "ul");
            srcCodeAnchorHTMLVec.addAll(INSERT_FIRST_DESCRIPTION_POS, firstDescription);
        }

        // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
        // STEP SEVEN: INSERT (This used to be complicated, finding an insertion-point)
        // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***

        pageDLs.addAll(srcCodeAnchorHTMLVec);


        // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
        // STEP EIGHT: Return Stats-Information
        // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***

        if (Messager.isVerbose()) Messager.println(
            "    HiLited '.java' Source-Code File  successfully to disk: " +
            C.BYELLOW + hiLitedSrcCodeFileName + C.RESET
        );

        // true is that the file was successfully hilited.  "NavButtons" needs to know
        return true;
    }


    // ********************************************************************************************
    // ********************************************************************************************
    // HiLite a Source-Code File
    // ********************************************************************************************
    // ********************************************************************************************


    // The CSS Class HLSCF => HiLited Source-Code File
    private static final TagNode MAIN_DIV = new TagNode("<DIV CLASS=HLSCF>");

    // This hilites a '.java' file, and saves the hilited file to disk.
    // This is a separate method, because it might be done more than once - if there are extra
    // files to hilite.
    //
    // NOTE: 'name' comes from jdhf.name - It *IS NOT* jdhf.fullyQualifiedName anymore!
    //
    // Since this is private, this method may only be called from this class.  This method 
    // *DOES NOT* reset the Messager's 'processorName' because it is done at the top of the main
    // method of this class.
    //
    // MESAGER ONLY USES: errorAndThrowJDE

    private static void hiLiteSrcCodeFile(
            Upgrade u, String name, String hiLitedSrcCodeFileName, String srcCodeAsStr,
            String dotDots
        )
    {
        // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
        // Invoke HiLite.ME on SourceCode
        // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***

        Vector<HTMLNode> hiLitedSource = null;

        try
            { hiLitedSource = u.hiLiter.hiLite(srcCodeAsStr, "java", false); }

        catch (Exception e)
        {
            // NOTE: This error needs to be thought of as "more likely" my error.  Unfortunately,
            //       for now, this method does not differentiate between the UNEXPECTED_ERROR and
            //       ERROR.
            //
            // This used to be a 'return false', but that causes 'return null' which causes
            // MainFilesProcessor to return false.  It is easier to read this as below... it has
            // been switched to throw new JavaDocError()

            Messager.assertFailGeneralPurpose(
                e,
                "There was a problem attempting to read either the Server 'http://HiLite.ME', " +
                "or the File generated an Exception when trying to read from the Cache. " +
                "Currently HiLiting File:\n" +
                "    [" + C.BYELLOW + hiLitedSrcCodeFileName + C.RESET + "]\n",
                null
            );
        }


        // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
        // Insert all the "add-ons" to the hilited source-code '.java.html' file
        // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***

        try
        {
            // The First Element is a <DIV>, replace this <DIV> with the pre-instantiated and
            // final static <DIV> TagNode that is listed directly above this method.
            hiLitedSource.setElementAt(MAIN_DIV, 0);

            // Insert Header and Footer
            hiLitedSource.addAll(0, retrieveHEADER(name));
            hiLitedSource.addAll(PAGE_FOOTER);

            // Insert the CSS Relative-URL link into hilited-source-code HTML file vector
            Features.insertCSSLink(hiLitedSource, dotDots + Upgrade.JAVA_DOC_CSS_FILE_NAME);
            Messager.ifVPrintln("    Inserted CSS Link");

            // Check for favicon request, and insert  into hilited-source-code HTML file vector
            if (u.faviconImageFileName != null)
            {
                Features.insertFavicon(hiLitedSource, dotDots + u.faviconImageFileName);
                Messager.ifVPrintln("\tInserted Favicon");
            }

            // Save the HiLited Source Code String to disk.
            // System.out.println("Writing File: " + C.BYELLOW + hiLitedSrcCodeFileName + C.RESET);
            FileRW.writeFile(Util.pageToString(hiLitedSource), hiLitedSrcCodeFileName);
        }
        catch (Exception e)
        {
            // Using "ERROR", rather than "UNEXPECTED_ERROR" because this is more likely the
            // O/S or the User's Mistake.  The try=code just inserts HTML into a Vector, and
            // writes the file to disk.
            //
            // Recently changed to Messager.errorThrowJDE

            Messager.assertFailGeneralPurpose(
                e,
                "Failed to write HiLited Source-Code File:\n" +
                "    [" + C.BYELLOW + hiLitedSrcCodeFileName + C.RESET + "]",
                null
            );
        }
    }


    // ********************************************************************************************
    // ********************************************************************************************
    // Retrieve the CONFIGURATION-CLASS-FILE from the 'upgrade-files/' directory
    // ********************************************************************************************
    // ********************************************************************************************


    // This is used internally the StrReplce -> Prepend Char Replacement Method.  This is used
    // inside the method below ==> Strictly used for error-messages.

    static final char[] TABS_NEWLINES = { '\t', '\n', '\r' };

    // Helper for error message printing
    static final String LIST_MSG(int i)
    { return "static field LIST[" + C.BGREEN + i + C.RESET + "]"; }

    // Helper for error message printing
    static final String LIST_MSG(int i, int j)
    { return "static field LIST[" + C.BGREEN + i + C.RESET + "][" + C.BGREEN + j + C.RESET + "]"; }

    static final String LIST_MSG(int i, int j, String elem)
    { return LIST_MSG(i, j) + ": [\"" + C.BCYAN + elem + C.RESET + "\"]\n"; }

    // MESSAGER: 
    //  1) SETS:        processorName & fileName
    //  2) INVOKES:     errors are logged using either 'errorExitingNow' or 'errorContinue'.
    //  3) RETURNS:     Any error's => return null.  Not Found/Present => return null.
    //  4) INVOKED-BY:  MainFilesProcessor - part *BEFORE* Main Loop, called only ONCE.
    //  5) EXPECTS:     NOTHING
    //  6) THROWS:      No explicity throws
    //
    // RETURN: This method returns 'null' if there isn't any defined extra-hilite Config-Class
    //         defined in the user's /upgrade-files/config-classes directory.
    //
    //         This method also returns 'null' if there were any errors that were sent to the
    //         Messager.  If this happens, when MainFilesProcessor checks if errors occured, it
    //         exits immediately.

    static final TreeMap<String, ArrayList<ExtraSrcLink>> readConfigurationClassFromDisk
        (String packageName, TreeSet<String> packageCIETList, String[] rootSourceFileDirectories)
    {
        Messager.setProcessorName("HiLiiteSrcCodeFile");


        // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
        // FIND IF "upgrade-files/ExtraHiLitedSrc.class" EXISTS for PACKAGE anywhere in CLASSPATH
        // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***

        String extraLinksPartialClassFileName = packageName.replace(".", File.separator) +
            File.separator + "upgrade-files" + File.separator + "config-classes" + File.separator +
            "ExtraHiLitedSrc.class";

        // Search the CLASS-PATH for:
        // "full/package/name/upgrade-files/config-classes/ExtraHiLitedSrc.class"
        //
        // NOTE: This call doesn't cause any exceptions, nor does it use the messager
        //
        // PARAMETER: 'true' means this is a 'file' (not a directory)

        String extraLinksClassFileName = HELPER.findFileNameInClassPath
            (extraLinksPartialClassFileName, rootSourceFileDirectories, true);

        if (extraLinksClassFileName != null) 
        {
            Messager.println(
                "Found 'ExtraHiLitedSrc' Configuration-Class: " +
                "[" + C.BYELLOW + extraLinksClassFileName + C.RESET + "]"
            );

            Messager.setCurrentFileName
                (extraLinksClassFileName, "User-Provided Extra-Src-Hiliting Configuration-Class");
        }
        else
        {
            // Finish the "Opening Statement" from the 'm.print' before the previous loop started
            if (Messager.isVerbose()) Messager.println(" ... Not Found");
            return null;
        }


        // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
        // Load the 'ExtraHiLitedSrc' Class into instance of java.lang.Class - TWO POSSIBLE NAMES
        // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***

        Class<?> extraLinksClass = null;

        // These are the two user options for the name of the package.
        String[] cNamesArr = new String[] { packageName + ".ExtraHiLitedSrc", "ExtraHiLitedSrc" };

        try 
            { extraLinksClass = FileRW.readClass(extraLinksClassFileName, cNamesArr); }

        catch (TypeNotPresentException e)
        {
            Messager.errorExitingNow(e, Messager.TNPE);
            return null;
        }

        catch (Exception e)
        {
            Messager.errorExitingNow
                (e, "Unexpected exception thrown attempting to read Configuration-Class");

            return null;
        }


        // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
        // Retrieve the 2-D String-Array of User-Provided "Extra-Links", and error check.
        // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***

        java.lang.reflect.Field listAsField = HELPER.getStaticField
            (extraLinksClass, "LIST", String[][].class, extraLinksClassFileName);

        if (listAsField == null) return null;

        String[][] list = (String[][]) HELPER.getStaticFieldEvaluation
                (listAsField, extraLinksClassFileName);

        if (list == null) return null;


        // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
        // Check for User-Error in the User-Provided 2-D String[] Array
        // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***

        boolean errors = false;

        for (int i=0; i < list.length; i++)
        {
            String[] extraLink = list[i];

            if (extraLink == null)
            {
                Messager.errorContinue(LIST_MSG(i) + " is null");
                errors=true;
                continue;
            }

            if (extraLink.length != 4)
            {
                Messager.userErrorContinue(
                    LIST_MSG(i) + " has length " +
                    "[" + C.BRED + ("" + extraLink.length) + C.RESET + "], but this should be " +
                    "precisely 4:\n    " +
                    "arr[0] => CIET-Name, arr[1] => Java-Src-File-Name, arr[2] => Link-Title, " +
                    "arr[3] => Link-Text"
                );

                errors=true;
                continue;
            }

            // Iterate each of the four string's inside of the "Extra Link Configuration"
            // Just make sure none are null, and none contain tabs or newlines.

            for (int j=0; j < extraLink.length; j++)

                if (extraLink[j] == null)
                {
                    Messager.errorContinue(LIST_MSG(i, j) + " is null.");
                    errors=true;
                    continue;
                }
                else if (StrCmpr.containsXOR(extraLink[j], "\n", "\r", "\t"))
                {
                    Messager.errorContinue(
                        LIST_MSG(i, j, StrReplace.r(extraLink[j], TABS_NEWLINES, '\\')) +
                        "contains a tab ('\\t') or a new-line character ('\\n', '\\r'), but " +
                        "this is not allowed."
                    );

                    errors=true;
                    continue;
                }

            // Check that the CIET/Type provided by the user is a valid java identifier
            if (! StringParse.isJavaTypeStr(extraLink[0]))
            {
                Messager.errorContinue(
                    LIST_MSG(i, 0, extraLink[0]) +
                    "This String is not a valid Java Type Identifier."
                );

                errors=true;
                continue;
            }

            // NEW ADDITION: Make sure the type is lited in the known types for this package.
            if (! packageCIETList.contains(extraLink[0]))
            {
                Messager.errorContinue(
                    LIST_MSG(i, 0, extraLink[0]) +
                    "This is not one of the types listed in the 'package-summary.html' file for " +
                    "this package"
                );

                errors=true;
                continue;
            }

            // Check that the Title-Bar Label is not going to overflow the screen
            // This is the descriptive title above the link!

            if (extraLink[1].length() > 80)
            {
                Messager.errorContinue(
                    LIST_MSG(i, 1, extraLink[1]) +
                    "has a String-Length [" + C.BRED + extraLink[2].length() + C.RESET + "], " +
                    "but it may not be over 80"
                );

                errors=true;
                continue;
            }

            if (Messager.reachedMaxErrorsOrWarnings()) return null;
        }

        if (errors) return null;


        // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
        // Convert 'LIST' 2D-String[][] Array Field into TreeMap<String, ArrayList<ExtraSrcLink>>
        // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***

        TreeMap<String, ArrayList<ExtraSrcLink>> ret = new TreeMap<>();

        for (String[] extraLink : list)
        {
            // Since each CIET/Type may have more than "Extra HiLited Source Code Link", the
            // TreeMap contains ArrayList<ExtraSrcLink> *RATHER THAN* just ExtraSrcLink.

            ArrayList<ExtraSrcLink> linksAL = ret.get(extraLink[0]);

            if (linksAL == null)
                ret.put(extraLink[0], linksAL = new ArrayList<>());

            linksAL.add(new ExtraSrcLink(extraLink));
        }

        return ret;
    } 
}