1 /* 2 * Copyright (c) 2005, 2017, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package java.util.spi; 27 28 import java.util.Locale; 29 import java.util.Objects; 30 31 /** 32 * An abstract class for service providers that 33 * provide localized names for the 34 * {@link java.util.Locale Locale} class. 35 * 36 * @since 1.6 37 */ 38 public abstract class LocaleNameProvider extends LocaleServiceProvider { 39 40 /** 41 * Sole constructor. (For invocation by subclass constructors, typically 42 * implicit.) 43 */ 44 protected LocaleNameProvider() { 45 } 46 47 /** 48 * Returns a localized name for the given <a href="http://www.rfc-editor.org/rfc/bcp/bcp47.txt"> 49 * IETF BCP47</a> language code and the given locale that is appropriate for 50 * display to the user. 51 * For example, if <code>languageCode</code> is "fr" and <code>locale</code> 52 * is en_US, getDisplayLanguage() will return "French"; if <code>languageCode</code> 53 * is "en" and <code>locale</code> is fr_FR, getDisplayLanguage() will return "anglais". 54 * If the name returned cannot be localized according to <code>locale</code>, 55 * (say, the provider does not have a Japanese name for Croatian), 56 * this method returns null. 57 * @param languageCode the language code string in the form of two to eight 58 * lower-case letters between 'a' (U+0061) and 'z' (U+007A) 59 * @param locale the desired locale 60 * @return the name of the given language code for the specified locale, or null if it's not 61 * available. 62 * @exception NullPointerException if <code>languageCode</code> or <code>locale</code> is null 63 * @exception IllegalArgumentException if <code>languageCode</code> is not in the form of 64 * two or three lower-case letters, or <code>locale</code> isn't 65 * one of the locales returned from 66 * {@link java.util.spi.LocaleServiceProvider#getAvailableLocales() 67 * getAvailableLocales()}. 68 * @see java.util.Locale#getDisplayLanguage(java.util.Locale) 69 */ 70 public abstract String getDisplayLanguage(String languageCode, Locale locale); 71 72 /** 73 * Returns a localized name for the given <a href="http://www.rfc-editor.org/rfc/bcp/bcp47.txt"> 74 * IETF BCP47</a> script code and the given locale that is appropriate for 75 * display to the user. 76 * For example, if <code>scriptCode</code> is "Latn" and <code>locale</code> 77 * is en_US, getDisplayScript() will return "Latin"; if <code>scriptCode</code> 78 * is "Cyrl" and <code>locale</code> is fr_FR, getDisplayScript() will return "cyrillique". 79 * If the name returned cannot be localized according to <code>locale</code>, 80 * (say, the provider does not have a Japanese name for Cyrillic), 81 * this method returns null. The default implementation returns null. 82 * @param scriptCode the four letter script code string in the form of title-case 83 * letters (the first letter is upper-case character between 'A' (U+0041) and 84 * 'Z' (U+005A) followed by three lower-case character between 'a' (U+0061) 85 * and 'z' (U+007A)). 86 * @param locale the desired locale 87 * @return the name of the given script code for the specified locale, or null if it's not 88 * available. 89 * @exception NullPointerException if <code>scriptCode</code> or <code>locale</code> is null 90 * @exception IllegalArgumentException if <code>scriptCode</code> is not in the form of 91 * four title case letters, or <code>locale</code> isn't 92 * one of the locales returned from 93 * {@link java.util.spi.LocaleServiceProvider#getAvailableLocales() 94 * getAvailableLocales()}. 95 * @see java.util.Locale#getDisplayScript(java.util.Locale) 96 * @since 1.7 97 */ 98 public String getDisplayScript(String scriptCode, Locale locale) { 99 return null; 100 } 101 102 /** 103 * Returns a localized name for the given <a href="http://www.rfc-editor.org/rfc/bcp/bcp47.txt"> 104 * IETF BCP47</a> region code (either ISO 3166 country code or UN M.49 area 105 * codes) and the given locale that is appropriate for display to the user. 106 * For example, if <code>countryCode</code> is "FR" and <code>locale</code> 107 * is en_US, getDisplayCountry() will return "France"; if <code>countryCode</code> 108 * is "US" and <code>locale</code> is fr_FR, getDisplayCountry() will return "Etats-Unis". 109 * If the name returned cannot be localized according to <code>locale</code>, 110 * (say, the provider does not have a Japanese name for Croatia), 111 * this method returns null. 112 * @param countryCode the country(region) code string in the form of two 113 * upper-case letters between 'A' (U+0041) and 'Z' (U+005A) or the UN M.49 area code 114 * in the form of three digit letters between '0' (U+0030) and '9' (U+0039). 115 * @param locale the desired locale 116 * @return the name of the given country code for the specified locale, or null if it's not 117 * available. 118 * @exception NullPointerException if <code>countryCode</code> or <code>locale</code> is null 119 * @exception IllegalArgumentException if <code>countryCode</code> is not in the form of 120 * two upper-case letters or three digit letters, or <code>locale</code> isn't 121 * one of the locales returned from 122 * {@link java.util.spi.LocaleServiceProvider#getAvailableLocales() 123 * getAvailableLocales()}. 124 * @see java.util.Locale#getDisplayCountry(java.util.Locale) 125 */ 126 public abstract String getDisplayCountry(String countryCode, Locale locale); 127 128 /** 129 * Returns a localized name for the given variant code and the given locale that 130 * is appropriate for display to the user. 131 * If the name returned cannot be localized according to <code>locale</code>, 132 * this method returns null. 133 * @param variant the variant string 134 * @param locale the desired locale 135 * @return the name of the given variant string for the specified locale, or null if it's not 136 * available. 137 * @exception NullPointerException if <code>variant</code> or <code>locale</code> is null 138 * @exception IllegalArgumentException if <code>locale</code> isn't 139 * one of the locales returned from 140 * {@link java.util.spi.LocaleServiceProvider#getAvailableLocales() 141 * getAvailableLocales()}. 142 * @see java.util.Locale#getDisplayVariant(java.util.Locale) 143 */ 144 public abstract String getDisplayVariant(String variant, Locale locale); 145 146 /** 147 * Returns a localized name for the given 148 * <a href="../Locale.html#def_locale_extension">Unicode extension</a> key, 149 * and the given locale that is appropriate for display to the user. 150 * If the name returned cannot be localized according to <code>locale</code>, 151 * this method returns null. 152 * @implSpec the default implementation returns <code>null</code>. 153 * @param key the Unicode Extension key, not null. 154 * @param locale the desired locale, not null. 155 * @return the name of the given key string for the specified locale, 156 * or null if it's not available. 157 * @exception NullPointerException if <code>key</code> or <code>locale</code> is null 158 * @exception IllegalArgumentException if <code>locale</code> isn't 159 * one of the locales returned from 160 * {@link java.util.spi.LocaleServiceProvider#getAvailableLocales() 161 * getAvailableLocales()}. 162 * @since 10 163 */ 164 public String getDisplayUnicodeExtensionKey(String key, Locale locale) { 165 Objects.requireNonNull(key); 166 Objects.requireNonNull(locale); 167 return null; 168 } 169 170 /** 171 * Returns a localized name for the given 172 * <a href="../Locale.html#def_locale_extension">Unicode extension</a> type, 173 * and the given locale that is appropriate for display to the user. 174 * If the name returned cannot be localized according to <code>locale</code>, 175 * this method returns null. 176 * @implSpec the default implementation returns <code>null</code>. 177 * @param type the Unicode Extension type, not null. 178 * @param key the Unicode Extension key for this <code>type</code>, not null. 179 * @param locale the desired locale, not null. 180 * @return the name of the given type string for the specified locale, 181 * or null if it's not available. 182 * @exception NullPointerException if <code>key</code>, <code>type</code> or <code>locale</code> is null 183 * @exception IllegalArgumentException if <code>locale</code> isn't 184 * one of the locales returned from 185 * {@link java.util.spi.LocaleServiceProvider#getAvailableLocales() 186 * getAvailableLocales()}. 187 * @since 10 188 */ 189 public String getDisplayUnicodeExtensionType(String type, String key, Locale locale) { 190 Objects.requireNonNull(type); 191 Objects.requireNonNull(key); 192 Objects.requireNonNull(locale); 193 return null; 194 } 195 }