< prev index next >

src/share/classes/sun/util/locale/provider/CalendarNameProviderImpl.java

Print this page

        

*** 1,7 **** /* ! * Copyright (c) 2012, 2017, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this --- 1,7 ---- /* ! * Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this
*** 33,44 **** import java.util.spi.CalendarNameProvider; import sun.util.calendar.CalendarSystem; import sun.util.calendar.Era; /** ! * Concrete implementation of the {@link java.util.spi.CalendarDataProvider ! * CalendarDataProvider} class for the JRE LocaleProviderAdapter. * * @author Masayoshi Okutsu * @author Naoto Sato */ public class CalendarNameProviderImpl extends CalendarNameProvider implements AvailableLanguageTags { --- 33,44 ---- import java.util.spi.CalendarNameProvider; import sun.util.calendar.CalendarSystem; import sun.util.calendar.Era; /** ! * Concrete implementation of the {@link java.util.spi.CalendarNameProvider ! * CalendarNameProvider} class for the JRE LocaleProviderAdapter. * * @author Masayoshi Okutsu * @author Naoto Sato */ public class CalendarNameProviderImpl extends CalendarNameProvider implements AvailableLanguageTags {
*** 67,93 **** String[] strings = javatime ? lr.getJavaTimeNames(key) : lr.getCalendarNames(key); if (strings != null && strings.length > 0) { if (field == DAY_OF_WEEK || field == YEAR) { --value; } ! if (value < 0 || value > strings.length) { return null; ! } else if (value == strings.length) { if (field == ERA && "japanese".equals(calendarType)) { - // get the supplemental era, if any, specified through - // the property "jdk.calendar.japanese.supplemental.era" - // which is always the last element. Era[] jeras = CalendarSystem.forName("japanese").getEras(); ! if (jeras.length == value) { Era supEra = jeras[value - 1]; // 0-based index ! return style == LONG ? supEra.getName() : supEra.getAbbreviation(); } } return null; } name = strings[value]; // If name is empty in standalone, try its `format' style. if (name.length() == 0 && (style == SHORT_STANDALONE || style == LONG_STANDALONE || style == NARROW_STANDALONE)) { --- 67,114 ---- String[] strings = javatime ? lr.getJavaTimeNames(key) : lr.getCalendarNames(key); if (strings != null && strings.length > 0) { if (field == DAY_OF_WEEK || field == YEAR) { --value; } ! if (value < 0) { return null; ! } else if (value >= strings.length) { if (field == ERA && "japanese".equals(calendarType)) { Era[] jeras = CalendarSystem.forName("japanese").getEras(); ! if (value <= jeras.length) { ! // Localized era name could not be retrieved from this provider. ! // This can occur either for NewEra or SupEra. ! // ! // If it's CLDR provider, try COMPAT first, which is guaranteed to have ! // the name for NewEra. ! if (type == LocaleProviderAdapter.Type.CLDR) { ! lr = LocaleProviderAdapter.forJRE().getLocaleResources(locale); ! key = getResourceKeyFor(LocaleProviderAdapter.Type.JRE, ! calendarType, field, style, javatime); ! strings = ! javatime ? lr.getJavaTimeNames(key) : lr.getCalendarNames(key); ! } ! if (strings == null || value >= strings.length) { ! // Get the default name for SupEra Era supEra = jeras[value - 1]; // 0-based index ! if (javatime) { ! return getBaseStyle(style) == NARROW_FORMAT ? ! supEra.getAbbreviation() : ! supEra.getName(); ! } else { ! return (style & LONG) != 0 ? supEra.getName() : supEra.getAbbreviation(); } } + } else { + return null; + } + } else { return null; } + } name = strings[value]; // If name is empty in standalone, try its `format' style. if (name.length() == 0 && (style == SHORT_STANDALONE || style == LONG_STANDALONE || style == NARROW_STANDALONE)) {
*** 156,166 **** } } return map; } ! private int getBaseStyle(int style) { return style & ~(SHORT_STANDALONE - SHORT_FORMAT); } /** * Comparator implementation for TreeMap which iterates keys from longest --- 177,187 ---- } } return map; } ! private static int getBaseStyle(int style) { return style & ~(SHORT_STANDALONE - SHORT_FORMAT); } /** * Comparator implementation for TreeMap which iterates keys from longest
*** 237,246 **** --- 258,272 ---- } return false; } private String getResourceKey(String type, int field, int style, boolean javatime) { + return getResourceKeyFor(this.type, type, field, style, javatime); + } + + private static String getResourceKeyFor(LocaleProviderAdapter.Type adapterType, + String type, int field, int style, boolean javatime) { int baseStyle = getBaseStyle(style); boolean isStandalone = (style != baseStyle); if ("gregory".equals(type)) { type = null;
*** 260,270 **** key.append("narrow."); } else { // JRE and CLDR use different resource key conventions // due to historical reasons. (JRE DateFormatSymbols.getEras returns // abbreviations while other getShort*() return abbreviations.) ! if (this.type == LocaleProviderAdapter.Type.JRE) { if (javatime) { if (baseStyle == LONG) { key.append("long."); } } --- 286,296 ---- key.append("narrow."); } else { // JRE and CLDR use different resource key conventions // due to historical reasons. (JRE DateFormatSymbols.getEras returns // abbreviations while other getShort*() return abbreviations.) ! if (adapterType == LocaleProviderAdapter.Type.JRE) { if (javatime) { if (baseStyle == LONG) { key.append("long."); } }
*** 312,322 **** break; } return key.length() > 0 ? key.toString() : null; } ! private String toStyleName(int baseStyle) { switch (baseStyle) { case SHORT: return "Abbreviations"; case NARROW_FORMAT: return "Narrows"; --- 338,348 ---- break; } return key.length() > 0 ? key.toString() : null; } ! private static String toStyleName(int baseStyle) { switch (baseStyle) { case SHORT: return "Abbreviations"; case NARROW_FORMAT: return "Narrows";
< prev index next >