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

Thu, 10 Oct 2013 10:51:15 -0700

author
bpatel
date
Thu, 10 Oct 2013 10:51:15 -0700
changeset 2101
933ba3f81a87
parent 2023
cf37c3775397
child 2525
2eb010b6cb22
permissions
-rw-r--r--

8025633: Fix javadoc to generate valid anchor names
Reviewed-by: jjg

     1 /*
     2  * Copyright (c) 1997, 2013, 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.javac.jvm.Profile;
    33 import com.sun.tools.doclets.formats.html.markup.*;
    34 import com.sun.tools.doclets.internal.toolkit.*;
    35 import com.sun.tools.doclets.internal.toolkit.util.*;
    37 /**
    38  * Generate the package index page "overview-summary.html" for the right-hand
    39  * frame. A click on the package name on this page will update the same frame
    40  * with the "package-summary.html" file for the clicked package.
    41  *
    42  *  <p><b>This is NOT part of any supported API.
    43  *  If you write code that depends on this, you do so at your own risk.
    44  *  This code and its internal interfaces are subject to change or
    45  *  deletion without notice.</b>
    46  *
    47  * @author Atul M Dambalkar
    48  * @author Bhavesh Patel (Modified)
    49  */
    50 public class PackageIndexWriter extends AbstractPackageIndexWriter {
    52     /**
    53      * Root of the program structure. Used for "overview" documentation.
    54      */
    55     private RootDoc root;
    57     /**
    58      * Map representing the group of packages as specified on the command line.
    59      *
    60      * @see Group
    61      */
    62     private Map<String,List<PackageDoc>> groupPackageMap;
    64     /**
    65      * List to store the order groups as specified on the command line.
    66      */
    67     private List<String> groupList;
    69     /**
    70      * Construct the PackageIndexWriter. Also constructs the grouping
    71      * information as provided on the command line by "-group" option. Stores
    72      * the order of groups specified by the user.
    73      *
    74      * @see Group
    75      */
    76     public PackageIndexWriter(ConfigurationImpl configuration,
    77                               DocPath filename)
    78                        throws IOException {
    79         super(configuration, filename);
    80         this.root = configuration.root;
    81         groupPackageMap = configuration.group.groupPackages(packages);
    82         groupList = configuration.group.getGroupList();
    83     }
    85     /**
    86      * Generate the package index page for the right-hand frame.
    87      *
    88      * @param configuration the current configuration of the doclet.
    89      */
    90     public static void generate(ConfigurationImpl configuration) {
    91         PackageIndexWriter packgen;
    92         DocPath filename = DocPaths.OVERVIEW_SUMMARY;
    93         try {
    94             packgen = new PackageIndexWriter(configuration, filename);
    95             packgen.buildPackageIndexFile("doclet.Window_Overview_Summary", true);
    96             packgen.close();
    97         } catch (IOException exc) {
    98             configuration.standardmessage.error(
    99                         "doclet.exception_encountered",
   100                         exc.toString(), filename);
   101             throw new DocletAbortException(exc);
   102         }
   103     }
   105     /**
   106      * Depending upon the grouping information and their titles, add
   107      * separate table indices for each package group.
   108      *
   109      * @param body the documentation tree to which the index will be added
   110      */
   111     protected void addIndex(Content body) {
   112         for (int i = 0; i < groupList.size(); i++) {
   113         String groupname = groupList.get(i);
   114         List<PackageDoc> list = groupPackageMap.get(groupname);
   115             if (list != null && list.size() > 0) {
   116                 addIndexContents(list.toArray(new PackageDoc[list.size()]),
   117                         groupname, configuration.getText("doclet.Member_Table_Summary",
   118                         groupname, configuration.getText("doclet.packages")), body);
   119             }
   120         }
   121     }
   123     /**
   124      * {@inheritDoc}
   125      */
   126     protected void addProfilesList(Content profileSummary, Content body) {
   127         Content h2 = HtmlTree.HEADING(HtmlTag.H2, profileSummary);
   128         Content profilesDiv = HtmlTree.DIV(h2);
   129         Content ul = new HtmlTree(HtmlTag.UL);
   130         String profileName;
   131         for (int i = 1; i < configuration.profiles.getProfileCount(); i++) {
   132             profileName = Profile.lookup(i).name;
   133             // If the profile has valid packages to be documented, add it to the
   134             // profiles list on overview-summary.html page.
   135             if (configuration.shouldDocumentProfile(profileName)) {
   136                 Content profileLinkContent = getTargetProfileLink("classFrame",
   137                         new StringContent(profileName), profileName);
   138                 Content li = HtmlTree.LI(profileLinkContent);
   139                 ul.addContent(li);
   140             }
   141         }
   142         profilesDiv.addContent(ul);
   143         Content div = HtmlTree.DIV(HtmlStyle.contentContainer, profilesDiv);
   144         body.addContent(div);
   145     }
   147     /**
   148      * {@inheritDoc}
   149      */
   150     protected void addPackagesList(PackageDoc[] packages, String text,
   151             String tableSummary, Content body) {
   152         Content table = HtmlTree.TABLE(HtmlStyle.overviewSummary, 0, 3, 0, tableSummary,
   153                 getTableCaption(new RawHtml(text)));
   154         table.addContent(getSummaryTableHeader(packageTableHeader, "col"));
   155         Content tbody = new HtmlTree(HtmlTag.TBODY);
   156         addPackagesList(packages, tbody);
   157         table.addContent(tbody);
   158         Content div = HtmlTree.DIV(HtmlStyle.contentContainer, table);
   159         body.addContent(div);
   160     }
   162     /**
   163      * Adds list of packages in the index table. Generate link to each package.
   164      *
   165      * @param packages Packages to which link is to be generated
   166      * @param tbody the documentation tree to which the list will be added
   167      */
   168     protected void addPackagesList(PackageDoc[] packages, Content tbody) {
   169         for (int i = 0; i < packages.length; i++) {
   170             if (packages[i] != null && packages[i].name().length() > 0) {
   171                 if (configuration.nodeprecated && Util.isDeprecated(packages[i]))
   172                     continue;
   173                 Content packageLinkContent = getPackageLink(packages[i],
   174                         getPackageName(packages[i]));
   175                 Content tdPackage = HtmlTree.TD(HtmlStyle.colFirst, packageLinkContent);
   176                 HtmlTree tdSummary = new HtmlTree(HtmlTag.TD);
   177                 tdSummary.addStyle(HtmlStyle.colLast);
   178                 addSummaryComment(packages[i], tdSummary);
   179                 HtmlTree tr = HtmlTree.TR(tdPackage);
   180                 tr.addContent(tdSummary);
   181                 if (i%2 == 0)
   182                     tr.addStyle(HtmlStyle.altColor);
   183                 else
   184                     tr.addStyle(HtmlStyle.rowColor);
   185                 tbody.addContent(tr);
   186             }
   187         }
   188     }
   190     /**
   191      * Adds the overview summary comment for this documentation. Add one line
   192      * summary at the top of the page and generate a link to the description,
   193      * which is added at the end of this page.
   194      *
   195      * @param body the documentation tree to which the overview header will be added
   196      */
   197     protected void addOverviewHeader(Content body) {
   198         if (root.inlineTags().length > 0) {
   199             HtmlTree subTitleDiv = new HtmlTree(HtmlTag.DIV);
   200             subTitleDiv.addStyle(HtmlStyle.subTitle);
   201             addSummaryComment(root, subTitleDiv);
   202             Content div = HtmlTree.DIV(HtmlStyle.header, subTitleDiv);
   203             Content see = seeLabel;
   204             see.addContent(" ");
   205             Content descPara = HtmlTree.P(see);
   206             Content descLink = getHyperLink(getDocLink(
   207                     SectionName.OVERVIEW_DESCRIPTION),
   208                     descriptionLabel, "", "");
   209             descPara.addContent(descLink);
   210             div.addContent(descPara);
   211             body.addContent(div);
   212         }
   213     }
   215     /**
   216      * Adds the overview comment as provided in the file specified by the
   217      * "-overview" option on the command line.
   218      *
   219      * @param htmltree the documentation tree to which the overview comment will
   220      *                 be added
   221      */
   222     protected void addOverviewComment(Content htmltree) {
   223         if (root.inlineTags().length > 0) {
   224             htmltree.addContent(
   225                     getMarkerAnchor(SectionName.OVERVIEW_DESCRIPTION));
   226             addInlineComment(root, htmltree);
   227         }
   228     }
   230     /**
   231      * Adds the tag information as provided in the file specified by the
   232      * "-overview" option on the command line.
   233      *
   234      * @param body the documentation tree to which the overview will be added
   235      */
   236     protected void addOverview(Content body) throws IOException {
   237         HtmlTree div = new HtmlTree(HtmlTag.DIV);
   238         div.addStyle(HtmlStyle.contentContainer);
   239         addOverviewComment(div);
   240         addTagsInfo(root, div);
   241         body.addContent(div);
   242     }
   244     /**
   245      * Adds the top text (from the -top option), the upper
   246      * navigation bar, and then the title (from the"-title"
   247      * option), at the top of page.
   248      *
   249      * @body the documentation tree to which the navigation bar header will be added
   250      */
   251     protected void addNavigationBarHeader(Content body) {
   252         addTop(body);
   253         addNavLinks(true, body);
   254         addConfigurationTitle(body);
   255     }
   257     /**
   258      * Adds the lower navigation bar and the bottom text
   259      * (from the -bottom option) at the bottom of page.
   260      *
   261      * @param body the documentation tree to which the navigation bar footer will be added
   262      */
   263     protected void addNavigationBarFooter(Content body) {
   264         addNavLinks(false, body);
   265         addBottom(body);
   266     }
   267 }

mercurial