langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/ModuleIndexFrameWriter.java
author jjg
Mon, 22 Aug 2016 16:32:40 -0700
changeset 40587 1c355ea550ed
parent 40303 96a1226aca18
child 45157 f5f796453339
permissions -rw-r--r--
8164130: Simplify doclet IOException handling Reviewed-by: bpatel, ksrini
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     1
/*
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     2
 * Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     4
 *
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    10
 *
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    15
 * accompanied this code).
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    16
 *
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    20
 *
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    23
 * questions.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    24
 */
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    25
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    26
package jdk.javadoc.internal.doclets.formats.html;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    27
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    28
import java.util.Map;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    29
import java.util.Set;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    30
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    31
import javax.lang.model.element.ModuleElement;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    32
import javax.lang.model.element.PackageElement;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    33
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    34
import jdk.javadoc.internal.doclets.formats.html.markup.HtmlConstants;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    35
import jdk.javadoc.internal.doclets.formats.html.markup.HtmlStyle;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    36
import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTag;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    37
import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTree;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    38
import jdk.javadoc.internal.doclets.formats.html.markup.RawHtml;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    39
import jdk.javadoc.internal.doclets.formats.html.markup.StringContent;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    40
import jdk.javadoc.internal.doclets.toolkit.Content;
40587
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40303
diff changeset
    41
