1 /*
2 * Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
67 String[] strings = javatime ? lr.getJavaTimeNames(key) : lr.getCalendarNames(key);
68
69 // If standalone names are requested and no "standalone." resources are found,
70 // try the default ones instead.
71 if (strings == null && key.indexOf("standalone.") != -1) {
72 key = key.replaceFirst("standalone.", "");
73 strings = javatime ? lr.getJavaTimeNames(key) : lr.getCalendarNames(key);
74 }
75
76 if (strings != null && strings.length > 0) {
77 if (field == DAY_OF_WEEK || field == YEAR) {
78 --value;
79 }
80 if (value < 0) {
81 return null;
82 } else if (value >= strings.length) {
83 if (field == ERA && "japanese".equals(calendarType)) {
84 Era[] jeras = CalendarSystem.forName("japanese").getEras();
85 if (value <= jeras.length) {
86 // Localized era name could not be retrieved from this provider.
87 // This can occur either for NewEra or SupEra.
88 //
89 // If it's CLDR provider, try COMPAT first, which is guaranteed to have
90 // the name for NewEra.
91 if (type == LocaleProviderAdapter.Type.CLDR) {
92 lr = LocaleProviderAdapter.forJRE().getLocaleResources(locale);
93 key = getResourceKeyFor(LocaleProviderAdapter.Type.JRE,
94 calendarType, field, style, javatime);
95 strings =
96 javatime ? lr.getJavaTimeNames(key) : lr.getCalendarNames(key);
97 }
98 if (strings == null || value >= strings.length) {
99 // Get the default name for SupEra
100 Era supEra = jeras[value - 1]; // 0-based index
101 if (javatime) {
102 return getBaseStyle(style) == NARROW_FORMAT ?
103 supEra.getAbbreviation() :
104 supEra.getName();
105 } else {
106 return (style & LONG) != 0 ?
107 supEra.getName() :
108 supEra.getAbbreviation();
109 }
110 }
|
1 /*
2 * Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
67 String[] strings = javatime ? lr.getJavaTimeNames(key) : lr.getCalendarNames(key);
68
69 // If standalone names are requested and no "standalone." resources are found,
70 // try the default ones instead.
71 if (strings == null && key.indexOf("standalone.") != -1) {
72 key = key.replaceFirst("standalone.", "");
73 strings = javatime ? lr.getJavaTimeNames(key) : lr.getCalendarNames(key);
74 }
75
76 if (strings != null && strings.length > 0) {
77 if (field == DAY_OF_WEEK || field == YEAR) {
78 --value;
79 }
80 if (value < 0) {
81 return null;
82 } else if (value >= strings.length) {
83 if (field == ERA && "japanese".equals(calendarType)) {
84 Era[] jeras = CalendarSystem.forName("japanese").getEras();
85 if (value <= jeras.length) {
86 // Localized era name could not be retrieved from this provider.
87 // This can occur either for Reiwa or SupEra.
88 //
89 // If it's CLDR provider, try COMPAT first, which is guaranteed to have
90 // the name for Reiwa.
91 if (type == LocaleProviderAdapter.Type.CLDR) {
92 lr = LocaleProviderAdapter.forJRE().getLocaleResources(locale);
93 key = getResourceKeyFor(LocaleProviderAdapter.Type.JRE,
94 calendarType, field, style, javatime);
95 strings =
96 javatime ? lr.getJavaTimeNames(key) : lr.getCalendarNames(key);
97 }
98 if (strings == null || value >= strings.length) {
99 // Get the default name for SupEra
100 Era supEra = jeras[value - 1]; // 0-based index
101 if (javatime) {
102 return getBaseStyle(style) == NARROW_FORMAT ?
103 supEra.getAbbreviation() :
104 supEra.getName();
105 } else {
106 return (style & LONG) != 0 ?
107 supEra.getName() :
108 supEra.getAbbreviation();
109 }
110 }
|