src/share/classes/com/sun/tools/doclets/formats/html/TagletWriterImpl.java

Fri, 18 Oct 2013 16:34:42 -0700

author
bpatel
date
Fri, 18 Oct 2013 16:34:42 -0700
changeset 2147
130b8c0e570e
parent 2116
bf6b11347b1a
child 2212
4cb9de4dd420
permissions
-rw-r--r--

8026567: Use meaningful style names for strong and italic styles.
Reviewed-by: jjg

duke@1 1 /*
jjg@1735 2 * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
duke@1 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@1 4 *
duke@1 5 * This code is free software; you can redistribute it and/or modify it
duke@1 6 * under the terms of the GNU General Public License version 2 only, as
ohair@554 7 * published by the Free Software Foundation. Oracle designates this
duke@1 8 * particular file as subject to the "Classpath" exception as provided
ohair@554 9 * by Oracle in the LICENSE file that accompanied this code.
duke@1 10 *
duke@1 11 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@1 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@1 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@1 14 * version 2 for more details (a copy is included in the LICENSE file that
duke@1 15 * accompanied this code).
duke@1 16 *
duke@1 17 * You should have received a copy of the GNU General Public License version
duke@1 18 * 2 along with this work; if not, write to the Free Software Foundation,
duke@1 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@1 20 *
ohair@554 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ohair@554 22 * or visit www.oracle.com if you need additional information or have any
ohair@554 23 * questions.
duke@1 24 */
duke@1 25
duke@1 26 package com.sun.tools.doclets.formats.html;
duke@1 27
bpatel@233 28 import com.sun.javadoc.*;
jjg@1743 29 import com.sun.tools.doclets.formats.html.markup.ContentBuilder;
jjg@1743 30 import com.sun.tools.doclets.formats.html.markup.HtmlStyle;
jjg@1742 31 import com.sun.tools.doclets.formats.html.markup.HtmlTree;
jjg@1743 32 import com.sun.tools.doclets.formats.html.markup.RawHtml;
jjg@1742 33 import com.sun.tools.doclets.formats.html.markup.StringContent;
duke@1 34 import com.sun.tools.doclets.internal.toolkit.*;
duke@1 35 import com.sun.tools.doclets.internal.toolkit.builders.SerializedFormBuilder;
duke@1 36 import com.sun.tools.doclets.internal.toolkit.taglets.*;
duke@1 37 import com.sun.tools.doclets.internal.toolkit.util.*;
duke@1 38
duke@1 39 /**
duke@1 40 * The taglet writer that writes HTML.
duke@1 41 *
jjg@1359 42 * <p><b>This is NOT part of any supported API.
jjg@1359 43 * If you write code that depends on this, you do so at your own risk.
jjg@1359 44 * This code and its internal interfaces are subject to change or
jjg@1359 45 * deletion without notice.</b>
jjg@1359 46 *
duke@1 47 * @since 1.5
duke@1 48 * @author Jamie Ho
bpatel@233 49 * @author Bhavesh Patel (Modified)
duke@1 50 */
duke@1 51
duke@1 52 public class TagletWriterImpl extends TagletWriter {
duke@1 53
jjg@1410 54 private final HtmlDocletWriter htmlWriter;
jjg@1410 55 private final ConfigurationImpl configuration;
duke@1 56
duke@1 57 public TagletWriterImpl(HtmlDocletWriter htmlWriter, boolean isFirstSentence) {
jjg@1410 58 super(isFirstSentence);
duke@1 59 this.htmlWriter = htmlWriter;
jjg@1410 60 configuration = htmlWriter.configuration;
duke@1 61 }
duke@1 62
duke@1 63 /**
duke@1 64 * {@inheritDoc}
duke@1 65 */
jjg@1751 66 public Content getOutputInstance() {
jjg@1751 67 return new ContentBuilder();
duke@1 68 }
duke@1 69
duke@1 70 /**
duke@1 71 * {@inheritDoc}
duke@1 72 */
jjg@1751 73 protected Content codeTagOutput(Tag tag) {
jjg@1911 74 Content result = HtmlTree.CODE(new StringContent(Util.normalizeNewlines(tag.text())));
jjg@1751 75 return result;
jjg@1742 76 }
jjg@1742 77
jjg@1742 78 /**
jjg@1742 79 * {@inheritDoc}
jjg@1742 80 */
jjg@1751 81 public Content getDocRootOutput() {
jjg@1751 82 String path;
jjg@1410 83 if (configuration.docrootparent.length() > 0)
jjg@1751 84 path = configuration.docrootparent;
jjg@1372 85 else if (htmlWriter.pathToRoot.isEmpty())
jjg@1751 86 path = ".";
bpatel@997 87 else
jjg@1751 88 path = htmlWriter.pathToRoot.getPath();
jjg@1751 89 return new StringContent(path);
duke@1 90 }
duke@1 91
duke@1 92 /**
duke@1 93 * {@inheritDoc}
duke@1 94 */
jjg@1751 95 public Content deprecatedTagOutput(Doc doc) {
jjg@1743 96 ContentBuilder result = new ContentBuilder();
duke@1 97 Tag[] deprs = doc.tags("deprecated");
duke@1 98 if (doc instanceof ClassDoc) {
duke@1 99 if (Util.isDeprecated((ProgramElementDoc) doc)) {
bpatel@2147 100 result.addContent(HtmlTree.SPAN(HtmlStyle.deprecatedLabel,
jjg@1743 101 new StringContent(configuration.getText("doclet.Deprecated"))));
jjg@1743 102 result.addContent(RawHtml.nbsp);
duke@1 103 if (deprs.length > 0) {
duke@1 104 Tag[] commentTags = deprs[0].inlineTags();
duke@1 105 if (commentTags.length > 0) {
jjg@1743 106 result.addContent(commentTagsToOutput(null, doc,
jjg@1751 107 deprs[0].inlineTags(), false)
duke@1 108 );
duke@1 109 }
duke@1 110 }
duke@1 111 }
duke@1 112 } else {
duke@1 113 MemberDoc member = (MemberDoc) doc;
duke@1 114 if (Util.isDeprecated((ProgramElementDoc) doc)) {
bpatel@2147 115 result.addContent(HtmlTree.SPAN(HtmlStyle.deprecatedLabel,
jjg@1743 116 new StringContent(configuration.getText("doclet.Deprecated"))));
jjg@1743 117 result.addContent(RawHtml.nbsp);
duke@1 118 if (deprs.length > 0) {
jjg@1751 119 Content body = commentTagsToOutput(null, doc,
jjg@1743 120 deprs[0].inlineTags(), false);
bpatel@2116 121 if (!body.isEmpty())
bpatel@2147 122 result.addContent(HtmlTree.SPAN(HtmlStyle.deprecationComment, body));
duke@1 123 }
duke@1 124 } else {
duke@1 125 if (Util.isDeprecated(member.containingClass())) {
bpatel@2147 126 result.addContent(HtmlTree.SPAN(HtmlStyle.deprecatedLabel,
jjg@1743 127 new StringContent(configuration.getText("doclet.Deprecated"))));
jjg@1743 128 result.addContent(RawHtml.nbsp);
duke@1 129 }
duke@1 130 }
duke@1 131 }
jjg@1751 132 return result;
duke@1 133 }
duke@1 134
duke@1 135 /**
duke@1 136 * {@inheritDoc}
duke@1 137 */
jjg@1751 138 protected Content literalTagOutput(Tag tag) {
jjg@1911 139 Content result = new StringContent(Util.normalizeNewlines(tag.text()));
jjg@1751 140 return result;
jjg@1742 141 }
jjg@1742 142
jjg@1742 143 /**
jjg@1742 144 * {@inheritDoc}
jjg@1742 145 */
duke@1 146 public MessageRetriever getMsgRetriever() {
jjg@1410 147 return configuration.message;
duke@1 148 }
duke@1 149
duke@1 150 /**
duke@1 151 * {@inheritDoc}
duke@1 152 */
jjg@1751 153 public Content getParamHeader(String header) {
bpatel@2147 154 HtmlTree result = HtmlTree.DT(HtmlTree.SPAN(HtmlStyle.paramLabel,
jjg@1743 155 new StringContent(header)));
jjg@1751 156 return result;
duke@1 157 }
duke@1 158
duke@1 159 /**
duke@1 160 * {@inheritDoc}
duke@1 161 */
jjg@1751 162 public Content paramTagOutput(ParamTag paramTag, String paramName) {
jjg@1743 163 ContentBuilder body = new ContentBuilder();
jjg@1743 164 body.addContent(HtmlTree.CODE(new RawHtml(paramName)));
jjg@1743 165 body.addContent(" - ");
jjg@1745 166 body.addContent(htmlWriter.commentTagsToContent(paramTag, null, paramTag.inlineTags(), false));
jjg@1743 167 HtmlTree result = HtmlTree.DD(body);
jjg@1751 168 return result;
duke@1 169 }
duke@1 170
duke@1 171 /**
duke@1 172 * {@inheritDoc}
duke@1 173 */
jjg@1751 174 public Content propertyTagOutput(Tag tag, String prefix) {
jjg@1749 175 Content body = new ContentBuilder();
jjg@1749 176 body.addContent(new RawHtml(prefix));
jjg@1749 177 body.addContent(" ");
jjg@1749 178 body.addContent(HtmlTree.CODE(new RawHtml(tag.text())));
jjg@1749 179 body.addContent(".");
jjg@1749 180 Content result = HtmlTree.P(body);
jjg@1751 181 return result;
jjg@1749 182 }
jjg@1749 183
jjg@1749 184 /**
jjg@1749 185 * {@inheritDoc}
jjg@1749 186 */
jjg@1751 187 public Content returnTagOutput(Tag returnTag) {
jjg@1743 188 ContentBuilder result = new ContentBuilder();
bpatel@2147 189 result.addContent(HtmlTree.DT(HtmlTree.SPAN(HtmlStyle.returnLabel,
jjg@1743 190 new StringContent(configuration.getText("doclet.Returns")))));
jjg@1745 191 result.addContent(HtmlTree.DD(htmlWriter.commentTagsToContent(
jjg@1745 192 returnTag, null, returnTag.inlineTags(), false)));
jjg@1751 193 return result;
duke@1 194 }
duke@1 195
duke@1 196 /**
duke@1 197 * {@inheritDoc}
duke@1 198 */
jjg@1751 199 public Content seeTagOutput(Doc holder, SeeTag[] seeTags) {
jjg@1743 200 ContentBuilder body = new ContentBuilder();
duke@1 201 if (seeTags.length > 0) {
duke@1 202 for (int i = 0; i < seeTags.length; ++i) {
jjg@1743 203 appendSeparatorIfNotEmpty(body);
jjg@1745 204 body.addContent(htmlWriter.seeTagToContent(seeTags[i]));
duke@1 205 }
duke@1 206 }
duke@1 207 if (holder.isField() && ((FieldDoc)holder).constantValue() != null &&
duke@1 208 htmlWriter instanceof ClassWriterImpl) {
duke@1 209 //Automatically add link to constant values page for constant fields.
jjg@1743 210 appendSeparatorIfNotEmpty(body);
jjg@1373 211 DocPath constantsPath =
jjg@1373 212 htmlWriter.pathToRoot.resolve(DocPaths.CONSTANT_VALUES);
jjg@1373 213 String whichConstant =
jjg@1373 214 ((ClassWriterImpl) htmlWriter).getClassDoc().qualifiedName() + "." + ((FieldDoc) holder).name();
jjg@1373 215 DocLink link = constantsPath.fragment(whichConstant);
jjg@1743 216 body.addContent(htmlWriter.getHyperLink(link,
jjg@1743 217 new StringContent(configuration.getText("doclet.Constants_Summary"))));
duke@1 218 }
duke@1 219 if (holder.isClass() && ((ClassDoc)holder).isSerializable()) {
duke@1 220 //Automatically add link to serialized form page for serializable classes.
bpatel@233 221 if ((SerializedFormBuilder.serialInclude(holder) &&
duke@1 222 SerializedFormBuilder.serialInclude(((ClassDoc)holder).containingPackage()))) {
jjg@1743 223 appendSeparatorIfNotEmpty(body);
jjg@1373 224 DocPath serialPath = htmlWriter.pathToRoot.resolve(DocPaths.SERIALIZED_FORM);
jjg@1373 225 DocLink link = serialPath.fragment(((ClassDoc)holder).qualifiedName());
jjg@1743 226 body.addContent(htmlWriter.getHyperLink(link,
jjg@1743 227 new StringContent(configuration.getText("doclet.Serialized_Form"))));
duke@1 228 }
duke@1 229 }
jjg@1743 230 if (body.isEmpty())
jjg@1751 231 return body;
jjg@1743 232
jjg@1743 233 ContentBuilder result = new ContentBuilder();
bpatel@2147 234 result.addContent(HtmlTree.DT(HtmlTree.SPAN(HtmlStyle.seeLabel,
jjg@1743 235 new StringContent(configuration.getText("doclet.See_Also")))));
jjg@1743 236 result.addContent(HtmlTree.DD(body));
jjg@1751 237 return result;
jjg@1743 238
duke@1 239 }
duke@1 240
jjg@1743 241 private void appendSeparatorIfNotEmpty(ContentBuilder body) {
jjg@1743 242 if (!body.isEmpty()) {
jjg@1743 243 body.addContent(", ");
jjg@1743 244 body.addContent(DocletConstants.NL);
duke@1 245 }
jjg@1743 246 }
duke@1 247
duke@1 248 /**
duke@1 249 * {@inheritDoc}
duke@1 250 */
jjg@1751 251 public Content simpleTagOutput(Tag[] simpleTags, String header) {
jjg@1743 252 ContentBuilder result = new ContentBuilder();
bpatel@2147 253 result.addContent(HtmlTree.DT(HtmlTree.SPAN(HtmlStyle.simpleTagLabel, new RawHtml(header))));
jjg@1743 254 ContentBuilder body = new ContentBuilder();
duke@1 255 for (int i = 0; i < simpleTags.length; i++) {
duke@1 256 if (i > 0) {
jjg@1743 257 body.addContent(", ");
duke@1 258 }
jjg@1745 259 body.addContent(htmlWriter.commentTagsToContent(
jjg@1745 260 simpleTags[i], null, simpleTags[i].inlineTags(), false));
duke@1 261 }
jjg@1743 262 result.addContent(HtmlTree.DD(body));
jjg@1751 263 return result;
duke@1 264 }
duke@1 265
duke@1 266 /**
duke@1 267 * {@inheritDoc}
duke@1 268 */
jjg@1751 269 public Content simpleTagOutput(Tag simpleTag, String header) {
jjg@1743 270 ContentBuilder result = new ContentBuilder();
bpatel@2147 271 result.addContent(HtmlTree.DT(HtmlTree.SPAN(HtmlStyle.simpleTagLabel, new RawHtml(header))));
jjg@1745 272 Content body = htmlWriter.commentTagsToContent(
jjg@1745 273 simpleTag, null, simpleTag.inlineTags(), false);
jjg@1743 274 result.addContent(HtmlTree.DD(body));
jjg@1751 275 return result;
duke@1 276 }
duke@1 277
duke@1 278 /**
duke@1 279 * {@inheritDoc}
duke@1 280 */
jjg@1751 281 public Content getThrowsHeader() {
bpatel@2147 282 HtmlTree result = HtmlTree.DT(HtmlTree.SPAN(HtmlStyle.throwsLabel,
jjg@1743 283 new StringContent(configuration.getText("doclet.Throws"))));
jjg@1751 284 return result;
duke@1 285 }
duke@1 286
duke@1 287 /**
duke@1 288 * {@inheritDoc}
duke@1 289 */
jjg@1751 290 public Content throwsTagOutput(ThrowsTag throwsTag) {
jjg@1743 291 ContentBuilder body = new ContentBuilder();
jjg@1743 292 Content excName = (throwsTag.exceptionType() == null) ?
jjg@1743 293 new RawHtml(throwsTag.exceptionName()) :
jjg@1735 294 htmlWriter.getLink(new LinkInfoImpl(configuration, LinkInfoImpl.Kind.MEMBER,
jjg@1743 295 throwsTag.exceptionType()));
jjg@1743 296 body.addContent(HtmlTree.CODE(excName));
jjg@1745 297 Content desc = htmlWriter.commentTagsToContent(throwsTag, null,
jjg@1743 298 throwsTag.inlineTags(), false);
jjg@1743 299 if (desc != null && !desc.isEmpty()) {
jjg@1743 300 body.addContent(" - ");
jjg@1745 301 body.addContent(desc);
duke@1 302 }
jjg@1751 303 HtmlTree result = HtmlTree.DD(body);
jjg@1751 304 return result;
duke@1 305 }
duke@1 306
duke@1 307 /**
duke@1 308 * {@inheritDoc}
duke@1 309 */
jjg@1751 310 public Content throwsTagOutput(Type throwsType) {
jjg@1743 311 HtmlTree result = HtmlTree.DD(HtmlTree.CODE(htmlWriter.getLink(
jjg@1743 312 new LinkInfoImpl(configuration, LinkInfoImpl.Kind.MEMBER, throwsType))));
jjg@1751 313 return result;
duke@1 314 }
duke@1 315
duke@1 316 /**
duke@1 317 * {@inheritDoc}
duke@1 318 */
jjg@1751 319 public Content valueTagOutput(FieldDoc field, String constantVal,
duke@1 320 boolean includeLink) {
jjg@1751 321 return includeLink ?
jjg@1735 322 htmlWriter.getDocLink(LinkInfoImpl.Kind.VALUE_TAG, field,
jjg@1751 323 constantVal, false) : new RawHtml(constantVal);
duke@1 324 }
duke@1 325
duke@1 326 /**
duke@1 327 * {@inheritDoc}
duke@1 328 */
jjg@1751 329 public Content commentTagsToOutput(Tag holderTag, Tag[] tags) {
duke@1 330 return commentTagsToOutput(holderTag, null, tags, false);
duke@1 331 }
duke@1 332
duke@1 333 /**
duke@1 334 * {@inheritDoc}
duke@1 335 */
jjg@1751 336 public Content commentTagsToOutput(Doc holderDoc, Tag[] tags) {
duke@1 337 return commentTagsToOutput(null, holderDoc, tags, false);
duke@1 338 }
duke@1 339
duke@1 340 /**
duke@1 341 * {@inheritDoc}
duke@1 342 */
jjg@1751 343 public Content commentTagsToOutput(Tag holderTag,
duke@1 344 Doc holderDoc, Tag[] tags, boolean isFirstSentence) {
jjg@1751 345 return htmlWriter.commentTagsToContent(
jjg@1751 346 holderTag, holderDoc, tags, isFirstSentence);
duke@1 347 }
duke@1 348
duke@1 349 /**
duke@1 350 * {@inheritDoc}
duke@1 351 */
duke@1 352 public Configuration configuration() {
jjg@1410 353 return configuration;
duke@1 354 }
duke@1 355 }

mercurial