src/share/classes/com/sun/tools/doclets/formats/html/ProfilePackageFrameWriter.java

changeset 0
959103a6100f
child 2525
2eb010b6cb22
equal deleted inserted replaced
-1:000000000000 0:959103a6100f
1 /*
2 * Copyright (c) 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 java.io.*;
29 import java.util.*;
30
31 import com.sun.javadoc.*;
32 import com.sun.tools.javac.jvm.Profile;
33 import com.sun.tools.doclets.formats.html.markup.*;
34 import com.sun.tools.doclets.internal.toolkit.*;
35 import com.sun.tools.doclets.internal.toolkit.util.*;
36
37 /**
38 * Class to generate file for each package contents of a profile in the left-hand bottom
39 * frame. This will list all the Class Kinds in the package for a profile. A click on any
40 * class-kind will update the right-hand frame with the clicked class-kind page.
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 * @author Bhavesh Patel
48 */
49 public class ProfilePackageFrameWriter extends HtmlDocletWriter {
50
51 /**
52 * The package being documented.
53 */
54 private PackageDoc packageDoc;
55
56 /**
57 * Constructor to construct ProfilePackageFrameWriter object and to generate
58 * "profilename-package-frame.html" file in the respective package directory.
59 * For example for profile compact1 and package "java.lang" this will generate file
60 * "compact1-package-frame.html" file in the "java/lang" directory. It will also
61 * create "java/lang" directory in the current or the destination directory
62 * if it doesn't exist.
63 *
64 * @param configuration the configuration of the doclet.
65 * @param packageDoc PackageDoc under consideration.
66 * @param profileName the name of the profile being documented
67 */
68 public ProfilePackageFrameWriter(ConfigurationImpl configuration,
69 PackageDoc packageDoc, String profileName)
70 throws IOException {
71 super(configuration, DocPath.forPackage(packageDoc).resolve(
72 DocPaths.profilePackageFrame(profileName)));
73 this.packageDoc = packageDoc;
74 }
75
76 /**
77 * Generate a profile package summary page for the left-hand bottom frame. Construct
78 * the ProfilePackageFrameWriter object and then uses it generate the file.
79 *
80 * @param configuration the current configuration of the doclet.
81 * @param packageDoc The package for which "profilename-package-frame.html" is to be generated.
82 * @param profileValue the value of the profile being documented
83 */
84 public static void generate(ConfigurationImpl configuration,
85 PackageDoc packageDoc, int profileValue) {
86 ProfilePackageFrameWriter profpackgen;
87 try {
88 String profileName = Profile.lookup(profileValue).name;
89 profpackgen = new ProfilePackageFrameWriter(configuration, packageDoc,
90 profileName);
91 StringBuilder winTitle = new StringBuilder(profileName);
92 String sep = " - ";
93 winTitle.append(sep);
94 String pkgName = Util.getPackageName(packageDoc);
95 winTitle.append(pkgName);
96 Content body = profpackgen.getBody(false,
97 profpackgen.getWindowTitle(winTitle.toString()));
98 Content profName = new StringContent(profileName);
99 Content sepContent = new StringContent(sep);
100 Content pkgNameContent = new RawHtml(pkgName);
101 Content heading = HtmlTree.HEADING(HtmlConstants.TITLE_HEADING, HtmlStyle.bar,
102 profpackgen.getTargetProfileLink("classFrame", profName, profileName));
103 heading.addContent(sepContent);
104 heading.addContent(profpackgen.getTargetProfilePackageLink(packageDoc,
105 "classFrame", pkgNameContent, profileName));
106 body.addContent(heading);
107 HtmlTree div = new HtmlTree(HtmlTag.DIV);
108 div.addStyle(HtmlStyle.indexContainer);
109 profpackgen.addClassListing(div, profileValue);
110 body.addContent(div);
111 profpackgen.printHtmlDocument(
112 configuration.metakeywords.getMetaKeywords(packageDoc), false, body);
113 profpackgen.close();
114 } catch (IOException exc) {
115 configuration.standardmessage.error(
116 "doclet.exception_encountered",
117 exc.toString(), DocPaths.PACKAGE_FRAME.getPath());
118 throw new DocletAbortException(exc);
119 }
120 }
121
122 /**
123 * Add class listing for all the classes in this package. Divide class
124 * listing as per the class kind and generate separate listing for
125 * Classes, Interfaces, Exceptions and Errors.
126 *
127 * @param contentTree the content tree to which the listing will be added
128 * @param profileValue the value of the profile being documented
129 */
130 protected void addClassListing(Content contentTree, int profileValue) {
131 if (packageDoc.isIncluded()) {
132 addClassKindListing(packageDoc.interfaces(),
133 getResource("doclet.Interfaces"), contentTree, profileValue);
134 addClassKindListing(packageDoc.ordinaryClasses(),
135 getResource("doclet.Classes"), contentTree, profileValue);
136 addClassKindListing(packageDoc.enums(),
137 getResource("doclet.Enums"), contentTree, profileValue);
138 addClassKindListing(packageDoc.exceptions(),
139 getResource("doclet.Exceptions"), contentTree, profileValue);
140 addClassKindListing(packageDoc.errors(),
141 getResource("doclet.Errors"), contentTree, profileValue);
142 addClassKindListing(packageDoc.annotationTypes(),
143 getResource("doclet.AnnotationTypes"), contentTree, profileValue);
144 }
145 }
146
147 /**
148 * Add specific class kind listing. Also add label to the listing.
149 *
150 * @param arr Array of specific class kinds, namely Class or Interface or Exception or Error
151 * @param labelContent content tree of the label to be added
152 * @param contentTree the content tree to which the class kind listing will be added
153 * @param profileValue the value of the profile being documented
154 */
155 protected void addClassKindListing(ClassDoc[] arr, Content labelContent,
156 Content contentTree, int profileValue) {
157 if(arr.length > 0) {
158 Arrays.sort(arr);
159 boolean printedHeader = false;
160 HtmlTree ul = new HtmlTree(HtmlTag.UL);
161 ul.setTitle(labelContent);
162 for (int i = 0; i < arr.length; i++) {
163 if (!isTypeInProfile(arr[i], profileValue)) {
164 continue;
165 }
166 if (!Util.isCoreClass(arr[i]) || !
167 configuration.isGeneratedDoc(arr[i])) {
168 continue;
169 }
170 if (!printedHeader) {
171 Content heading = HtmlTree.HEADING(HtmlConstants.CONTENT_HEADING,
172 true, labelContent);
173 contentTree.addContent(heading);
174 printedHeader = true;
175 }
176 Content arr_i_name = new StringContent(arr[i].name());
177 if (arr[i].isInterface()) arr_i_name = HtmlTree.SPAN(HtmlStyle.interfaceName, arr_i_name);
178 Content link = getLink(new LinkInfoImpl(configuration,
179 LinkInfoImpl.Kind.PACKAGE_FRAME, arr[i]).label(arr_i_name).target("classFrame"));
180 Content li = HtmlTree.LI(link);
181 ul.addContent(li);
182 }
183 contentTree.addContent(ul);
184 }
185 }
186 }

mercurial