Tue, 09 Oct 2012 19:10:00 -0700
8000663: clean up langtools imports
Reviewed-by: darcy
1 /*
2 * Copyright (c) 1998, 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 left-hand bottom
38 * frame. This will list all the Class Kinds in the package. A click on any
39 * class-kind will update the right-hand frame with the clicked class-kind page.
40 *
41 * @author Atul M Dambalkar
42 * @author Bhavesh Patel (Modified)
43 */
44 public class PackageFrameWriter extends HtmlDocletWriter {
46 /**
47 * The package being documented.
48 */
49 private PackageDoc packageDoc;
51 /**
52 * The classes to be documented. Use this to filter out classes
53 * that will not be documented.
54 */
55 private Set<ClassDoc> documentedClasses;
57 /**
58 * The name of the output file.
59 */
60 public static final String OUTPUT_FILE_NAME = "package-frame.html";
62 /**
63 * Constructor to construct PackageFrameWriter object and to generate
64 * "package-frame.html" file in the respective package directory.
65 * For example for package "java.lang" this will generate file
66 * "package-frame.html" file in the "java/lang" directory. It will also
67 * create "java/lang" directory in the current or the destination directory
68 * if it doesen't exist.
69 *
70 * @param configuration the configuration of the doclet.
71 * @param packageDoc PackageDoc under consideration.
72 */
73 public PackageFrameWriter(ConfigurationImpl configuration,
74 PackageDoc packageDoc)
75 throws IOException {
76 super(configuration, DirectoryManager.getDirectoryPath(packageDoc), OUTPUT_FILE_NAME, DirectoryManager.getRelativePath(packageDoc));
77 this.packageDoc = packageDoc;
78 if (configuration.root.specifiedPackages().length == 0) {
79 documentedClasses = new HashSet<ClassDoc>(Arrays.asList(configuration.root.classes()));
80 }
81 }
83 /**
84 * Generate a package summary page for the left-hand bottom frame. Construct
85 * the PackageFrameWriter object and then uses it generate the file.
86 *
87 * @param configuration the current configuration of the doclet.
88 * @param packageDoc The package for which "pacakge-frame.html" is to be generated.
89 */
90 public static void generate(ConfigurationImpl configuration,
91 PackageDoc packageDoc) {
92 PackageFrameWriter packgen;
93 try {
94 packgen = new PackageFrameWriter(configuration, packageDoc);
95 String pkgName = Util.getPackageName(packageDoc);
96 Content body = packgen.getBody(false, packgen.getWindowTitle(pkgName));
97 Content pkgNameContent = new RawHtml(pkgName);
98 Content heading = HtmlTree.HEADING(HtmlConstants.TITLE_HEADING, HtmlStyle.bar,
99 packgen.getTargetPackageLink(packageDoc, "classFrame", pkgNameContent));
100 body.addContent(heading);
101 HtmlTree div = new HtmlTree(HtmlTag.DIV);
102 div.addStyle(HtmlStyle.indexContainer);
103 packgen.addClassListing(div);
104 body.addContent(div);
105 packgen.printHtmlDocument(
106 configuration.metakeywords.getMetaKeywords(packageDoc), false, body);
107 packgen.close();
108 } catch (IOException exc) {
109 configuration.standardmessage.error(
110 "doclet.exception_encountered",
111 exc.toString(), OUTPUT_FILE_NAME);
112 throw new DocletAbortException();
113 }
114 }
116 /**
117 * Add class listing for all the classes in this package. Divide class
118 * listing as per the class kind and generate separate listing for
119 * Classes, Interfaces, Exceptions and Errors.
120 *
121 * @param contentTree the content tree to which the listing will be added
122 */
123 protected void addClassListing(Content contentTree) {
124 Configuration config = configuration();
125 if (packageDoc.isIncluded()) {
126 addClassKindListing(packageDoc.interfaces(),
127 getResource("doclet.Interfaces"), contentTree);
128 addClassKindListing(packageDoc.ordinaryClasses(),
129 getResource("doclet.Classes"), contentTree);
130 addClassKindListing(packageDoc.enums(),
131 getResource("doclet.Enums"), contentTree);
132 addClassKindListing(packageDoc.exceptions(),
133 getResource("doclet.Exceptions"), contentTree);
134 addClassKindListing(packageDoc.errors(),
135 getResource("doclet.Errors"), contentTree);
136 addClassKindListing(packageDoc.annotationTypes(),
137 getResource("doclet.AnnotationTypes"), contentTree);
138 } else {
139 String name = Util.getPackageName(packageDoc);
140 addClassKindListing(config.classDocCatalog.interfaces(name),
141 getResource("doclet.Interfaces"), contentTree);
142 addClassKindListing(config.classDocCatalog.ordinaryClasses(name),
143 getResource("doclet.Classes"), contentTree);
144 addClassKindListing(config.classDocCatalog.enums(name),
145 getResource("doclet.Enums"), contentTree);
146 addClassKindListing(config.classDocCatalog.exceptions(name),
147 getResource("doclet.Exceptions"), contentTree);
148 addClassKindListing(config.classDocCatalog.errors(name),
149 getResource("doclet.Errors"), contentTree);
150 addClassKindListing(config.classDocCatalog.annotationTypes(name),
151 getResource("doclet.AnnotationTypes"), contentTree);
152 }
153 }
155 /**
156 * Add specific class kind listing. Also add label to the listing.
157 *
158 * @param arr Array of specific class kinds, namely Class or Interface or Exception or Error
159 * @param labelContent content tree of the label to be added
160 * @param contentTree the content tree to which the class kind listing will be added
161 */
162 protected void addClassKindListing(ClassDoc[] arr, Content labelContent,
163 Content contentTree) {
164 if(arr.length > 0) {
165 Arrays.sort(arr);
166 boolean printedHeader = false;
167 HtmlTree ul = new HtmlTree(HtmlTag.UL);
168 ul.addAttr(HtmlAttr.TITLE, labelContent.toString());
169 for (int i = 0; i < arr.length; i++) {
170 if (documentedClasses != null &&
171 !documentedClasses.contains(arr[i])) {
172 continue;
173 }
174 if (!Util.isCoreClass(arr[i]) || !
175 configuration.isGeneratedDoc(arr[i])) {
176 continue;
177 }
178 if (!printedHeader) {
179 Content heading = HtmlTree.HEADING(HtmlConstants.CONTENT_HEADING,
180 true, labelContent);
181 contentTree.addContent(heading);
182 printedHeader = true;
183 }
184 Content link = new RawHtml (getLink(new LinkInfoImpl(
185 LinkInfoImpl.PACKAGE_FRAME, arr[i],
186 (arr[i].isInterface() ? italicsText(arr[i].name()) :
187 arr[i].name()),"classFrame")));
188 Content li = HtmlTree.LI(link);
189 ul.addContent(li);
190 }
191 contentTree.addContent(ul);
192 }
193 }
194 }