jdk/src/share/classes/sun/util/resources/LocaleData.java
author katakai
Sat, 26 Feb 2011 03:53:06 -0800
changeset 8695 e83968c6ceda
parent 6501 684810d882b3
child 9035 1255eb81cc2f
permissions -rw-r--r--
6998391: Serbian (Latin) locale support Reviewed-by: naoto
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
6501
684810d882b3 6875847: Java Locale Enhancement
naoto
parents: 5506
diff changeset
     2
 * Copyright (c) 1996, 2010, 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.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
8695
e83968c6ceda 6998391: Serbian (Latin) locale support
katakai
parents: 6501
diff changeset
   174
      if (localeString.length() == 0) {
2
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(); ) {
8695
e83968c6ceda 6998391: Serbian (Latin) locale support
katakai
parents: 6501
diff changeset
   179
                Locale loc = l.next();
e83968c6ceda 6998391: Serbian (Latin) locale support
katakai
parents: 6501
diff changeset
   180
                String lstr = null;
e83968c6ceda 6998391: Serbian (Latin) locale support
katakai
parents: 6501
diff changeset
   181
                if (loc.getScript().length() > 0) {
e83968c6ceda 6998391: Serbian (Latin) locale support
katakai
parents: 6501
diff changeset
   182
                    lstr = loc.toLanguageTag().replace('-', '_');
e83968c6ceda 6998391: Serbian (Latin) locale support
katakai
parents: 6501
diff changeset
   183
                } else {
e83968c6ceda 6998391: Serbian (Latin) locale support
katakai
parents: 6501
diff changeset
   184
                    lstr = loc.toString();
e83968c6ceda 6998391: Serbian (Latin) locale support
katakai
parents: 6501
diff changeset
   185
                    int idx = lstr.indexOf("_#");
e83968c6ceda 6998391: Serbian (Latin) locale support
katakai
parents: 6501
diff changeset
   186
                    if (idx >= 0) {
e83968c6ceda 6998391: Serbian (Latin) locale support
katakai
parents: 6501
diff changeset
   187
                        lstr = lstr.substring(0, idx);
e83968c6ceda 6998391: Serbian (Latin) locale support
katakai
parents: 6501
diff changeset
   188
                    }
6501
684810d882b3 6875847: Java Locale Enhancement
naoto
parents: 5506
diff changeset
   189
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                /* Every locale string in the locale string list returned from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
                   the above getSupportedLocaleString is enclosed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
                   within two white spaces so that we could check some locale
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
                   such as "en".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
                */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
                if (lstr.length() != 0 && localeString.indexOf(" " + lstr + " ") == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
                    l.remove();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
            return candidates;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
         * Overrides "getFallbackLocale" to return null so
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
         * that the fallback locale will be null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
         * @param baseName the resource bundle base name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
         *        locale   the requested locale for the resource bundle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
         * @return null for the fallback locale.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
         * @exception NullPointerException if baseName or locale is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        @Override
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        public Locale getFallbackLocale(String baseName, Locale locale) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
            if (baseName == null || locale == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
                throw new NullPointerException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * Returns true if the non European resources jar file exists in jre
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * extension directory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * @returns true if the jar file is there. Otherwise, returns false.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    private static boolean isNonEuroLangSupported() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        final String sep = File.separator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        String localeDataJar =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
            java.security.AccessController.doPrivileged(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
             new sun.security.action.GetPropertyAction("java.home")) +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
            sep + "lib" + sep + "ext" + sep + localeDataJarName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        /* Peek at the installed extension directory to see if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
           localedata.jar is installed or not.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        final File f = new File(localeDataJar);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        boolean isNonEuroResJarExist =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
            AccessController.doPrivileged(new PrivilegedAction<Boolean>() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                    public Boolean run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
                        return Boolean.valueOf(f.exists());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                }).booleanValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        return isNonEuroResJarExist;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     * This method gets the locale string list from LocaleDataMetaInfo class and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     * then contructs the Locale array based on the locale string returned above.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     * @returns the Locale array for the supported locale of JRE.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    private static Locale[] createLocaleList() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        String supportedLocaleString = LocaleDataMetaInfo.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
            getSupportedLocaleString("sun.text.resources.FormatData");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        if (supportedLocaleString.length() == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        /* Look for "|" and construct a new locale string list. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        int barIndex = supportedLocaleString.indexOf("|");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        StringTokenizer localeStringTokenizer = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        if (isNonEuroLangSupported()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
            localeStringTokenizer = new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
                StringTokenizer(supportedLocaleString.substring(0, barIndex) +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
                                supportedLocaleString.substring(barIndex + 1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
            localeStringTokenizer = new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
                StringTokenizer(supportedLocaleString.substring(0, barIndex));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        Locale[] locales = new Locale[localeStringTokenizer.countTokens()];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        for (int i = 0; i < locales.length; i++) {
8695
e83968c6ceda 6998391: Serbian (Latin) locale support
katakai
parents: 6501
diff changeset
   273
            String currentToken = localeStringTokenizer.nextToken().replace('_','-');
e83968c6ceda 6998391: Serbian (Latin) locale support
katakai
parents: 6501
diff changeset
   274
            if (currentToken.equals("ja-JP-JP")) {
e83968c6ceda 6998391: Serbian (Latin) locale support
katakai
parents: 6501
diff changeset
   275
                currentToken = "ja-JP-u-ca-japanese-x-lvariant-JP";
e83968c6ceda 6998391: Serbian (Latin) locale support
katakai
parents: 6501
diff changeset
   276
            } else if (currentToken.equals("th-TH-TH")) {
e83968c6ceda 6998391: Serbian (Latin) locale support
katakai
parents: 6501
diff changeset
   277
                currentToken = "th-TH-u-nu-thai-x-lvariant-TH";
e83968c6ceda 6998391: Serbian (Latin) locale support
katakai
parents: 6501
diff changeset
   278
            } else if (currentToken.equals("no-NO-NY")) {
e83968c6ceda 6998391: Serbian (Latin) locale support
katakai
parents: 6501
diff changeset
   279
                currentToken = "no-NO-x-lvariant-NY";
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
            }
8695
e83968c6ceda 6998391: Serbian (Latin) locale support
katakai
parents: 6501
diff changeset
   281
            locales[i] = Locale.forLanguageTag(currentToken);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        return locales;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
}