Thu, 15 Nov 2012 19:54:20 -0800
8002079: update DocFile to use a JavaFileManager
Reviewed-by: darcy
1 /*
2 * Copyright (c) 1997, 2012, 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 = new RawHtml(getLink(new LinkInfoImpl(
182 configuration, LinkInfoImpl.CONTEXT_PACKAGE, classes[i],
183 false)));
184 Content tdClass = HtmlTree.TD(HtmlStyle.colFirst, classContent);
185 HtmlTree tr = HtmlTree.TR(tdClass);
186 if (i%2 == 0)
187 tr.addStyle(HtmlStyle.altColor);
188 else
189 tr.addStyle(HtmlStyle.rowColor);
190 HtmlTree tdClassDescription = new HtmlTree(HtmlTag.TD);
191 tdClassDescription.addStyle(HtmlStyle.colLast);
192 if (Util.isDeprecated(classes[i])) {
193 tdClassDescription.addContent(deprecatedLabel);
194 if (classes[i].tags("deprecated").length > 0) {
195 addSummaryDeprecatedComment(classes[i],
196 classes[i].tags("deprecated")[0], tdClassDescription);
197 }
198 }
199 else
200 addSummaryComment(classes[i], tdClassDescription);
201 tr.addContent(tdClassDescription);
202 tbody.addContent(tr);
203 }
204 table.addContent(tbody);
205 Content li = HtmlTree.LI(HtmlStyle.blockList, table);
206 summaryContentTree.addContent(li);
207 }
208 }
210 /**
211 * {@inheritDoc}
212 */
213 public void addPackageDescription(Content packageContentTree) {
214 if (packageDoc.inlineTags().length > 0) {
215 packageContentTree.addContent(getMarkerAnchor("package_description"));
216 Content h2Content = new StringContent(
217 configuration.getText("doclet.Package_Description",
218 packageDoc.name()));
219 packageContentTree.addContent(HtmlTree.HEADING(HtmlConstants.PACKAGE_HEADING,
220 true, h2Content));
221 addInlineComment(packageDoc, packageContentTree);
222 }
223 }
225 /**
226 * {@inheritDoc}
227 */
228 public void addPackageTags(Content packageContentTree) {
229 addTagsInfo(packageDoc, packageContentTree);
230 }
232 /**
233 * {@inheritDoc}
234 */
235 public void addPackageFooter(Content contentTree) {
236 addNavLinks(false, contentTree);
237 addBottom(contentTree);
238 }
240 /**
241 * {@inheritDoc}
242 */
243 public void printDocument(Content contentTree) throws IOException {
244 printHtmlDocument(configuration.metakeywords.getMetaKeywords(packageDoc),
245 true, contentTree);
246 }
248 /**
249 * Get "Use" link for this pacakge in the navigation bar.
250 *
251 * @return a content tree for the class use link
252 */
253 protected Content getNavLinkClassUse() {
254 Content useLink = getHyperLink(DocPaths.PACKAGE_USE,
255 useLabel, "", "");
256 Content li = HtmlTree.LI(useLink);
257 return li;
258 }
260 /**
261 * Get "PREV PACKAGE" link in the navigation bar.
262 *
263 * @return a content tree for the previous link
264 */
265 public Content getNavLinkPrevious() {
266 Content li;
267 if (prev == null) {
268 li = HtmlTree.LI(prevpackageLabel);
269 } else {
270 DocPath path = DocPath.relativePath(packageDoc, prev);
271 li = HtmlTree.LI(getHyperLink(path.resolve(DocPaths.PACKAGE_SUMMARY),
272 prevpackageLabel, "", ""));
273 }
274 return li;
275 }
277 /**
278 * Get "NEXT PACKAGE" link in the navigation bar.
279 *
280 * @return a content tree for the next link
281 */
282 public Content getNavLinkNext() {
283 Content li;
284 if (next == null) {
285 li = HtmlTree.LI(nextpackageLabel);
286 } else {
287 DocPath path = DocPath.relativePath(packageDoc, next);
288 li = HtmlTree.LI(getHyperLink(path.resolve(DocPaths.PACKAGE_SUMMARY),
289 nextpackageLabel, "", ""));
290 }
291 return li;
292 }
294 /**
295 * Get "Tree" link in the navigation bar. This will be link to the package
296 * tree file.
297 *
298 * @return a content tree for the tree link
299 */
300 protected Content getNavLinkTree() {
301 Content useLink = getHyperLink(DocPaths.PACKAGE_TREE,
302 treeLabel, "", "");
303 Content li = HtmlTree.LI(useLink);
304 return li;
305 }
307 /**
308 * Highlight "Package" in the navigation bar, as this is the package page.
309 *
310 * @return a content tree for the package link
311 */
312 protected Content getNavLinkPackage() {
313 Content li = HtmlTree.LI(HtmlStyle.navBarCell1Rev, packageLabel);
314 return li;
315 }
316 }