import jdk.javadoc.internal.doclets.toolkit.util.DocFileIOException;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    42
import jdk.javadoc.internal.doclets.toolkit.util.DocPath;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    43
import jdk.javadoc.internal.doclets.toolkit.util.DocPaths;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    44
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    45
/**
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    46
 * Generate the module index for the left-hand frame in the generated output.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    47
 * A click on the module name in this frame will update the page in the top
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    48
 * left hand frame with the listing of packages of the clicked module.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    49
 *
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    50
 *  <p><b>This is NOT part of any supported API.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    51
 *  If you write code that depends on this, you do so at your own risk.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    52
 *  This code and its internal interfaces are subject to change or
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    53
 *  deletion without notice.</b>
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    54
 *
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    55
 * @author Bhavesh Patel
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    56
 */
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    57
public class ModuleIndexFrameWriter extends AbstractModuleIndexWriter {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    58
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    59
    /**
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    60
     * Construct the ModuleIndexFrameWriter object.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    61
     *
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    62
     * @param configuration the configuration object
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    63
     * @param filename Name of the module index file to be generated.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    64
     */
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    65
    public ModuleIndexFrameWriter(ConfigurationImpl configuration,
40587
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40303
diff changeset
    66
                                   DocPath filename) {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    67
        super(configuration, filename);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    68
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    69
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    70
    /**
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    71
     * Generate the module index file named "module-overview-frame.html".
40587
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40303
diff changeset
    72
     * @throws DocFileIOException
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    73
     * @param configuration the configuration object
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    74
     */
40587
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40303
diff changeset
    75
    public static void generate(ConfigurationImpl configuration) throws DocFileIOException {
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    76
        DocPath filename = DocPaths.MODULE_OVERVIEW_FRAME;
40587
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40303
diff changeset
    77
        ModuleIndexFrameWriter modulegen = new ModuleIndexFrameWriter(configuration, filename);
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40303
diff changeset
    78
        modulegen.buildModuleIndexFile("doclet.Window_Overview", false);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    79
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    80
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    81
    /**
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    82
     * {@inheritDoc}
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    83
     */
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    84
    protected void addModulesList(Map<ModuleElement, Set<PackageElement>> modules, String text,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    85
            String tableSummary, Content body) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    86
        Content heading = HtmlTree.HEADING(HtmlConstants.MODULE_HEADING, true,
40303
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents: 40229
diff changeset
    87
                contents.modulesLabel);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    88
        HtmlTree htmlTree = (configuration.allowTag(HtmlTag.MAIN))
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    89
                ? HtmlTree.MAIN(HtmlStyle.indexContainer, heading)
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    90
                : HtmlTree.DIV(HtmlStyle.indexContainer, heading);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    91
        HtmlTree ul = new HtmlTree(HtmlTag.UL);
40303
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents: 40229
diff changeset
    92
        ul.setTitle(contents.modulesLabel);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    93
        for (ModuleElement mdle: modules.keySet()) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    94
            ul.addContent(getModuleLink(mdle));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    95
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    96
        htmlTree.addContent(ul);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    97
        body.addContent(htmlTree);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    98
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
    99
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   100
    /**
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   101
     * Returns each module name as a separate link.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   102
     *
40229
09f4478d07e5 8154817: Fix the click-through navigation for modules
bpatel
parents: 36526
diff changeset
   103
     * @param mdle the module being documented
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   104
     * @return content for the module link
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   105
     */
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   106
    protected Content getModuleLink(ModuleElement mdle) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   107
        Content moduleLinkContent;
40229
09f4478d07e5 8154817: Fix the click-through navigation for modules
bpatel
parents: 36526
diff changeset
   108
        Content mdlLabel = new StringContent(mdle.getQualifiedName());
09f4478d07e5 8154817: Fix the click-through navigation for modules
bpatel
parents: 36526
diff changeset
   109
        moduleLinkContent = getModuleFramesHyperLink(mdle, mdlLabel, "packageListFrame");
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   110
        Content li = HtmlTree.LI(moduleLinkContent);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   111
        return li;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   112
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   113
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   114
    /**
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   115
     * {@inheritDoc}
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   116
     */
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   117
    protected void addNavigationBarHeader(Content body) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   118
        Content headerContent;
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   119
        if (configuration.packagesheader.length() > 0) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   120
            headerContent = new RawHtml(replaceDocRootDir(configuration.packagesheader));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   121
        } else {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   122
            headerContent = new RawHtml(replaceDocRootDir(configuration.header));
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   123
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   124
        Content heading = HtmlTree.HEADING(HtmlConstants.TITLE_HEADING, true,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   125
                HtmlStyle.bar, headerContent);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   126
        body.addContent(heading);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   127
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   128
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   129
    /**
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   130
     * Do nothing as there is no overview information in this page.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   131
     */
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   132
    protected void addOverviewHeader(Content body) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   133
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   134
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   135
    /**
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   136
     * Adds "All Classes" link for the top of the left-hand frame page to the
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   137
     * documentation tree.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   138
     *
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   139
     * @param ul the Content object to which the all classes link should be added
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   140
     */
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   141
    protected void addAllClassesLink(Content ul) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   142
        Content linkContent = getHyperLink(DocPaths.ALLCLASSES_FRAME,
40303
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents: 40229
diff changeset
   143
                contents.allClassesLabel, "", "packageFrame");
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   144
        Content li = HtmlTree.LI(linkContent);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   145
        ul.addContent(li);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   146
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   147
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   148
    /**
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   149
     * Adds "All Packages" link for the top of the left-hand frame page to the
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   150
     * documentation tree.
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   151
     *
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   152
     * @param ul the Content object to which the all packages link should be added
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   153
     */
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   154
    protected void addAllPackagesLink(Content ul) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   155
        Content linkContent = getHyperLink(DocPaths.OVERVIEW_FRAME,
40303
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents: 40229
diff changeset
   156
                contents.allPackagesLabel, "", "packageListFrame");
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   157
        Content li = HtmlTree.LI(linkContent);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   158
        ul.addContent(li);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   159
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   160
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   161
    /**
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   162
     * {@inheritDoc}
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   163
     */
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   164
    protected void addNavigationBarFooter(Content body) {
40303
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents: 40229
diff changeset
   165
        Content p = HtmlTree.P(Contents.SPACE);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   166
        body.addContent(p);
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   167
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   168
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   169
    protected void addModulePackagesList(Map<ModuleElement, Set<PackageElement>> modules, String text,
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   170
            String tableSummary, Content body, ModuleElement mdle) {
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   171
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents:
diff changeset
   172
}