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

import java.util.Properties;

class GeneralPurpose
{

    // This builds an HTML Element into {@code String} which may be passed to the constructor that
    // accepts a {@code String} as input ({@link #TagNode(java.lang.String)}).

    static String generateElementString(
            final String            tok,
            final Properties        attributes,
            final Iterable<String>  keyOnlyAttributes,
            final SD                quotes,
            final boolean           addEndingForwardSlash
        )
    {
        String computedQuote = (quotes == null) ? "" : ("" + quotes.quote);

        HTMLTokException.check(tok);

        // The HTML Element is "built" using a StringBuilder
        StringBuilder sb = new StringBuilder();
        sb.append("<" + tok);

        // If there are any Inner-Tag Key-Value pairs, insert them first.
        if ((attributes != null) && (attributes.size() > 0))

            for (String key : attributes.stringPropertyNames())
            {
                String value = attributes.getProperty(key);

                InnerTagKeyException.check(key, value);

                QuotesException.check(
                    value, quotes,
                    "parameter 'Properties' contains:\nkey:\t" + key + "\nvalue:\t" + value + "\n"
                );

                sb.append(" " + key + '=' + computedQuote + value + computedQuote);
            }

        // If there are any Key-Only Inner-Tags (Boolean Attributes), insert them next.
        if (keyOnlyAttributes != null)

            for (String keyOnlyAttribute : keyOnlyAttributes) 
            {
                InnerTagKeyException.check(keyOnlyAttribute);
                sb.append(" " + keyOnlyAttribute);
            }

        // Add a closing forward-slash
        sb.append(addEndingForwardSlash ? " />" : ">");

        // Build the String, using the StringBuilder, and return the newly-constructed HTML Element
        return sb.toString();
    }

    static String toStringAV(final TagNode tn)
    {
        StringBuilder sb = new StringBuilder();

        // Basic information.  This info is common to ALL instances of TagNode
        sb.append(
            "TagNode.str: [" + tn.str + "], TagNode.tok: [" + tn.tok + "], " +
            "TagNode.isClosing: [" + tn.isClosing + "]\n"
        );

        // Not all instances of TagNode will have attributes.
        Properties attributes = RetrieveAllAttr.allAV(tn, false, true);

        sb.append(
            "CONTAINS a total of (" + attributes.size() + ") attributes / inner-tag " +
            "key-value pairs" + (attributes.size() == 0 ? "." : ":") + "\n"
        );


        // If there are inner-tags / attributes, then add them to the output-string, each on a
        // separate line.

        for (String key : attributes.stringPropertyNames())
            sb.append("(KEY, VALUE):\t[" + key + "], [" + attributes.get(key) + "]\n");

        // Build the string from the StringBuilder, and return it.
        return sb.toString();    
    }
}