jdk/src/share/classes/sun/util/resources/LocaleData.java
author okutsu
Mon, 10 Dec 2012 10:52:11 +0900
changeset 14765 0987999ed367
parent 13583 dc0017b1a452
child 15260 7af2d7a87806
permissions -rw-r--r--
8000983: Support narrow display names for calendar fields 8003267: Support generic time zone names in TimeZoneNameProvider (SPI) Reviewed-by: naoto
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11138
diff changeset
     2
 * Copyright (c) 1996, 2012, 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
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * (C) Copyright Taligent, Inc. 1996, 1997 - All Rights Reserved
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * (C) Copyright IBM Corp. 1996 - 1998 - All Rights Reserved
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 * The original version of this source code and documentation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * is copyrighted and owned by Taligent, Inc., a wholly-owned
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * subsidiary of IBM. These materials are provided under terms
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * of a License Agreement between Taligent and Sun. This technology
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * is protected by multiple US and International patents.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * This notice and attribution to Taligent may not be removed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * Taligent is a registered trademark of Taligent, Inc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
package sun.util.resources;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import java.security.AccessController;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import java.security.PrivilegedAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import java.util.Iterator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import java.util.List;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import java.util.Locale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
import java.util.ResourceBundle;
14765
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 13583
diff changeset
    49
import sun.util.locale.provider.LocaleDataMetaInfo;
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11138
diff changeset
    50
import sun.util.locale.provider.LocaleProviderAdapter;
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11138
diff changeset
    51
