< prev index next >

src/java.base/share/classes/sun/util/locale/provider/CalendarDataUtility.java

Print this page
rev 47480 : [mq]: 8176841

*** 1,7 **** /* ! * Copyright (c) 2012, 2013, 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, 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
*** 26,35 **** --- 26,36 ---- package sun.util.locale.provider; import static java.util.Calendar.*; import java.util.Locale; import java.util.Map; + import java.util.Optional; import java.util.spi.CalendarDataProvider; import java.util.spi.CalendarNameProvider; /** * {@code CalendarDataUtility} is a utility class for calling the
*** 45,66 **** // No instantiation private CalendarDataUtility() { } public static int retrieveFirstDayOfWeek(Locale locale) { LocaleServiceProviderPool pool = LocaleServiceProviderPool.getPool(CalendarDataProvider.class); Integer value = pool.getLocalizedObject(CalendarWeekParameterGetter.INSTANCE, ! locale, true, FIRST_DAY_OF_WEEK); return (value != null && (value >= SUNDAY && value <= SATURDAY)) ? value : SUNDAY; } public static int retrieveMinimalDaysInFirstWeek(Locale locale) { LocaleServiceProviderPool pool = LocaleServiceProviderPool.getPool(CalendarDataProvider.class); Integer value = pool.getLocalizedObject(CalendarWeekParameterGetter.INSTANCE, ! locale, true, MINIMAL_DAYS_IN_FIRST_WEEK); return (value != null && (value >= 1 && value <= 7)) ? value : 1; } public static String retrieveFieldValueName(String id, int field, int value, int style, Locale locale) { LocaleServiceProviderPool pool = --- 46,92 ---- // No instantiation private CalendarDataUtility() { } public static int retrieveFirstDayOfWeek(Locale locale) { + // Look for the Unicode Extension in the locale parameter + if (locale.hasExtensions()) { + String fw = locale.getUnicodeLocaleType("fw"); + if (fw != null) { + switch (fw.toLowerCase(Locale.ROOT)) { + case "mon": + return MONDAY; + case "tue": + return TUESDAY; + case "wed": + return WEDNESDAY; + case "thu": + return THURSDAY; + case "fri": + return FRIDAY; + case "sat": + return SATURDAY; + case "sun": + return SUNDAY; + } + } + } + LocaleServiceProviderPool pool = LocaleServiceProviderPool.getPool(CalendarDataProvider.class); Integer value = pool.getLocalizedObject(CalendarWeekParameterGetter.INSTANCE, ! findRegionOverride(locale).orElse(locale), ! true, FIRST_DAY_OF_WEEK); return (value != null && (value >= SUNDAY && value <= SATURDAY)) ? value : SUNDAY; } public static int retrieveMinimalDaysInFirstWeek(Locale locale) { LocaleServiceProviderPool pool = LocaleServiceProviderPool.getPool(CalendarDataProvider.class); Integer value = pool.getLocalizedObject(CalendarWeekParameterGetter.INSTANCE, ! findRegionOverride(locale).orElse(locale), ! true, MINIMAL_DAYS_IN_FIRST_WEEK); return (value != null && (value >= 1 && value <= 7)) ? value : 1; } public static String retrieveFieldValueName(String id, int field, int value, int style, Locale locale) { LocaleServiceProviderPool pool =
*** 100,109 **** --- 126,160 ---- normalizeCalendarType(id), field, style, false); } return map; } + /** + * Utility to look for a region override extension + */ + public static Optional<Locale> findRegionOverride(Locale l) { + String rg = l.getUnicodeLocaleType("rg"); + Locale override = null; + + if (rg != null && rg.length() == 6) { + // UN M.49 code should not be allowed here + // cannot use regex here, as it could be a recursive call + rg = rg.toUpperCase(Locale.ROOT); + if (rg.charAt(0) >= 0x0041 && + rg.charAt(0) <= 0x005A && + rg.charAt(1) >= 0x0041 && + rg.charAt(1) <= 0x005A && + rg.substring(2).equals("ZZZZ")) { + override = new Locale.Builder().setLocale(l) + .setRegion(rg.substring(0, 2)) + .build(); + } + } + + return Optional.ofNullable(override); + } + static String normalizeCalendarType(String requestID) { String type; if (requestID.equals("gregorian") || requestID.equals("iso8601")) { type = "gregory"; } else if (requestID.startsWith("islamic")) {
< prev index next >