duke@1: /* jjg@1357: * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. duke@1: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@1: * duke@1: * This code is free software; you can redistribute it and/or modify it duke@1: * under the terms of the GNU General Public License version 2 only, as ohair@554: * published by the Free Software Foundation. Oracle designates this duke@1: * particular file as subject to the "Classpath" exception as provided ohair@554: * by Oracle in the LICENSE file that accompanied this code. duke@1: * duke@1: * This code is distributed in the hope that it will be useful, but WITHOUT duke@1: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@1: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@1: * version 2 for more details (a copy is included in the LICENSE file that duke@1: * accompanied this code). duke@1: * duke@1: * You should have received a copy of the GNU General Public License version duke@1: * 2 along with this work; if not, write to the Free Software Foundation, duke@1: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@1: * ohair@554: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA ohair@554: * or visit www.oracle.com if you need additional information or have any ohair@554: * questions. duke@1: */ duke@1: duke@1: package com.sun.tools.doclets.formats.html; duke@1: bpatel@766: import java.io.*; bpatel@766: import java.util.*; jjg@1357: bpatel@766: import com.sun.javadoc.*; jjg@1357: import com.sun.tools.doclets.formats.html.markup.*; duke@1: import com.sun.tools.doclets.internal.toolkit.*; duke@1: import com.sun.tools.doclets.internal.toolkit.util.*; duke@1: duke@1: /** duke@1: * Class to generate file for each package contents in the right-hand duke@1: * frame. This will list all the Class Kinds in the package. A click on any duke@1: * class-kind will update the frame with the clicked class-kind page. duke@1: * duke@1: * @author Atul M Dambalkar bpatel@243: * @author Bhavesh Patel (Modified) duke@1: */ duke@1: public class PackageWriterImpl extends HtmlDocletWriter duke@1: implements PackageSummaryWriter { duke@1: duke@1: /** duke@1: * The prev package name in the alpha-order list. duke@1: */ duke@1: protected PackageDoc prev; duke@1: duke@1: /** duke@1: * The next package name in the alpha-order list. duke@1: */ duke@1: protected PackageDoc next; duke@1: duke@1: /** duke@1: * The package being documented. duke@1: */ duke@1: protected PackageDoc packageDoc; duke@1: duke@1: /** duke@1: * The name of the output file. duke@1: */ duke@1: private static final String OUTPUT_FILE_NAME = "package-summary.html"; duke@1: duke@1: /** duke@1: * Constructor to construct PackageWriter object and to generate duke@1: * "package-summary.html" file in the respective package directory. duke@1: * For example for package "java.lang" this will generate file duke@1: * "package-summary.html" file in the "java/lang" directory. It will also duke@1: * create "java/lang" directory in the current or the destination directory duke@1: * if it doesen't exist. duke@1: * duke@1: * @param configuration the configuration of the doclet. duke@1: * @param packageDoc PackageDoc under consideration. duke@1: * @param prev Previous package in the sorted array. duke@1: * @param next Next package in the sorted array. duke@1: */ duke@1: public PackageWriterImpl(ConfigurationImpl configuration, duke@1: PackageDoc packageDoc, PackageDoc prev, PackageDoc next) duke@1: throws IOException { duke@1: super(configuration, DirectoryManager.getDirectoryPath(packageDoc), OUTPUT_FILE_NAME, duke@1: DirectoryManager.getRelativePath(packageDoc.name())); duke@1: this.prev = prev; duke@1: this.next = next; duke@1: this.packageDoc = packageDoc; duke@1: } duke@1: duke@1: /** duke@1: * Return the name of the output file. duke@1: * duke@1: * @return the name of the output file. duke@1: */ duke@1: public String getOutputFileName() { duke@1: return OUTPUT_FILE_NAME; duke@1: } duke@1: duke@1: /** duke@1: * {@inheritDoc} duke@1: */ bpatel@766: public Content getPackageHeader(String heading) { bpatel@766: String pkgName = packageDoc.name(); bpatel@766: Content bodyTree = getBody(true, getWindowTitle(pkgName)); bpatel@766: addTop(bodyTree); bpatel@766: addNavLinks(true, bodyTree); bpatel@766: HtmlTree div = new HtmlTree(HtmlTag.DIV); bpatel@766: div.addStyle(HtmlStyle.header); bpatel@766: Content annotationContent = new HtmlTree(HtmlTag.P); bpatel@766: addAnnotationInfo(packageDoc, annotationContent); bpatel@766: div.addContent(annotationContent); bpatel@766: Content tHeading = HtmlTree.HEADING(HtmlConstants.TITLE_HEADING, true, bpatel@766: HtmlStyle.title, packageLabel); bpatel@766: tHeading.addContent(getSpace()); bpatel@766: Content packageHead = new RawHtml(heading); bpatel@766: tHeading.addContent(packageHead); bpatel@766: div.addContent(tHeading); bpatel@995: addDeprecationInfo(div); bpatel@766: if (packageDoc.inlineTags().length > 0 && ! configuration.nocomment) { bpatel@995: HtmlTree docSummaryDiv = new HtmlTree(HtmlTag.DIV); bpatel@995: docSummaryDiv.addStyle(HtmlStyle.docSummary); bpatel@995: addSummaryComment(packageDoc, docSummaryDiv); bpatel@995: div.addContent(docSummaryDiv); bpatel@766: Content space = getSpace(); bpatel@766: Content descLink = getHyperLink("", "package_description", bpatel@766: descriptionLabel, "", ""); bpatel@766: Content descPara = new HtmlTree(HtmlTag.P, seeLabel, space, descLink); bpatel@766: div.addContent(descPara); duke@1: } bpatel@766: bodyTree.addContent(div); bpatel@766: return bodyTree; duke@1: } duke@1: duke@1: /** duke@1: * {@inheritDoc} duke@1: */ bpatel@766: public Content getContentHeader() { bpatel@766: HtmlTree div = new HtmlTree(HtmlTag.DIV); bpatel@766: div.addStyle(HtmlStyle.contentContainer); bpatel@766: return div; bpatel@766: } bpatel@766: bpatel@766: /** bpatel@995: * Add the package deprecation information to the documentation tree. bpatel@995: * bpatel@995: * @param div the content tree to which the deprecation information will be added bpatel@995: */ bpatel@995: public void addDeprecationInfo(Content div) { bpatel@995: Tag[] deprs = packageDoc.tags("deprecated"); bpatel@995: if (Util.isDeprecated(packageDoc)) { bpatel@995: HtmlTree deprDiv = new HtmlTree(HtmlTag.DIV); bpatel@995: deprDiv.addStyle(HtmlStyle.deprecatedContent); bpatel@995: Content deprPhrase = HtmlTree.SPAN(HtmlStyle.strong, deprecatedPhrase); bpatel@995: deprDiv.addContent(deprPhrase); bpatel@995: if (deprs.length > 0) { bpatel@995: Tag[] commentTags = deprs[0].inlineTags(); bpatel@995: if (commentTags.length > 0) { bpatel@995: addInlineDeprecatedComment(packageDoc, deprs[0], deprDiv); bpatel@995: } bpatel@995: } bpatel@995: div.addContent(deprDiv); bpatel@995: } bpatel@995: } bpatel@995: bpatel@995: /** bpatel@766: * {@inheritDoc} bpatel@766: */ bpatel@766: public Content getSummaryHeader() { bpatel@766: HtmlTree ul = new HtmlTree(HtmlTag.UL); bpatel@766: ul.addStyle(HtmlStyle.blockList); bpatel@766: return ul; bpatel@766: } bpatel@766: bpatel@766: /** bpatel@766: * {@inheritDoc} bpatel@766: */ bpatel@766: public void addClassesSummary(ClassDoc[] classes, String label, bpatel@766: String tableSummary, String[] tableHeader, Content summaryContentTree) { bpatel@766: if(classes.length > 0) { bpatel@766: Arrays.sort(classes); bpatel@766: Content caption = getTableCaption(label); bpatel@766: Content table = HtmlTree.TABLE(HtmlStyle.packageSummary, 0, 3, 0, bpatel@766: tableSummary, caption); bpatel@766: table.addContent(getSummaryTableHeader(tableHeader, "col")); bpatel@766: Content tbody = new HtmlTree(HtmlTag.TBODY); bpatel@766: for (int i = 0; i < classes.length; i++) { bpatel@766: if (!Util.isCoreClass(classes[i]) || bpatel@766: !configuration.isGeneratedDoc(classes[i])) { bpatel@766: continue; bpatel@766: } bpatel@766: Content classContent = new RawHtml(getLink(new LinkInfoImpl( bpatel@766: LinkInfoImpl.CONTEXT_PACKAGE, classes[i], false))); bpatel@766: Content tdClass = HtmlTree.TD(HtmlStyle.colFirst, classContent); bpatel@766: HtmlTree tr = HtmlTree.TR(tdClass); bpatel@766: if (i%2 == 0) bpatel@766: tr.addStyle(HtmlStyle.altColor); bpatel@766: else bpatel@766: tr.addStyle(HtmlStyle.rowColor); bpatel@766: HtmlTree tdClassDescription = new HtmlTree(HtmlTag.TD); bpatel@766: tdClassDescription.addStyle(HtmlStyle.colLast); bpatel@766: if (Util.isDeprecated(classes[i])) { bpatel@766: tdClassDescription.addContent(deprecatedLabel); bpatel@766: if (classes[i].tags("deprecated").length > 0) { bpatel@766: addSummaryDeprecatedComment(classes[i], bpatel@766: classes[i].tags("deprecated")[0], tdClassDescription); bpatel@766: } bpatel@766: } bpatel@766: else bpatel@766: addSummaryComment(classes[i], tdClassDescription); bpatel@766: tr.addContent(tdClassDescription); bpatel@766: tbody.addContent(tr); bpatel@766: } bpatel@766: table.addContent(tbody); bpatel@766: Content li = HtmlTree.LI(HtmlStyle.blockList, table); bpatel@766: summaryContentTree.addContent(li); duke@1: } duke@1: } duke@1: duke@1: /** duke@1: * {@inheritDoc} duke@1: */ bpatel@766: public void addPackageDescription(Content packageContentTree) { bpatel@766: if (packageDoc.inlineTags().length > 0) { bpatel@766: packageContentTree.addContent(getMarkerAnchor("package_description")); bpatel@766: Content h2Content = new StringContent( bpatel@766: configuration.getText("doclet.Package_Description", bpatel@766: packageDoc.name())); bpatel@766: packageContentTree.addContent(HtmlTree.HEADING(HtmlConstants.PACKAGE_HEADING, bpatel@766: true, h2Content)); bpatel@766: addInlineComment(packageDoc, packageContentTree); duke@1: } duke@1: } duke@1: duke@1: /** duke@1: * {@inheritDoc} duke@1: */ bpatel@766: public void addPackageTags(Content packageContentTree) { bpatel@766: addTagsInfo(packageDoc, packageContentTree); duke@1: } duke@1: duke@1: /** bpatel@766: * {@inheritDoc} duke@1: */ bpatel@766: public void addPackageFooter(Content contentTree) { bpatel@766: addNavLinks(false, contentTree); bpatel@766: addBottom(contentTree); duke@1: } duke@1: duke@1: /** bpatel@766: * {@inheritDoc} duke@1: */ bpatel@766: public void printDocument(Content contentTree) { bpatel@766: printHtmlDocument(configuration.metakeywords.getMetaKeywords(packageDoc), bpatel@766: true, contentTree); bpatel@766: } bpatel@766: bpatel@766: /** bpatel@766: * Get "Use" link for this pacakge in the navigation bar. bpatel@766: * bpatel@766: * @return a content tree for the class use link bpatel@766: */ bpatel@766: protected Content getNavLinkClassUse() { bpatel@766: Content useLink = getHyperLink("package-use.html", "", bpatel@766: useLabel, "", ""); bpatel@766: Content li = HtmlTree.LI(useLink); bpatel@766: return li; bpatel@766: } bpatel@766: bpatel@766: /** bpatel@766: * Get "PREV PACKAGE" link in the navigation bar. bpatel@766: * bpatel@766: * @return a content tree for the previous link bpatel@766: */ bpatel@766: public Content getNavLinkPrevious() { bpatel@766: Content li; duke@1: if (prev == null) { bpatel@766: li = HtmlTree.LI(prevpackageLabel); duke@1: } else { duke@1: String path = DirectoryManager.getRelativePath(packageDoc.name(), duke@1: prev.name()); bpatel@766: li = HtmlTree.LI(getHyperLink(path + "package-summary.html", "", bpatel@766: prevpackageLabel, "", "")); duke@1: } bpatel@766: return li; duke@1: } duke@1: duke@1: /** bpatel@766: * Get "NEXT PACKAGE" link in the navigation bar. bpatel@766: * bpatel@766: * @return a content tree for the next link duke@1: */ bpatel@766: public Content getNavLinkNext() { bpatel@766: Content li; duke@1: if (next == null) { bpatel@766: li = HtmlTree.LI(nextpackageLabel); duke@1: } else { duke@1: String path = DirectoryManager.getRelativePath(packageDoc.name(), duke@1: next.name()); bpatel@766: li = HtmlTree.LI(getHyperLink(path + "package-summary.html", "", bpatel@766: nextpackageLabel, "", "")); duke@1: } bpatel@766: return li; duke@1: } duke@1: duke@1: /** bpatel@766: * Get "Tree" link in the navigation bar. This will be link to the package duke@1: * tree file. bpatel@766: * bpatel@766: * @return a content tree for the tree link duke@1: */ bpatel@766: protected Content getNavLinkTree() { bpatel@766: Content useLink = getHyperLink("package-tree.html", "", bpatel@766: treeLabel, "", ""); bpatel@766: Content li = HtmlTree.LI(useLink); bpatel@766: return li; duke@1: } duke@1: duke@1: /** duke@1: * Highlight "Package" in the navigation bar, as this is the package page. bpatel@766: * bpatel@766: * @return a content tree for the package link duke@1: */ bpatel@766: protected Content getNavLinkPackage() { bpatel@766: Content li = HtmlTree.LI(HtmlStyle.navBarCell1Rev, packageLabel); bpatel@766: return li; duke@1: } duke@1: }