import static sun.util.locale.provider.LocaleProviderAdapter.Type.JRE;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * Provides information about and access to resource bundles in the
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11138
diff changeset
    55
 * sun.text.resources and sun.util.resources packages or in their corresponding
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11138
diff changeset
    56
 * packages for CLDR.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * @author Asmus Freytag
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * @author Mark Davis
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
public class LocaleData {
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11138
diff changeset
    63
    private final LocaleProviderAdapter.Type type;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11138
diff changeset
    65
    public LocaleData(LocaleProviderAdapter.Type type) {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11138
diff changeset
    66
        this.type = type;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     * Gets a calendar data resource bundle, using privileges
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     * to allow accessing a sun.* package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     */
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11138
diff changeset
    73
    public ResourceBundle getCalendarData(Locale locale) {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11138
diff changeset
    74
        return getBundle(type.getUtilResourcesPackage() + ".CalendarData", locale);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * Gets a currency names resource bundle, using privileges
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * to allow accessing a sun.* package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     */
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11138
diff changeset
    81
    public OpenListResourceBundle getCurrencyNames(Locale locale) {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11138
diff changeset
    82
        return (OpenListResourceBundle) getBundle(type.getUtilResourcesPackage() + ".CurrencyNames", locale);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * Gets a locale names resource bundle, using privileges
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * to allow accessing a sun.* package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     */
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11138
diff changeset
    89
    public OpenListResourceBundle getLocaleNames(Locale locale) {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11138
diff changeset
    90
        return (OpenListResourceBundle) getBundle(type.getUtilResourcesPackage() + ".LocaleNames", locale);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * Gets a time zone names resource bundle, using privileges
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * to allow accessing a sun.* package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     */
14765
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 13583
diff changeset
    97
    public TimeZoneNamesBundle getTimeZoneNames(Locale locale) {
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 13583
diff changeset
    98
        return (TimeZoneNamesBundle) getBundle(type.getUtilResourcesPackage() + ".TimeZoneNames", locale);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * Gets a collation data resource bundle, using privileges
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * to allow accessing a sun.* package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     */
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11138
diff changeset
   105
    public ResourceBundle getCollationData(Locale locale) {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11138
diff changeset
   106
        return getBundle(type.getTextResourcesPackage() + ".CollationData", locale);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * Gets a date format data resource bundle, using privileges
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * to allow accessing a sun.* package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     */
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11138
diff changeset
   113
    public ResourceBundle getDateFormatData(Locale locale) {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11138
diff changeset
   114
        return getBundle(type.getTextResourcesPackage() + ".FormatData", locale);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * Gets a number format data resource bundle, using privileges
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * to allow accessing a sun.* package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     */
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11138
diff changeset
   121
    public ResourceBundle getNumberFormatData(Locale locale) {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11138
diff changeset
   122
        return getBundle(type.getTextResourcesPackage() + ".FormatData", locale);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11138
diff changeset
   125
    public static ResourceBundle getBundle(final String baseName, final Locale locale) {
11138
9121a1a92512 7117469: Warning cleanup for j.u.Currency and j.u.Locale related classes
naoto
parents: 9035
diff changeset
   126
        return AccessController.doPrivileged(new PrivilegedAction<ResourceBundle>() {
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11138
diff changeset
   127
                @Override
11138
9121a1a92512 7117469: Warning cleanup for j.u.Currency and j.u.Locale related classes
naoto
parents: 9035
diff changeset
   128
                public ResourceBundle run() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
                    return ResourceBundle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
                        getBundle(baseName, locale,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
                                  LocaleDataResourceBundleControl.getRBControlInstance());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
            });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11138
diff changeset
   136
    private static class LocaleDataResourceBundleControl extends ResourceBundle.Control {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        /* Singlton instance of ResourceBundle.Control. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        private static LocaleDataResourceBundleControl rbControlInstance =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
            new LocaleDataResourceBundleControl();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        public static LocaleDataResourceBundleControl getRBControlInstance() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
            return rbControlInstance;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
         * This method overrides the default implementation to search
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
         * from a prebaked locale string list to determin the candidate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
         * locale list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
         * @param baseName the resource bundle base name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
         *        locale   the requested locale for the resource bundle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
         * @returns a list of candidate locales to search from.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
         * @exception NullPointerException if baseName or locale is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        @Override
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
         public List<Locale> getCandidateLocales(String baseName, Locale locale) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
            List<Locale> candidates = super.getCandidateLocales(baseName, locale);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
            /* Get the locale string list from LocaleDataMetaInfo class. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
            String localeString = LocaleDataMetaInfo.getSupportedLocaleString(baseName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
14765
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 13583
diff changeset
   161
            if (localeString != null && localeString.length() != 0) {
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 13583
diff changeset
   162
                for (Iterator<Locale> l = candidates.iterator(); l.hasNext();) {
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 13583
diff changeset
   163
                    Locale loc = l.next();
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 13583
diff changeset
   164
                    String lstr;
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 13583
diff changeset
   165
                    if (loc.getScript().length() > 0) {
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 13583
diff changeset
   166
                        lstr = loc.toLanguageTag().replace('-', '_');
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 13583
diff changeset
   167
                    } else {
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 13583
diff changeset
   168
                        lstr = loc.toString();
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 13583
diff changeset
   169
                        int idx = lstr.indexOf("_#");
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 13583
diff changeset
   170
                        if (idx >= 0) {
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 13583
diff changeset
   171
                            lstr = lstr.substring(0, idx);
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 13583
diff changeset
   172
                        }
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 13583
diff changeset
   173
                    }
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 13583
diff changeset
   174
                    /* Every locale string in the locale string list returned from
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 13583
diff changeset
   175
                     the above getSupportedLocaleString is enclosed
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 13583
diff changeset
   176
                     within two white spaces so that we could check some locale
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 13583
diff changeset
   177
                     such as "en".
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 13583
diff changeset
   178
                     */
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 13583
diff changeset
   179
                    if (lstr.length() != 0 && localeString.indexOf(" " + lstr + " ") == -1) {
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 13583
diff changeset
   180
                        l.remove();
8695
e83968c6ceda 6998391: Serbian (Latin) locale support
katakai
parents: 6501
diff changeset
   181
                    }
6501
684810d882b3 6875847: Java Locale Enhancement
naoto
parents: 5506
diff changeset
   182
                }
14765
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 13583
diff changeset
   183
            }
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 13583
diff changeset
   184
            // Force fallback to Locale.ENGLISH for CLDR time zone names support
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 13583
diff changeset
   185
            if (locale.getLanguage() != "en"
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 13583
diff changeset
   186
                    && baseName.contains(CLDR) && baseName.endsWith("TimeZoneNames")) {
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 13583
diff changeset
   187
                candidates.add(candidates.size() - 1, Locale.ENGLISH);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
            return candidates;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
         * Overrides "getFallbackLocale" to return null so
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
         * that the fallback locale will be null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
         * @param baseName the resource bundle base name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
         *        locale   the requested locale for the resource bundle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
         * @return null for the fallback locale.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
         * @exception NullPointerException if baseName or locale is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        @Override
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        public Locale getFallbackLocale(String baseName, Locale locale) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
            if (baseName == null || locale == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
                throw new NullPointerException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11138
diff changeset
   208
        private static final String CLDR      = ".cldr";
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11138
diff changeset
   210
        /**
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11138
diff changeset
   211
         * Changes baseName to its per-language package name and
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11138
diff changeset
   212
         * calls the super class implementation. For example,
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11138
diff changeset
   213
         * if the baseName is "sun.text.resources.FormatData" and locale is ja_JP,
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11138
diff changeset
   214
         * the baseName is changed to "sun.text.resources.ja.FormatData". If
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11138
diff changeset
   215
         * baseName contains "cldr", such as "sun.text.resources.cldr.FormatData",
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11138
diff changeset
   216
         * the name is changed to "sun.text.resources.cldr.jp.FormatData".
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11138
diff changeset
   217
         */
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11138
diff changeset
   218
        @Override
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11138
diff changeset
   219
        public String toBundleName(String baseName, Locale locale) {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11138
diff changeset
   220
            String newBaseName = baseName;
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11138
diff changeset
   221
            String lang = locale.getLanguage();
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11138
diff changeset
   222
            if (lang.length() > 0) {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11138
diff changeset
   223
                if (baseName.startsWith(JRE.getUtilResourcesPackage())
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11138
diff changeset
   224
                        || baseName.startsWith(JRE.getTextResourcesPackage())) {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11138
diff changeset
   225
                    // Assume the lengths are the same.
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11138
diff changeset
   226
                    assert JRE.getUtilResourcesPackage().length()
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11138
diff changeset
   227
                        == JRE.getTextResourcesPackage().length();
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11138
diff changeset
   228
                    int index = JRE.getUtilResourcesPackage().length();
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11138
diff changeset
   229
                    if (baseName.indexOf(CLDR, index) > 0) {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11138
diff changeset
   230
                        index += CLDR.length();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
                    }
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11138
diff changeset
   232
                    newBaseName = baseName.substring(0, index + 1) + lang
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11138
diff changeset
   233
                                      + baseName.substring(index);
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11138
diff changeset
   234
                }
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11138
diff changeset
   235
            }
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11138
diff changeset
   236
            return super.toBundleName(newBaseName, locale);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
}