jdk/src/share/classes/sun/util/locale/provider/CalendarDataProviderImpl.java
author naoto
Tue, 21 Aug 2012 11:00:30 -0700
changeset 13583 dc0017b1a452
child 14024 694c379c2958
permissions -rw-r--r--
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) Reviewed-by: erikj, sherman, peytoia
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
     1
/*
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
     2
 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
     4
 *
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    10
 *
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    15
 * accompanied this code).
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    16
 *
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    20
 *
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    23
 * questions.
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    24
 */
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    25
package sun.util.locale.provider;
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    26
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    27
import static java.util.Calendar.*;
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    28
import java.util.HashMap;
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    29
import java.util.Locale;
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    30
import java.util.Map;
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    31
import java.util.ResourceBundle;
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    32
import java.util.Set;
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    33
import java.util.spi.CalendarDataProvider;
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    34
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    35
/**
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    36
 * Concrete implementation of the  {@link java.util.spi.CalendarDataProvider
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    37
 * CalendarDataProvider} class for the JRE LocaleProviderAdapter.
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    38
 *
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    39
 * @author Masayoshi Okutsu
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    40
 * @author Naoto Sato
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    41
 */
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    42
public class CalendarDataProviderImpl extends CalendarDataProvider implements AvailableLanguageTags {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    43
    private final LocaleProviderAdapter.Type type;
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    44
    private final Set<String> langtags;
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    45
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    46
    public CalendarDataProviderImpl(LocaleProviderAdapter.Type type, Set<String> langtags) {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    47
        this.type = type;
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    48
        this.langtags = langtags;
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    49
    }
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    50
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    51
    @Override
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    52
    public int getFirstDayOfWeek(Locale locale) {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    53
        return getIntData(CalendarDataUtility.FIRST_DAY_OF_WEEK, locale);
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    54
    }
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    55
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    56
    @Override
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    57
    public int getMinimalDaysInFirstWeek(Locale locale) {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    58
        return getIntData(CalendarDataUtility.MINIMAL_DAYS_IN_FIRST_WEEK, locale);
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    59
    }
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    60
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    61
    @Override
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    62
    public String getDisplayName(String calendarType, int field, int value, int style, Locale locale) {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    63
        String name = null;
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    64
        String key = getKey(calendarType, field, style);
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    65
        if (key != null) {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    66
            ResourceBundle rb = LocaleProviderAdapter.forType(type).getLocaleData().getDateFormatData(locale);
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    67
            if (rb.containsKey(key)) {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    68
                String[] strings = rb.getStringArray(key);
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    69
                if (strings.length > 0) {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    70
                    if (field == DAY_OF_WEEK || field == YEAR) {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    71
                        --value;
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    72
                    }
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    73
                    name = strings[value];
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    74
                    // If name is empty in standalone, try its `format' style.
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    75
                    if (name.length() == 0
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    76
                            && (style == SHORT_STANDALONE || style == LONG_STANDALONE)) {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    77
                        name = getDisplayName(calendarType, field, value,
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    78
                                              style == SHORT_STANDALONE ? SHORT_FORMAT : LONG_FORMAT,
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    79
                                              locale);
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    80
                    }
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    81
                }
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    82
            }
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    83
        }
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    84
        return name;
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    85
    }
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    86
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    87
    @Override
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    88
    public Map<String, Integer> getDisplayNames(String calendarType, int field, int style, Locale locale) {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    89
        Map<String, Integer> names;
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    90
        if (style == ALL_STYLES) {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    91
            names = getDisplayNamesImpl(calendarType, field, SHORT_FORMAT, locale);
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    92
            if (field != AM_PM) {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    93
                for (int st : new int[] { SHORT_STANDALONE, LONG_FORMAT, LONG_STANDALONE }) {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    94
                    names.putAll(getDisplayNamesImpl(calendarType, field, st, locale));
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    95
                }
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    96
            }
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    97
        } else {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    98
            // specific style
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    99
            names = getDisplayNamesImpl(calendarType, field, style, locale);
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   100
        }
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   101
        return names.isEmpty() ? null : names;
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   102
    }
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   103
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   104
    private Map<String, Integer> getDisplayNamesImpl(String calendarType, int field,
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   105
                                                     int style, Locale locale) {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   106
        String key = getKey(calendarType, field, style);
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   107
        Map<String, Integer> map = new HashMap<>();
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   108
        if (key != null) {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   109
            ResourceBundle rb = LocaleProviderAdapter.forType(type).getLocaleData().getDateFormatData(locale);
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   110
            if (rb.containsKey(key)) {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   111
                String[] strings = rb.getStringArray(key);
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   112
                if (field == YEAR) {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   113
                    if (strings.length > 0) {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   114
                        map.put(strings[0], 1);
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   115
                    }
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   116
                } else {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   117
                    int base = (field == DAY_OF_WEEK) ? 1 : 0;
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   118
                    for (int i = 0; i < strings.length; i++) {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   119
                        String name = strings[i];
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   120
                        // Ignore any empty string (some standalone month names
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   121
                        // are not defined)
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   122
                        if (name.length() == 0) {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   123
                            continue;
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   124
                        }
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   125
                        map.put(name, base + i);
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   126
                    }
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   127
                }
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   128
            }
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   129
        }
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   130
        return map;
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   131
    }
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   132
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   133
    @Override
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   134
    public Locale[] getAvailableLocales() {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   135
        return LocaleProviderAdapter.toLocaleArray(langtags);
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   136
    }
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   137
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   138
    @Override
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   139
    public boolean isSupportedLocale(Locale locale) {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   140
        if (locale == Locale.ROOT) {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   141
            return true;
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   142
        }
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   143
        String calendarType = null;
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   144
        if (locale.hasExtensions()) {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   145
            calendarType = locale.getUnicodeLocaleType("ca");
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   146
            locale = locale.stripExtensions();
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   147
        }
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   148
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   149
        if (calendarType != null) {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   150
            switch (calendarType) {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   151
            case "buddhist":
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   152
            case "japanese":
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   153
            case "gregory":
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   154
                break;
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   155
            default:
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   156
                // Unknown calendar type
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   157
                return false;
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   158
            }
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   159
        }
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   160
        if (langtags.contains(locale.toLanguageTag())) {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   161
            return true;
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   162
        }
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   163
        if (type == LocaleProviderAdapter.Type.JRE) {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   164
            String oldname = locale.toString().replace('_', '-');
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   165
            return langtags.contains(oldname);
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   166
        }
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   167
        return false;
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   168
    }
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   169
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   170
    @Override
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   171
    public Set<String> getAvailableLanguageTags() {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   172
        return langtags;
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   173
    }
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   174
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   175
    private int getIntData(String key, Locale locale) {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   176
        ResourceBundle rb = LocaleProviderAdapter.forType(type).getLocaleData().getCalendarData(locale);
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   177
        if (rb.containsKey(key)) {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   178
            String firstday = rb.getString(key);
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   179
            return Integer.parseInt(firstday);
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   180
        }
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   181
        // Note that the base bundle of CLDR doesn't have the Calendar week parameters.
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   182
        return 0;
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   183
    }
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   184
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   185
    private String getKey(String type, int field, int style) {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   186
        boolean standalone = (style & 0x8000) != 0;
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   187
        style &= ~0x8000;
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   188
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   189
        if ("gregory".equals(type)) {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   190
            type = null;
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   191
        }
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   192
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   193
        StringBuilder key = new StringBuilder();
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   194
        switch (field) {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   195
        case ERA:
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   196
            if (type != null) {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   197
                key.append(type).append('.');
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   198
            }
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   199
            if (style == SHORT) {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   200
                key.append("short.");
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   201
            }
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   202
            key.append("Eras");
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   203
            break;
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   204
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   205
        case YEAR:
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   206
            key.append(type).append(".FirstYear");
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   207
            break;
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   208
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   209
        case MONTH:
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   210
            if (standalone) {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   211
                key.append("standalone.");
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   212
            }
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   213
            key.append(style == SHORT ? "MonthAbbreviations" : "MonthNames");
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   214
            break;
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   215
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   216
        case DAY_OF_WEEK:
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   217
            key.append(style == SHORT ? "DayAbbreviations" : "DayNames");
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   218
            break;
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   219
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   220
        case AM_PM:
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   221
            key.append("AmPmMarkers");
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   222
            break;
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   223
        }
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   224
        return key.length() > 0 ? key.toString() : null;
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   225
    }
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   226
}