aoqi@0: /* aoqi@0: * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. Oracle designates this aoqi@0: * particular file as subject to the "Classpath" exception as provided aoqi@0: * by Oracle in the LICENSE file that accompanied this code. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: */ aoqi@0: aoqi@0: package com.sun.tools.doclets.formats.html; aoqi@0: aoqi@0: import java.io.*; aoqi@0: import java.util.*; aoqi@0: aoqi@0: import com.sun.javadoc.*; aoqi@0: import com.sun.tools.doclets.formats.html.markup.*; aoqi@0: import com.sun.tools.doclets.internal.toolkit.*; aoqi@0: import com.sun.tools.doclets.internal.toolkit.util.*; aoqi@0: aoqi@0: /** aoqi@0: * Class to generate file for each package contents in the right-hand aoqi@0: * frame. This will list all the Class Kinds in the package. A click on any aoqi@0: * class-kind will update the frame with the clicked class-kind page. aoqi@0: * aoqi@0: *

This is NOT part of any supported API. aoqi@0: * If you write code that depends on this, you do so at your own risk. aoqi@0: * This code and its internal interfaces are subject to change or aoqi@0: * deletion without notice. aoqi@0: * aoqi@0: * @author Atul M Dambalkar aoqi@0: * @author Bhavesh Patel (Modified) aoqi@0: */ aoqi@0: public class PackageWriterImpl extends HtmlDocletWriter aoqi@0: implements PackageSummaryWriter { aoqi@0: aoqi@0: /** aoqi@0: * The prev package name in the alpha-order list. aoqi@0: */ aoqi@0: protected PackageDoc prev; aoqi@0: aoqi@0: /** aoqi@0: * The next package name in the alpha-order list. aoqi@0: */ aoqi@0: protected PackageDoc next; aoqi@0: aoqi@0: /** aoqi@0: * The package being documented. aoqi@0: */ aoqi@0: protected PackageDoc packageDoc; aoqi@0: aoqi@0: /** aoqi@0: * Constructor to construct PackageWriter object and to generate aoqi@0: * "package-summary.html" file in the respective package directory. aoqi@0: * For example for package "java.lang" this will generate file aoqi@0: * "package-summary.html" file in the "java/lang" directory. It will also aoqi@0: * create "java/lang" directory in the current or the destination directory aoqi@0: * if it doesn't exist. aoqi@0: * aoqi@0: * @param configuration the configuration of the doclet. aoqi@0: * @param packageDoc PackageDoc under consideration. aoqi@0: * @param prev Previous package in the sorted array. aoqi@0: * @param next Next package in the sorted array. aoqi@0: */ aoqi@0: public PackageWriterImpl(ConfigurationImpl configuration, aoqi@0: PackageDoc packageDoc, PackageDoc prev, PackageDoc next) aoqi@0: throws IOException { aoqi@0: super(configuration, DocPath.forPackage(packageDoc).resolve(DocPaths.PACKAGE_SUMMARY)); aoqi@0: this.prev = prev; aoqi@0: this.next = next; aoqi@0: this.packageDoc = packageDoc; aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * {@inheritDoc} aoqi@0: */ aoqi@0: public Content getPackageHeader(String heading) { aoqi@0: String pkgName = packageDoc.name(); aoqi@0: Content bodyTree = getBody(true, getWindowTitle(pkgName)); aoqi@0: addTop(bodyTree); aoqi@0: addNavLinks(true, bodyTree); aoqi@0: HtmlTree div = new HtmlTree(HtmlTag.DIV); aoqi@0: div.addStyle(HtmlStyle.header); aoqi@0: Content annotationContent = new HtmlTree(HtmlTag.P); aoqi@0: addAnnotationInfo(packageDoc, annotationContent); aoqi@0: div.addContent(annotationContent); aoqi@0: Content tHeading = HtmlTree.HEADING(HtmlConstants.TITLE_HEADING, true, aoqi@0: HtmlStyle.title, packageLabel); aoqi@0: tHeading.addContent(getSpace()); aoqi@0: Content packageHead = new StringContent(heading); aoqi@0: tHeading.addContent(packageHead); aoqi@0: div.addContent(tHeading); aoqi@0: addDeprecationInfo(div); aoqi@0: if (packageDoc.inlineTags().length > 0 && ! configuration.nocomment) { aoqi@0: HtmlTree docSummaryDiv = new HtmlTree(HtmlTag.DIV); aoqi@0: docSummaryDiv.addStyle(HtmlStyle.docSummary); aoqi@0: addSummaryComment(packageDoc, docSummaryDiv); aoqi@0: div.addContent(docSummaryDiv); aoqi@0: Content space = getSpace(); aoqi@0: Content descLink = getHyperLink(getDocLink( aoqi@0: SectionName.PACKAGE_DESCRIPTION), aoqi@0: descriptionLabel, "", ""); aoqi@0: Content descPara = new HtmlTree(HtmlTag.P, seeLabel, space, descLink); aoqi@0: div.addContent(descPara); aoqi@0: } aoqi@0: bodyTree.addContent(div); aoqi@0: return bodyTree; aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * {@inheritDoc} aoqi@0: */ aoqi@0: public Content getContentHeader() { aoqi@0: HtmlTree div = new HtmlTree(HtmlTag.DIV); aoqi@0: div.addStyle(HtmlStyle.contentContainer); aoqi@0: return div; aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Add the package deprecation information to the documentation tree. aoqi@0: * aoqi@0: * @param div the content tree to which the deprecation information will be added aoqi@0: */ aoqi@0: public void addDeprecationInfo(Content div) { aoqi@0: Tag[] deprs = packageDoc.tags("deprecated"); aoqi@0: if (Util.isDeprecated(packageDoc)) { aoqi@0: HtmlTree deprDiv = new HtmlTree(HtmlTag.DIV); aoqi@0: deprDiv.addStyle(HtmlStyle.deprecatedContent); aoqi@0: Content deprPhrase = HtmlTree.SPAN(HtmlStyle.deprecatedLabel, deprecatedPhrase); aoqi@0: deprDiv.addContent(deprPhrase); aoqi@0: if (deprs.length > 0) { aoqi@0: Tag[] commentTags = deprs[0].inlineTags(); aoqi@0: if (commentTags.length > 0) { aoqi@0: addInlineDeprecatedComment(packageDoc, deprs[0], deprDiv); aoqi@0: } aoqi@0: } aoqi@0: div.addContent(deprDiv); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * {@inheritDoc} aoqi@0: */ aoqi@0: public Content getSummaryHeader() { aoqi@0: HtmlTree ul = new HtmlTree(HtmlTag.UL); aoqi@0: ul.addStyle(HtmlStyle.blockList); aoqi@0: return ul; aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * {@inheritDoc} aoqi@0: */ aoqi@0: public void addClassesSummary(ClassDoc[] classes, String label, aoqi@0: String tableSummary, String[] tableHeader, Content summaryContentTree) { aoqi@0: if(classes.length > 0) { aoqi@0: Arrays.sort(classes); aoqi@0: Content caption = getTableCaption(new RawHtml(label)); aoqi@0: Content table = HtmlTree.TABLE(HtmlStyle.typeSummary, 0, 3, 0, aoqi@0: tableSummary, caption); aoqi@0: table.addContent(getSummaryTableHeader(tableHeader, "col")); aoqi@0: Content tbody = new HtmlTree(HtmlTag.TBODY); aoqi@0: for (int i = 0; i < classes.length; i++) { aoqi@0: if (!Util.isCoreClass(classes[i]) || aoqi@0: !configuration.isGeneratedDoc(classes[i])) { aoqi@0: continue; aoqi@0: } aoqi@0: Content classContent = getLink(new LinkInfoImpl( aoqi@0: configuration, LinkInfoImpl.Kind.PACKAGE, classes[i])); aoqi@0: Content tdClass = HtmlTree.TD(HtmlStyle.colFirst, classContent); aoqi@0: HtmlTree tr = HtmlTree.TR(tdClass); aoqi@0: if (i%2 == 0) aoqi@0: tr.addStyle(HtmlStyle.altColor); aoqi@0: else aoqi@0: tr.addStyle(HtmlStyle.rowColor); aoqi@0: HtmlTree tdClassDescription = new HtmlTree(HtmlTag.TD); aoqi@0: tdClassDescription.addStyle(HtmlStyle.colLast); aoqi@0: if (Util.isDeprecated(classes[i])) { aoqi@0: tdClassDescription.addContent(deprecatedLabel); aoqi@0: if (classes[i].tags("deprecated").length > 0) { aoqi@0: addSummaryDeprecatedComment(classes[i], aoqi@0: classes[i].tags("deprecated")[0], tdClassDescription); aoqi@0: } aoqi@0: } aoqi@0: else aoqi@0: addSummaryComment(classes[i], tdClassDescription); aoqi@0: tr.addContent(tdClassDescription); aoqi@0: tbody.addContent(tr); aoqi@0: } aoqi@0: table.addContent(tbody); aoqi@0: Content li = HtmlTree.LI(HtmlStyle.blockList, table); aoqi@0: summaryContentTree.addContent(li); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * {@inheritDoc} aoqi@0: */ aoqi@0: public void addPackageDescription(Content packageContentTree) { aoqi@0: if (packageDoc.inlineTags().length > 0) { aoqi@0: packageContentTree.addContent( aoqi@0: getMarkerAnchor(SectionName.PACKAGE_DESCRIPTION)); aoqi@0: Content h2Content = new StringContent( aoqi@0: configuration.getText("doclet.Package_Description", aoqi@0: packageDoc.name())); aoqi@0: packageContentTree.addContent(HtmlTree.HEADING(HtmlConstants.PACKAGE_HEADING, aoqi@0: true, h2Content)); aoqi@0: addInlineComment(packageDoc, packageContentTree); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * {@inheritDoc} aoqi@0: */ aoqi@0: public void addPackageTags(Content packageContentTree) { aoqi@0: addTagsInfo(packageDoc, packageContentTree); aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * {@inheritDoc} aoqi@0: */ aoqi@0: public void addPackageFooter(Content contentTree) { aoqi@0: addNavLinks(false, contentTree); aoqi@0: addBottom(contentTree); aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * {@inheritDoc} aoqi@0: */ aoqi@0: public void printDocument(Content contentTree) throws IOException { aoqi@0: printHtmlDocument(configuration.metakeywords.getMetaKeywords(packageDoc), aoqi@0: true, contentTree); aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Get "Use" link for this pacakge in the navigation bar. aoqi@0: * aoqi@0: * @return a content tree for the class use link aoqi@0: */ aoqi@0: protected Content getNavLinkClassUse() { aoqi@0: Content useLink = getHyperLink(DocPaths.PACKAGE_USE, aoqi@0: useLabel, "", ""); aoqi@0: Content li = HtmlTree.LI(useLink); aoqi@0: return li; aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Get "PREV PACKAGE" link in the navigation bar. aoqi@0: * aoqi@0: * @return a content tree for the previous link aoqi@0: */ aoqi@0: public Content getNavLinkPrevious() { aoqi@0: Content li; aoqi@0: if (prev == null) { aoqi@0: li = HtmlTree.LI(prevpackageLabel); aoqi@0: } else { aoqi@0: DocPath path = DocPath.relativePath(packageDoc, prev); aoqi@0: li = HtmlTree.LI(getHyperLink(path.resolve(DocPaths.PACKAGE_SUMMARY), aoqi@0: prevpackageLabel, "", "")); aoqi@0: } aoqi@0: return li; aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Get "NEXT PACKAGE" link in the navigation bar. aoqi@0: * aoqi@0: * @return a content tree for the next link aoqi@0: */ aoqi@0: public Content getNavLinkNext() { aoqi@0: Content li; aoqi@0: if (next == null) { aoqi@0: li = HtmlTree.LI(nextpackageLabel); aoqi@0: } else { aoqi@0: DocPath path = DocPath.relativePath(packageDoc, next); aoqi@0: li = HtmlTree.LI(getHyperLink(path.resolve(DocPaths.PACKAGE_SUMMARY), aoqi@0: nextpackageLabel, "", "")); aoqi@0: } aoqi@0: return li; aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Get "Tree" link in the navigation bar. This will be link to the package aoqi@0: * tree file. aoqi@0: * aoqi@0: * @return a content tree for the tree link aoqi@0: */ aoqi@0: protected Content getNavLinkTree() { aoqi@0: Content useLink = getHyperLink(DocPaths.PACKAGE_TREE, aoqi@0: treeLabel, "", ""); aoqi@0: Content li = HtmlTree.LI(useLink); aoqi@0: return li; aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Highlight "Package" in the navigation bar, as this is the package page. aoqi@0: * aoqi@0: * @return a content tree for the package link aoqi@0: */ aoqi@0: protected Content getNavLinkPackage() { aoqi@0: Content li = HtmlTree.LI(HtmlStyle.navBarCell1Rev, packageLabel); aoqi@0: return li; aoqi@0: } aoqi@0: }