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

Thu, 13 Sep 2012 14:29:36 -0700

author
jjg
date
Thu, 13 Sep 2012 14:29:36 -0700
changeset 1326
30c36e23f154
parent 995
62bc3775d5bb
child 1357
c75be5bc5283
permissions
-rw-r--r--

7177970: fix issues in langtools doc comments
Reviewed-by: mcimadamore

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

mercurial