1.1 --- a/src/share/classes/com/sun/tools/doclets/formats/html/TagletWriterImpl.java Tue May 14 10:14:54 2013 -0700 1.2 +++ b/src/share/classes/com/sun/tools/doclets/formats/html/TagletWriterImpl.java Tue May 14 10:14:54 2013 -0700 1.3 @@ -26,9 +26,12 @@ 1.4 package com.sun.tools.doclets.formats.html; 1.5 1.6 import com.sun.javadoc.*; 1.7 +import com.sun.tools.doclets.formats.html.markup.ContentBuilder; 1.8 import com.sun.tools.doclets.formats.html.markup.HtmlAttr; 1.9 +import com.sun.tools.doclets.formats.html.markup.HtmlStyle; 1.10 import com.sun.tools.doclets.formats.html.markup.HtmlTag; 1.11 import com.sun.tools.doclets.formats.html.markup.HtmlTree; 1.12 +import com.sun.tools.doclets.formats.html.markup.RawHtml; 1.13 import com.sun.tools.doclets.formats.html.markup.StringContent; 1.14 import com.sun.tools.doclets.internal.toolkit.*; 1.15 import com.sun.tools.doclets.internal.toolkit.builders.SerializedFormBuilder; 1.16 @@ -63,7 +66,7 @@ 1.17 * {@inheritDoc} 1.18 */ 1.19 public TagletOutput getOutputInstance() { 1.20 - return new TagletOutputImpl(""); 1.21 + return new TagletOutputImpl(); 1.22 } 1.23 1.24 /** 1.25 @@ -71,7 +74,7 @@ 1.26 */ 1.27 protected TagletOutput codeTagOutput(Tag tag) { 1.28 Content result = HtmlTree.CODE(new StringContent(tag.text())); 1.29 - return new TagletOutputImpl(result.toString()); 1.30 + return new TagletOutputImpl(result); 1.31 } 1.32 1.33 /** 1.34 @@ -90,18 +93,17 @@ 1.35 * {@inheritDoc} 1.36 */ 1.37 public TagletOutput deprecatedTagOutput(Doc doc) { 1.38 - StringBuilder output = new StringBuilder(); 1.39 + ContentBuilder result = new ContentBuilder(); 1.40 Tag[] deprs = doc.tags("deprecated"); 1.41 if (doc instanceof ClassDoc) { 1.42 if (Util.isDeprecated((ProgramElementDoc) doc)) { 1.43 - output.append("<span class=\"strong\">" + 1.44 - configuration. 1.45 - getText("doclet.Deprecated") + "</span> "); 1.46 + result.addContent(HtmlTree.SPAN(HtmlStyle.strong, 1.47 + new StringContent(configuration.getText("doclet.Deprecated")))); 1.48 + result.addContent(RawHtml.nbsp); 1.49 if (deprs.length > 0) { 1.50 Tag[] commentTags = deprs[0].inlineTags(); 1.51 if (commentTags.length > 0) { 1.52 - 1.53 - output.append(commentTagsToOutput(null, doc, 1.54 + result.addContent(commentTagsToOutput(null, doc, 1.55 deprs[0].inlineTags(), false).toString() 1.56 ); 1.57 } 1.58 @@ -110,24 +112,23 @@ 1.59 } else { 1.60 MemberDoc member = (MemberDoc) doc; 1.61 if (Util.isDeprecated((ProgramElementDoc) doc)) { 1.62 - output.append("<span class=\"strong\">" + 1.63 - configuration. 1.64 - getText("doclet.Deprecated") + "</span> "); 1.65 + result.addContent(HtmlTree.SPAN(HtmlStyle.strong, 1.66 + new StringContent(configuration.getText("doclet.Deprecated")))); 1.67 + result.addContent(RawHtml.nbsp); 1.68 if (deprs.length > 0) { 1.69 - output.append("<i>"); 1.70 - output.append(commentTagsToOutput(null, doc, 1.71 - deprs[0].inlineTags(), false).toString()); 1.72 - output.append("</i>"); 1.73 + TagletOutput body = commentTagsToOutput(null, doc, 1.74 + deprs[0].inlineTags(), false); 1.75 + result.addContent(HtmlTree.I(new RawHtml(body.toString()))); 1.76 } 1.77 } else { 1.78 if (Util.isDeprecated(member.containingClass())) { 1.79 - output.append("<span class=\"strong\">" + 1.80 - configuration. 1.81 - getText("doclet.Deprecated") + "</span> "); 1.82 + result.addContent(HtmlTree.SPAN(HtmlStyle.strong, 1.83 + new StringContent(configuration.getText("doclet.Deprecated")))); 1.84 + result.addContent(RawHtml.nbsp); 1.85 } 1.86 } 1.87 } 1.88 - return new TagletOutputImpl(output.toString()); 1.89 + return new TagletOutputImpl(result); 1.90 } 1.91 1.92 /** 1.93 @@ -136,7 +137,7 @@ 1.94 protected TagletOutput expertTagOutput(Tag tag) { 1.95 HtmlTree result = new HtmlTree(HtmlTag.SUB, new StringContent(tag.text())); 1.96 result.addAttr(HtmlAttr.ID, "expert"); 1.97 - return new TagletOutputImpl(result.toString()); 1.98 + return new TagletOutputImpl(result); 1.99 } 1.100 1.101 /** 1.102 @@ -144,7 +145,7 @@ 1.103 */ 1.104 protected TagletOutput literalTagOutput(Tag tag) { 1.105 Content result = new StringContent(tag.text()); 1.106 - return new TagletOutputImpl(result.toString()); 1.107 + return new TagletOutputImpl(result); 1.108 } 1.109 1.110 /** 1.111 @@ -158,95 +159,102 @@ 1.112 * {@inheritDoc} 1.113 */ 1.114 public TagletOutput getParamHeader(String header) { 1.115 - StringBuilder result = new StringBuilder(); 1.116 - result.append("<dt>"); 1.117 - result.append("<span class=\"strong\">").append(header).append("</span></dt>"); 1.118 - return new TagletOutputImpl(result.toString()); 1.119 + HtmlTree result = HtmlTree.DT(HtmlTree.SPAN(HtmlStyle.strong, 1.120 + new StringContent(header))); 1.121 + return new TagletOutputImpl(result); 1.122 } 1.123 1.124 /** 1.125 * {@inheritDoc} 1.126 */ 1.127 public TagletOutput paramTagOutput(ParamTag paramTag, String paramName) { 1.128 - TagletOutput result = new TagletOutputImpl("<dd><code>" + paramName + "</code>" 1.129 - + " - " + htmlWriter.commentTagsToString(paramTag, null, paramTag.inlineTags(), false) + "</dd>"); 1.130 - return result; 1.131 + ContentBuilder body = new ContentBuilder(); 1.132 + body.addContent(HtmlTree.CODE(new RawHtml(paramName))); 1.133 + body.addContent(" - "); 1.134 + body.addContent(new RawHtml(htmlWriter.commentTagsToString(paramTag, null, paramTag.inlineTags(), false))); 1.135 + HtmlTree result = HtmlTree.DD(body); 1.136 + return new TagletOutputImpl(result); 1.137 } 1.138 1.139 /** 1.140 * {@inheritDoc} 1.141 */ 1.142 public TagletOutput returnTagOutput(Tag returnTag) { 1.143 - TagletOutput result = new TagletOutputImpl(DocletConstants.NL + "<dt>" + 1.144 - "<span class=\"strong\">" + configuration.getText("doclet.Returns") + 1.145 - "</span>" + "</dt>" + "<dd>" + 1.146 - htmlWriter.commentTagsToString(returnTag, null, returnTag.inlineTags(), 1.147 - false) + "</dd>"); 1.148 - return result; 1.149 + ContentBuilder result = new ContentBuilder(); 1.150 + result.addContent(HtmlTree.DT(HtmlTree.SPAN(HtmlStyle.strong, 1.151 + new StringContent(configuration.getText("doclet.Returns"))))); 1.152 + result.addContent(HtmlTree.DD(new RawHtml(htmlWriter.commentTagsToString( 1.153 + returnTag, null, returnTag.inlineTags(), false)))); 1.154 + return new TagletOutputImpl(result); 1.155 } 1.156 1.157 /** 1.158 * {@inheritDoc} 1.159 */ 1.160 public TagletOutput seeTagOutput(Doc holder, SeeTag[] seeTags) { 1.161 - String result = ""; 1.162 + ContentBuilder body = new ContentBuilder(); 1.163 if (seeTags.length > 0) { 1.164 - result = addSeeHeader(result); 1.165 for (int i = 0; i < seeTags.length; ++i) { 1.166 - if (i > 0) { 1.167 - result += ", " + DocletConstants.NL; 1.168 - } 1.169 - result += htmlWriter.seeTagToString(seeTags[i]); 1.170 + appendSeparatorIfNotEmpty(body); 1.171 + body.addContent(new RawHtml(htmlWriter.seeTagToString(seeTags[i]))); 1.172 } 1.173 } 1.174 if (holder.isField() && ((FieldDoc)holder).constantValue() != null && 1.175 htmlWriter instanceof ClassWriterImpl) { 1.176 //Automatically add link to constant values page for constant fields. 1.177 - result = addSeeHeader(result); 1.178 + appendSeparatorIfNotEmpty(body); 1.179 DocPath constantsPath = 1.180 htmlWriter.pathToRoot.resolve(DocPaths.CONSTANT_VALUES); 1.181 String whichConstant = 1.182 ((ClassWriterImpl) htmlWriter).getClassDoc().qualifiedName() + "." + ((FieldDoc) holder).name(); 1.183 DocLink link = constantsPath.fragment(whichConstant); 1.184 - result += htmlWriter.getHyperLinkString(link, 1.185 - configuration.getText("doclet.Constants_Summary")); 1.186 + body.addContent(htmlWriter.getHyperLink(link, 1.187 + new StringContent(configuration.getText("doclet.Constants_Summary")))); 1.188 } 1.189 if (holder.isClass() && ((ClassDoc)holder).isSerializable()) { 1.190 //Automatically add link to serialized form page for serializable classes. 1.191 if ((SerializedFormBuilder.serialInclude(holder) && 1.192 SerializedFormBuilder.serialInclude(((ClassDoc)holder).containingPackage()))) { 1.193 - result = addSeeHeader(result); 1.194 + appendSeparatorIfNotEmpty(body); 1.195 DocPath serialPath = htmlWriter.pathToRoot.resolve(DocPaths.SERIALIZED_FORM); 1.196 DocLink link = serialPath.fragment(((ClassDoc)holder).qualifiedName()); 1.197 - result += htmlWriter.getHyperLinkString(link, 1.198 - configuration.getText("doclet.Serialized_Form")); 1.199 + body.addContent(htmlWriter.getHyperLink(link, 1.200 + new StringContent(configuration.getText("doclet.Serialized_Form")))); 1.201 } 1.202 } 1.203 - return result.equals("") ? null : new TagletOutputImpl(result + "</dd>"); 1.204 + if (body.isEmpty()) 1.205 + return new TagletOutputImpl(body); 1.206 + 1.207 + ContentBuilder result = new ContentBuilder(); 1.208 + result.addContent(HtmlTree.DT(HtmlTree.SPAN(HtmlStyle.strong, 1.209 + new StringContent(configuration.getText("doclet.See_Also"))))); 1.210 + result.addContent(HtmlTree.DD(body)); 1.211 + return new TagletOutputImpl(result); 1.212 + 1.213 } 1.214 1.215 - private String addSeeHeader(String result) { 1.216 - if (result != null && result.length() > 0) { 1.217 - return result + ", " + DocletConstants.NL; 1.218 - } else { 1.219 - return "<dt><span class=\"strong\">" + 1.220 - configuration.getText("doclet.See_Also") + "</span></dt><dd>"; 1.221 + private void appendSeparatorIfNotEmpty(ContentBuilder body) { 1.222 + if (!body.isEmpty()) { 1.223 + body.addContent(", "); 1.224 + body.addContent(DocletConstants.NL); 1.225 } 1.226 - } 1.227 + } 1.228 1.229 /** 1.230 * {@inheritDoc} 1.231 */ 1.232 public TagletOutput simpleTagOutput(Tag[] simpleTags, String header) { 1.233 - String result = "<dt><span class=\"strong\">" + header + "</span></dt>" + DocletConstants.NL + 1.234 - " <dd>"; 1.235 + ContentBuilder result = new ContentBuilder(); 1.236 + result.addContent(HtmlTree.DT(HtmlTree.SPAN(HtmlStyle.strong, new RawHtml(header)))); 1.237 + ContentBuilder body = new ContentBuilder(); 1.238 for (int i = 0; i < simpleTags.length; i++) { 1.239 if (i > 0) { 1.240 - result += ", "; 1.241 + body.addContent(", "); 1.242 } 1.243 - result += htmlWriter.commentTagsToString(simpleTags[i], null, simpleTags[i].inlineTags(), false); 1.244 + body.addContent(new RawHtml(htmlWriter.commentTagsToString( 1.245 + simpleTags[i], null, simpleTags[i].inlineTags(), false))); 1.246 } 1.247 - result += "</dd>" + DocletConstants.NL; 1.248 + result.addContent(HtmlTree.DD(body)); 1.249 return new TagletOutputImpl(result); 1.250 } 1.251 1.252 @@ -254,46 +262,50 @@ 1.253 * {@inheritDoc} 1.254 */ 1.255 public TagletOutput simpleTagOutput(Tag simpleTag, String header) { 1.256 - return new TagletOutputImpl("<dt><span class=\"strong\">" + header + "</span></dt>" + " <dd>" 1.257 - + htmlWriter.commentTagsToString(simpleTag, null, simpleTag.inlineTags(), false) 1.258 - + "</dd>" + DocletConstants.NL); 1.259 + ContentBuilder result = new ContentBuilder(); 1.260 + result.addContent(HtmlTree.DT(HtmlTree.SPAN(HtmlStyle.strong, new RawHtml(header)))); 1.261 + Content body = new RawHtml(htmlWriter.commentTagsToString( 1.262 + simpleTag, null, simpleTag.inlineTags(), false)); 1.263 + result.addContent(HtmlTree.DD(body)); 1.264 + return new TagletOutputImpl(result); 1.265 } 1.266 1.267 /** 1.268 * {@inheritDoc} 1.269 */ 1.270 public TagletOutput getThrowsHeader() { 1.271 - return new TagletOutputImpl(DocletConstants.NL + "<dt>" + "<span class=\"strong\">" + 1.272 - configuration.getText("doclet.Throws") + "</span></dt>"); 1.273 + HtmlTree result = HtmlTree.DT(HtmlTree.SPAN(HtmlStyle.strong, 1.274 + new StringContent(configuration.getText("doclet.Throws")))); 1.275 + return new TagletOutputImpl(result); 1.276 } 1.277 1.278 /** 1.279 * {@inheritDoc} 1.280 */ 1.281 public TagletOutput throwsTagOutput(ThrowsTag throwsTag) { 1.282 - String result = DocletConstants.NL + "<dd>"; 1.283 - result += throwsTag.exceptionType() == null ? 1.284 - htmlWriter.codeText(throwsTag.exceptionName()) : 1.285 - htmlWriter.codeText( 1.286 + ContentBuilder body = new ContentBuilder(); 1.287 + Content excName = (throwsTag.exceptionType() == null) ? 1.288 + new RawHtml(throwsTag.exceptionName()) : 1.289 htmlWriter.getLink(new LinkInfoImpl(configuration, LinkInfoImpl.Kind.MEMBER, 1.290 - throwsTag.exceptionType())).toString()); 1.291 - TagletOutput text = new TagletOutputImpl( 1.292 - htmlWriter.commentTagsToString(throwsTag, null, 1.293 - throwsTag.inlineTags(), false)); 1.294 - if (text != null && text.toString().length() > 0) { 1.295 - result += " - " + text; 1.296 + throwsTag.exceptionType())); 1.297 + body.addContent(HtmlTree.CODE(excName)); 1.298 + String desc = htmlWriter.commentTagsToString(throwsTag, null, 1.299 + throwsTag.inlineTags(), false); 1.300 + if (desc != null && !desc.isEmpty()) { 1.301 + body.addContent(" - "); 1.302 + body.addContent(new RawHtml(desc)); 1.303 } 1.304 - result += "</dd>"; 1.305 - return new TagletOutputImpl(result); 1.306 + HtmlTree res2 = HtmlTree.DD(body); 1.307 + return new TagletOutputImpl(res2); 1.308 } 1.309 1.310 /** 1.311 * {@inheritDoc} 1.312 */ 1.313 public TagletOutput throwsTagOutput(Type throwsType) { 1.314 - return new TagletOutputImpl(DocletConstants.NL + "<dd>" + 1.315 - htmlWriter.codeText(htmlWriter.getLink( 1.316 - new LinkInfoImpl(configuration, LinkInfoImpl.Kind.MEMBER, throwsType)).toString()) + "</dd>"); 1.317 + HtmlTree result = HtmlTree.DD(HtmlTree.CODE(htmlWriter.getLink( 1.318 + new LinkInfoImpl(configuration, LinkInfoImpl.Kind.MEMBER, throwsType)))); 1.319 + return new TagletOutputImpl(result); 1.320 } 1.321 1.322 /** 1.323 @@ -303,7 +315,7 @@ 1.324 boolean includeLink) { 1.325 return new TagletOutputImpl(includeLink ? 1.326 htmlWriter.getDocLink(LinkInfoImpl.Kind.VALUE_TAG, field, 1.327 - constantVal, false).toString() : constantVal); 1.328 + constantVal, false) : new RawHtml(constantVal)); 1.329 } 1.330 1.331 /** 1.332 @@ -325,8 +337,8 @@ 1.333 */ 1.334 public TagletOutput commentTagsToOutput(Tag holderTag, 1.335 Doc holderDoc, Tag[] tags, boolean isFirstSentence) { 1.336 - return new TagletOutputImpl(htmlWriter.commentTagsToString( 1.337 - holderTag, holderDoc, tags, isFirstSentence)); 1.338 + return new TagletOutputImpl(new RawHtml(htmlWriter.commentTagsToString( 1.339 + holderTag, holderDoc, tags, isFirstSentence))); 1.340 } 1.341 1.342 /** 1.343 @@ -335,13 +347,4 @@ 1.344 public Configuration configuration() { 1.345 return configuration; 1.346 } 1.347 - 1.348 - /** 1.349 - * Return an instance of a TagletWriter that knows how to write HTML. 1.350 - * 1.351 - * @return an instance of a TagletWriter that knows how to write HTML. 1.352 - */ 1.353 - public TagletOutput getTagletOutputInstance() { 1.354 - return new TagletOutputImpl(""); 1.355 - } 1.356 }