src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/SingleIndexWriter.java
author hannesw
Wed, 27 Nov 2019 13:08:16 +0100
changeset 59294 48b88b9c11eb
parent 54610 a9ab154b1384
permissions -rw-r--r--
8223378: CSS solution for navbar problem with <a> elements is not ideal Reviewed-by: jjg
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
53863
d001808c57e8 8218998: Add metadata to generated API documentation files
jjg
parents: 53562
diff changeset
     2
 * Copyright (c) 1998, 2019, Oracle and/or its affiliates. All rights reserved.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
06bc494ca11e Initial load
duke
parents:
diff changeset
     4
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
06bc494ca11e Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 10
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 10
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    10
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
06bc494ca11e Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
06bc494ca11e Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
06bc494ca11e Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
06bc494ca11e Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
06bc494ca11e Initial load
duke
parents:
diff changeset
    16
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
06bc494ca11e Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
06bc494ca11e Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
06bc494ca11e Initial load
duke
parents:
diff changeset
    20
 *
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 10
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 10
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 10
diff changeset
    23
 * questions.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    24
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    25
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 33920
diff changeset
    26
package jdk.javadoc.internal.doclets.formats.html;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    27
54610
a9ab154b1384 8222669: Create and use new html.Entity class
jjg
parents: 54350
diff changeset
    28
import java.util.Set;
a9ab154b1384 8222669: Create and use new html.Entity class
jjg
parents: 54350
diff changeset
    29
import java.util.TreeSet;
14258
8d2148961366 8000663: clean up langtools imports
jjg
parents: 7681
diff changeset
    30
59294
48b88b9c11eb 8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents: 54610
diff changeset
    31
import jdk.javadoc.internal.doclets.formats.html.markup.BodyContents;
48b88b9c11eb 8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents: 54610
diff changeset
    32
import jdk.javadoc.internal.doclets.formats.html.markup.ContentBuilder;
54610
a9ab154b1384 8222669: Create and use new html.Entity class
jjg
parents: 54350
diff changeset
    33
import jdk.javadoc.internal.doclets.formats.html.markup.Entity;
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 33920
diff changeset
    34
import jdk.javadoc.internal.doclets.formats.html.markup.HtmlStyle;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 33920
diff changeset
    35
import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTag;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 33920
diff changeset
    36
import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTree;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 33920
diff changeset
    37
import jdk.javadoc.internal.doclets.formats.html.markup.StringContent;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 33920
diff changeset
    38
import jdk.javadoc.internal.doclets.toolkit.Content;
40587
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40303
diff changeset
    39
import jdk.javadoc.internal.doclets.toolkit.util.DocFileIOException;
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 33920
diff changeset
    40
import jdk.javadoc.internal.doclets.toolkit.util.DocPath;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 33920
diff changeset
    41
import jdk.javadoc.internal.doclets.toolkit.util.DocPaths;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 33920
diff changeset
    42
import jdk.javadoc.internal.doclets.toolkit.util.IndexBuilder;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 33920
diff changeset
    43
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    44
06bc494ca11e Initial load
duke
parents:
diff changeset
    45
/**
06bc494ca11e Initial load
duke
parents:
diff changeset
    46
 * Generate only one index file for all the Member Names with Indexing in
06bc494ca11e Initial load
duke
parents:
diff changeset
    47
 * Unicode Order. The name of the generated file is "index-all.html" and it is
06bc494ca11e Initial load
duke
parents:
diff changeset
    48
 * generated in current or the destination directory.
06bc494ca11e Initial load
duke
parents:
diff changeset
    49
 *
14260
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 14258
diff changeset
    50
 *  <p><b>This is NOT part of any supported API.
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 14258
diff changeset
    51
 *  If you write code that depends on this, you do so at your own risk.
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 14258
diff changeset
    52
 *  This code and its internal interfaces are subject to change or
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 14258
diff changeset
    53
 *  deletion without notice.</b>
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 14258
diff changeset
    54
 *
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    55
 * @see java.lang.Character
06bc494ca11e Initial load
duke
parents:
diff changeset
    56
 * @author Atul M Dambalkar
7614
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
    57
 * @author Bhavesh Patel (Modified)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    58
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    59
public class SingleIndexWriter extends AbstractIndexWriter {
06bc494ca11e Initial load
duke
parents:
diff changeset
    60
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 33920
diff changeset
    61
    private Set<Character> elements;
33920
bd731341c405 8141492: Implement search feature in javadoc
bpatel
parents: 29957
diff changeset
    62
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    63
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    64
     * Construct the SingleIndexWriter with filename "index-all.html" and the
06bc494ca11e Initial load
duke
parents:
diff changeset
    65
     * {@link IndexBuilder}
06bc494ca11e Initial load
duke
parents:
diff changeset
    66
     *
40587
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40303
diff changeset
    67
     * @param configuration the configuration for this doclet
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    68
     * @param filename     Name of the index file to be generated.
06bc494ca11e Initial load
duke
parents:
diff changeset
    69
     * @param indexbuilder Unicode based Index from {@link IndexBuilder}
06bc494ca11e Initial load
duke
parents:
diff changeset
    70
     */
