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

Wed, 10 Oct 2012 16:48:21 -0700

author
jjg
date
Wed, 10 Oct 2012 16:48:21 -0700
changeset 1359
25e14ad23cef
parent 1357
c75be5bc5283
child 1364
8db45b13526e
permissions
-rw-r--r--

8000665: fix "internal API" comments on javadoc files
Reviewed-by: darcy

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

mercurial