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

Wed, 07 Aug 2013 15:00:24 -0700

author
bpatel
date
Wed, 07 Aug 2013 15:00:24 -0700
changeset 1935
8c55df2442c1
parent 1911
80e75aa6a707
child 2116
bf6b11347b1a
permissions
-rw-r--r--

7198274: RFE : Javadoc Accessibility : Use CSS styles rather than <strong> or <i> tags
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)) {
jjg@1743 100 result.addContent(HtmlTree.SPAN(HtmlStyle.strong,
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)) {
jjg@1743 115 result.addContent(HtmlTree.SPAN(HtmlStyle.strong,
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@1935 121 result.addContent(HtmlTree.SPAN(HtmlStyle.italic, body));
duke@1 122 }
duke@1 123 } else {
duke@1 124 if (Util.isDeprecated(member.containingClass())) {
jjg@1743 125 result.addContent(HtmlTree.SPAN(HtmlStyle.strong,
jjg@1743 126 new StringContent(configuration.getText("doclet.Deprecated"))));
jjg@1743 127 result.addContent(RawHtml.nbsp);
duke@1 128 }
duke@1 129 }
duke@1 130 }
jjg@1751 131 return result;
duke@1 132 }
duke@1 133
duke@1 134 /**
duke@1 135 * {@inheritDoc}
duke@1 136 */
jjg@1751 137 protected Content literalTagOutput(Tag tag) {
jjg@1911 138 Content result = new StringContent(Util.normalizeNewlines(tag.text()));
jjg@1751 139 return result;
jjg@1742 140 }
jjg@1742 141
jjg@1742 142 /**
jjg@1742 143 * {@inheritDoc}
jjg@1742 144 */
duke@1 145 public MessageRetriever getMsgRetriever() {
jjg@1410 146 return configuration.message;
duke@1 147 }
duke@1 148
duke@1 149 /**
duke@1 150 * {@inheritDoc}
duke@1 151 */
jjg@1751 152 public Content getParamHeader(String header) {
jjg@1743 153 HtmlTree result = HtmlTree.DT(HtmlTree.SPAN(HtmlStyle.strong,
jjg@1743 154 new StringContent(header)));
jjg@1751 155 return result;
duke@1 156 }
duke@1 157
duke@1 158 /**
duke@1 159 * {@inheritDoc}
duke@1 160 */
jjg@1751 161 public Content paramTagOutput(ParamTag paramTag, String paramName) {
jjg@1743 162 ContentBuilder body = new ContentBuilder();
jjg@1743 163 body.addContent(HtmlTree.CODE(new RawHtml(paramName)));
jjg@1743 164 body.addContent(" - ");
jjg@1745 165 body.addContent(htmlWriter.commentTagsToContent(paramTag, null, paramTag.inlineTags(), false));
jjg@1743 166 HtmlTree result = HtmlTree.DD(body);
jjg@1751 167 return result;
duke@1 168 }
duke@1 169
duke@1 170 /**
duke@1 171 * {@inheritDoc}
duke@1 172 */
jjg@1751 173 public Content propertyTagOutput(Tag tag, String prefix) {
jjg@1749 174 Content body = new ContentBuilder();
jjg@1749 175 body.addContent(new RawHtml(prefix));
jjg@1749 176 body.addContent(" ");
jjg@1749 177 body.addContent(HtmlTree.CODE(new RawHtml(tag.text())));
jjg@1749 178 body.addContent(".");
jjg@1749 179 Content result = HtmlTree.P(body);
jjg@1751 180 return result;
jjg@1749 181 }
jjg@1749 182
jjg@1749 183 /**
jjg@1749 184 * {@inheritDoc}
jjg@1749 185 */
jjg@1751 186 public Content returnTagOutput(Tag returnTag) {
jjg@1743 187 ContentBuilder result = new ContentBuilder();
jjg@1743 188 result.addContent(HtmlTree.DT(HtmlTree.SPAN(HtmlStyle.strong,
jjg@1743 189 new StringContent(configuration.getText("doclet.Returns")))));
jjg@1745 190 result.addContent(HtmlTree.DD(htmlWriter.commentTagsToContent(
jjg@1745 191 returnTag, null, returnTag.inlineTags(), false)));
jjg@1751 192 return result;
duke@1 193 }
duke@1 194
duke@1 195 /**
duke@1 196 * {@inheritDoc}
duke@1 197 */
jjg@1751 198 public Content seeTagOutput(Doc holder, SeeTag[] seeTags) {
jjg@1743 199 ContentBuilder body = new ContentBuilder();
duke@1 200 if (seeTags.length > 0) {
duke@1 201 for (int i = 0; i < seeTags.length; ++i) {
jjg@1743 202 appendSeparatorIfNotEmpty(body);
jjg@1745 203 body.addContent(htmlWriter.seeTagToContent(seeTags[i]));
duke@1 204 }
duke@1 205 }
duke@1 206 if (holder.isField() && ((FieldDoc)holder).constantValue() != null &&
duke@1 207 htmlWriter instanceof ClassWriterImpl) {
duke@1 208 //Automatically add link to constant values page for constant fields.
jjg@1743 209 appendSeparatorIfNotEmpty(body);
jjg@1373 210 DocPath constantsPath =
jjg@1373 211 htmlWriter.pathToRoot.resolve(DocPaths.CONSTANT_VALUES);
jjg@1373 212 String whichConstant =
jjg@1373 213 ((ClassWriterImpl) htmlWriter).getClassDoc().qualifiedName() + "." + ((FieldDoc) holder).name();
jjg@1373 214 DocLink link = constantsPath.fragment(whichConstant);
jjg@1743 215 body.addContent(htmlWriter.getHyperLink(link,
jjg@1743 216 new StringContent(configuration.getText("doclet.Constants_Summary"))));
duke@1 217 }
duke@1 218 if (holder.isClass() && ((ClassDoc)holder).isSerializable()) {
duke@1 219 //Automatically add link to serialized form page for serializable classes.
bpatel@233 220 if ((SerializedFormBuilder.serialInclude(holder) &&
duke@1 221 SerializedFormBuilder.serialInclude(((ClassDoc)holder).containingPackage()))) {
jjg@1743 222 appendSeparatorIfNotEmpty(body);
jjg@1373 223 DocPath serialPath = htmlWriter.pathToRoot.resolve(DocPaths.SERIALIZED_FORM);
jjg@1373 224 DocLink link = serialPath.fragment(((ClassDoc)holder).qualifiedName());
jjg@1743 225 body.addContent(htmlWriter.getHyperLink(link,
jjg@1743 226 new StringContent(configuration.getText("doclet.Serialized_Form"))));
duke@1 227 }
duke@1 228 }
jjg@1743 229 if (body.isEmpty())
jjg@1751 230 return body;
jjg@1743 231
jjg@1743 232 ContentBuilder result = new ContentBuilder();
jjg@1743 233 result.addContent(HtmlTree.DT(HtmlTree.SPAN(HtmlStyle.strong,
jjg@1743 234 new StringContent(configuration.getText("doclet.See_Also")))));
jjg@1743 235 result.addContent(HtmlTree.DD(body));
jjg@1751 236 return result;
jjg@1743 237
duke@1 238 }
duke@1 239
jjg@1743 240 private void appendSeparatorIfNotEmpty(ContentBuilder body) {
jjg@1743 241 if (!body.isEmpty()) {
jjg@1743 242 body.addContent(", ");
jjg@1743 243 body.addContent(DocletConstants.NL);
duke@1 244 }
jjg@1743 245 }
duke@1 246
duke@1 247 /**
duke@1 248 * {@inheritDoc}
duke@1 249 */
jjg@1751 250 public Content simpleTagOutput(Tag[] simpleTags, String header) {
jjg@1743 251 ContentBuilder result = new ContentBuilder();
jjg@1743 252 result.addContent(HtmlTree.DT(HtmlTree.SPAN(HtmlStyle.strong, new RawHtml(header))));
jjg@1743 253 ContentBuilder body = new ContentBuilder();
duke@1 254 for (int i = 0; i < simpleTags.length; i++) {
duke@1 255 if (i > 0) {
jjg@1743 256 body.addContent(", ");
duke@1 257 }
jjg@1745 258 body.addContent(htmlWriter.commentTagsToContent(
jjg@1745 259 simpleTags[i], null, simpleTags[i].inlineTags(), false));
duke@1 260 }
jjg@1743 261 result.addContent(HtmlTree.DD(body));
jjg@1751 262 return result;
duke@1 263 }
duke@1 264
duke@1 265 /**
duke@1 266 * {@inheritDoc}
duke@1 267 */
jjg@1751 268 public Content simpleTagOutput(Tag simpleTag, String header) {
jjg@1743 269 ContentBuilder result = new ContentBuilder();
jjg@1743 270 result.addContent(HtmlTree.DT(HtmlTree.SPAN(HtmlStyle.strong, new RawHtml(header))));
jjg@1745 271 Content body = htmlWriter.commentTagsToContent(
jjg@1745 272 simpleTag, null, simpleTag.inlineTags(), false);
jjg@1743 273 result.addContent(HtmlTree.DD(body));
jjg@1751 274 return result;
duke@1 275 }
duke@1 276
duke@1 277 /**
duke@1 278 * {@inheritDoc}
duke@1 279 */
jjg@1751 280 public Content getThrowsHeader() {
jjg@1743 281 HtmlTree result = HtmlTree.DT(HtmlTree.SPAN(HtmlStyle.strong,
jjg@1743 282 new StringContent(configuration.getText("doclet.Throws"))));
jjg@1751 283 return result;
duke@1 284 }
duke@1 285
duke@1 286 /**
duke@1 287 * {@inheritDoc}
duke@1 288 */
jjg@1751 289 public Content throwsTagOutput(ThrowsTag throwsTag) {
jjg@1743 290 ContentBuilder body = new ContentBuilder();
jjg@1743 291 Content excName = (throwsTag.exceptionType() == null) ?
jjg@1743 292 new RawHtml(throwsTag.exceptionName()) :
jjg@1735 293 htmlWriter.getLink(new LinkInfoImpl(configuration, LinkInfoImpl.Kind.MEMBER,
jjg@1743 294 throwsTag.exceptionType()));
jjg@1743 295 body.addContent(HtmlTree.CODE(excName));
jjg@1745 296 Content desc = htmlWriter.commentTagsToContent(throwsTag, null,
jjg@1743 297 throwsTag.inlineTags(), false);
jjg@1743 298 if (desc != null && !desc.isEmpty()) {
jjg@1743 299 body.addContent(" - ");
jjg@1745 300 body.addContent(desc);
duke@1 301 }
jjg@1751 302 HtmlTree result = HtmlTree.DD(body);
jjg@1751 303 return result;
duke@1 304 }
duke@1 305
duke@1 306 /**
duke@1 307 * {@inheritDoc}
duke@1 308 */
jjg@1751 309 public Content throwsTagOutput(Type throwsType) {
jjg@1743 310 HtmlTree result = HtmlTree.DD(HtmlTree.CODE(htmlWriter.getLink(
jjg@1743 311 new LinkInfoImpl(configuration, LinkInfoImpl.Kind.MEMBER, throwsType))));
jjg@1751 312 return result;
duke@1 313 }
duke@1 314
duke@1 315 /**
duke@1 316 * {@inheritDoc}
duke@1 317 */
jjg@1751 318 public Content valueTagOutput(FieldDoc field, String constantVal,
duke@1 319 boolean includeLink) {
jjg@1751 320 return includeLink ?
jjg@1735 321 htmlWriter.getDocLink(LinkInfoImpl.Kind.VALUE_TAG, field,
jjg@1751 322 constantVal, false) : new RawHtml(constantVal);
duke@1 323 }
duke@1 324
duke@1 325 /**
duke@1 326 * {@inheritDoc}
duke@1 327 */
jjg@1751 328 public Content commentTagsToOutput(Tag holderTag, Tag[] tags) {
duke@1 329 return commentTagsToOutput(holderTag, null, tags, false);
duke@1 330 }
duke@1 331
duke@1 332 /**
duke@1 333 * {@inheritDoc}
duke@1 334 */
jjg@1751 335 public Content commentTagsToOutput(Doc holderDoc, Tag[] tags) {
duke@1 336 return commentTagsToOutput(null, holderDoc, tags, false);
duke@1 337 }
duke@1 338
duke@1 339 /**
duke@1 340 * {@inheritDoc}
duke@1 341 */
jjg@1751 342 public Content commentTagsToOutput(Tag holderTag,
duke@1 343 Doc holderDoc, Tag[] tags, boolean isFirstSentence) {
jjg@1751 344 return htmlWriter.commentTagsToContent(
jjg@1751 345 holderTag, holderDoc, tags, isFirstSentence);
duke@1 346 }
duke@1 347
duke@1 348 /**
duke@1 349 * {@inheritDoc}
duke@1 350 */
duke@1 351 public Configuration configuration() {
jjg@1410 352 return configuration;
duke@1 353 }
duke@1 354 }

mercurial