Thu, 13 Jan 2011 21:28:38 -0800
7010528: javadoc performance regression
Reviewed-by: jjg
1 /*
2 * Copyright (c) 1998, 2010, 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.*;
30 import com.sun.javadoc.*;
31 import com.sun.tools.doclets.internal.toolkit.util.*;
32 import com.sun.tools.doclets.formats.html.markup.*;
33 import com.sun.tools.doclets.internal.toolkit.*;
35 /**
36 * Class to generate Tree page for a package. The name of the file generated is
37 * "package-tree.html" and it is generated in the respective package directory.
38 *
39 * @author Atul M Dambalkar
40 * @author Bhavesh Patel (Modified)
41 */
42 public class PackageTreeWriter extends AbstractTreeWriter {
44 /**
45 * Package for which tree is to be generated.
46 */
47 protected PackageDoc packagedoc;
49 /**
50 * The previous package name in the alpha-order list.
51 */
52 protected PackageDoc prev;
54 /**
55 * The next package name in the alpha-order list.
56 */
57 protected PackageDoc next;
59 /**
60 * Constructor.
61 * @throws IOException
62 * @throws DocletAbortException
63 */
64 public PackageTreeWriter(ConfigurationImpl configuration,
65 String path, String filename,
66 PackageDoc packagedoc,
67 PackageDoc prev, PackageDoc next)
68 throws IOException {
69 super(configuration, path, filename,
70 new ClassTree(
71 configuration.classDocCatalog.allClasses(packagedoc),
72 configuration),
73 packagedoc);
74 this.packagedoc = packagedoc;
75 this.prev = prev;
76 this.next = next;
77 }
79 /**
80 * Construct a PackageTreeWriter object and then use it to generate the
81 * package tree page.
82 *
83 * @param pkg Package for which tree file is to be generated.
84 * @param prev Previous package in the alpha-ordered list.
85 * @param next Next package in the alpha-ordered list.
86 * @param noDeprecated If true, do not generate any information for
87 * deprecated classe or interfaces.
88 * @throws DocletAbortException
89 */
90 public static void generate(ConfigurationImpl configuration,
91 PackageDoc pkg, PackageDoc prev,
92 PackageDoc next, boolean noDeprecated) {
93 PackageTreeWriter packgen;
94 String path = DirectoryManager.getDirectoryPath(pkg);
95 String filename = "package-tree.html";
96 try {
97 packgen = new PackageTreeWriter(configuration, path, filename, pkg,
98 prev, next);
99 packgen.generatePackageTreeFile();
100 packgen.close();
101 } catch (IOException exc) {
102 configuration.standardmessage.error(
103 "doclet.exception_encountered",
104 exc.toString(), filename);
105 throw new DocletAbortException();
106 }
107 }
109 /**
110 * Generate a separate tree file for each package.
111 */
112 protected void generatePackageTreeFile() throws IOException {
113 Content body = getPackageTreeHeader();
114 Content headContent = getResource("doclet.Hierarchy_For_Package",
115 Util.getPackageName(packagedoc));
116 Content heading = HtmlTree.HEADING(HtmlConstants.TITLE_HEADING, false,
117 HtmlStyle.title, headContent);
118 Content div = HtmlTree.DIV(HtmlStyle.header, heading);
119 if (configuration.packages.length > 1) {
120 addLinkToMainTree(div);
121 }
122 body.addContent(div);
123 HtmlTree divTree = new HtmlTree(HtmlTag.DIV);
124 divTree.addStyle(HtmlStyle.contentContainer);
125 addTree(classtree.baseclasses(), "doclet.Class_Hierarchy", divTree);
126 addTree(classtree.baseinterfaces(), "doclet.Interface_Hierarchy", divTree);
127 addTree(classtree.baseAnnotationTypes(), "doclet.Annotation_Type_Hierarchy", divTree);
128 addTree(classtree.baseEnums(), "doclet.Enum_Hierarchy", divTree);
129 body.addContent(divTree);
130 addNavLinks(false, body);
131 addBottom(body);
132 printHtmlDocument(null, true, body);
133 }
135 /**
136 * Get the package tree header.
137 *
138 * @return a content tree for the header
139 */
140 protected Content getPackageTreeHeader() {
141 String title = packagedoc.name() + " " +
142 configuration.getText("doclet.Window_Class_Hierarchy");
143 Content bodyTree = getBody(true, getWindowTitle(title));
144 addTop(bodyTree);
145 addNavLinks(true, bodyTree);
146 return bodyTree;
147 }
149 /**
150 * Add a link to the tree for all the packages.
151 *
152 * @param div the content tree to which the link will be added
153 */
154 protected void addLinkToMainTree(Content div) {
155 Content span = HtmlTree.SPAN(HtmlStyle.strong,
156 getResource("doclet.Package_Hierarchies"));
157 div.addContent(span);
158 HtmlTree ul = new HtmlTree (HtmlTag.UL);
159 ul.addStyle(HtmlStyle.horizontal);
160 ul.addContent(getNavLinkMainTree(configuration.getText("doclet.All_Packages")));
161 div.addContent(ul);
162 }
164 /**
165 * Get link for the previous package tree file.
166 *
167 * @return a content tree for the link
168 */
169 protected Content getNavLinkPrevious() {
170 if (prev == null) {
171 return getNavLinkPrevious(null);
172 } else {
173 String path = DirectoryManager.getRelativePath(packagedoc.name(),
174 prev.name());
175 return getNavLinkPrevious(path + "package-tree.html");
176 }
177 }
179 /**
180 * Get link for the next package tree file.
181 *
182 * @return a content tree for the link
183 */
184 protected Content getNavLinkNext() {
185 if (next == null) {
186 return getNavLinkNext(null);
187 } else {
188 String path = DirectoryManager.getRelativePath(packagedoc.name(),
189 next.name());
190 return getNavLinkNext(path + "package-tree.html");
191 }
192 }
194 /**
195 * Get link to the package summary page for the package of this tree.
196 *
197 * @return a content tree for the package link
198 */
199 protected Content getNavLinkPackage() {
200 Content linkContent = getHyperLink("package-summary.html", "",
201 packageLabel);
202 Content li = HtmlTree.LI(linkContent);
203 return li;
204 }
205 }