jdk/src/share/classes/java/util/spi/LocaleNameProvider.java
author ohair
Wed, 06 Apr 2011 22:06:11 -0700
changeset 9035 1255eb81cc2f
parent 8146 f1b64e82649f
permissions -rw-r--r--
7033660: Update copyright year to 2011 on any files changed in 2011 Reviewed-by: dholmes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
9035
1255eb81cc2f 7033660: Update copyright year to 2011 on any files changed in 2011
ohair
parents: 8146
diff changeset
     2
 * Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package java.util.spi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.util.Locale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * An abstract class for service providers that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * provide localized names for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * {@link java.util.Locale Locale} class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * @since        1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
public abstract class LocaleNameProvider extends LocaleServiceProvider {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
     * Sole constructor.  (For invocation by subclass constructors, typically
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
     * implicit.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    protected LocaleNameProvider() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    /**
6501
684810d882b3 6875847: Java Locale Enhancement
naoto
parents: 5506
diff changeset
    47
     * Returns a localized name for the given <a href="http://www.rfc-editor.org/rfc/bcp/bcp47.txt">
684810d882b3 6875847: Java Locale Enhancement
naoto
parents: 5506
diff changeset
    48
     * IETF BCP47</a> language code and the given locale that is appropriate for
684810d882b3 6875847: Java Locale Enhancement
naoto
parents: 5506
diff changeset
    49
     * display to the user.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
     * For example, if <code>languageCode</code> is "fr" and <code>locale</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
     * is en_US, getDisplayLanguage() will return "French"; if <code>languageCode</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
     * is "en" and <code>locale</code> is fr_FR, getDisplayLanguage() will return "anglais".
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
     * If the name returned cannot be localized according to <code>locale</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
     * (say, the provider does not have a Japanese name for Croatian),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
     * this method returns null.
6501
684810d882b3 6875847: Java Locale Enhancement
naoto
parents: 5506
diff changeset
    56
     * @param languageCode the language code string in the form of two to eight
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
     *     lower-case letters between 'a' (U+0061) and 'z' (U+007A)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
     * @param locale the desired locale
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
     * @return the name of the given language code for the specified locale, or null if it's not
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
     *     available.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
     * @exception NullPointerException if <code>languageCode</code> or <code>locale</code> is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     * @exception IllegalArgumentException if <code>languageCode</code> is not in the form of
6501
684810d882b3 6875847: Java Locale Enhancement
naoto
parents: 5506
diff changeset
    63
     *     two or three lower-case letters, or <code>locale</code> isn't
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     *     one of the locales returned from
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     *     {@link java.util.spi.LocaleServiceProvider#getAvailableLocales()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     *     getAvailableLocales()}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     * @see java.util.Locale#getDisplayLanguage(java.util.Locale)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    public abstract String getDisplayLanguage(String languageCode, Locale locale);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    /**
6501
684810d882b3 6875847: Java Locale Enhancement
naoto
parents: 5506
diff changeset
    72
     * Returns a localized name for the given <a href="http://www.rfc-editor.org/rfc/bcp/bcp47.txt">
684810d882b3 6875847: Java Locale Enhancement
naoto
parents: 5506
diff changeset
    73
     * IETF BCP47</a> script code and the given locale that is appropriate for
684810d882b3 6875847: Java Locale Enhancement
naoto
parents: 5506
diff changeset
    74
     * display to the user.
684810d882b3 6875847: Java Locale Enhancement
naoto
parents: 5506
diff changeset
    75
     * For example, if <code>scriptCode</code> is "Latn" and <code>locale</code>
684810d882b3 6875847: Java Locale Enhancement
naoto
parents: 5506
diff changeset
    76
     * is en_US, getDisplayScript() will return "Latin"; if <code>scriptCode</code>
684810d882b3 6875847: Java Locale Enhancement
naoto
parents: 5506
diff changeset
    77
     * is "Cyrl" and <code>locale</code> is fr_FR, getDisplayScript() will return "cyrillique".
684810d882b3 6875847: Java Locale Enhancement
naoto
parents: 5506
diff changeset
    78
     * If the name returned cannot be localized according to <code>locale</code>,
684810d882b3 6875847: Java Locale Enhancement
naoto
parents: 5506
diff changeset
    79
     * (say, the provider does not have a Japanese name for Cyrillic),
8146
f1b64e82649f 7013282: No appropriate CCC request for listed JDK 7 changes in java.util.spi package (b121)
naoto
parents: 7252
diff changeset
    80
     * this method returns null. The default implementation returns null.
6501
684810d882b3 6875847: Java Locale Enhancement
naoto
parents: 5506
diff changeset
    81
     * @param scriptCode the four letter script code string in the form of title-case
684810d882b3 6875847: Java Locale Enhancement
naoto
parents: 5506
diff changeset
    82
     *     letters (the first letter is upper-case character between 'A' (U+0041) and
684810d882b3 6875847: Java Locale Enhancement
naoto
parents: 5506
diff changeset
    83
     *     'Z' (U+005A) followed by three lower-case character between 'a' (U+0061)
684810d882b3 6875847: Java Locale Enhancement
naoto
parents: 5506
diff changeset
    84
     *     and 'z' (U+007A)).
684810d882b3 6875847: Java Locale Enhancement
naoto
parents: 5506
diff changeset
    85
     * @param locale the desired locale
684810d882b3 6875847: Java Locale Enhancement
naoto
parents: 5506
diff changeset
    86
     * @return the name of the given script code for the specified locale, or null if it's not
684810d882b3 6875847: Java Locale Enhancement
naoto
parents: 5506
diff changeset
    87
     *     available.
684810d882b3 6875847: Java Locale Enhancement
naoto
parents: 5506
diff changeset
    88
     * @exception NullPointerException if <code>scriptCode</code> or <code>locale</code> is null
684810d882b3 6875847: Java Locale Enhancement
naoto
parents: 5506
diff changeset
    89
     * @exception IllegalArgumentException if <code>scriptCode</code> is not in the form of
684810d882b3 6875847: Java Locale Enhancement
naoto
parents: 5506
diff changeset
    90
     *     four title case letters, or <code>locale</code> isn't
684810d882b3 6875847: Java Locale Enhancement
naoto
parents: 5506
diff changeset
    91
     *     one of the locales returned from
684810d882b3 6875847: Java Locale Enhancement
naoto
parents: 5506
diff changeset
    92
     *     {@link java.util.spi.LocaleServiceProvider#getAvailableLocales()
684810d882b3 6875847: Java Locale Enhancement
naoto
parents: 5506
diff changeset
    93
     *     getAvailableLocales()}.
684810d882b3 6875847: Java Locale Enhancement
naoto
parents: 5506
diff changeset
    94
     * @see java.util.Locale#getDisplayScript(java.util.Locale)
684810d882b3 6875847: Java Locale Enhancement
naoto
parents: 5506
diff changeset
    95
     * @since 1.7
684810d882b3 6875847: Java Locale Enhancement
naoto
parents: 5506
diff changeset
    96
     */
7252
2316b2e837d8 7000136: Backward compatibility problem in LocaleNameProvider
naoto
parents: 6501
diff changeset
    97
    public String getDisplayScript(String scriptCode, Locale locale) {
2316b2e837d8 7000136: Backward compatibility problem in LocaleNameProvider
naoto
parents: 6501
diff changeset
    98
        return null;
2316b2e837d8 7000136: Backward compatibility problem in LocaleNameProvider
naoto
parents: 6501
diff changeset
    99
    }
6501
684810d882b3 6875847: Java Locale Enhancement
naoto
parents: 5506
diff changeset
   100
684810d882b3 6875847: Java Locale Enhancement
naoto
parents: 5506
diff changeset
   101
    /**
684810d882b3 6875847: Java Locale Enhancement
naoto
parents: 5506
diff changeset
   102
     * Returns a localized name for the given <a href="http://www.rfc-editor.org/rfc/bcp/bcp47.txt">
684810d882b3 6875847: Java Locale Enhancement
naoto
parents: 5506
diff changeset
   103
     * IETF BCP47</a> region code (either ISO 3166 country code or UN M.49 area
684810d882b3 6875847: Java Locale Enhancement
naoto
parents: 5506
diff changeset
   104
     * codes) and the given locale that is appropriate for display to the user.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * For example, if <code>countryCode</code> is "FR" and <code>locale</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * is en_US, getDisplayCountry() will return "France"; if <code>countryCode</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * is "US" and <code>locale</code> is fr_FR, getDisplayCountry() will return "Etats-Unis".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * If the name returned cannot be localized according to <code>locale</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * (say, the provider does not have a Japanese name for Croatia),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * this method returns null.
6501
684810d882b3 6875847: Java Locale Enhancement
naoto
parents: 5506
diff changeset
   111
     * @param countryCode the country(region) code string in the form of two
684810d882b3 6875847: Java Locale Enhancement
naoto
parents: 5506
diff changeset
   112
     *     upper-case letters between 'A' (U+0041) and 'Z' (U+005A) or the UN M.49 area code
684810d882b3 6875847: Java Locale Enhancement
naoto
parents: 5506
diff changeset
   113
     *     in the form of three digit letters between '0' (U+0030) and '9' (U+0039).
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * @param locale the desired locale
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * @return the name of the given country code for the specified locale, or null if it's not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     *     available.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * @exception NullPointerException if <code>countryCode</code> or <code>locale</code> is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * @exception IllegalArgumentException if <code>countryCode</code> is not in the form of
6501
684810d882b3 6875847: Java Locale Enhancement
naoto
parents: 5506
diff changeset
   119
     *     two upper-case letters or three digit letters, or <code>locale</code> isn't
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     *     one of the locales returned from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     *     {@link java.util.spi.LocaleServiceProvider#getAvailableLocales()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     *     getAvailableLocales()}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * @see java.util.Locale#getDisplayCountry(java.util.Locale)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    public abstract String getDisplayCountry(String countryCode, Locale locale);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * Returns a localized name for the given variant code and the given locale that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * is appropriate for display to the user.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * If the name returned cannot be localized according to <code>locale</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * this method returns null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * @param variant the variant string
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * @param locale the desired locale
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * @return the name of the given variant string for the specified locale, or null if it's not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     *     available.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * @exception NullPointerException if <code>variant</code> or <code>locale</code> is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * @exception IllegalArgumentException if <code>locale</code> isn't
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     *     one of the locales returned from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     *     {@link java.util.spi.LocaleServiceProvider#getAvailableLocales()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     *     getAvailableLocales()}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * @see java.util.Locale#getDisplayVariant(java.util.Locale)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    public abstract String getDisplayVariant(String variant, Locale locale);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
}