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

Fri, 05 Oct 2012 14:13:47 -0700

author
bpatel
date
Fri, 05 Oct 2012 14:13:47 -0700
changeset 1349
d604fd09480b
parent 995
62bc3775d5bb
child 1357
c75be5bc5283
permissions
-rw-r--r--

7132631: The help-doc.html generates an invalid link to constant-values.html
Reviewed-by: jjg

duke@1 1 /*
bpatel@943 2 * Copyright (c) 1997, 2011, 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.*;
bpatel@766 30 import com.sun.javadoc.*;
duke@1 31 import com.sun.tools.doclets.internal.toolkit.*;
duke@1 32 import com.sun.tools.doclets.internal.toolkit.util.*;
bpatel@766 33 import com.sun.tools.doclets.formats.html.markup.*;
duke@1 34
duke@1 35 /**
duke@1 36 * Class to generate file for each package contents in the right-hand
duke@1 37 * frame. This will list all the Class Kinds in the package. A click on any
duke@1 38 * class-kind will update the frame with the clicked class-kind page.
duke@1 39 *
duke@1 40 * @author Atul M Dambalkar
bpatel@243 41 * @author Bhavesh Patel (Modified)
duke@1 42 */
duke@1 43 public class PackageWriterImpl extends HtmlDocletWriter
duke@1 44 implements PackageSummaryWriter {
duke@1 45
duke@1 46 /**
duke@1 47 * The prev package name in the alpha-order list.
duke@1 48 */
duke@1 49 protected PackageDoc prev;
duke@1 50
duke@1 51 /**
duke@1 52 * The next package name in the alpha-order list.
duke@1 53 */
duke@1 54 protected PackageDoc next;
duke@1 55
duke@1 56 /**
duke@1 57 * The package being documented.
duke@1 58 */
duke@1 59 protected PackageDoc packageDoc;
duke@1 60
duke@1 61 /**
duke@1 62 * The name of the output file.
duke@1 63 */
duke@1 64 private static final String OUTPUT_FILE_NAME = "package-summary.html";
duke@1 65
duke@1 66 /**
duke@1 67 * Constructor to construct PackageWriter object and to generate
duke@1 68 * "package-summary.html" file in the respective package directory.
duke@1 69 * For example for package "java.lang" this will generate file
duke@1 70 * "package-summary.html" file in the "java/lang" directory. It will also
duke@1 71 * create "java/lang" directory in the current or the destination directory
duke@1 72 * if it doesen't exist.
duke@1 73 *
duke@1 74 * @param configuration the configuration of the doclet.
duke@1 75 * @param packageDoc PackageDoc under consideration.
duke@1 76 * @param prev Previous package in the sorted array.
duke@1 77 * @param next Next package in the sorted array.
duke@1 78 */
duke@1 79 public PackageWriterImpl(ConfigurationImpl configuration,
duke@1 80 PackageDoc packageDoc, PackageDoc prev, PackageDoc next)
duke@1 81 throws IOException {
duke@1 82 super(configuration, DirectoryManager.getDirectoryPath(packageDoc), OUTPUT_FILE_NAME,
duke@1 83 DirectoryManager.getRelativePath(packageDoc.name()));
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 * Return the name of the output file.
duke@1 91 *
duke@1 92 * @return the name of the output file.
duke@1 93 */
duke@1 94 public String getOutputFileName() {
duke@1 95 return OUTPUT_FILE_NAME;
duke@1 96 }
duke@1 97
duke@1 98 /**
duke@1 99 * {@inheritDoc}
duke@1 100 */
bpatel@766 101 public Content getPackageHeader(String heading) {
bpatel@766 102 String pkgName = packageDoc.name();
bpatel@766 103 Content bodyTree = getBody(true, getWindowTitle(pkgName));
bpatel@766 104 addTop(bodyTree);
bpatel@766 105 addNavLinks(true, bodyTree);
bpatel@766 106 HtmlTree div = new HtmlTree(HtmlTag.DIV);
bpatel@766 107 div.addStyle(HtmlStyle.header);
bpatel@766 108 Content annotationContent = new HtmlTree(HtmlTag.P);
bpatel@766 109 addAnnotationInfo(packageDoc, annotationContent);
bpatel@766 110 div.addContent(annotationContent);
bpatel@766 111 Content tHeading = HtmlTree.HEADING(HtmlConstants.TITLE_HEADING, true,
bpatel@766 112 HtmlStyle.title, packageLabel);
bpatel@766 113 tHeading.addContent(getSpace());
bpatel@766 114 Content packageHead = new RawHtml(heading);
bpatel@766 115 tHeading.addContent(packageHead);
bpatel@766 116 div.addContent(tHeading);
bpatel@995 117 addDeprecationInfo(div);
bpatel@766 118 if (packageDoc.inlineTags().length > 0 && ! configuration.nocomment) {
bpatel@995 119 HtmlTree docSummaryDiv = new HtmlTree(HtmlTag.DIV);
bpatel@995 120 docSummaryDiv.addStyle(HtmlStyle.docSummary);
bpatel@995 121 addSummaryComment(packageDoc, docSummaryDiv);
bpatel@995 122 div.addContent(docSummaryDiv);
bpatel@766 123 Content space = getSpace();
bpatel@766 124 Content descLink = getHyperLink("", "package_description",
bpatel@766 125 descriptionLabel, "", "");
bpatel@766 126 Content descPara = new HtmlTree(HtmlTag.P, seeLabel, space, descLink);
bpatel@766 127 div.addContent(descPara);
duke@1 128 }
bpatel@766 129 bodyTree.addContent(div);
bpatel@766 130 return bodyTree;
duke@1 131 }
duke@1 132
duke@1 133 /**
duke@1 134 * {@inheritDoc}
duke@1 135 */
bpatel@766 136 public Content getContentHeader() {
bpatel@766 137 HtmlTree div = new HtmlTree(HtmlTag.DIV);
bpatel@766 138 div.addStyle(HtmlStyle.contentContainer);
bpatel@766 139 return div;
bpatel@766 140 }
bpatel@766 141
bpatel@766 142 /**
bpatel@995 143 * Add the package deprecation information to the documentation tree.
bpatel@995 144 *
bpatel@995 145 * @param div the content tree to which the deprecation information will be added
bpatel@995 146 */
bpatel@995 147 public void addDeprecationInfo(Content div) {
bpatel@995 148 Tag[] deprs = packageDoc.tags("deprecated");
bpatel@995 149 if (Util.isDeprecated(packageDoc)) {
bpatel@995 150 HtmlTree deprDiv = new HtmlTree(HtmlTag.DIV);
bpatel@995 151 deprDiv.addStyle(HtmlStyle.deprecatedContent);
bpatel@995 152 Content deprPhrase = HtmlTree.SPAN(HtmlStyle.strong, deprecatedPhrase);
bpatel@995 153 deprDiv.addContent(deprPhrase);
bpatel@995 154 if (deprs.length > 0) {
bpatel@995 155 Tag[] commentTags = deprs[0].inlineTags();
bpatel@995 156 if (commentTags.length > 0) {
bpatel@995 157 addInlineDeprecatedComment(packageDoc, deprs[0], deprDiv);
bpatel@995 158 }
bpatel@995 159 }
bpatel@995 160 div.addContent(deprDiv);
bpatel@995 161 }
bpatel@995 162 }
bpatel@995 163
bpatel@995 164 /**
bpatel@766 165 * {@inheritDoc}
bpatel@766 166 */
bpatel@766 167 public Content getSummaryHeader() {
bpatel@766 168 HtmlTree ul = new HtmlTree(HtmlTag.UL);
bpatel@766 169 ul.addStyle(HtmlStyle.blockList);
bpatel@766 170 return ul;
bpatel@766 171 }
bpatel@766 172
bpatel@766 173 /**
bpatel@766 174 * {@inheritDoc}
bpatel@766 175 */
bpatel@766 176 public void addClassesSummary(ClassDoc[] classes, String label,
bpatel@766 177 String tableSummary, String[] tableHeader, Content summaryContentTree) {
bpatel@766 178 if(classes.length > 0) {
bpatel@766 179 Arrays.sort(classes);
bpatel@766 180 Content caption = getTableCaption(label);
bpatel@766 181 Content table = HtmlTree.TABLE(HtmlStyle.packageSummary, 0, 3, 0,
bpatel@766 182 tableSummary, caption);
bpatel@766 183 table.addContent(getSummaryTableHeader(tableHeader, "col"));
bpatel@766 184 Content tbody = new HtmlTree(HtmlTag.TBODY);
bpatel@766 185 for (int i = 0; i < classes.length; i++) {
bpatel@766 186 if (!Util.isCoreClass(classes[i]) ||
bpatel@766 187 !configuration.isGeneratedDoc(classes[i])) {
bpatel@766 188 continue;
bpatel@766 189 }
bpatel@766 190 Content classContent = new RawHtml(getLink(new LinkInfoImpl(
bpatel@766 191 LinkInfoImpl.CONTEXT_PACKAGE, classes[i], false)));
bpatel@766 192 Content tdClass = HtmlTree.TD(HtmlStyle.colFirst, classContent);
bpatel@766 193 HtmlTree tr = HtmlTree.TR(tdClass);
bpatel@766 194 if (i%2 == 0)
bpatel@766 195 tr.addStyle(HtmlStyle.altColor);
bpatel@766 196 else
bpatel@766 197 tr.addStyle(HtmlStyle.rowColor);
bpatel@766 198 HtmlTree tdClassDescription = new HtmlTree(HtmlTag.TD);
bpatel@766 199 tdClassDescription.addStyle(HtmlStyle.colLast);
bpatel@766 200 if (Util.isDeprecated(classes[i])) {
bpatel@766 201 tdClassDescription.addContent(deprecatedLabel);
bpatel@766 202 if (classes[i].tags("deprecated").length > 0) {
bpatel@766 203 addSummaryDeprecatedComment(classes[i],
bpatel@766 204 classes[i].tags("deprecated")[0], tdClassDescription);
bpatel@766 205 }
bpatel@766 206 }
bpatel@766 207 else
bpatel@766 208 addSummaryComment(classes[i], tdClassDescription);
bpatel@766 209 tr.addContent(tdClassDescription);
bpatel@766 210 tbody.addContent(tr);
bpatel@766 211 }
bpatel@766 212 table.addContent(tbody);
bpatel@766 213 Content li = HtmlTree.LI(HtmlStyle.blockList, table);
bpatel@766 214 summaryContentTree.addContent(li);
duke@1 215 }
duke@1 216 }
duke@1 217
duke@1 218 /**
duke@1 219 * {@inheritDoc}
duke@1 220 */
bpatel@766 221 public void addPackageDescription(Content packageContentTree) {
bpatel@766 222 if (packageDoc.inlineTags().length > 0) {
bpatel@766 223 packageContentTree.addContent(getMarkerAnchor("package_description"));
bpatel@766 224 Content h2Content = new StringContent(
bpatel@766 225 configuration.getText("doclet.Package_Description",
bpatel@766 226 packageDoc.name()));
bpatel@766 227 packageContentTree.addContent(HtmlTree.HEADING(HtmlConstants.PACKAGE_HEADING,
bpatel@766 228 true, h2Content));
bpatel@766 229 addInlineComment(packageDoc, packageContentTree);
duke@1 230 }
duke@1 231 }
duke@1 232
duke@1 233 /**
duke@1 234 * {@inheritDoc}
duke@1 235 */
bpatel@766 236 public void addPackageTags(Content packageContentTree) {
bpatel@766 237 addTagsInfo(packageDoc, packageContentTree);
duke@1 238 }
duke@1 239
duke@1 240 /**
bpatel@766 241 * {@inheritDoc}
duke@1 242 */
bpatel@766 243 public void addPackageFooter(Content contentTree) {
bpatel@766 244 addNavLinks(false, contentTree);
bpatel@766 245 addBottom(contentTree);
duke@1 246 }
duke@1 247
duke@1 248 /**
bpatel@766 249 * {@inheritDoc}
duke@1 250 */
bpatel@766 251 public void printDocument(Content contentTree) {
bpatel@766 252 printHtmlDocument(configuration.metakeywords.getMetaKeywords(packageDoc),
bpatel@766 253 true, contentTree);
bpatel@766 254 }
bpatel@766 255
bpatel@766 256 /**
bpatel@766 257 * Get "Use" link for this pacakge in the navigation bar.
bpatel@766 258 *
bpatel@766 259 * @return a content tree for the class use link
bpatel@766 260 */
bpatel@766 261 protected Content getNavLinkClassUse() {
bpatel@766 262 Content useLink = getHyperLink("package-use.html", "",
bpatel@766 263 useLabel, "", "");
bpatel@766 264 Content li = HtmlTree.LI(useLink);
bpatel@766 265 return li;
bpatel@766 266 }
bpatel@766 267
bpatel@766 268 /**
bpatel@766 269 * Get "PREV PACKAGE" link in the navigation bar.
bpatel@766 270 *
bpatel@766 271 * @return a content tree for the previous link
bpatel@766 272 */
bpatel@766 273 public Content getNavLinkPrevious() {
bpatel@766 274 Content li;
duke@1 275 if (prev == null) {
bpatel@766 276 li = HtmlTree.LI(prevpackageLabel);
duke@1 277 } else {
duke@1 278 String path = DirectoryManager.getRelativePath(packageDoc.name(),
duke@1 279 prev.name());
bpatel@766 280 li = HtmlTree.LI(getHyperLink(path + "package-summary.html", "",
bpatel@766 281 prevpackageLabel, "", ""));
duke@1 282 }
bpatel@766 283 return li;
duke@1 284 }
duke@1 285
duke@1 286 /**
bpatel@766 287 * Get "NEXT PACKAGE" link in the navigation bar.
bpatel@766 288 *
bpatel@766 289 * @return a content tree for the next link
duke@1 290 */
bpatel@766 291 public Content getNavLinkNext() {
bpatel@766 292 Content li;
duke@1 293 if (next == null) {
bpatel@766 294 li = HtmlTree.LI(nextpackageLabel);
duke@1 295 } else {
duke@1 296 String path = DirectoryManager.getRelativePath(packageDoc.name(),
duke@1 297 next.name());
bpatel@766 298 li = HtmlTree.LI(getHyperLink(path + "package-summary.html", "",
bpatel@766 299 nextpackageLabel, "", ""));
duke@1 300 }
bpatel@766 301 return li;
duke@1 302 }
duke@1 303
duke@1 304 /**
bpatel@766 305 * Get "Tree" link in the navigation bar. This will be link to the package
duke@1 306 * tree file.
bpatel@766 307 *
bpatel@766 308 * @return a content tree for the tree link
duke@1 309 */
bpatel@766 310 protected Content getNavLinkTree() {
bpatel@766 311 Content useLink = getHyperLink("package-tree.html", "",
bpatel@766 312 treeLabel, "", "");
bpatel@766 313 Content li = HtmlTree.LI(useLink);
bpatel@766 314 return li;
duke@1 315 }
duke@1 316
duke@1 317 /**
duke@1 318 * Highlight "Package" in the navigation bar, as this is the package page.
bpatel@766 319 *
bpatel@766 320 * @return a content tree for the package link
duke@1 321 */
bpatel@766 322 protected Content getNavLinkPackage() {
bpatel@766 323 Content li = HtmlTree.LI(HtmlStyle.navBarCell1Rev, packageLabel);
bpatel@766 324 return li;
duke@1 325 }
duke@1 326 }

mercurial