8176841: Additional Unicode Language-Tag Extensions

8189134: New system properties for the default Locale extensions
8190918: Retrieve the region specific data regardless of language in locale
8191349: Add a new method in j.t.f.DateTimeFormatter to reflect Unicode extensions

Reviewed-by: scolebourne, lancea, rriggs, rgoel, nishjain
This commit is contained in:
Naoto Sato 2017-12-12 10:21:58 -08:00
parent 3246c46f41
commit f065141ddc
55 changed files with 3631 additions and 890 deletions

View file

@ -97,6 +97,13 @@ import sun.util.locale.provider.LocaleServiceProviderPool;
* DateFormat df = DateFormat.getDateInstance(DateFormat.LONG, Locale.FRANCE);
* }</pre>
* </blockquote>
*
* <p>If the specified locale contains "ca" (calendar), "rg" (region override),
* and/or "tz" (timezone) <a href="../util/Locale.html#def_locale_extension">Unicode
* extensions</a>, the calendar, the country and/or the time zone for formatting
* are overridden. If both "ca" and "rg" are specified, the calendar from the "ca"
* extension supersedes the implicit one from the "rg" extension.
*
* <p>You can use a DateFormat to parse also.
* <blockquote>
* <pre>{@code

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 1996, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1996, 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
@ -49,6 +49,7 @@ import java.util.Objects;
import java.util.ResourceBundle;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import sun.util.locale.provider.CalendarDataUtility;
import sun.util.locale.provider.LocaleProviderAdapter;
import sun.util.locale.provider.LocaleServiceProviderPool;
import sun.util.locale.provider.ResourceBundleBasedAdapter;
@ -82,6 +83,10 @@ import sun.util.locale.provider.TimeZoneNameUtility;
* </pre>
* </blockquote>
*
* <p>If the locale contains "rg" (region override)
* <a href="../util/Locale.html#def_locale_extension">Unicode extension</a>,
* the symbols are overridden for the designated region.
*
* <p>
* <code>DateFormatSymbols</code> objects are cloneable. When you obtain
* a <code>DateFormatSymbols</code> object, feel free to modify the
@ -716,15 +721,18 @@ public class DateFormatSymbols implements Serializable, Cloneable {
}
dfs = new DateFormatSymbols(false);
// check for region override
Locale override = CalendarDataUtility.findRegionOverride(locale);
// Initialize the fields from the ResourceBundle for locale.
LocaleProviderAdapter adapter
= LocaleProviderAdapter.getAdapter(DateFormatSymbolsProvider.class, locale);
= LocaleProviderAdapter.getAdapter(DateFormatSymbolsProvider.class, override);
// Avoid any potential recursions
if (!(adapter instanceof ResourceBundleBasedAdapter)) {
adapter = LocaleProviderAdapter.getResourceBundleBased();
}
ResourceBundle resource
= ((ResourceBundleBasedAdapter)adapter).getLocaleData().getDateFormatData(locale);
= ((ResourceBundleBasedAdapter)adapter).getLocaleData().getDateFormatData(override);
dfs.locale = locale;
// JRE and CLDR use different keys

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1996, 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
@ -44,6 +44,7 @@ import java.io.Serializable;
import java.text.spi.DecimalFormatSymbolsProvider;
import java.util.Currency;
import java.util.Locale;
import sun.util.locale.provider.CalendarDataUtility;
import sun.util.locale.provider.LocaleProviderAdapter;
import sun.util.locale.provider.LocaleServiceProviderPool;
import sun.util.locale.provider.ResourceBundleBasedAdapter;
@ -56,6 +57,10 @@ import sun.util.locale.provider.ResourceBundleBasedAdapter;
* of these symbols, you can get the <code>DecimalFormatSymbols</code> object from
* your <code>DecimalFormat</code> and modify it.
*
* <p>If the locale contains "rg" (region override)
* <a href="../util/Locale.html#def_locale_extension">Unicode extension</a>,
* the symbols are overridden for the designated region.
*
* @see java.util.Locale
* @see DecimalFormat
* @author Mark Davis
@ -609,13 +614,18 @@ public class DecimalFormatSymbols implements Cloneable, Serializable {
private void initialize( Locale locale ) {
this.locale = locale;
// check for region override
Locale override = locale.getUnicodeLocaleType("nu") == null ?
CalendarDataUtility.findRegionOverride(locale) :
locale;
// get resource bundle data
LocaleProviderAdapter adapter = LocaleProviderAdapter.getAdapter(DecimalFormatSymbolsProvider.class, locale);
LocaleProviderAdapter adapter = LocaleProviderAdapter.getAdapter(DecimalFormatSymbolsProvider.class, override);
// Avoid potential recursions
if (!(adapter instanceof ResourceBundleBasedAdapter)) {
adapter = LocaleProviderAdapter.getResourceBundleBased();
}
Object[] data = adapter.getLocaleResources(locale).getDecimalFormatSymbolsData();
Object[] data = adapter.getLocaleResources(override).getDecimalFormatSymbolsData();
String[] numberElements = (String[]) data[0];
decimalSeparator = numberElements[0].charAt(0);

View file

@ -96,7 +96,14 @@ import sun.util.locale.provider.LocaleServiceProviderPool;
* NumberFormat nf = NumberFormat.getInstance(Locale.FRENCH);
* }</pre>
* </blockquote>
* You can also use a <code>NumberFormat</code> to parse numbers:
*
* <p>If the locale contains "nu" (numbers) and/or "rg" (region override)
* <a href="../util/Locale.html#def_locale_extension">Unicode extensions</a>,
* the decimal digits, and/or the country used for formatting are overridden.
* If both "nu" and "rg" are specified, the decimal digits from the "nu"
* extension supersedes the implicit one from the "rg" extension.
*
* <p>You can also use a {@code NumberFormat} to parse numbers:
* <blockquote>
* <pre>{@code
* myNumber = nf.parse(myString);

View file

@ -672,7 +672,7 @@ public class SimpleDateFormat extends DateFormat {
// However, the calendar should use the current default TimeZone.
// If this is not contained in the locale zone strings, then the zone
// will be formatted using generic GMT+/-H:MM nomenclature.
calendar = Calendar.getInstance(TimeZone.getDefault(), loc);
calendar = Calendar.getInstance(loc);
}
}