45417
f7479ee8de69 8177848: Rename Configuration(Impl) classes
ksrini
parents: 40587
diff changeset
    71
    public SingleIndexWriter(HtmlConfiguration configuration,
14357
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents: 14260
diff changeset
    72
                             DocPath filename,
40587
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40303
diff changeset
    73
                             IndexBuilder indexbuilder) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    74
        super(configuration, filename, indexbuilder);
06bc494ca11e Initial load
duke
parents:
diff changeset
    75
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    76
06bc494ca11e Initial load
duke
parents:
diff changeset
    77
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    78
     * Generate single index file, for all Unicode characters.
06bc494ca11e Initial load
duke
parents:
diff changeset
    79
     *
40587
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40303
diff changeset
    80
     * @param configuration the configuration for this doclet
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    81
     * @param indexbuilder IndexBuilder built by {@link IndexBuilder}
40587
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40303
diff changeset
    82
     * @throws DocFileIOException if there is a problem generating the index
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    83
     */
45417
f7479ee8de69 8177848: Rename Configuration(Impl) classes
ksrini
parents: 40587
diff changeset
    84
    public static void generate(HtmlConfiguration configuration,
40587
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40303
diff changeset
    85
                                IndexBuilder indexbuilder) throws DocFileIOException {
14357
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents: 14260
diff changeset
    86
        DocPath filename = DocPaths.INDEX_ALL;
40587
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40303
diff changeset
    87
        SingleIndexWriter indexgen = new SingleIndexWriter(configuration,
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40303
diff changeset
    88
                                         filename, indexbuilder);
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40303
diff changeset
    89
        indexgen.generateIndexFile();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    90
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    91
06bc494ca11e Initial load
duke
parents:
diff changeset
    92
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    93
     * Generate the contents of each index file, with Header, Footer,
06bc494ca11e Initial load
duke
parents:
diff changeset
    94
     * Member Field, Method and Constructor Description.
40587
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40303
diff changeset
    95
     * @throws DocFileIOException if there is a problem generating the index
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    96
     */
40587
1c355ea550ed 8164130: Simplify doclet IOException handling
jjg
parents: 40303
diff changeset
    97
    protected void generateIndexFile() throws DocFileIOException {
52644
43efb4ca6d6c 8214139: Remove wrapper methods from {Base,Html}Configuration
jjg
parents: 50167
diff changeset
    98
        String title = resources.getText("doclet.Window_Single_Index");
54350
4f9772f4403d 8215599: Remove support for javadoc "frames" mode
pmuthuswamy
parents: 54060
diff changeset
    99
        HtmlTree body = getBody(getWindowTitle(title));
59294
48b88b9c11eb 8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents: 54610
diff changeset
   100
        Content headerContent = new ContentBuilder();
48b88b9c11eb 8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents: 54610
diff changeset
   101
        addTop(headerContent);
49551
0d4786e42471 8196200: Implement a navigation builder in javadoc
bpatel
parents: 47850
diff changeset
   102
        navBar.setUserHeader(getUserHeaderFooter(true));
59294
48b88b9c11eb 8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents: 54610
diff changeset
   103
        headerContent.add(navBar.getContent(true));
7614
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   104
        HtmlTree divTree = new HtmlTree(HtmlTag.DIV);
47846
4e78aba768f0 8190295: Introduce a new Table builder class
jjg
parents: 47216
diff changeset
   105
        divTree.setStyle(HtmlStyle.contentContainer);
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 33920
diff changeset
   106
        elements = new TreeSet<>(indexbuilder.getIndexMap().keySet());
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 33920
diff changeset
   107
        elements.addAll(configuration.tagSearchIndexKeys);
7614
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   108
        addLinksForIndexes(divTree);
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 33920
diff changeset
   109
        for (Character unicode : elements) {
33920
bd731341c405 8141492: Implement search feature in javadoc
bpatel
parents: 29957
diff changeset
   110
            if (configuration.tagSearchIndexMap.get(unicode) == null) {
bd731341c405 8141492: Implement search feature in javadoc
bpatel
parents: 29957
diff changeset
   111
                addContents(unicode, indexbuilder.getMemberList(unicode), divTree);
bd731341c405 8141492: Implement search feature in javadoc
bpatel
parents: 29957
diff changeset
   112
            } else if (indexbuilder.getMemberList(unicode) == null) {
bd731341c405 8141492: Implement search feature in javadoc
bpatel
parents: 29957
diff changeset
   113
                addSearchContents(unicode, configuration.tagSearchIndexMap.get(unicode), divTree);
bd731341c405 8141492: Implement search feature in javadoc
bpatel
parents: 29957
diff changeset
   114
            } else {
bd731341c405 8141492: Implement search feature in javadoc
bpatel
parents: 29957
diff changeset
   115
                addContents(unicode, indexbuilder.getMemberList(unicode),
bd731341c405 8141492: Implement search feature in javadoc
bpatel
parents: 29957
diff changeset
   116
                        configuration.tagSearchIndexMap.get(unicode), divTree);
bd731341c405 8141492: Implement search feature in javadoc
bpatel
parents: 29957
diff changeset
   117
            }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   118
        }
7614
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   119
        addLinksForIndexes(divTree);
53991
786825220790 8219801: Pages do not have <h1>
jjg
parents: 53880
diff changeset
   120
        HtmlTree footer = HtmlTree.FOOTER();
49551
0d4786e42471 8196200: Implement a navigation builder in javadoc
bpatel
parents: 47850
diff changeset
   121
        navBar.setUserFooter(getUserHeaderFooter(false));
54060
53a95878619f 8220202: Simplify/standardize method naming for HtmlTree
jjg
parents: 53991
diff changeset
   122
        footer.add(navBar.getContent(false));
53991
786825220790 8219801: Pages do not have <h1>
jjg
parents: 53880
diff changeset
   123
        addBottom(footer);
59294
48b88b9c11eb 8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents: 54610
diff changeset
   124
        body.add(new BodyContents()
48b88b9c11eb 8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents: 54610
diff changeset
   125
                .setHeader(headerContent)
48b88b9c11eb 8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents: 54610
diff changeset
   126
                .addMainContent(HtmlTree.DIV(HtmlStyle.header,
48b88b9c11eb 8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents: 54610
diff changeset
   127
                        HtmlTree.HEADING(Headings.PAGE_TITLE_HEADING,
48b88b9c11eb 8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents: 54610
diff changeset
   128
                                contents.getContent("doclet.Index"))))
48b88b9c11eb 8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents: 54610
diff changeset
   129
                .addMainContent(divTree)
48b88b9c11eb 8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents: 54610
diff changeset
   130
                .setFooter(footer)
48b88b9c11eb 8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents: 54610
diff changeset
   131
                .toContent());
33920
bd731341c405 8141492: Implement search feature in javadoc
bpatel
parents: 29957
diff changeset
   132
        createSearchIndexFiles();
53880
3f1e9372557f 8219497: Unused parameter in HtmlDocletWriter::printHtmlDocument
jjg
parents: 53863
diff changeset
   133
        printHtmlDocument(null, "index", body);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   134
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   135
06bc494ca11e Initial load
duke
parents:
diff changeset
   136
    /**
7614
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   137
     * Add links for all the Index Files per unicode character.
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   138
     *
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   139
     * @param contentTree the content tree to which the links for indexes will be added
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   140
     */
7614
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   141
    protected void addLinksForIndexes(Content contentTree) {
33920
bd731341c405 8141492: Implement search feature in javadoc
bpatel
parents: 29957
diff changeset
   142
        for (Object ch : elements) {
bd731341c405 8141492: Implement search feature in javadoc
bpatel
parents: 29957
diff changeset
   143
            String unicode = ch.toString();
54060
53a95878619f 8220202: Simplify/standardize method naming for HtmlTree
jjg
parents: 53991
diff changeset
   144
            contentTree.add(
47850
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents: 47846
diff changeset
   145
                    links.createLink(getNameForIndex(unicode),
33920
bd731341c405 8141492: Implement search feature in javadoc
bpatel
parents: 29957
diff changeset
   146
                            new StringContent(unicode)));
54610
a9ab154b1384 8222669: Create and use new html.Entity class
jjg
parents: 54350
diff changeset
   147
            contentTree.add(Entity.NO_BREAK_SPACE);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   148
        }
54060
53a95878619f 8220202: Simplify/standardize method naming for HtmlTree
jjg
parents: 53991
diff changeset
   149
        contentTree.add(new HtmlTree(HtmlTag.BR));
53a95878619f 8220202: Simplify/standardize method naming for HtmlTree
jjg
parents: 53991
diff changeset
   150
        contentTree.add(links.createLink(DocPaths.ALLCLASSES_INDEX,
50167
cc705c956798 8196201: Generate pages to list all classes and all packages in javadoc output
bpatel
parents: 49551
diff changeset
   151
                contents.allClassesLabel));
cc705c956798 8196201: Generate pages to list all classes and all packages in javadoc output
bpatel
parents: 49551
diff changeset
   152
        if (!configuration.packages.isEmpty()) {
54610
a9ab154b1384 8222669: Create and use new html.Entity class
jjg
parents: 54350
diff changeset
   153
            contentTree.add(Entity.NO_BREAK_SPACE);
54060
53a95878619f 8220202: Simplify/standardize method naming for HtmlTree
jjg
parents: 53991
diff changeset
   154
            contentTree.add(links.createLink(DocPaths.ALLPACKAGES_INDEX,
50167
cc705c956798 8196201: Generate pages to list all classes and all packages in javadoc output
bpatel
parents: 49551
diff changeset
   155
                    contents.allPackagesLabel));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   156
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   157
}
50167
cc705c956798 8196201: Generate pages to list all classes and all packages in javadoc output
bpatel
parents: 49551
diff changeset
   158
}