Thu, 10 Oct 2013 10:51:15 -0700
8025633: Fix javadoc to generate valid anchor names
Reviewed-by: jjg
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 */
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 * Class to generate file for each profile package contents in the right-hand
39 * frame. This will list all the Class Kinds in the package. A click on any
40 * class-kind will update the 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 ProfilePackageWriterImpl extends HtmlDocletWriter
50 implements ProfilePackageSummaryWriter {
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 profile package being documented.
64 */
65 protected PackageDoc packageDoc;
67 /**
68 * The name of the profile being documented.
69 */
70 protected String profileName;
72 /**
73 * The value of the profile being documented.
74 */
75 protected int profileValue;
77 /**
78 * Constructor to construct ProfilePackageWriter object and to generate
79 * "profilename-package-summary.html" file in the respective package directory.
80 * For example for profile compact1 and package "java.lang" this will generate file
81 * "compact1-package-summary.html" file in the "java/lang" directory. It will also
82 * create "java/lang" directory in the current or the destination directory
83 * if it doesn't exist.
84 *
85 * @param configuration the configuration of the doclet.
86 * @param packageDoc PackageDoc under consideration.
87 * @param prev Previous package in the sorted array.
88 * @param next Next package in the sorted array.
89 * @param profile The profile being documented.
90 */
91 public ProfilePackageWriterImpl(ConfigurationImpl configuration,
92 PackageDoc packageDoc, PackageDoc prev, PackageDoc next,
93 Profile profile) throws IOException {
94 super(configuration, DocPath.forPackage(packageDoc).resolve(
95 DocPaths.profilePackageSummary(profile.name)));
96 this.prev = prev;
97 this.next = next;
98 this.packageDoc = packageDoc;
99 this.profileName = profile.name;
100 this.profileValue = profile.value;
101 }
103 /**
104 * {@inheritDoc}
105 */
106 public Content getPackageHeader(String heading) {
107 String pkgName = packageDoc.name();
108 Content bodyTree = getBody(true, getWindowTitle(pkgName));
109 addTop(bodyTree);
110 addNavLinks(true, bodyTree);
111 HtmlTree div = new HtmlTree(HtmlTag.DIV);
112 div.addStyle(HtmlStyle.header);
113 Content profileContent = new StringContent(profileName);
114 Content profileNameDiv = HtmlTree.DIV(HtmlStyle.subTitle, profileContent);
115 div.addContent(profileNameDiv);
116 Content annotationContent = new HtmlTree(HtmlTag.P);
117 addAnnotationInfo(packageDoc, annotationContent);
118 div.addContent(annotationContent);
119 Content tHeading = HtmlTree.HEADING(HtmlConstants.TITLE_HEADING, true,
120 HtmlStyle.title, packageLabel);
121 tHeading.addContent(getSpace());
122 Content packageHead = new RawHtml(heading);
123 tHeading.addContent(packageHead);
124 div.addContent(tHeading);
125 addDeprecationInfo(div);
126 if (packageDoc.inlineTags().length > 0 && ! configuration.nocomment) {
127 HtmlTree docSummaryDiv = new HtmlTree(HtmlTag.DIV);
128 docSummaryDiv.addStyle(HtmlStyle.docSummary);
129 addSummaryComment(packageDoc, docSummaryDiv);
130 div.addContent(docSummaryDiv);
131 Content space = getSpace();
132 Content descLink = getHyperLink(getDocLink(
133 SectionName.PACKAGE_DESCRIPTION),
134 descriptionLabel, "", "");
135 Content descPara = new HtmlTree(HtmlTag.P, seeLabel, space, descLink);
136 div.addContent(descPara);
137 }
138 bodyTree.addContent(div);
139 return bodyTree;
140 }
142 /**
143 * {@inheritDoc}
144 */
145 public Content getContentHeader() {
146 HtmlTree div = new HtmlTree(HtmlTag.DIV);
147 div.addStyle(HtmlStyle.contentContainer);
148 return div;
149 }
151 /**
152 * Add the package deprecation information to the documentation tree.
153 *
154 * @param div the content tree to which the deprecation information will be added
155 */
156 public void addDeprecationInfo(Content div) {
157 Tag[] deprs = packageDoc.tags("deprecated");
158 if (Util.isDeprecated(packageDoc)) {
159 HtmlTree deprDiv = new HtmlTree(HtmlTag.DIV);
160 deprDiv.addStyle(HtmlStyle.deprecatedContent);
161 Content deprPhrase = HtmlTree.SPAN(HtmlStyle.strong, deprecatedPhrase);
162 deprDiv.addContent(deprPhrase);
163 if (deprs.length > 0) {
164 Tag[] commentTags = deprs[0].inlineTags();
165 if (commentTags.length > 0) {
166 addInlineDeprecatedComment(packageDoc, deprs[0], deprDiv);
167 }
168 }
169 div.addContent(deprDiv);
170 }
171 }
173 /**
174 * {@inheritDoc}
175 */
176 public void addClassesSummary(ClassDoc[] classes, String label,
177 String tableSummary, String[] tableHeader, Content packageSummaryContentTree) {
178 addClassesSummary(classes, label, tableSummary, tableHeader,
179 packageSummaryContentTree, profileValue);
180 }
182 /**
183 * {@inheritDoc}
184 */
185 public Content getSummaryHeader() {
186 HtmlTree ul = new HtmlTree(HtmlTag.UL);
187 ul.addStyle(HtmlStyle.blockList);
188 return ul;
189 }
191 /**
192 * {@inheritDoc}
193 */
194 public void addPackageDescription(Content packageContentTree) {
195 if (packageDoc.inlineTags().length > 0) {
196 packageContentTree.addContent(
197 getMarkerAnchor(SectionName.PACKAGE_DESCRIPTION));
198 Content h2Content = new StringContent(
199 configuration.getText("doclet.Package_Description",
200 packageDoc.name()));
201 packageContentTree.addContent(HtmlTree.HEADING(HtmlConstants.PACKAGE_HEADING,
202 true, h2Content));
203 addInlineComment(packageDoc, packageContentTree);
204 }
205 }
207 /**
208 * {@inheritDoc}
209 */
210 public void addPackageTags(Content packageContentTree) {
211 addTagsInfo(packageDoc, packageContentTree);
212 }
214 /**
215 * {@inheritDoc}
216 */
217 public void addPackageFooter(Content contentTree) {
218 addNavLinks(false, contentTree);
219 addBottom(contentTree);
220 }
222 /**
223 * {@inheritDoc}
224 */
225 public void printDocument(Content contentTree) throws IOException {
226 printHtmlDocument(configuration.metakeywords.getMetaKeywords(packageDoc),
227 true, contentTree);
228 }
230 /**
231 * Get "Use" link for this package in the navigation bar.
232 *
233 * @return a content tree for the class use link
234 */
235 protected Content getNavLinkClassUse() {
236 Content useLink = getHyperLink(DocPaths.PACKAGE_USE,
237 useLabel, "", "");
238 Content li = HtmlTree.LI(useLink);
239 return li;
240 }
242 /**
243 * Get "PREV PACKAGE" link in the navigation bar.
244 *
245 * @return a content tree for the previous link
246 */
247 public Content getNavLinkPrevious() {
248 Content li;
249 if (prev == null) {
250 li = HtmlTree.LI(prevpackageLabel);
251 } else {
252 DocPath path = DocPath.relativePath(packageDoc, prev);
253 li = HtmlTree.LI(getHyperLink(path.resolve(DocPaths.profilePackageSummary(profileName)),
254 prevpackageLabel, "", ""));
255 }
256 return li;
257 }
259 /**
260 * Get "NEXT PACKAGE" link in the navigation bar.
261 *
262 * @return a content tree for the next link
263 */
264 public Content getNavLinkNext() {
265 Content li;
266 if (next == null) {
267 li = HtmlTree.LI(nextpackageLabel);
268 } else {
269 DocPath path = DocPath.relativePath(packageDoc, next);
270 li = HtmlTree.LI(getHyperLink(path.resolve(DocPaths.profilePackageSummary(profileName)),
271 nextpackageLabel, "", ""));
272 }
273 return li;
274 }
276 /**
277 * Get "Tree" link in the navigation bar. This will be link to the package
278 * tree file.
279 *
280 * @return a content tree for the tree link
281 */
282 protected Content getNavLinkTree() {
283 Content useLink = getHyperLink(DocPaths.PACKAGE_TREE,
284 treeLabel, "", "");
285 Content li = HtmlTree.LI(useLink);
286 return li;
287 }
289 /**
290 * Highlight "Package" in the navigation bar, as this is the package page.
291 *
292 * @return a content tree for the package link
293 */
294 protected Content getNavLinkPackage() {
295 Content li = HtmlTree.LI(HtmlStyle.navBarCell1Rev, packageLabel);
296 return li;
297 }
298 }