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

Thu, 10 Oct 2013 10:51:15 -0700

author
bpatel
date
Thu, 10 Oct 2013 10:51:15 -0700
changeset 2101
933ba3f81a87
parent 2084
6e186ca11ec0
child 2147
130b8c0e570e
permissions
-rw-r--r--

8025633: Fix javadoc to generate valid anchor names
Reviewed-by: jjg

duke@1 1 /*
jjg@1735 2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
duke@1 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@1 4 *
duke@1 5 * This code is free software; you can redistribute it and/or modify it
duke@1 6 * under the terms of the GNU General Public License version 2 only, as
ohair@554 7 * published by the Free Software Foundation. Oracle designates this
duke@1 8 * particular file as subject to the "Classpath" exception as provided
ohair@554 9 * by Oracle in the LICENSE file that accompanied this code.
duke@1 10 *
duke@1 11 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@1 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@1 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@1 14 * version 2 for more details (a copy is included in the LICENSE file that
duke@1 15 * accompanied this code).
duke@1 16 *
duke@1 17 * You should have received a copy of the GNU General Public License version
duke@1 18 * 2 along with this work; if not, write to the Free Software Foundation,
duke@1 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@1 20 *
ohair@554 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ohair@554 22 * or visit www.oracle.com if you need additional information or have any
ohair@554 23 * questions.
duke@1 24 */
duke@1 25
duke@1 26 package com.sun.tools.doclets.formats.html;
duke@1 27
bpatel@766 28 import java.io.*;
bpatel@766 29 import java.util.*;
jjg@1357 30
bpatel@766 31 import com.sun.javadoc.*;
jjg@1357 32 import com.sun.tools.doclets.formats.html.markup.*;
duke@1 33 import com.sun.tools.doclets.internal.toolkit.*;
duke@1 34 import com.sun.tools.doclets.internal.toolkit.util.*;
duke@1 35
duke@1 36 /**
duke@1 37 * Class to generate file for each package contents in the right-hand
duke@1 38 * frame. This will list all the Class Kinds in the package. A click on any
duke@1 39 * class-kind will update the frame with the clicked class-kind page.
duke@1 40 *
jjg@1359 41 * <p><b>This is NOT part of any supported API.
jjg@1359 42 * If you write code that depends on this, you do so at your own risk.
jjg@1359 43 * This code and its internal interfaces are subject to change or
jjg@1359 44 * deletion without notice.</b>
jjg@1359 45 *
duke@1 46 * @author Atul M Dambalkar
bpatel@243 47 * @author Bhavesh Patel (Modified)
duke@1 48 */
duke@1 49 public class PackageWriterImpl extends HtmlDocletWriter
duke@1 50 implements PackageSummaryWriter {
duke@1 51
duke@1 52 /**
duke@1 53 * The prev package name in the alpha-order list.
duke@1 54 */
duke@1 55 protected PackageDoc prev;
duke@1 56
duke@1 57 /**
duke@1 58 * The next package name in the alpha-order list.
duke@1 59 */
duke@1 60 protected PackageDoc next;
duke@1 61
duke@1 62 /**
duke@1 63 * The package being documented.
duke@1 64 */
duke@1 65 protected PackageDoc packageDoc;
duke@1 66
duke@1 67 /**
duke@1 68 * Constructor to construct PackageWriter object and to generate
duke@1 69 * "package-summary.html" file in the respective package directory.
duke@1 70 * For example for package "java.lang" this will generate file
duke@1 71 * "package-summary.html" file in the "java/lang" directory. It will also
duke@1 72 * create "java/lang" directory in the current or the destination directory
jjg@1372 73 * if it doesn't exist.
duke@1 74 *
duke@1 75 * @param configuration the configuration of the doclet.
duke@1 76 * @param packageDoc PackageDoc under consideration.
duke@1 77 * @param prev Previous package in the sorted array.
duke@1 78 * @param next Next package in the sorted array.
duke@1 79 */
duke@1 80 public PackageWriterImpl(ConfigurationImpl configuration,
jjg@1372 81 PackageDoc packageDoc, PackageDoc prev, PackageDoc next)
jjg@1372 82 throws IOException {
jjg@1372 83 super(configuration, DocPath.forPackage(packageDoc).resolve(DocPaths.PACKAGE_SUMMARY));
duke@1 84 this.prev = prev;
duke@1 85 this.next = next;
duke@1 86 this.packageDoc = packageDoc;
duke@1 87 }
duke@1 88
duke@1 89 /**
duke@1 90 * {@inheritDoc}
duke@1 91 */
bpatel@766 92 public Content getPackageHeader(String heading) {
bpatel@766 93 String pkgName = packageDoc.name();
bpatel@766 94 Content bodyTree = getBody(true, getWindowTitle(pkgName));
bpatel@766 95 addTop(bodyTree);
bpatel@766 96 addNavLinks(true, bodyTree);
bpatel@766 97 HtmlTree div = new HtmlTree(HtmlTag.DIV);
bpatel@766 98 div.addStyle(HtmlStyle.header);
bpatel@766 99 Content annotationContent = new HtmlTree(HtmlTag.P);
bpatel@766 100 addAnnotationInfo(packageDoc, annotationContent);
bpatel@766 101 div.addContent(annotationContent);
bpatel@766 102 Content tHeading = HtmlTree.HEADING(HtmlConstants.TITLE_HEADING, true,
bpatel@766 103 HtmlStyle.title, packageLabel);
bpatel@766 104 tHeading.addContent(getSpace());
jjg@1746 105 Content packageHead = new StringContent(heading);
bpatel@766 106 tHeading.addContent(packageHead);
bpatel@766 107 div.addContent(tHeading);
bpatel@995 108 addDeprecationInfo(div);
bpatel@766 109 if (packageDoc.inlineTags().length > 0 && ! configuration.nocomment) {
bpatel@995 110 HtmlTree docSummaryDiv = new HtmlTree(HtmlTag.DIV);
bpatel@995 111 docSummaryDiv.addStyle(HtmlStyle.docSummary);
bpatel@995 112 addSummaryComment(packageDoc, docSummaryDiv);
bpatel@995 113 div.addContent(docSummaryDiv);
bpatel@766 114 Content space = getSpace();
bpatel@2101 115 Content descLink = getHyperLink(getDocLink(
bpatel@2101 116 SectionName.PACKAGE_DESCRIPTION),
bpatel@766 117 descriptionLabel, "", "");
bpatel@766 118 Content descPara = new HtmlTree(HtmlTag.P, seeLabel, space, descLink);
bpatel@766 119 div.addContent(descPara);
duke@1 120 }
bpatel@766 121 bodyTree.addContent(div);
bpatel@766 122 return bodyTree;
duke@1 123 }
duke@1 124
duke@1 125 /**
duke@1 126 * {@inheritDoc}
duke@1 127 */
bpatel@766 128 public Content getContentHeader() {
bpatel@766 129 HtmlTree div = new HtmlTree(HtmlTag.DIV);
bpatel@766 130 div.addStyle(HtmlStyle.contentContainer);
bpatel@766 131 return div;
bpatel@766 132 }
bpatel@766 133
bpatel@766 134 /**
bpatel@995 135 * Add the package deprecation information to the documentation tree.
bpatel@995 136 *
bpatel@995 137 * @param div the content tree to which the deprecation information will be added
bpatel@995 138 */
bpatel@995 139 public void addDeprecationInfo(Content div) {
bpatel@995 140 Tag[] deprs = packageDoc.tags("deprecated");
bpatel@995 141 if (Util.isDeprecated(packageDoc)) {
bpatel@995 142 HtmlTree deprDiv = new HtmlTree(HtmlTag.DIV);
bpatel@995 143 deprDiv.addStyle(HtmlStyle.deprecatedContent);
bpatel@995 144 Content deprPhrase = HtmlTree.SPAN(HtmlStyle.strong, deprecatedPhrase);
bpatel@995 145 deprDiv.addContent(deprPhrase);
bpatel@995 146 if (deprs.length > 0) {
bpatel@995 147 Tag[] commentTags = deprs[0].inlineTags();
bpatel@995 148 if (commentTags.length > 0) {
bpatel@995 149 addInlineDeprecatedComment(packageDoc, deprs[0], deprDiv);
bpatel@995 150 }
bpatel@995 151 }
bpatel@995 152 div.addContent(deprDiv);
bpatel@995 153 }
bpatel@995 154 }
bpatel@995 155
bpatel@995 156 /**
bpatel@766 157 * {@inheritDoc}
bpatel@766 158 */
bpatel@766 159 public Content getSummaryHeader() {
bpatel@766 160 HtmlTree ul = new HtmlTree(HtmlTag.UL);
bpatel@766 161 ul.addStyle(HtmlStyle.blockList);
bpatel@766 162 return ul;
bpatel@766 163 }
bpatel@766 164
bpatel@766 165 /**
bpatel@766 166 * {@inheritDoc}
bpatel@766 167 */
bpatel@766 168 public void addClassesSummary(ClassDoc[] classes, String label,
bpatel@766 169 String tableSummary, String[] tableHeader, Content summaryContentTree) {
bpatel@766 170 if(classes.length > 0) {
bpatel@766 171 Arrays.sort(classes);
jjg@1747 172 Content caption = getTableCaption(new RawHtml(label));
bpatel@2084 173 Content table = HtmlTree.TABLE(HtmlStyle.typeSummary, 0, 3, 0,
bpatel@766 174 tableSummary, caption);
bpatel@766 175 table.addContent(getSummaryTableHeader(tableHeader, "col"));
bpatel@766 176 Content tbody = new HtmlTree(HtmlTag.TBODY);
bpatel@766 177 for (int i = 0; i < classes.length; i++) {
bpatel@766 178 if (!Util.isCoreClass(classes[i]) ||
bpatel@766 179 !configuration.isGeneratedDoc(classes[i])) {
bpatel@766 180 continue;
bpatel@766 181 }
jjg@1736 182 Content classContent = getLink(new LinkInfoImpl(
jjg@1738 183 configuration, LinkInfoImpl.Kind.PACKAGE, classes[i]));
bpatel@766 184 Content tdClass = HtmlTree.TD(HtmlStyle.colFirst, classContent);
bpatel@766 185 HtmlTree tr = HtmlTree.TR(tdClass);
bpatel@766 186 if (i%2 == 0)
bpatel@766 187 tr.addStyle(HtmlStyle.altColor);
bpatel@766 188 else
bpatel@766 189 tr.addStyle(HtmlStyle.rowColor);
bpatel@766 190 HtmlTree tdClassDescription = new HtmlTree(HtmlTag.TD);
bpatel@766 191 tdClassDescription.addStyle(HtmlStyle.colLast);
bpatel@766 192 if (Util.isDeprecated(classes[i])) {
bpatel@766 193 tdClassDescription.addContent(deprecatedLabel);
bpatel@766 194 if (classes[i].tags("deprecated").length > 0) {
bpatel@766 195 addSummaryDeprecatedComment(classes[i],
bpatel@766 196 classes[i].tags("deprecated")[0], tdClassDescription);
bpatel@766 197 }
bpatel@766 198 }
bpatel@766 199 else
bpatel@766 200 addSummaryComment(classes[i], tdClassDescription);
bpatel@766 201 tr.addContent(tdClassDescription);
bpatel@766 202 tbody.addContent(tr);
bpatel@766 203 }
bpatel@766 204 table.addContent(tbody);
bpatel@766 205 Content li = HtmlTree.LI(HtmlStyle.blockList, table);
bpatel@766 206 summaryContentTree.addContent(li);
duke@1 207 }
duke@1 208 }
duke@1 209
duke@1 210 /**
duke@1 211 * {@inheritDoc}
duke@1 212 */
bpatel@766 213 public void addPackageDescription(Content packageContentTree) {
bpatel@766 214 if (packageDoc.inlineTags().length > 0) {
bpatel@2101 215 packageContentTree.addContent(
bpatel@2101 216 getMarkerAnchor(SectionName.PACKAGE_DESCRIPTION));
bpatel@766 217 Content h2Content = new StringContent(
bpatel@766 218 configuration.getText("doclet.Package_Description",
bpatel@766 219 packageDoc.name()));
bpatel@766 220 packageContentTree.addContent(HtmlTree.HEADING(HtmlConstants.PACKAGE_HEADING,
bpatel@766 221 true, h2Content));
bpatel@766 222 addInlineComment(packageDoc, packageContentTree);
duke@1 223 }
duke@1 224 }
duke@1 225
duke@1 226 /**
duke@1 227 * {@inheritDoc}
duke@1 228 */
bpatel@766 229 public void addPackageTags(Content packageContentTree) {
bpatel@766 230 addTagsInfo(packageDoc, packageContentTree);
duke@1 231 }
duke@1 232
duke@1 233 /**
bpatel@766 234 * {@inheritDoc}
duke@1 235 */
bpatel@766 236 public void addPackageFooter(Content contentTree) {
bpatel@766 237 addNavLinks(false, contentTree);
bpatel@766 238 addBottom(contentTree);
duke@1 239 }
duke@1 240
duke@1 241 /**
bpatel@766 242 * {@inheritDoc}
duke@1 243 */
jjg@1364 244 public void printDocument(Content contentTree) throws IOException {
bpatel@766 245 printHtmlDocument(configuration.metakeywords.getMetaKeywords(packageDoc),
bpatel@766 246 true, contentTree);
bpatel@766 247 }
bpatel@766 248
bpatel@766 249 /**
bpatel@766 250 * Get "Use" link for this pacakge in the navigation bar.
bpatel@766 251 *
bpatel@766 252 * @return a content tree for the class use link
bpatel@766 253 */
bpatel@766 254 protected Content getNavLinkClassUse() {
jjg@1373 255 Content useLink = getHyperLink(DocPaths.PACKAGE_USE,
bpatel@766 256 useLabel, "", "");
bpatel@766 257 Content li = HtmlTree.LI(useLink);
bpatel@766 258 return li;
bpatel@766 259 }
bpatel@766 260
bpatel@766 261 /**
bpatel@766 262 * Get "PREV PACKAGE" link in the navigation bar.
bpatel@766 263 *
bpatel@766 264 * @return a content tree for the previous link
bpatel@766 265 */
bpatel@766 266 public Content getNavLinkPrevious() {
bpatel@766 267 Content li;
duke@1 268 if (prev == null) {
bpatel@766 269 li = HtmlTree.LI(prevpackageLabel);
duke@1 270 } else {
jjg@1372 271 DocPath path = DocPath.relativePath(packageDoc, prev);
jjg@1373 272 li = HtmlTree.LI(getHyperLink(path.resolve(DocPaths.PACKAGE_SUMMARY),
bpatel@766 273 prevpackageLabel, "", ""));
duke@1 274 }
bpatel@766 275 return li;
duke@1 276 }
duke@1 277
duke@1 278 /**
bpatel@766 279 * Get "NEXT PACKAGE" link in the navigation bar.
bpatel@766 280 *
bpatel@766 281 * @return a content tree for the next link
duke@1 282 */
bpatel@766 283 public Content getNavLinkNext() {
bpatel@766 284 Content li;
duke@1 285 if (next == null) {
bpatel@766 286 li = HtmlTree.LI(nextpackageLabel);
duke@1 287 } else {
jjg@1372 288 DocPath path = DocPath.relativePath(packageDoc, next);
jjg@1373 289 li = HtmlTree.LI(getHyperLink(path.resolve(DocPaths.PACKAGE_SUMMARY),
bpatel@766 290 nextpackageLabel, "", ""));
duke@1 291 }
bpatel@766 292 return li;
duke@1 293 }
duke@1 294
duke@1 295 /**
bpatel@766 296 * Get "Tree" link in the navigation bar. This will be link to the package
duke@1 297 * tree file.
bpatel@766 298 *
bpatel@766 299 * @return a content tree for the tree link
duke@1 300 */
bpatel@766 301 protected Content getNavLinkTree() {
jjg@1373 302 Content useLink = getHyperLink(DocPaths.PACKAGE_TREE,
bpatel@766 303 treeLabel, "", "");
bpatel@766 304 Content li = HtmlTree.LI(useLink);
bpatel@766 305 return li;
duke@1 306 }
duke@1 307
duke@1 308 /**
duke@1 309 * Highlight "Package" in the navigation bar, as this is the package page.
bpatel@766 310 *
bpatel@766 311 * @return a content tree for the package link
duke@1 312 */
bpatel@766 313 protected Content getNavLinkPackage() {
bpatel@766 314 Content li = HtmlTree.LI(HtmlStyle.navBarCell1Rev, packageLabel);
bpatel@766 315 return li;
duke@1 316 }
duke@1 317 }

mercurial