|
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 */ |
|
25 |
|
26 package com.sun.tools.doclets.formats.html; |
|
27 |
|
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.*; |
|
38 |
|
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 */ |
|
51 |
|
52 public class TagletWriterImpl extends TagletWriter { |
|
53 |
|
54 private final HtmlDocletWriter htmlWriter; |
|
55 private final ConfigurationImpl configuration; |
|
56 |
|
57 public TagletWriterImpl(HtmlDocletWriter htmlWriter, boolean isFirstSentence) { |
|
58 super(isFirstSentence); |
|
59 this.htmlWriter = htmlWriter; |
|
60 configuration = htmlWriter.configuration; |
|
61 } |
|
62 |
|
63 /** |
|
64 * {@inheritDoc} |
|
65 */ |
|
66 public Content getOutputInstance() { |
|
67 return new ContentBuilder(); |
|
68 } |
|
69 |
|
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 } |
|
77 |
|
78 /** |
|
79 * {@inheritDoc} |
|
80 */ |
|
81 public Content getDocRootOutput() { |
|
82 String path; |
|
83 if (htmlWriter.pathToRoot.isEmpty()) |
|
84 path = "."; |
|
85 else |
|
86 path = htmlWriter.pathToRoot.getPath(); |
|
87 return new StringContent(path); |
|
88 } |
|
89 |
|
90 /** |
|
91 * {@inheritDoc} |
|
92 */ |
|
93 public Content deprecatedTagOutput(Doc doc) { |
|
94 ContentBuilder result = new ContentBuilder(); |
|
95 Tag[] deprs = doc.tags("deprecated"); |
|
96 if (doc instanceof ClassDoc) { |
|
97 if (Util.isDeprecated((ProgramElementDoc) doc)) { |
|
98 result.addContent(HtmlTree.SPAN(HtmlStyle.deprecatedLabel, |
|
99 new StringContent(configuration.getText("doclet.Deprecated")))); |
|
100 result.addContent(RawHtml.nbsp); |
|
101 if (deprs.length > 0) { |
|
102 Tag[] commentTags = deprs[0].inlineTags(); |
|
103 if (commentTags.length > 0) { |
|
104 result.addContent(commentTagsToOutput(null, doc, |
|
105 deprs[0].inlineTags(), false) |
|
106 ); |
|
107 } |
|
108 } |
|
109 } |
|
110 } else { |
|
111 MemberDoc member = (MemberDoc) doc; |
|
112 if (Util.isDeprecated((ProgramElementDoc) doc)) { |
|
113 result.addContent(HtmlTree.SPAN(HtmlStyle.deprecatedLabel, |
|
114 new StringContent(configuration.getText("doclet.Deprecated")))); |
|
115 result.addContent(RawHtml.nbsp); |
|
116 if (deprs.length > 0) { |
|
117 Content body = commentTagsToOutput(null, doc, |
|
118 deprs[0].inlineTags(), false); |
|
119 if (!body.isEmpty()) |
|
120 result.addContent(HtmlTree.SPAN(HtmlStyle.deprecationComment, body)); |
|
121 } |
|
122 } else { |
|
123 if (Util.isDeprecated(member.containingClass())) { |
|
124 result.addContent(HtmlTree.SPAN(HtmlStyle.deprecatedLabel, |
|
125 new StringContent(configuration.getText("doclet.Deprecated")))); |
|
126 result.addContent(RawHtml.nbsp); |
|
127 } |
|
128 } |
|
129 } |
|
130 return result; |
|
131 } |
|
132 |
|
133 /** |
|
134 * {@inheritDoc} |
|
135 */ |
|
136 protected Content literalTagOutput(Tag tag) { |
|
137 Content result = new StringContent(Util.normalizeNewlines(tag.text())); |
|
138 return result; |
|
139 } |
|
140 |
|
141 /** |
|
142 * {@inheritDoc} |
|
143 */ |
|
144 public MessageRetriever getMsgRetriever() { |
|
145 return configuration.message; |
|
146 } |
|
147 |
|
148 /** |
|
149 * {@inheritDoc} |
|
150 */ |
|
151 public Content getParamHeader(String header) { |
|
152 HtmlTree result = HtmlTree.DT(HtmlTree.SPAN(HtmlStyle.paramLabel, |
|
153 new StringContent(header))); |
|
154 return result; |
|
155 } |
|
156 |
|
157 /** |
|
158 * {@inheritDoc} |
|
159 */ |
|
160 public Content paramTagOutput(ParamTag paramTag, String paramName) { |
|
161 ContentBuilder body = new ContentBuilder(); |
|
162 body.addContent(HtmlTree.CODE(new RawHtml(paramName))); |
|
163 body.addContent(" - "); |
|
164 body.addContent(htmlWriter.commentTagsToContent(paramTag, null, paramTag.inlineTags(), false)); |
|
165 HtmlTree result = HtmlTree.DD(body); |
|
166 return result; |
|
167 } |
|
168 |
|
169 /** |
|
170 * {@inheritDoc} |
|
171 */ |
|
172 public Content propertyTagOutput(Tag tag, String prefix) { |
|
173 Content body = new ContentBuilder(); |
|
174 body.addContent(new RawHtml(prefix)); |
|
175 body.addContent(" "); |
|
176 body.addContent(HtmlTree.CODE(new RawHtml(tag.text()))); |
|
177 body.addContent("."); |
|
178 Content result = HtmlTree.P(body); |
|
179 return result; |
|
180 } |
|
181 |
|
182 /** |
|
183 * {@inheritDoc} |
|
184 */ |
|
185 public Content returnTagOutput(Tag returnTag) { |
|
186 ContentBuilder result = new ContentBuilder(); |
|
187 result.addContent(HtmlTree.DT(HtmlTree.SPAN(HtmlStyle.returnLabel, |
|
188 new StringContent(configuration.getText("doclet.Returns"))))); |
|
189 result.addContent(HtmlTree.DD(htmlWriter.commentTagsToContent( |
|
190 returnTag, null, returnTag.inlineTags(), false))); |
|
191 return result; |
|
192 } |
|
193 |
|
194 /** |
|
195 * {@inheritDoc} |
|
196 */ |
|
197 public Content seeTagOutput(Doc holder, SeeTag[] seeTags) { |
|
198 ContentBuilder body = new ContentBuilder(); |
|
199 if (seeTags.length > 0) { |
|
200 for (int i = 0; i < seeTags.length; ++i) { |
|
201 appendSeparatorIfNotEmpty(body); |
|
202 body.addContent(htmlWriter.seeTagToContent(seeTags[i])); |
|
203 } |
|
204 } |
|
205 if (holder.isField() && ((FieldDoc)holder).constantValue() != null && |
|
206 htmlWriter instanceof ClassWriterImpl) { |
|
207 //Automatically add link to constant values page for constant fields. |
|
208 appendSeparatorIfNotEmpty(body); |
|
209 DocPath constantsPath = |
|
210 htmlWriter.pathToRoot.resolve(DocPaths.CONSTANT_VALUES); |
|
211 String whichConstant = |
|
212 ((ClassWriterImpl) htmlWriter).getClassDoc().qualifiedName() + "." + ((FieldDoc) holder).name(); |
|
213 DocLink link = constantsPath.fragment(whichConstant); |
|
214 body.addContent(htmlWriter.getHyperLink(link, |
|
215 new StringContent(configuration.getText("doclet.Constants_Summary")))); |
|
216 } |
|
217 if (holder.isClass() && ((ClassDoc)holder).isSerializable()) { |
|
218 //Automatically add link to serialized form page for serializable classes. |
|
219 if ((SerializedFormBuilder.serialInclude(holder) && |
|
220 SerializedFormBuilder.serialInclude(((ClassDoc)holder).containingPackage()))) { |
|
221 appendSeparatorIfNotEmpty(body); |
|
222 DocPath serialPath = htmlWriter.pathToRoot.resolve(DocPaths.SERIALIZED_FORM); |
|
223 DocLink link = serialPath.fragment(((ClassDoc)holder).qualifiedName()); |
|
224 body.addContent(htmlWriter.getHyperLink(link, |
|
225 new StringContent(configuration.getText("doclet.Serialized_Form")))); |
|
226 } |
|
227 } |
|
228 if (body.isEmpty()) |
|
229 return body; |
|
230 |
|
231 ContentBuilder result = new ContentBuilder(); |
|
232 result.addContent(HtmlTree.DT(HtmlTree.SPAN(HtmlStyle.seeLabel, |
|
233 new StringContent(configuration.getText("doclet.See_Also"))))); |
|
234 result.addContent(HtmlTree.DD(body)); |
|
235 return result; |
|
236 |
|
237 } |
|
238 |
|
239 private void appendSeparatorIfNotEmpty(ContentBuilder body) { |
|
240 if (!body.isEmpty()) { |
|
241 body.addContent(", "); |
|
242 body.addContent(DocletConstants.NL); |
|
243 } |
|
244 } |
|
245 |
|
246 /** |
|
247 * {@inheritDoc} |
|
248 */ |
|
249 public Content simpleTagOutput(Tag[] simpleTags, String header) { |
|
250 ContentBuilder result = new ContentBuilder(); |
|
251 result.addContent(HtmlTree.DT(HtmlTree.SPAN(HtmlStyle.simpleTagLabel, new RawHtml(header)))); |
|
252 ContentBuilder body = new ContentBuilder(); |
|
253 for (int i = 0; i < simpleTags.length; i++) { |
|
254 if (i > 0) { |
|
255 body.addContent(", "); |
|
256 } |
|
257 body.addContent(htmlWriter.commentTagsToContent( |
|
258 simpleTags[i], null, simpleTags[i].inlineTags(), false)); |
|
259 } |
|
260 result.addContent(HtmlTree.DD(body)); |
|
261 return result; |
|
262 } |
|
263 |
|
264 /** |
|
265 * {@inheritDoc} |
|
266 */ |
|
267 public Content simpleTagOutput(Tag simpleTag, String header) { |
|
268 ContentBuilder result = new ContentBuilder(); |
|
269 result.addContent(HtmlTree.DT(HtmlTree.SPAN(HtmlStyle.simpleTagLabel, new RawHtml(header)))); |
|
270 Content body = htmlWriter.commentTagsToContent( |
|
271 simpleTag, null, simpleTag.inlineTags(), false); |
|
272 result.addContent(HtmlTree.DD(body)); |
|
273 return result; |
|
274 } |
|
275 |
|
276 /** |
|
277 * {@inheritDoc} |
|
278 */ |
|
279 public Content getThrowsHeader() { |
|
280 HtmlTree result = HtmlTree.DT(HtmlTree.SPAN(HtmlStyle.throwsLabel, |
|
281 new StringContent(configuration.getText("doclet.Throws")))); |
|
282 return result; |
|
283 } |
|
284 |
|
285 /** |
|
286 * {@inheritDoc} |
|
287 */ |
|
288 public Content throwsTagOutput(ThrowsTag throwsTag) { |
|
289 ContentBuilder body = new ContentBuilder(); |
|
290 Content excName = (throwsTag.exceptionType() == null) ? |
|
291 new RawHtml(throwsTag.exceptionName()) : |
|
292 htmlWriter.getLink(new LinkInfoImpl(configuration, LinkInfoImpl.Kind.MEMBER, |
|
293 throwsTag.exceptionType())); |
|
294 body.addContent(HtmlTree.CODE(excName)); |
|
295 Content desc = htmlWriter.commentTagsToContent(throwsTag, null, |
|
296 throwsTag.inlineTags(), false); |
|
297 if (desc != null && !desc.isEmpty()) { |
|
298 body.addContent(" - "); |
|
299 body.addContent(desc); |
|
300 } |
|
301 HtmlTree result = HtmlTree.DD(body); |
|
302 return result; |
|
303 } |
|
304 |
|
305 /** |
|
306 * {@inheritDoc} |
|
307 */ |
|
308 public Content throwsTagOutput(Type throwsType) { |
|
309 HtmlTree result = HtmlTree.DD(HtmlTree.CODE(htmlWriter.getLink( |
|
310 new LinkInfoImpl(configuration, LinkInfoImpl.Kind.MEMBER, throwsType)))); |
|
311 return result; |
|
312 } |
|
313 |
|
314 /** |
|
315 * {@inheritDoc} |
|
316 */ |
|
317 public Content valueTagOutput(FieldDoc field, String constantVal, |
|
318 boolean includeLink) { |
|
319 return includeLink ? |
|
320 htmlWriter.getDocLink(LinkInfoImpl.Kind.VALUE_TAG, field, |
|
321 constantVal, false) : new RawHtml(constantVal); |
|
322 } |
|
323 |
|
324 /** |
|
325 * {@inheritDoc} |
|
326 */ |
|
327 public Content commentTagsToOutput(Tag holderTag, Tag[] tags) { |
|
328 return commentTagsToOutput(holderTag, null, tags, false); |
|
329 } |
|
330 |
|
331 /** |
|
332 * {@inheritDoc} |
|
333 */ |
|
334 public Content commentTagsToOutput(Doc holderDoc, Tag[] tags) { |
|
335 return commentTagsToOutput(null, holderDoc, tags, false); |
|
336 } |
|
337 |
|
338 /** |
|
339 * {@inheritDoc} |
|
340 */ |
|
341 public Content commentTagsToOutput(Tag holderTag, |
|
342 Doc holderDoc, Tag[] tags, boolean isFirstSentence) { |
|
343 return htmlWriter.commentTagsToContent( |
|
344 holderTag, holderDoc, tags, isFirstSentence); |
|
345 } |
|
346 |
|
347 /** |
|
348 * {@inheritDoc} |
|
349 */ |
|
350 public Configuration configuration() { |
|
351 return configuration; |
|
352 } |
|
353 } |