langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/PackageIndexWriter.java
changeset 40587 1c355ea550ed
parent 40500 f293dbb81a53
child 41157 b235a429089a
equal deleted inserted replaced
40519:e17429a7e843 40587:1c355ea550ed
    23  * questions.
    23  * questions.
    24  */
    24  */
    25 
    25 
    26 package jdk.javadoc.internal.doclets.formats.html;
    26 package jdk.javadoc.internal.doclets.formats.html;
    27 
    27 
    28 import java.io.*;
       
    29 import java.util.*;
    28 import java.util.*;
    30 
    29 
    31 import javax.lang.model.element.PackageElement;
    30 import javax.lang.model.element.PackageElement;
    32 
    31 
    33 import jdk.javadoc.doclet.DocletEnvironment;
       
    34 import jdk.javadoc.internal.doclets.formats.html.markup.ContentBuilder;
    32 import jdk.javadoc.internal.doclets.formats.html.markup.ContentBuilder;
    35 import jdk.javadoc.internal.doclets.formats.html.markup.HtmlStyle;
    33 import jdk.javadoc.internal.doclets.formats.html.markup.HtmlStyle;
    36 import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTag;
    34 import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTag;
    37 import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTree;
    35 import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTree;
    38 import jdk.javadoc.internal.doclets.formats.html.markup.RawHtml;
    36 import jdk.javadoc.internal.doclets.formats.html.markup.RawHtml;
    39 import jdk.javadoc.internal.doclets.toolkit.Content;
    37 import jdk.javadoc.internal.doclets.toolkit.Content;
    40 import jdk.javadoc.internal.doclets.toolkit.Messages;
    38 import jdk.javadoc.internal.doclets.toolkit.util.DocFileIOException;
    41 import jdk.javadoc.internal.doclets.toolkit.util.DocPath;
    39 import jdk.javadoc.internal.doclets.toolkit.util.DocPath;
    42 import jdk.javadoc.internal.doclets.toolkit.util.DocPaths;
    40 import jdk.javadoc.internal.doclets.toolkit.util.DocPaths;
    43 import jdk.javadoc.internal.doclets.toolkit.util.DocletAbortException;
       
    44 import jdk.javadoc.internal.doclets.toolkit.util.Group;
    41 import jdk.javadoc.internal.doclets.toolkit.util.Group;
    45 
    42 
    46 /**
    43 /**
    47  * Generate the package index page "overview-summary.html" for the right-hand
    44  * Generate the package index page "overview-summary.html" for the right-hand
    48  * frame. A click on the package name on this page will update the same frame
    45  * frame. A click on the package name on this page will update the same frame
    56  * @author Atul M Dambalkar
    53  * @author Atul M Dambalkar
    57  * @author Bhavesh Patel (Modified)
    54  * @author Bhavesh Patel (Modified)
    58  */
    55  */
    59 public class PackageIndexWriter extends AbstractPackageIndexWriter {
    56 public class PackageIndexWriter extends AbstractPackageIndexWriter {
    60 
    57 
    61     /**
       
    62      * Root of the program structure. Used for "overview" documentation.
       
    63      */
       
    64     private DocletEnvironment docEnv;
       
    65 
    58 
    66     /**
    59     /**
    67      * Map representing the group of packages as specified on the command line.
    60      * Map representing the group of packages as specified on the command line.
    68      *
    61      *
    69      * @see Group
    62      * @see Group
    70      */
    63      */
    71     private Map<String, SortedSet<PackageElement>> groupPackageMap;
    64     private final Map<String, SortedSet<PackageElement>> groupPackageMap;
    72 
    65 
    73     /**
    66     /**
    74      * List to store the order groups as specified on the command line.
    67      * List to store the order groups as specified on the command line.
    75      */
    68      */
    76     private List<String> groupList;
    69     private final List<String> groupList;
    77 
    70 
    78     /**
    71     /**
    79      * HTML tree for main tag.
    72      * HTML tree for main tag.
    80      */
    73      */
    81     private HtmlTree htmlTree = HtmlTree.MAIN();
    74     private final HtmlTree htmlTree = HtmlTree.MAIN();
    82 
    75 
    83     /**
    76     /**
    84      * Construct the PackageIndexWriter. Also constructs the grouping
    77      * Construct the PackageIndexWriter. Also constructs the grouping
    85      * information as provided on the command line by "-group" option. Stores
    78      * information as provided on the command line by "-group" option. Stores
    86      * the order of groups specified by the user.
    79      * the order of groups specified by the user.
    87      *
    80      *
       
    81      * @param configuration the configuration for this doclet
       
    82      * @param filename the path of the page to be generated
    88      * @see Group
    83      * @see Group
    89      */
    84      */
    90     public PackageIndexWriter(ConfigurationImpl configuration, DocPath filename) throws IOException {
    85     public PackageIndexWriter(ConfigurationImpl configuration, DocPath filename) {
    91         super(configuration, filename);
    86         super(configuration, filename);
    92         this.docEnv = configuration.docEnv;
       
    93         groupPackageMap = configuration.group.groupPackages(packages);
    87         groupPackageMap = configuration.group.groupPackages(packages);
    94         groupList = configuration.group.getGroupList();
    88         groupList = configuration.group.getGroupList();
    95     }
    89     }
    96 
    90 
    97     /**
    91     /**
    98      * Generate the package index page for the right-hand frame.
    92      * Generate the package index page for the right-hand frame.
    99      *
    93      *
   100      * @param configuration the current configuration of the doclet.
    94      * @param configuration the current configuration of the doclet.
   101      */
    95      * @throws DocFileIOException if there is a problem generating the package index page
   102     public static void generate(ConfigurationImpl configuration) {
    96      */
   103         PackageIndexWriter packgen;
    97     public static void generate(ConfigurationImpl configuration) throws DocFileIOException {
   104         DocPath filename = DocPaths.overviewSummary(configuration.frames);
    98         DocPath filename = DocPaths.overviewSummary(configuration.frames);
   105         try {
    99         PackageIndexWriter packgen = new PackageIndexWriter(configuration, filename);
   106             packgen = new PackageIndexWriter(configuration, filename);
   100         packgen.buildPackageIndexFile("doclet.Window_Overview_Summary", true);
   107             packgen.buildPackageIndexFile("doclet.Window_Overview_Summary", true);
       
   108         } catch (IOException exc) {
       
   109             Messages messages = configuration.getMessages();
       
   110             messages.error("doclet.exception_encountered",
       
   111                         exc.toString(), filename);
       
   112             throw new DocletAbortException(exc);
       
   113         }
       
   114     }
   101     }
   115 
   102 
   116     /**
   103     /**
   117      * Depending upon the grouping information and their titles, add
   104      * Depending upon the grouping information and their titles, add
   118      * separate table indices for each package group.
   105      * separate table indices for each package group.
   119      *
   106      *
   120      * @param body the documentation tree to which the index will be added
   107      * @param body the documentation tree to which the index will be added
   121      */
   108      */
       
   109     @Override
   122     protected void addIndex(Content body) {
   110     protected void addIndex(Content body) {
   123         for (String groupname : groupList) {
   111         for (String groupname : groupList) {
   124             SortedSet<PackageElement> list = groupPackageMap.get(groupname);
   112             SortedSet<PackageElement> list = groupPackageMap.get(groupname);
   125             if (list != null && !list.isEmpty()) {
   113             if (list != null && !list.isEmpty()) {
   126                 addIndexContents(list,
   114                 addIndexContents(list,
   131     }
   119     }
   132 
   120 
   133     /**
   121     /**
   134      * {@inheritDoc}
   122      * {@inheritDoc}
   135      */
   123      */
       
   124     @Override
   136     protected void addPackagesList(Collection<PackageElement> packages, String text,
   125     protected void addPackagesList(Collection<PackageElement> packages, String text,
   137             String tableSummary, Content body) {
   126             String tableSummary, Content body) {
   138         Content table = (configuration.isOutputHtml5())
   127         Content table = (configuration.isOutputHtml5())
   139                 ? HtmlTree.TABLE(HtmlStyle.overviewSummary, getTableCaption(new RawHtml(text)))
   128                 ? HtmlTree.TABLE(HtmlStyle.overviewSummary, getTableCaption(new RawHtml(text)))
   140                 : HtmlTree.TABLE(HtmlStyle.overviewSummary, tableSummary, getTableCaption(new RawHtml(text)));
   129                 : HtmlTree.TABLE(HtmlStyle.overviewSummary, tableSummary, getTableCaption(new RawHtml(text)));
   181      * summary at the top of the page and generate a link to the description,
   170      * summary at the top of the page and generate a link to the description,
   182      * which is added at the end of this page.
   171      * which is added at the end of this page.
   183      *
   172      *
   184      * @param body the documentation tree to which the overview header will be added
   173      * @param body the documentation tree to which the overview header will be added
   185      */
   174      */
       
   175     @Override
   186     protected void addOverviewHeader(Content body) {
   176     protected void addOverviewHeader(Content body) {
   187         addConfigurationTitle(body);
   177         addConfigurationTitle(body);
   188         if (!utils.getBody(configuration.overviewElement).isEmpty()) {
   178         if (!utils.getBody(configuration.overviewElement).isEmpty()) {
   189             HtmlTree subTitleDiv = new HtmlTree(HtmlTag.DIV);
   179             HtmlTree subTitleDiv = new HtmlTree(HtmlTag.DIV);
   190             subTitleDiv.addStyle(HtmlStyle.subTitle);
   180             subTitleDiv.addStyle(HtmlStyle.subTitle);
   225      * Adds the tag information as provided in the file specified by the
   215      * Adds the tag information as provided in the file specified by the
   226      * "-overview" option on the command line.
   216      * "-overview" option on the command line.
   227      *
   217      *
   228      * @param body the documentation tree to which the overview will be added
   218      * @param body the documentation tree to which the overview will be added
   229      */
   219      */
   230     protected void addOverview(Content body) throws IOException {
   220     @Override
       
   221     protected void addOverview(Content body) {
   231         HtmlTree div = new HtmlTree(HtmlTag.DIV);
   222         HtmlTree div = new HtmlTree(HtmlTag.DIV);
   232         div.addStyle(HtmlStyle.contentContainer);
   223         div.addStyle(HtmlStyle.contentContainer);
   233         addOverviewComment(div);
   224         addOverviewComment(div);
   234         if (configuration.allowTag(HtmlTag.MAIN)) {
   225         if (configuration.allowTag(HtmlTag.MAIN)) {
   235             htmlTree.addContent(div);
   226             htmlTree.addContent(div);
   244      * navigation bar, and then the title (from the"-title"
   235      * navigation bar, and then the title (from the"-title"
   245      * option), at the top of page.
   236      * option), at the top of page.
   246      *
   237      *
   247      * @param body the documentation tree to which the navigation bar header will be added
   238      * @param body the documentation tree to which the navigation bar header will be added
   248      */
   239      */
       
   240     @Override
   249     protected void addNavigationBarHeader(Content body) {
   241     protected void addNavigationBarHeader(Content body) {
   250         Content htmlTree = (configuration.allowTag(HtmlTag.HEADER))
   242         Content htmlTree = (configuration.allowTag(HtmlTag.HEADER))
   251                 ? HtmlTree.HEADER()
   243                 ? HtmlTree.HEADER()
   252                 : body;
   244                 : body;
   253         addTop(htmlTree);
   245         addTop(htmlTree);
   261      * Adds the lower navigation bar and the bottom text
   253      * Adds the lower navigation bar and the bottom text
   262      * (from the -bottom option) at the bottom of page.
   254      * (from the -bottom option) at the bottom of page.
   263      *
   255      *
   264      * @param body the documentation tree to which the navigation bar footer will be added
   256      * @param body the documentation tree to which the navigation bar footer will be added
   265      */
   257      */
       
   258     @Override
   266     protected void addNavigationBarFooter(Content body) {
   259     protected void addNavigationBarFooter(Content body) {
   267         Content htmlTree = (configuration.allowTag(HtmlTag.FOOTER))
   260         Content htmlTree = (configuration.allowTag(HtmlTag.FOOTER))
   268                 ? HtmlTree.FOOTER()
   261                 ? HtmlTree.FOOTER()
   269                 : body;
   262                 : body;
   270         addNavLinks(false, htmlTree);
   263         addNavLinks(false, htmlTree);