Print this page
rev 5696 : 6336885: RFE: Locale Data Deployment Enhancements
4609153: Provide locale data for Indic locales
5104387: Support for gl_ES locale (galician language)
6337471: desktop/system locale preferences support
7056139: (cal) SPI support for locale-dependent Calendar parameters
7058206: Provide CalendarData SPI for week params and display field value names
7073852: Support multiple scripts for digits and decimal symbols per locale
7079560: [Fmt-Da] Context dependent month names support in SimpleDateFormat
7171324: getAvailableLocales() of locale sensitive services should return the actual availability of locales
7151414: (cal) Support calendar type identification
7168528: LocaleServiceProvider needs to be aware of Locale extensions
7171372: (cal) locale's default Calendar should be created if unknown calendar is specified
Summary: JEP 127: Improve Locale Data Packaging and Adopt Unicode CLDR Data (part 1 w/o packaging changes. by Naoto Sato and Masayoshi Okutsu)
Split |
Close |
Expand all |
Collapse all |
--- old/src/share/classes/java/util/spi/CurrencyNameProvider.java
+++ new/src/share/classes/java/util/spi/CurrencyNameProvider.java
1 1 /*
2 2 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
3 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 4 *
5 5 * This code is free software; you can redistribute it and/or modify it
6 6 * under the terms of the GNU General Public License version 2 only, as
7 7 * published by the Free Software Foundation. Oracle designates this
8 8 * particular file as subject to the "Classpath" exception as provided
9 9 * by Oracle in the LICENSE file that accompanied this code.
10 10 *
11 11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 14 * version 2 for more details (a copy is included in the LICENSE file that
15 15 * accompanied this code).
16 16 *
17 17 * You should have received a copy of the GNU General Public License version
18 18 * 2 along with this work; if not, write to the Free Software Foundation,
19 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 20 *
21 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
↓ open down ↓ |
21 lines elided |
↑ open up ↑ |
22 22 * or visit www.oracle.com if you need additional information or have any
23 23 * questions.
24 24 */
25 25
26 26 package java.util.spi;
27 27
28 28 import java.util.Arrays;
29 29 import java.util.Currency;
30 30 import java.util.List;
31 31 import java.util.Locale;
32 +import java.util.ResourceBundle.Control;
32 33
33 34 /**
34 35 * An abstract class for service providers that
35 36 * provide localized currency symbols and display names for the
36 37 * {@link java.util.Currency Currency} class.
37 38 * Note that currency symbols are considered names when determining
38 39 * behaviors described in the
39 40 * {@link java.util.spi.LocaleServiceProvider LocaleServiceProvider}
40 41 * specification.
41 42 *
42 43 * @since 1.6
43 44 */
44 45 public abstract class CurrencyNameProvider extends LocaleServiceProvider {
45 46
46 47 /**
47 48 * Sole constructor. (For invocation by subclass constructors, typically
48 49 * implicit.)
49 50 */
50 51 protected CurrencyNameProvider() {
51 52 }
52 53
53 54 /**
54 55 * Gets the symbol of the given currency code for the specified locale.
55 56 * For example, for "USD" (US Dollar), the symbol is "$" if the specified
56 57 * locale is the US, while for other locales it may be "US$". If no
57 58 * symbol can be determined, null should be returned.
58 59 *
59 60 * @param currencyCode the ISO 4217 currency code, which
60 61 * consists of three upper-case letters between 'A' (U+0041) and
61 62 * 'Z' (U+005A)
62 63 * @param locale the desired locale
63 64 * @return the symbol of the given currency code for the specified locale, or null if
64 65 * the symbol is not available for the locale
65 66 * @exception NullPointerException if <code>currencyCode</code> or
66 67 * <code>locale</code> is null
67 68 * @exception IllegalArgumentException if <code>currencyCode</code> is not in
68 69 * the form of three upper-case letters, or <code>locale</code> isn't
69 70 * one of the locales returned from
70 71 * {@link java.util.spi.LocaleServiceProvider#getAvailableLocales()
71 72 * getAvailableLocales()}.
72 73 * @see java.util.Currency#getSymbol(java.util.Locale)
73 74 */
74 75 public abstract String getSymbol(String currencyCode, Locale locale);
75 76
76 77 /**
77 78 * Returns a name for the currency that is appropriate for display to the
78 79 * user. The default implementation returns null.
79 80 *
80 81 * @param currencyCode the ISO 4217 currency code, which
81 82 * consists of three upper-case letters between 'A' (U+0041) and
82 83 * 'Z' (U+005A)
83 84 * @param locale the desired locale
84 85 * @return the name for the currency that is appropriate for display to the
85 86 * user, or null if the name is not available for the locale
86 87 * @exception IllegalArgumentException if <code>currencyCode</code> is not in
87 88 * the form of three upper-case letters, or <code>locale</code> isn't
88 89 * one of the locales returned from
89 90 * {@link java.util.spi.LocaleServiceProvider#getAvailableLocales()
90 91 * getAvailableLocales()}.
91 92 * @exception NullPointerException if <code>currencyCode</code> or
92 93 * <code>locale</code> is <code>null</code>
93 94 * @since 1.7
94 95 */
95 96 public String getDisplayName(String currencyCode, Locale locale) {
96 97 if (currencyCode == null || locale == null) {
97 98 throw new NullPointerException();
98 99 }
99 100
100 101 // Check whether the currencyCode is valid
101 102 char[] charray = currencyCode.toCharArray();
↓ open down ↓ |
60 lines elided |
↑ open up ↑ |
102 103 if (charray.length != 3) {
103 104 throw new IllegalArgumentException("The currencyCode is not in the form of three upper-case letters.");
104 105 }
105 106 for (char c : charray) {
106 107 if (c < 'A' || c > 'Z') {
107 108 throw new IllegalArgumentException("The currencyCode is not in the form of three upper-case letters.");
108 109 }
109 110 }
110 111
111 112 // Check whether the locale is valid
112 - List<Locale> avail = Arrays.asList(getAvailableLocales());
113 - if (!avail.contains(locale)) {
114 - throw new IllegalArgumentException("The locale is not available");
113 + Control c = Control.getNoFallbackControl(Control.FORMAT_DEFAULT);
114 + for (Locale l : getAvailableLocales()) {
115 + if (c.getCandidateLocales("", l).contains(locale)) {
116 + return null;
117 + }
115 118 }
116 119
117 - return null;
120 + throw new IllegalArgumentException("The locale is not available");
118 121 }
119 122 }
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX