Tue, 14 May 2013 10:14:54 -0700
8012175: Convert TagletOutputImpl to use ContentBuilder instead of StringBuilder
Reviewed-by: darcy
1 /*
2 * Copyright (c) 1997, 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 java.io.*;
29 import java.util.*;
31 import com.sun.javadoc.*;
32 import com.sun.tools.doclets.formats.html.markup.*;
33 import com.sun.tools.doclets.internal.toolkit.*;
34 import com.sun.tools.doclets.internal.toolkit.util.*;
36 /**
37 * Class to generate file for each package contents in the right-hand
38 * frame. This will list all the Class Kinds in the package. A click on any
39 * class-kind will update the frame with the clicked class-kind page.
40 *
41 * <p><b>This is NOT part of any supported API.
42 * If you write code that depends on this, you do so at your own risk.
43 * This code and its internal interfaces are subject to change or
44 * deletion without notice.</b>
45 *
46 * @author Atul M Dambalkar
47 * @author Bhavesh Patel (Modified)
48 */
49 public class PackageWriterImpl extends HtmlDocletWriter
50 implements PackageSummaryWriter {
52 /**
53 * The prev package name in the alpha-order list.
54 */
55 protected PackageDoc prev;
57 /**
58 * The next package name in the alpha-order list.
59 */
60 protected PackageDoc next;
62 /**
63 * The package being documented.
64 */
65 protected PackageDoc packageDoc;
67 /**
68 * Constructor to construct PackageWriter object and to generate
69 * "package-summary.html" file in the respective package directory.
70 * For example for package "java.lang" this will generate file
71 * "package-summary.html" file in the "java/lang" directory. It will also
72 * create "java/lang" directory in the current or the destination directory
73 * if it doesn't exist.
74 *
75 * @param configuration the configuration of the doclet.
76 * @param packageDoc PackageDoc under consideration.
77 * @param prev Previous package in the sorted array.
78 * @param next Next package in the sorted array.
79 */
80 public PackageWriterImpl(ConfigurationImpl configuration,
81 PackageDoc packageDoc, PackageDoc prev, PackageDoc next)
82 throws IOException {
83 super(configuration, DocPath.forPackage(packageDoc).resolve(DocPaths.PACKAGE_SUMMARY));
84 this.prev = prev;
85 this.next = next;
86 this.packageDoc = packageDoc;
87 }
89 /**
90 * {@inheritDoc}
91 */
92 public Content getPackageHeader(String heading) {
93 String pkgName = packageDoc.name();
94 Content bodyTree = getBody(true, getWindowTitle(pkgName));
95 addTop(bodyTree);
96 addNavLinks(true, bodyTree);
97 HtmlTree div = new HtmlTree(HtmlTag.DIV);
98 div.addStyle(HtmlStyle.header);
99 Content annotationContent = new HtmlTree(HtmlTag.P);
100 addAnnotationInfo(packageDoc, annotationContent);
101 div.addContent(annotationContent);
102 Content tHeading = HtmlTree.HEADING(HtmlConstants.TITLE_HEADING, true,
103 HtmlStyle.title, packageLabel);
104 tHeading.addContent(getSpace());
105 Content packageHead = new RawHtml(heading);
106 tHeading.addContent(packageHead);
107 div.addContent(tHeading);
108 addDeprecationInfo(div);
109 if (packageDoc.inlineTags().length > 0 && ! configuration.nocomment) {
110 HtmlTree docSummaryDiv = new HtmlTree(HtmlTag.DIV);
111 docSummaryDiv.addStyle(HtmlStyle.docSummary);
112 addSummaryComment(packageDoc, docSummaryDiv);
113 div.addContent(docSummaryDiv);
114 Content space = getSpace();
115 Content descLink = getHyperLink(DocLink.fragment("package_description"),
116 descriptionLabel, "", "");
117 Content descPara = new HtmlTree(HtmlTag.P, seeLabel, space, descLink);
118 div.addContent(descPara);
119 }
120 bodyTree.addContent(div);
121 return bodyTree;
122 }
124 /**
125 * {@inheritDoc}
126 */
127 public Content getContentHeader() {
128 HtmlTree div = new HtmlTree(HtmlTag.DIV);
129 div.addStyle(HtmlStyle.contentContainer);
130 return div;
131 }
133 /**
134 * Add the package deprecation information to the documentation tree.
135 *
136 * @param div the content tree to which the deprecation information will be added
137 */
138 public void addDeprecationInfo(Content div) {
139 Tag[] deprs = packageDoc.tags("deprecated");
140 if (Util.isDeprecated(packageDoc)) {
141 HtmlTree deprDiv = new HtmlTree(HtmlTag.DIV);
142 deprDiv.addStyle(HtmlStyle.deprecatedContent);
143 Content deprPhrase = HtmlTree.SPAN(HtmlStyle.strong, deprecatedPhrase);
144 deprDiv.addContent(deprPhrase);
145 if (deprs.length > 0) {
146 Tag[] commentTags = deprs[0].inlineTags();
147 if (commentTags.length > 0) {
148 addInlineDeprecatedComment(packageDoc, deprs[0], deprDiv);
149 }
150 }
151 div.addContent(deprDiv);
152 }
153 }
155 /**
156 * {@inheritDoc}
157 */
158 public Content getSummaryHeader() {
159 HtmlTree ul = new HtmlTree(HtmlTag.UL);
160 ul.addStyle(HtmlStyle.blockList);
161 return ul;
162 }
164 /**
165 * {@inheritDoc}
166 */
167 public void addClassesSummary(ClassDoc[] classes, String label,
168 String tableSummary, String[] tableHeader, Content summaryContentTree) {
169 if(classes.length > 0) {
170 Arrays.sort(classes);
171 Content caption = getTableCaption(label);
172 Content table = HtmlTree.TABLE(HtmlStyle.packageSummary, 0, 3, 0,
173 tableSummary, caption);
174 table.addContent(getSummaryTableHeader(tableHeader, "col"));
175 Content tbody = new HtmlTree(HtmlTag.TBODY);
176 for (int i = 0; i < classes.length; i++) {
177 if (!Util.isCoreClass(classes[i]) ||
178 !configuration.isGeneratedDoc(classes[i])) {
179 continue;
180 }
181 Content classContent = getLink(new LinkInfoImpl(
182 configuration, LinkInfoImpl.Kind.PACKAGE, classes[i]));
183 Content tdClass = HtmlTree.TD(HtmlStyle.colFirst, classContent);
184 HtmlTree tr = HtmlTree.TR(tdClass);
185 if (i%2 == 0)
186 tr.addStyle(HtmlStyle.altColor);
187 else
188 tr.addStyle(HtmlStyle.rowColor);
189 HtmlTree tdClassDescription = new HtmlTree(HtmlTag.TD);
190 tdClassDescription.addStyle(HtmlStyle.colLast);
191 if (Util.isDeprecated(classes[i])) {
192 tdClassDescription.addContent(deprecatedLabel);
193 if (classes[i].tags("deprecated").length > 0) {
194 addSummaryDeprecatedComment(classes[i],
195 classes[i].tags("deprecated")[0], tdClassDescription);
196 }
197 }
198 else
199 addSummaryComment(classes[i], tdClassDescription);
200 tr.addContent(tdClassDescription);
201 tbody.addContent(tr);
202 }
203 table.addContent(tbody);
204 Content li = HtmlTree.LI(HtmlStyle.blockList, table);
205 summaryContentTree.addContent(li);
206 }
207 }
209 /**
210 * {@inheritDoc}
211 */
212 public void addPackageDescription(Content packageContentTree) {
213 if (packageDoc.inlineTags().length > 0) {
214 packageContentTree.addContent(getMarkerAnchor("package_description"));
215 Content h2Content = new StringContent(
216 configuration.getText("doclet.Package_Description",
217 packageDoc.name()));
218 packageContentTree.addContent(HtmlTree.HEADING(HtmlConstants.PACKAGE_HEADING,
219 true, h2Content));
220 addInlineComment(packageDoc, packageContentTree);
221 }
222 }
224 /**
225 * {@inheritDoc}
226 */
227 public void addPackageTags(Content packageContentTree) {
228 addTagsInfo(packageDoc, packageContentTree);
229 }
231 /**
232 * {@inheritDoc}
233 */
234 public void addPackageFooter(Content contentTree) {
235 addNavLinks(false, contentTree);
236 addBottom(contentTree);
237 }
239 /**
240 * {@inheritDoc}
241 */
242 public void printDocument(Content contentTree) throws IOException {
243 printHtmlDocument(configuration.metakeywords.getMetaKeywords(packageDoc),
244 true, contentTree);
245 }
247 /**
248 * Get "Use" link for this pacakge in the navigation bar.
249 *
250 * @return a content tree for the class use link
251 */
252 protected Content getNavLinkClassUse() {
253 Content useLink = getHyperLink(DocPaths.PACKAGE_USE,
254 useLabel, "", "");
255 Content li = HtmlTree.LI(useLink);
256 return li;
257 }
259 /**
260 * Get "PREV PACKAGE" link in the navigation bar.
261 *
262 * @return a content tree for the previous link
263 */
264 public Content getNavLinkPrevious() {
265 Content li;
266 if (prev == null) {
267 li = HtmlTree.LI(prevpackageLabel);
268 } else {
269 DocPath path = DocPath.relativePath(packageDoc, prev);
270 li = HtmlTree.LI(getHyperLink(path.resolve(DocPaths.PACKAGE_SUMMARY),
271 prevpackageLabel, "", ""));
272 }
273 return li;
274 }
276 /**
277 * Get "NEXT PACKAGE" link in the navigation bar.
278 *
279 * @return a content tree for the next link
280 */
281 public Content getNavLinkNext() {
282 Content li;
283 if (next == null) {
284 li = HtmlTree.LI(nextpackageLabel);
285 } else {
286 DocPath path = DocPath.relativePath(packageDoc, next);
287 li = HtmlTree.LI(getHyperLink(path.resolve(DocPaths.PACKAGE_SUMMARY),
288 nextpackageLabel, "", ""));
289 }
290 return li;
291 }
293 /**
294 * Get "Tree" link in the navigation bar. This will be link to the package
295 * tree file.
296 *
297 * @return a content tree for the tree link
298 */
299 protected Content getNavLinkTree() {
300 Content useLink = getHyperLink(DocPaths.PACKAGE_TREE,
301 treeLabel, "", "");
302 Content li = HtmlTree.LI(useLink);
303 return li;
304 }
306 /**
307 * Highlight "Package" in the navigation bar, as this is the package page.
308 *
309 * @return a content tree for the package link
310 */
311 protected Content getNavLinkPackage() {
312 Content li = HtmlTree.LI(HtmlStyle.navBarCell1Rev, packageLabel);
313 return li;
314 }
315 }