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.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.*;
37 /**
38 * Generate the package index page "overview-summary.html" for the right-hand
39 * frame. A click on the package name on this page will update the same frame
40 * with the "package-summary.html" file for the clicked package.
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 Atul M Dambalkar
48 * @author Bhavesh Patel (Modified)
49 */
50 public class PackageIndexWriter extends AbstractPackageIndexWriter {
52 /**
53 * Root of the program structure. Used for "overview" documentation.
54 */
55 private RootDoc root;
57 /**
58 * Map representing the group of packages as specified on the command line.
59 *
60 * @see Group
61 */
62 private Map<String,List<PackageDoc>> groupPackageMap;
64 /**
65 * List to store the order groups as specified on the command line.
66 */
67 private List<String> groupList;
69 /**
70 * Construct the PackageIndexWriter. Also constructs the grouping
71 * information as provided on the command line by "-group" option. Stores
72 * the order of groups specified by the user.
73 *
74 * @see Group
75 */
76 public PackageIndexWriter(ConfigurationImpl configuration,
77 DocPath filename)
78 throws IOException {
79 super(configuration, filename);
80 this.root = configuration.root;
81 groupPackageMap = configuration.group.groupPackages(packages);
82 groupList = configuration.group.getGroupList();
83 }
85 /**
86 * Generate the package index page for the right-hand frame.
87 *
88 * @param configuration the current configuration of the doclet.
89 */
90 public static void generate(ConfigurationImpl configuration) {
91 PackageIndexWriter packgen;
92 DocPath filename = DocPaths.OVERVIEW_SUMMARY;
93 try {
94 packgen = new PackageIndexWriter(configuration, filename);
95 packgen.buildPackageIndexFile("doclet.Window_Overview_Summary", true);
96 packgen.close();
97 } catch (IOException exc) {
98 configuration.standardmessage.error(
99 "doclet.exception_encountered",
100 exc.toString(), filename);
101 throw new DocletAbortException();
102 }
103 }
105 /**
106 * Depending upon the grouping information and their titles, add
107 * separate table indices for each package group.
108 *
109 * @param body the documentation tree to which the index will be added
110 */
111 protected void addIndex(Content body) {
112 for (int i = 0; i < groupList.size(); i++) {
113 String groupname = groupList.get(i);
114 List<PackageDoc> list = groupPackageMap.get(groupname);
115 if (list != null && list.size() > 0) {
116 addIndexContents(list.toArray(new PackageDoc[list.size()]),
117 groupname, configuration.getText("doclet.Member_Table_Summary",
118 groupname, configuration.getText("doclet.packages")), body);
119 }
120 }
121 }
123 /**
124 * {@inheritDoc}
125 */
126 protected void addProfilesList(String profileSummary, String profilesTableSummary,
127 Content body) {
128 Content table = HtmlTree.TABLE(HtmlStyle.overviewSummary, 0, 3, 0, profilesTableSummary,
129 getTableCaption(profileSummary));
130 table.addContent(getSummaryTableHeader(profileTableHeader, "col"));
131 Content tbody = new HtmlTree(HtmlTag.TBODY);
132 addProfilesList(tbody);
133 table.addContent(tbody);
134 Content div = HtmlTree.DIV(HtmlStyle.contentContainer, table);
135 body.addContent(div);
136 }
138 /**
139 * {@inheritDoc}
140 */
141 protected void addPackagesList(PackageDoc[] packages, String text,
142 String tableSummary, Content body) {
143 Content table = HtmlTree.TABLE(HtmlStyle.overviewSummary, 0, 3, 0, tableSummary,
144 getTableCaption(text));
145 table.addContent(getSummaryTableHeader(packageTableHeader, "col"));
146 Content tbody = new HtmlTree(HtmlTag.TBODY);
147 addPackagesList(packages, tbody);
148 table.addContent(tbody);
149 Content div = HtmlTree.DIV(HtmlStyle.contentContainer, table);
150 body.addContent(div);
151 }
153 /**
154 * Adds list of profiles in the index table. Generate link to each profile.
155 *
156 * @param tbody the documentation tree to which the list will be added
157 */
158 protected void addProfilesList(Content tbody) {
159 for (int i = 1; i < configuration.profiles.getProfileCount(); i++) {
160 String profileName = Profile.lookup(i).name;
161 Content profileLinkContent = getTargetProfileLink("classFrame",
162 new StringContent(profileName), profileName);
163 Content tdProfile = HtmlTree.TD(HtmlStyle.colFirst, profileLinkContent);
164 HtmlTree tdSummary = new HtmlTree(HtmlTag.TD);
165 tdSummary.addStyle(HtmlStyle.colLast);
166 tdSummary.addContent(getSpace());
167 HtmlTree tr = HtmlTree.TR(tdProfile);
168 tr.addContent(tdSummary);
169 if (i % 2 == 0) {
170 tr.addStyle(HtmlStyle.altColor);
171 } else {
172 tr.addStyle(HtmlStyle.rowColor);
173 }
174 tbody.addContent(tr);
175 }
176 }
178 /**
179 * Adds list of packages in the index table. Generate link to each package.
180 *
181 * @param packages Packages to which link is to be generated
182 * @param tbody the documentation tree to which the list will be added
183 */
184 protected void addPackagesList(PackageDoc[] packages, Content tbody) {
185 for (int i = 0; i < packages.length; i++) {
186 if (packages[i] != null && packages[i].name().length() > 0) {
187 if (configuration.nodeprecated && Util.isDeprecated(packages[i]))
188 continue;
189 Content packageLinkContent = getPackageLink(packages[i],
190 getPackageName(packages[i]));
191 Content tdPackage = HtmlTree.TD(HtmlStyle.colFirst, packageLinkContent);
192 HtmlTree tdSummary = new HtmlTree(HtmlTag.TD);
193 tdSummary.addStyle(HtmlStyle.colLast);
194 addSummaryComment(packages[i], tdSummary);
195 HtmlTree tr = HtmlTree.TR(tdPackage);
196 tr.addContent(tdSummary);
197 if (i%2 == 0)
198 tr.addStyle(HtmlStyle.altColor);
199 else
200 tr.addStyle(HtmlStyle.rowColor);
201 tbody.addContent(tr);
202 }
203 }
204 }
206 /**
207 * Adds the overview summary comment for this documentation. Add one line
208 * summary at the top of the page and generate a link to the description,
209 * which is added at the end of this page.
210 *
211 * @param body the documentation tree to which the overview header will be added
212 */
213 protected void addOverviewHeader(Content body) {
214 if (root.inlineTags().length > 0) {
215 HtmlTree subTitleDiv = new HtmlTree(HtmlTag.DIV);
216 subTitleDiv.addStyle(HtmlStyle.subTitle);
217 addSummaryComment(root, subTitleDiv);
218 Content div = HtmlTree.DIV(HtmlStyle.header, subTitleDiv);
219 Content see = seeLabel;
220 see.addContent(" ");
221 Content descPara = HtmlTree.P(see);
222 Content descLink = getHyperLink(DocLink.fragment("overview_description"),
223 descriptionLabel, "", "");
224 descPara.addContent(descLink);
225 div.addContent(descPara);
226 body.addContent(div);
227 }
228 }
230 /**
231 * Adds the overview comment as provided in the file specified by the
232 * "-overview" option on the command line.
233 *
234 * @param htmltree the documentation tree to which the overview comment will
235 * be added
236 */
237 protected void addOverviewComment(Content htmltree) {
238 if (root.inlineTags().length > 0) {
239 htmltree.addContent(getMarkerAnchor("overview_description"));
240 addInlineComment(root, htmltree);
241 }
242 }
244 /**
245 * Adds the tag information as provided in the file specified by the
246 * "-overview" option on the command line.
247 *
248 * @param body the documentation tree to which the overview will be added
249 */
250 protected void addOverview(Content body) throws IOException {
251 HtmlTree div = new HtmlTree(HtmlTag.DIV);
252 div.addStyle(HtmlStyle.contentContainer);
253 addOverviewComment(div);
254 addTagsInfo(root, div);
255 body.addContent(div);
256 }
258 /**
259 * Adds the top text (from the -top option), the upper
260 * navigation bar, and then the title (from the"-title"
261 * option), at the top of page.
262 *
263 * @body the documentation tree to which the navigation bar header will be added
264 */
265 protected void addNavigationBarHeader(Content body) {
266 addTop(body);
267 addNavLinks(true, body);
268 addConfigurationTitle(body);
269 }
271 /**
272 * Adds the lower navigation bar and the bottom text
273 * (from the -bottom option) at the bottom of page.
274 *
275 * @param body the documentation tree to which the navigation bar footer will be added
276 */
277 protected void addNavigationBarFooter(Content body) {
278 addNavLinks(false, body);
279 addBottom(body);
280 }
281 }