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