001package Torello.JavaDoc.Annotations; 002 003import Torello.HTML.TagNode; 004import Torello.HTML.TextNode; 005import Torello.HTML.HTMLNode; 006 007import Torello.Java.StrCSV; 008 009import Torello.Java.ReadOnly.ReadOnlyList; 010import Torello.Java.ReadOnly.ReadOnlyArrayList; 011import Torello.Java.ReadOnly.ROArrayListBuilder; 012 013import Torello.JavaDoc.Messager.Messager; 014import Torello.JavaDoc.Messager.MsgVerbose; 015 016import Torello.JDUInternal.Miscellaneous.Where.JDUAnnotations; 017 018import com.sun.source.tree.ExpressionTree; 019import com.sun.source.tree.AssignmentTree; 020 021import java.util.List; 022 023import static com.sun.source.tree.Tree.Kind.ASSIGNMENT; 024 025 026// EXPORTS: 027// String[] CSSClass() default { }; 028// String[] EmbedTagFileID() default { }; 029// 030// package Torello.JDUInternal.Features.EXTERNAL_HTML_FILES 031// The classes in this package do the processing for inserting the HTML from External-HTML 032// Files into Java-Doc '.html' Output-Files. It places an HTML <IMG SRC=...> at the top of 033// the page. The Imge contains a Wooden-Panel, and the User's JDHBI HTML for that class is 034// then placed on top of / over the Wood-Paneling 035 036 037/** 038 * An internally used data-record class used for storing all user-supplied annotation data 039 * associated with a single use / application of the {@link JDHeaderBackgroundImg} annotation. 040 * 041 * @see Torello.JavaDoc.Annotations.JDHeaderBackgroundImg 042 */ 043@Torello.JavaDoc.Annotations.JDHeaderBackgroundImg(EmbedTagFileID="MIRROR_JDHBI") 044public class JDHBIMirror implements AnnotationMirror 045{ 046 // ******************************************************************************************** 047 // ******************************************************************************************** 048 // Static Constants 049 // ******************************************************************************************** 050 // ******************************************************************************************** 051 052 053 private static final String JDHBI_ATTR_NAME = 054 Torello.JDUInternal.Features.EXTERNAL_HTML_FILES.ReplaceTags.EXPORT.JDHBI_ATTR_NAME(); 055 056 private static final String JDHBI_ATTR_VALUE = 057 Torello.JDUInternal.Features.EXTERNAL_HTML_FILES.ReplaceTags.EXPORT.JDHBI_ATTR_VALUE(); 058 059 // Used simply to insert a new-line character into an HTML-Vector 060 private static final TextNode NEW_LINE = new TextNode("\n"); 061 062 063 // ******************************************************************************************** 064 // ******************************************************************************************** 065 // Public, Final, ReadOnly, Mirrored Fields 066 // ******************************************************************************************** 067 // ******************************************************************************************** 068 069 070 /** Holds data extracted from {@link JDHeaderBackgroundImg#EmbedTagFileID()} */ 071 public final ReadOnlyList<HTMLNode> externalEmbedTags; 072 073 /** Holds data extracted from {@link JDHeaderBackgroundImg#CSSClass()} */ 074 public final TagNode tnDIV; 075 076 077 // ******************************************************************************************** 078 // ******************************************************************************************** 079 // interface AnnotationMirror 080 // ******************************************************************************************** 081 // ******************************************************************************************** 082 083 084 // Stores the actual text of the @StaticFunctional annotation which was placed. 085 // This is nothing more than the exact line that was originally inserted into the class. 086 // The only reason this is even needed (in case you are wondering) is because the error 087 // checking & error printing code outputs this text when printing an error message. 088 089 private final String annotationAsStr; 090 091 /** {@inheritDoc} */ @Override 092 public String getAnnotationAsString() { return annotationAsStr; } 093 094 /** {@inheritDoc} */ @Override 095 public String getAnnotationName() { return "JDHeaderBackgroundImg"; } 096 097 098 // ******************************************************************************************** 099 // ******************************************************************************************** 100 // Package-Private Constructor, Invoked by class "TypeAnnotationMirrors" 101 // ******************************************************************************************** 102 // ******************************************************************************************** 103 104 105 JDHBIMirror( 106 final List<? extends ExpressionTree> arguments, 107 final String annotationAsStr 108 ) 109 { 110 this.annotationAsStr = annotationAsStr; 111 112 ReadOnlyList<String> cssClasses = null; 113 ReadOnlyList<String> embedTagFileIDs = null; 114 ReadOnlyList<HTMLNode> externalEmbedTags = null; 115 TagNode tnDIV = null; 116 117 for (ExpressionTree argument : arguments) 118 { 119 /* 120 System.out.println( 121 "argument: " + argument.toString() + '\n' + 122 "argument.getKind(): " + argument.getKind().toString() + '\n' + 123 "argument.getClass().getSimpleName(): " + argument.getClass().getSimpleName() 124 ); 125 */ 126 127 // System.out.println(argument); 128 129 if (argument.getKind() != ASSIGNMENT) Messager.assertFail( 130 "The ExpressionTree returned by the @JDHeaderBackgroundImg arguments list was " + 131 "not of type ASSIGNMENT, but rather " + argument.getKind() + '\n' + 132 "ExpressionTree.toString(): " + argument.toString() + '\n' + 133 "All Annotation Expressions: " + StrCSV.toCSV(arguments, true, true, null), 134 null, 135 JDUAnnotations.JDHBIMirror 136 ); 137 138 String elemName = ((AssignmentTree) argument).getVariable().toString(); 139 ExpressionTree elemValue = ((AssignmentTree) argument).getExpression(); 140 141 /* 142 System.out.println( 143 " elemName: " + elemName + '\n' + 144 " elemValue.toString(): " + elemValue.toString() + '\n' + 145 " elemValue.getKind(): " + elemValue.getKind().toString() + '\n' + 146 " elemValue.getClass(): " + elemValue.getClass().getSimpleName() + '\n' 147 ); 148 */ 149 150 if (elemName.equals("CSSClass")) cssClasses = 151 HELPER.handleStringArray(elemValue, "CSSClass", JDUAnnotations.CSSLMirror); 152 153 else if (elemName.equals("EmbedTagFileID")) embedTagFileIDs = 154 HELPER.handleStringArray(elemValue, "EmbedTagFileID", JDUAnnotations.CSSLMirror); 155 156 else Messager.assertFail( 157 "There was an Expression Variable-Name that was neither 'CSSClass' nor " + 158 "'EmbedTagFileID', but rather: " + elemName, 159 null, 160 JDUAnnotations.JDHBIMirror 161 ); 162 } 163 164 if (embedTagFileIDs == null) 165 externalEmbedTags = ReadOnlyArrayList.emptyROAL(); 166 167 else 168 { 169 int i = 0; 170 171 ROArrayListBuilder<HTMLNode> roalb = new ROArrayListBuilder<>(); 172 173 for (String embedTagFileID : embedTagFileIDs) 174 { 175 roalb.add( 176 new TagNode( 177 "<EMBED DATA-" + JDHBI_ATTR_NAME + '=' + JDHBI_ATTR_VALUE + 178 " CLASS='external-html' DATA-FILE-ID=" + 179 embedTagFileIDs.get(i++) +">" 180 )); 181 182 roalb.add(NEW_LINE); 183 } 184 185 externalEmbedTags = roalb.build(); 186 } 187 188 189 // These are used in class "EmbedTag" which does all of the HTML work for 190 // "JDHeaderBackgroundImg" 191 192 if (cssClasses == null) 193 tnDIV = null; 194 195 else if (cssClasses.size() == 1) 196 tnDIV = new TagNode("<DIV CLASS=" + cssClasses.get(0) + ">"); 197 198 else 199 { 200 // When the user uses the annotation as below: 201 // @JDHeaderBackgroundImg(CSSClass={"MyCSSClassA", "MyCSSClassB", "MyCSSClassC", ...}) 202 203 final StringBuilder sb = new StringBuilder(); 204 205 for (String cssClass : cssClasses) sb.append(cssClass + " "); 206 207 tnDIV = new TagNode 208 ("<DIV CLASS='" + sb.subSequence(0, sb.length() - 1) + "'>"); 209 } 210 211 if (MsgVerbose.isVerbose()) MsgVerbose.println( 212 "@JDHeaderBackgroundImg Annotation-Processing Mirror Class:" + 213 " cssClasses: " + StrCSV.toCSV(cssClasses, true, false, null) + '\n' + 214 " embedTagFileIDs: " + StrCSV.toCSV(embedTagFileIDs, true, false, null) 215 ); 216 217 this.externalEmbedTags = externalEmbedTags; 218 this.tnDIV = tnDIV; 219 } 220 221 // ******************************************************************************************** 222 // ******************************************************************************************** 223 // toString 224 // ******************************************************************************************** 225 // ******************************************************************************************** 226 227 228 /** {@inheritDoc} */ @Override 229 public String toString() 230 { 231 // public final ReadOnlyList<HTMLNode> externalEmbedTags; 232 // public final TagNode tnDIV; 233 // 234 // " externalEmbedTags: ".length() ==> 23 235 236 return 237 annotationAsStr + '\n' + 238 "{\n" + 239 " externalEmbedTags: " + HELPER.TOSTR(this.externalEmbedTags, 23) + '\n' + 240 " tnDIV: " + HELPER.TOSTR(this.tnDIV.str, 23) + '\n' + 241 "}"; 242 243 } 244}