src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/Resources.java
author bpatel
Thu, 17 May 2018 12:59:53 -0700
changeset 50167 cc705c956798
parent 47216 71c04702a3d5
child 53562 0d9dee001667
permissions -rw-r--r--
8196201: Generate pages to list all classes and all packages in javadoc output Reviewed-by: jjg
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
40303
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
     1
/*
50167
cc705c956798 8196201: Generate pages to list all classes and all packages in javadoc output
bpatel
parents: 47216
diff changeset
     2
 * Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
40303
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
     4
 *
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    10
 *
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    15
 * accompanied this code).
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    16
 *
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    20
 *
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    23
 * questions.
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    24
 */
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    25
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    26
package jdk.javadoc.internal.doclets.toolkit;
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    27
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    28
import java.text.MessageFormat;
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    29
import java.util.Locale;
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    30
import java.util.MissingResourceException;
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    31
import java.util.ResourceBundle;
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    32
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    33
/**
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    34
 * Access to the localizable resources used by a doclet.
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    35
 * The resources are split across two resource bundles:
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    36
 * one that contains format-neutral strings common to
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    37
 * all supported formats, and one that contains strings
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    38
 * specific to the selected doclet, such as the standard
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    39
 * HTML doclet.
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    40
 */
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    41
public class Resources {
50167
cc705c956798 8196201: Generate pages to list all classes and all packages in javadoc output
bpatel
parents: 47216
diff changeset
    42
    public final String annotationTypeSummary;
cc705c956798 8196201: Generate pages to list all classes and all packages in javadoc output
bpatel
parents: 47216
diff changeset
    43
    public final String annotationTypeTableSummary;
cc705c956798 8196201: Generate pages to list all classes and all packages in javadoc output
bpatel
parents: 47216
diff changeset
    44
    public final String classSummary;
cc705c956798 8196201: Generate pages to list all classes and all packages in javadoc output
bpatel
parents: 47216
diff changeset
    45
    public final String classTableSummary;
45417
f7479ee8de69 8177848: Rename Configuration(Impl) classes
ksrini
parents: 40303
diff changeset
    46
    private final BaseConfiguration configuration;
40303
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    47
    private final String commonBundleName;
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    48
    private final String docletBundleName;
50167
cc705c956798 8196201: Generate pages to list all classes and all packages in javadoc output
bpatel
parents: 47216
diff changeset
    49
    public final String enumSummary;
cc705c956798 8196201: Generate pages to list all classes and all packages in javadoc output
bpatel
parents: 47216
diff changeset
    50
    public final String enumTableSummary;
cc705c956798 8196201: Generate pages to list all classes and all packages in javadoc output
bpatel
parents: 47216
diff changeset
    51
    public final String errorSummary;
cc705c956798 8196201: Generate pages to list all classes and all packages in javadoc output
bpatel
parents: 47216
diff changeset
    52
    public final String errorTableSummary;
cc705c956798 8196201: Generate pages to list all classes and all packages in javadoc output
bpatel
parents: 47216
diff changeset
    53
    public final String exceptionSummary;
cc705c956798 8196201: Generate pages to list all classes and all packages in javadoc output
bpatel
parents: 47216
diff changeset
    54
    public final String exceptionTableSummary;
cc705c956798 8196201: Generate pages to list all classes and all packages in javadoc output
bpatel
parents: 47216
diff changeset
    55
    public final String interfaceSummary;
cc705c956798 8196201: Generate pages to list all classes and all packages in javadoc output
bpatel
parents: 47216
diff changeset
    56
    public final String interfaceTableSummary;
cc705c956798 8196201: Generate pages to list all classes and all packages in javadoc output
bpatel
parents: 47216
diff changeset
    57
    public final String packageSummary;
cc705c956798 8196201: Generate pages to list all classes and all packages in javadoc output
bpatel
parents: 47216
diff changeset
    58
    public final String packageTableSummary;
40303
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    59
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    60
    protected ResourceBundle commonBundle;
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    61
    protected ResourceBundle docletBundle;
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    62
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    63
    /**
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    64
     * Creates a {@code Resources} to provide access the resource
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    65
     * bundles used by a doclet.
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    66
     *
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    67
     * @param configuration the configuration for the doclet,
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    68
     *  to provide access the locale to be used when accessing the
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    69
     *  names resource bundles.
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    70
     * @param commonBundleName the name of the bundle containing the strings
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    71
     *  common to all output formats
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    72
     * @param docletBundleName the name of the bundle containing the strings
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    73
     *  specific to a particular format
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    74
     */
45417
f7479ee8de69 8177848: Rename Configuration(Impl) classes
ksrini
parents: 40303
diff changeset
    75
    public Resources(BaseConfiguration configuration, String commonBundleName, String docletBundleName) {
40303
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    76
        this.configuration = configuration;
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    77
        this.commonBundleName = commonBundleName;
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
    78
        this.docletBundleName = docletBundleName;
50167
cc705c956798 8196201: Generate pages to list all classes and all packages in javadoc output
bpatel
parents: 47216
diff changeset
    79
        this.annotationTypeSummary = getText("doclet.Annotation_Types_Summary");
cc705c956798 8196201: Generate pages to list all classes and all packages in javadoc output
bpatel
parents: 47216
diff changeset
    80
        this.annotationTypeTableSummary = getText("doclet.Member_Table_Summary",
cc705c956798 8196201: Generate pages to list all classes and all packages in javadoc output
bpatel
parents: 47216
diff changeset
    81
                this.annotationTypeSummary, getText("doclet.annotationtypes"));
cc705c956798 8196201: Generate pages to list all classes and all packages in javadoc output
bpatel
parents: 47216
diff changeset
    82
        this.classSummary = getText("doclet.Class_Summary");
cc705c956798 8196201: Generate pages to list all classes and all packages in javadoc output
bpatel
parents: 47216
diff changeset
    83
        this.classTableSummary = getText("doclet.Member_Table_Summary",
cc705c956798 8196201: Generate pages to list all classes and all packages in javadoc output
bpatel
parents: 47216
diff changeset
    84
                this.classSummary, getText("doclet.classes"));
cc705c956798 8196201: Generate pages to list all classes and all packages in javadoc output
bpatel
parents: 47216
diff changeset
    85
        this.enumSummary = getText("doclet.Enum_Summary");
cc705c956798 8196201: Generate pages to list all classes and all packages in javadoc output
bpatel
parents: 47216
diff changeset
    86
        this.enumTableSummary = getText("doclet.Member_Table_Summary",
cc705c956798 8196201: Generate pages to list all classes and all packages in javadoc output
bpatel
parents: 47216
diff changeset
    87
                this.enumSummary, getText("doclet.enums"));
cc705c956798 8196201: Generate pages to list all classes and all packages in javadoc output
bpatel
parents: 47216
diff changeset
    88
        this.errorSummary = getText("doclet.Error_Summary");
cc705c956798 8196201: Generate pages to list all classes and all packages in javadoc output
bpatel
parents: 47216
diff changeset
    89
        this.errorTableSummary = getText("doclet.Member_Table_Summary",
cc705c956798 8196201: Generate pages to list all classes and all packages in javadoc output
bpatel
parents: 47216
diff changeset
    90
                this.errorSummary, getText("doclet.errors"));
cc705c956798 8196201: Generate pages to list all classes and all packages in javadoc output
bpatel
parents: 47216
diff changeset
    91
        this.exceptionSummary = getText("doclet.Exception_Summary");
cc705c956798 8196201: Generate pages to list all classes and all packages in javadoc output
bpatel
parents: 47216
diff changeset
    92
        this.exceptionTableSummary = getText("doclet.Member_Table_Summary",
cc705c956798 8196201: Generate pages to list all classes and all packages in javadoc output
bpatel
parents: 47216
diff changeset
    93
                this.exceptionSummary, getText("doclet.exceptions"));
cc705c956798 8196201: Generate pages to list all classes and all packages in javadoc output
bpatel
parents: 47216
diff changeset
    94
        this.interfaceSummary = getText("doclet.Interface_Summary");
cc705c956798 8196201: Generate pages to list all classes and all packages in javadoc output
bpatel
parents: 47216
diff changeset
    95
        this.interfaceTableSummary = getText("doclet.Member_Table_Summary",
cc705c956798 8196201: Generate pages to list all classes and all packages in javadoc output
bpatel
parents: 47216
diff changeset
    96
                this.interfaceSummary, getText("doclet.interfaces"));
cc705c956798 8196201: Generate pages to list all classes and all packages in javadoc output
bpatel
parents: 47216
diff changeset
    97
        this.packageSummary = getText("doclet.Package_Summary");
cc705c956798 8196201: Generate pages to list all classes and all packages in javadoc output
bpatel
parents: 47216
diff changeset
    98
        this.packageTableSummary = getText("doclet.Member_Table_Summary",
cc705c956798 8196201: Generate pages to list all classes and all packages in javadoc output
bpatel
parents: 47216
diff changeset
    99
                this.packageSummary, getText("doclet.packages"));
40303
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
   100
    }
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
   101
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
   102
    /**
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
   103
     * Gets the string for the given key from one of the doclet's
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
   104
     * resource bundles.
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
   105
     *
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
   106
     * The more specific bundle is checked first;
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
   107
     * if it is not there, the common bundle is then checked.
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
   108
     *
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
   109
     * @param key the key for the desired string
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
   110
     * @return the string for the given key
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
   111
     * @throws MissingResourceException if the key is not found in either
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
   112
     *  bundle.
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
   113
     */
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
   114
    public String getText(String key) throws MissingResourceException {
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
   115
        initBundles();
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
   116
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
   117
        if (docletBundle.containsKey(key))
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
   118
            return docletBundle.getString(key);
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
   119
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
   120
        return commonBundle.getString(key);
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
   121
    }
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
   122
    /**
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
   123
     * Gets the string for the given key from one of the doclet's
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
   124
     * resource bundles, substituting additional arguments into
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
   125
     * into the resulting string with {@link MessageFormat#format}.
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
   126
     *
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
   127
     * The more specific bundle is checked first;
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
   128
     * if it is not there, the common bundle is then checked.
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
   129
     *
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
   130
     * @param key the key for the desired string
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
   131
     * @param args values to be substituted into the resulting string
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
   132
     * @return the string for the given key
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
   133
     * @throws MissingResourceException if the key is not found in either
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
   134
     *  bundle.
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
   135
     */
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
   136
    public String getText(String key, Object... args) throws MissingResourceException {
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
   137
        return MessageFormat.format(getText(key), args);
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
   138
    }
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
   139
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
   140
    /**
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
   141
     * Lazily initializes the bundles. This is (currently) necessary because
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
   142
     * this object may be created before the locale to be used is known.
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
   143
     */
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
   144
    protected void initBundles() {
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
   145
        if (commonBundle == null) {
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
   146
            Locale locale = configuration.getLocale();
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
   147
            this.commonBundle = ResourceBundle.getBundle(commonBundleName, locale);
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
   148
            this.docletBundle = ResourceBundle.getBundle(docletBundleName, locale);
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
   149
        }
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
   150
    }
96a1226aca18 8160697: HTMLWriter needs perf cleanup
jjg
parents:
diff changeset
   151
}