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

import Torello.Java.ReadOnly.ReadOnlyMap;
import Torello.JDUInternal.Features.STATS.StatsInternal;
import Torello.JDUInternal.MainJDU.ClassUpgradeData.UpgradeSettings;

import Torello.JavaDoc.Messager.Messager;

import java.io.File;
import java.util.Objects;

class GlobalEmbedTags 
{
    static Torello.JDUInternal.Features.STATS.StatsInternal globalMapAndStats 
        (final UpgradeSettings.Builder settingsBuilder)
    {
        final boolean mapB  = settingsBuilder.interimGlobalTagIDMap         != null;
        final boolean fileB = settingsBuilder.interimGlobalTagIDMapFileName != null;

        if (mapB && fileB) throw new UpgradeException(
            "Both Configuration-Method:\n" +
            "Upgrade.setProjectGlobalEmbedTagsMap​(ReadOnlyMap<String,​String> tagIDMap)\n" +
            "and Configuration-Method:\n" +
            "Upgrade.setProjectGlobalEmbedTagsMapFile​(String tagIDMapFileName)\n" +
            "have been invoked - but one of them may be assigned a value, or this exception " +
            "throws."
        );

        if (mapB)       return setMap(settingsBuilder);
        else if (fileB) return setMapFile(settingsBuilder);
        else            return new StatsInternal();
    }

    private static Torello.JDUInternal.Features.STATS.StatsInternal setMapFile
        (final UpgradeSettings.Builder settingsBuilder)
    {
        final String tagIDMapFileName = settingsBuilder.interimGlobalTagIDMapFileName;

        if (tagIDMapFileName == null) throw new UpgradeException
            ("The parameter 'tagIDMapFileName' (as a String) was passed NULL.");

        final File tagIDMapFile = new File(tagIDMapFileName);

        if (! tagIDMapFile.exists()) throw new UpgradeException
            ("The <EMBED> Tag ID Map File Provided doesn't exist:\n[" + tagIDMapFileName + "]");

        if (! tagIDMapFile.isFile()) throw new UpgradeException
            ("The <EMBED> Tag ID Map File Provided isn't a file:\n[" + tagIDMapFileName + "]");

        settingsBuilder.projectGlobalEmbedTagsMap = 
            Torello.JDUInternal.Features.EXTERNAL_HTML_FILES.ReadUserConfig.API_LoadUserTags
                .read(tagIDMapFile, settingsBuilder.checkBalance, "");


        // Register this with the 'Stats' class.  This keeps a count of the use of each of these
        // tags in Java Doc Pages, and outputs a 'Stats.html' file at the end.
        // 
        // this.stats = new StatsInternal(settingsBuilder.projectGlobalEmbedTagsMap);

        return new Torello.JDUInternal.Features.STATS.StatsInternal
            (settingsBuilder.projectGlobalEmbedTagsMap);
    }

    private static Torello.JDUInternal.Features.STATS.StatsInternal setMap
        (final UpgradeSettings.Builder settingsBuilder)
    {
        final ReadOnlyMap<String, String> tagIDMap = settingsBuilder.projectGlobalEmbedTagsMap;

        Objects.requireNonNull(
            tagIDMap,
            "The parameter 'tagIDMap' (a ReadOnlyMap<String, String>) was passed NULL."
        );


        // This needs to be set "outside" of the class "API_CheckTagMap" - because of this whole
        // entire issue.  "User Provided Map Instance", "Instance, Not File"

        Messager.setCurrentFileName("User Provided Map Instance", "Instance, Not File");

        // This map is the "Project-Global" Tag-Map
        final boolean res =
            Torello.JDUInternal.Features.EXTERNAL_HTML_FILES.ReadUserConfig.API_LoadUserTags
                .checkMap(tagIDMap, settingsBuilder.checkBalance, "");

        if (! res) throw new UpgradeException(
            "There were errors when checking the HTML Validity of the External-HTML Global " +
            "EMBED TAG FILES."
        );

        // Copy the Embed-Tag Map, (ID ==> FileName Map) into 'this' (internally-stored) map.
        settingsBuilder.projectGlobalEmbedTagsMap = tagIDMap;


        // Register this with the 'Stats' class.  This keeps a count of the use of each of these
        // tags in Java Doc Pages, and outputs a 'Stats.html' file at the end.
        // 
        // this.stats = new StatsInternal(this.settingsBuilder.projectGlobalEmbedTagsMap);

        return new Torello.JDUInternal.Features.STATS.StatsInternal
            (settingsBuilder.projectGlobalEmbedTagsMap);
    }
}