jdk/src/share/classes/sun/util/resources/LocaleData.java
author yhuang
Sun, 20 Dec 2009 19:31:57 -0800
changeset 4610 541b2cf4746e
parent 2 90ce3da70b43
child 5506 202f599c92aa
permissions -rw-r--r--
6910489: Slovenia Locale, wrong firstDayOfWeek number Reviewed-by: yhuang, peytoia
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Portions Copyright 1996-2005 Sun Microsystems, Inc.  All Rights Reserved.
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
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
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
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.io.File;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import java.security.AccessController;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import java.security.PrivilegedAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import java.util.Iterator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import java.util.List;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
import java.util.Locale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
import java.util.ResourceBundle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
import java.util.StringTokenizer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
import sun.util.LocaleDataMetaInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * Provides information about and access to resource bundles in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * sun.text.resources and sun.util.resources package.
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 {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    private static final String localeDataJarName = "localedata.jar";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     * Lazy load available locales.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    private static class AvailableLocales {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
         static final Locale[] localeList = createLocaleList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     * Returns a list of the installed locales. Currently, this simply returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * the list of locales for which a sun.text.resources.FormatData bundle
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * exists. This bundle family happens to be the one with the broadest
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * locale coverage in the JRE.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    public static Locale[] getAvailableLocales() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        return AvailableLocales.localeList.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * Gets a calendar data resource bundle, using privileges
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     * to allow accessing a sun.* package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    public static ResourceBundle getCalendarData(Locale locale) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        return getBundle("sun.util.resources.CalendarData", locale);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * Gets a currency names resource bundle, using privileges
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * to allow accessing a sun.* package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    public static OpenListResourceBundle getCurrencyNames(Locale locale) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        return (OpenListResourceBundle)getBundle("sun.util.resources.CurrencyNames", locale);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * Gets a locale names resource bundle, using privileges
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * to allow accessing a sun.* package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    public static OpenListResourceBundle getLocaleNames(Locale locale) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        return (OpenListResourceBundle)getBundle("sun.util.resources.LocaleNames", locale);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * Gets a time zone names resource bundle, using privileges
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * to allow accessing a sun.* package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    public static OpenListResourceBundle getTimeZoneNames(Locale locale) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        return (OpenListResourceBundle)getBundle("sun.util.resources.TimeZoneNames", locale);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * Gets a collation data resource bundle, using privileges
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * to allow accessing a sun.* package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    public static ResourceBundle getCollationData(Locale locale) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        return getBundle("sun.text.resources.CollationData", locale);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * Gets a date format data resource bundle, using privileges
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * to allow accessing a sun.* package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    public static ResourceBundle getDateFormatData(Locale locale) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        return getBundle("sun.text.resources.FormatData", locale);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * Gets a number format data resource bundle, using privileges
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * to allow accessing a sun.* package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    public static ResourceBundle getNumberFormatData(Locale locale) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        return getBundle("sun.text.resources.FormatData", locale);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    private static ResourceBundle getBundle(final String baseName, final Locale locale) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        return (ResourceBundle) AccessController.doPrivileged(new PrivilegedAction() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
                public Object run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
                    return ResourceBundle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
                        getBundle(baseName, locale,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
                                  LocaleDataResourceBundleControl.getRBControlInstance());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
            });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    static class LocaleDataResourceBundleControl extends ResourceBundle.Control {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        /* Singlton instance of ResourceBundle.Control. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        private static LocaleDataResourceBundleControl rbControlInstance =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
            new LocaleDataResourceBundleControl();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        public static LocaleDataResourceBundleControl getRBControlInstance() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
            return rbControlInstance;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
         * This method overrides the default implementation to search
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
         * from a prebaked locale string list to determin the candidate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
         * locale list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
         * @param baseName the resource bundle base name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
         *        locale   the requested locale for the resource bundle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
         * @returns a list of candidate locales to search from.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
         * @exception NullPointerException if baseName or locale is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        @Override
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
         public List<Locale> getCandidateLocales(String baseName, Locale locale) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            List<Locale> candidates = super.getCandidateLocales(baseName, locale);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            /* Get the locale string list from LocaleDataMetaInfo class. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
            String localeString = LocaleDataMetaInfo.getSupportedLocaleString(baseName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
            if (localeString.length() == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                return candidates;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
            for (Iterator<Locale> l = candidates.iterator(); l.hasNext(); ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
                String lstr = l.next().toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
                /* Every locale string in the locale string list returned from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
                   the above getSupportedLocaleString is enclosed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                   within two white spaces so that we could check some locale
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
                   such as "en".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                if (lstr.length() != 0 && localeString.indexOf(" " + lstr + " ") == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
                    l.remove();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
                }
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
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * Returns true if the non European resources jar file exists in jre
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * extension directory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * @returns true if the jar file is there. Otherwise, returns false.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    private static boolean isNonEuroLangSupported() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        final String sep = File.separator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        String localeDataJar =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
            java.security.AccessController.doPrivileged(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
             new sun.security.action.GetPropertyAction("java.home")) +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            sep + "lib" + sep + "ext" + sep + localeDataJarName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        /* Peek at the installed extension directory to see if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
           localedata.jar is installed or not.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        final File f = new File(localeDataJar);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        boolean isNonEuroResJarExist =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            AccessController.doPrivileged(new PrivilegedAction<Boolean>() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
                    public Boolean run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
                        return Boolean.valueOf(f.exists());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
                }).booleanValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        return isNonEuroResJarExist;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * This method gets the locale string list from LocaleDataMetaInfo class and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * then contructs the Locale array based on the locale string returned above.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * @returns the Locale array for the supported locale of JRE.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    private static Locale[] createLocaleList() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        String supportedLocaleString = LocaleDataMetaInfo.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
            getSupportedLocaleString("sun.text.resources.FormatData");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        if (supportedLocaleString.length() == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        /* Look for "|" and construct a new locale string list. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        int barIndex = supportedLocaleString.indexOf("|");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        StringTokenizer localeStringTokenizer = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        if (isNonEuroLangSupported()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
            localeStringTokenizer = new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
                StringTokenizer(supportedLocaleString.substring(0, barIndex) +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
                                supportedLocaleString.substring(barIndex + 1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
            localeStringTokenizer = new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
                StringTokenizer(supportedLocaleString.substring(0, barIndex));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        Locale[] locales = new Locale[localeStringTokenizer.countTokens()];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        for (int i = 0; i < locales.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
            String currentToken = localeStringTokenizer.nextToken();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
            int p2 = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
            int p1 = currentToken.indexOf('_');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
            String language = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
            String country = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
            String variant = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
            if (p1 == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
                language = currentToken;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
                language = currentToken.substring(0, p1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
                p2 = currentToken.indexOf('_', p1 + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
                if (p2 == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
                    country = currentToken.substring(p1 + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
                    country = currentToken.substring(p1 + 1, p2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
                    if (p2 < currentToken.length()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
                        variant = currentToken.substring(p2 + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
            locales[i] = new Locale(language, country, variant);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        return locales;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
}