001package Torello.Browser.JsonAST; 002 003import java.util.Vector; 004 005import Torello.Java.StrIndent; 006import Torello.Java.StrCSV; 007import Torello.Java.UnreachableError; 008 009import Torello.Java.ReadOnly.ReadOnlyList; 010 011/** 012 * Generates the HTML for the elements of the {@code "domains"} array. In the JSON spec files, the 013 * {@code "domains"} array is the top level array of objects for the whole file. 014 */ 015@Torello.JavaDoc.Annotations.StaticFunctional 016@Torello.JavaDoc.Annotations.JDHeaderBackgroundImg(EmbedTagFileID="TOHTML_JDHBI") 017public class HTML$Domain 018{ 019 private HTML$Domain() { } 020 021 022 // ******************************************************************************************** 023 // ******************************************************************************************** 024 // Static Constants 025 // ******************************************************************************************** 026 // ******************************************************************************************** 027 028 029 private static final String typeTableHeader = 030 "<TR><TH>Type ID</TH><TH>Type</TH><TH>Description</TH><TH>Flags</TH></TR>\n"; 031 032 private static final String commandTableHeader = 033 "<TR><TH>Name</TH><TH>Description</TH><TH>Flags</TH></TR>\n"; 034 035 private static final String eventTableHeader = 036 "<TR><TH>Name</TH><TH>Description</TH><TH>Flags</TH></TR>\n"; 037 038 039 // ******************************************************************************************** 040 // ******************************************************************************************** 041 // Main 042 // ******************************************************************************************** 043 // ******************************************************************************************** 044 045 046 static String run(final Domain domain) 047 { 048 final StringBuilder sb = new StringBuilder(); 049 050 051 // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** 052 // Two Flags & the Pointless / Unused "Dependencies" crapola 053 // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** 054 055 final String depStr; 056 057 if (domain.depAsStrs.size() > 0) depStr = 058 "Dependencies: <CODE>" + StrCSV.toCSV 059 (domain.depAsStrs, true, true, null)+ "</CODE><BR /><BR />\n"; 060 061 else depStr = ""; 062 063 064 // This is the one that has a <p>...</p> 065 // String descStr = this.description.replace("<", "<").replace(">", ">); 066 067 sb.append( 068 "<H1>" + domain.name + "</H1>\n" + 069 (domain.experimental ? "<CODE>[Experimental]</CODE><BR /><BR />\n" : "") + 070 ((domain.description != null) ? (domain.description + "\n<BR /><BR />\n") : "") + 071 depStr 072 ); 073 074 075 // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** 076 // Add the Buttons 077 // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** 078 079 if (domain.types.size() > 0) sb.append 080 ("<BUTTON onclick=\"showSubDIV('" + domain.name + " TYPES');\">Types</BUTTON>\n"); 081 082 if (domain.commands.size() > 0) sb.append 083 ("<BUTTON onclick=\"showSubDIV('" + domain.name + " COMMANDS');\">Commands</BUTTON>\n"); 084 085 if (domain.events.size() > 0) sb.append 086 ("<BUTTON onclick=\"showSubDIV('" + domain.name + " EVENTS');\">Events</BUTTON>\n"); 087 088 089 // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** 090 // The HTML lists, themselves 091 // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** 092 093 if ((domain.types != null) && (domain.types.size() > 0)) 094 appendAll(domain.name, WhichTCE.Type, typeTableHeader, domain.types, sb); 095 096 if ((domain.commands != null) && (domain.commands.size() > 0)) 097 appendAll(domain.name, WhichTCE.Command, commandTableHeader, domain.commands, sb); 098 099 if ((domain.events != null) && (domain.events.size() > 0)) 100 appendAll(domain.name, WhichTCE.Event, eventTableHeader, domain.events, sb); 101 102 103 // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** 104 // BUILD IT, INDENT IT, RETURN IT 105 // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** 106 107 return 108 "<DIV ID=" + domain.name + " CLASS=MAIN STYLE='display: none'>\n" + 109 StrIndent.indent(sb.toString(), 4) + 110 "</DIV>\n\n"; 111 } 112 113 114 // ******************************************************************************************** 115 // ******************************************************************************************** 116 // Append the TCE's 117 // ******************************************************************************************** 118 // ******************************************************************************************** 119 120 121 @SuppressWarnings("unchecked") // to 'javac' the switch statement "doesn't count" 122 private static void appendAll( 123 final String domainName, 124 final WhichTCE sectionKind, 125 final String tableHeader, 126 final ReadOnlyList<? extends TCE> tceList, 127 final StringBuilder sb 128 ) 129 { 130 final String secName = sectionKind.toString().toUpperCase() + "S"; 131 final StringBuilder sbInner = new StringBuilder(); 132 133 sbInner.append( 134 "<H2>" + secName + "</H2>\n" + 135 "<TABLE CLASS='OUTER " + secName + "'>\n" + 136 tableHeader 137 ); 138 139 switch (sectionKind) 140 { 141 case Type: 142 for (final TypeNode tableRow : (ReadOnlyList<TypeNode>) tceList) 143 sbInner.append(HTML$TypeNode.run(tableRow)); 144 145 break; 146 147 case Command: 148 for (final CommandNode tableRow : (ReadOnlyList<CommandNode>) tceList) 149 sbInner.append(HTML$CommandNode.run(tableRow)); 150 151 break; 152 153 case Event: 154 for (final EventNode tableRow : (ReadOnlyList<EventNode>) tceList) 155 sbInner.append(HTML$EventNode.run(tableRow)); 156 157 break; 158 159 default: throw new UnreachableError(); 160 } 161 162 163 sbInner.append("</TABLE>\n<BR /><BR />\n\n"); 164 165 sb.append( 166 "<DIV CLASS='INNER " + domainName + " " + secName + 167 "' STYLE='display: none'>\n" + 168 StrIndent.indent(sbInner.toString(), 4) + 169 "</DIV>\n\n" 170 ); 171 } 172}