001package Torello.Browser.JsonAST;
002
003import Torello.Java.Additional.Ret2;
004import Torello.Java.StrIndent;
005
006import java.util.Vector;
007
008/**
009 * Generates the HTML for the elements of the {@code "commands"} array, which is a sub-property 
010 * of a {@code "domain"} object.
011 */
012@Torello.JavaDoc.Annotations.StaticFunctional
013@Torello.JavaDoc.Annotations.JDHeaderBackgroundImg(EmbedTagFileID="TOHTML_JDHBI")
014public class HTML$CommandNode
015{
016    private HTML$CommandNode() { }
017
018    static String run(final CommandNode command)
019    {
020        // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
021        // FLAGS HTML, Possible 'Redirect' Note
022        // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
023
024        final Ret2<String, String> r2 =
025            HTML$TCE.flagsAndRedirectNote(command, command.redirect);
026
027        final String flagsStr = r2.a;
028        final String rNote    = r2.b;
029
030
031        // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
032        // HTML Inner-Tables: 'Parameters', 'Returns' (Not 'properties')
033        // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
034
035        final StringBuilder sb = new StringBuilder();
036
037        if (command.parameters != null)
038            HTML$TCE.appendPPRs(sb, command.parameters, "PARAMETERS");
039
040        if (command.returns != null)
041            HTML$TCE.appendPPRs(sb, command.returns, "RETURNS");
042
043        final String innerTablesRow;
044
045        if (sb.length() == 0) innerTablesRow = "";
046
047        else innerTablesRow =
048            "<TR><TD COLSPAN=3>\n" + 
049            StrIndent.indent(sb.toString(), 4) +
050            "</TD></TR>\n";
051
052
053        // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
054        // Return the HTML
055        // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
056
057        final String descStr = command.description.replace("<", "&lt;").replace(">", "&gt;");
058
059        return 
060            "<TR>\n" +
061            "    <TD CLASS=MAINNAME>" +
062                "<SPAN CLASS=MAINNAME>" + command.name + "</SPAN>" +
063                rNote + "</TD>\n" +
064            "    <TD>" + descStr + "</TD>\n" +
065            "    <TD>" + flagsStr + "</TD>\n" +
066            "</TR>\n" +
067            innerTablesRow;
068    }
069}