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

import Torello.Java.Additional.Ret2;
import Torello.Java.StrIndent;

import java.util.Vector;

/**
 * Generates the HTML for the elements of the {@code "commands"} array, which is a sub-property 
 * of a {@code "domain"} object.
 */
@Torello.JavaDoc.Annotations.StaticFunctional
@Torello.JavaDoc.Annotations.JDHeaderBackgroundImg(EmbedTagFileID="TOHTML_JDHBI")
public class HTML$CommandNode
{
    private HTML$CommandNode() { }

    static String run(final CommandNode command)
    {
        // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
        // FLAGS HTML, Possible 'Redirect' Note
        // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***

        final Ret2<String, String> r2 =
            HTML$TCE.flagsAndRedirectNote(command, command.redirect);

        final String flagsStr = r2.a;
        final String rNote    = r2.b;


        // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
        // HTML Inner-Tables: 'Parameters', 'Returns' (Not 'properties')
        // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***

        final StringBuilder sb = new StringBuilder();

        if (command.parameters != null)
            HTML$TCE.appendPPRs(sb, command.parameters, "PARAMETERS");

        if (command.returns != null)
            HTML$TCE.appendPPRs(sb, command.returns, "RETURNS");

        final String innerTablesRow;

        if (sb.length() == 0) innerTablesRow = "";

        else innerTablesRow =
            "<TR><TD COLSPAN=3>\n" + 
            StrIndent.indent(sb.toString(), 4) +
            "</TD></TR>\n";


        // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
        // Return the HTML
        // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***

        final String descStr = command.description.replace("<", "&lt;").replace(">", "&gt;");

        return 
            "<TR>\n" +
            "    <TD CLASS=MAINNAME>" +
                "<SPAN CLASS=MAINNAME>" + command.name + "</SPAN>" +
                rNote + "</TD>\n" +
            "    <TD>" + descStr + "</TD>\n" +
            "    <TD>" + flagsStr + "</TD>\n" +
            "</TR>\n" +
            innerTablesRow;
    }
}