Java Code Examples for java.util.ResourceBundle#getStringArray()
The following examples show how to use
java.util.ResourceBundle#getStringArray() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LocaleResources.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 6 votes |
String[] getCalendarNames(String key) { String[] names = null; String cacheKey = CALENDAR_NAMES + key; removeEmptyReferences(); ResourceReference data = cache.get(cacheKey); if (data == null || ((names = (String[]) data.get()) == null)) { ResourceBundle rb = localeData.getDateFormatData(locale); if (rb.containsKey(key)) { names = rb.getStringArray(key); cache.put(cacheKey, new ResourceReference(cacheKey, (Object) names, referenceQueue)); } } return names; }
Example 2
Source File: LocaleResources.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
String[] getJavaTimeNames(String key) { String[] names = null; String cacheKey = CALENDAR_NAMES + key; removeEmptyReferences(); ResourceReference data = cache.get(cacheKey); if (data == null || ((names = (String[]) data.get()) == null)) { ResourceBundle rb = getJavaTimeFormatData(); if (rb.containsKey(key)) { names = rb.getStringArray(key); cache.put(cacheKey, new ResourceReference(cacheKey, (Object) names, referenceQueue)); } } return names; }
Example 3
Source File: LocaleResources.java From jdk8u_jdk with GNU General Public License v2.0 | 6 votes |
String[] getJavaTimeNames(String key) { String[] names = null; String cacheKey = CALENDAR_NAMES + key; removeEmptyReferences(); ResourceReference data = cache.get(cacheKey); if (data == null || ((names = (String[]) data.get()) == null)) { ResourceBundle rb = getJavaTimeFormatData(); if (rb.containsKey(key)) { names = rb.getStringArray(key); cache.put(cacheKey, new ResourceReference(cacheKey, (Object) names, referenceQueue)); } } return names; }
Example 4
Source File: LocaleResources.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
String[] getJavaTimeNames(String key) { String[] names = null; String cacheKey = CALENDAR_NAMES + key; removeEmptyReferences(); ResourceReference data = cache.get(cacheKey); if (data == null || ((names = (String[]) data.get()) == null)) { ResourceBundle rb = getJavaTimeFormatData(); if (rb.containsKey(key)) { names = rb.getStringArray(key); cache.put(cacheKey, new ResourceReference(cacheKey, (Object) names, referenceQueue)); } } return names; }
Example 5
Source File: LocaleResources.java From Bytecoder with Apache License 2.0 | 6 votes |
String[] getCalendarNames(String key) { String[] names = null; String cacheKey = CALENDAR_NAMES + key; removeEmptyReferences(); ResourceReference data = cache.get(cacheKey); if (data == null || ((names = (String[]) data.get()) == null)) { ResourceBundle rb = localeData.getDateFormatData(locale); if (rb.containsKey(key)) { names = rb.getStringArray(key); cache.put(cacheKey, new ResourceReference(cacheKey, (Object) names, referenceQueue)); } } return names; }
Example 6
Source File: LocaleResources.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 6 votes |
String[] getJavaTimeNames(String key) { String[] names = null; String cacheKey = CALENDAR_NAMES + key; removeEmptyReferences(); ResourceReference data = cache.get(cacheKey); if (data == null || ((names = (String[]) data.get()) == null)) { ResourceBundle rb = getJavaTimeFormatData(); if (rb.containsKey(key)) { names = rb.getStringArray(key); cache.put(cacheKey, new ResourceReference(cacheKey, (Object) names, referenceQueue)); } } return names; }
Example 7
Source File: LocaleResources.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
public String[] getNumberPatterns() { String[] numberPatterns = null; removeEmptyReferences(); ResourceReference data = cache.get(NUMBER_PATTERNS_CACHEKEY); if (data == null || ((numberPatterns = (String[]) data.get()) == null)) { ResourceBundle resource = localeData.getNumberFormatData(locale); numberPatterns = resource.getStringArray("NumberPatterns"); cache.put(NUMBER_PATTERNS_CACHEKEY, new ResourceReference(NUMBER_PATTERNS_CACHEKEY, (Object) numberPatterns, referenceQueue)); } return numberPatterns; }
Example 8
Source File: LocaleResources.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
public String[] getNumberPatterns() { String[] numberPatterns = null; removeEmptyReferences(); ResourceReference data = cache.get(NUMBER_PATTERNS_CACHEKEY); if (data == null || ((numberPatterns = (String[]) data.get()) == null)) { ResourceBundle resource = localeData.getNumberFormatData(locale); numberPatterns = resource.getStringArray("NumberPatterns"); cache.put(NUMBER_PATTERNS_CACHEKEY, new ResourceReference(NUMBER_PATTERNS_CACHEKEY, (Object) numberPatterns, referenceQueue)); } return numberPatterns; }
Example 9
Source File: LocaleResources.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
public Object[] getDecimalFormatSymbolsData() { Object[] dfsdata; removeEmptyReferences(); ResourceReference data = cache.get(DECIMAL_FORMAT_SYMBOLS_DATA_CACHEKEY); if (data == null || ((dfsdata = (Object[]) data.get()) == null)) { // Note that only dfsdata[0] is prepared here in this method. Other // elements are provided by the caller, yet they are cached here. ResourceBundle rb = localeData.getNumberFormatData(locale); dfsdata = new Object[3]; // NumberElements look up. First, try the Unicode extension String numElemKey; String numberType = locale.getUnicodeLocaleType("nu"); if (numberType != null) { numElemKey = numberType + ".NumberElements"; if (rb.containsKey(numElemKey)) { dfsdata[0] = rb.getStringArray(numElemKey); } } // Next, try DefaultNumberingSystem value if (dfsdata[0] == null && rb.containsKey("DefaultNumberingSystem")) { numElemKey = rb.getString("DefaultNumberingSystem") + ".NumberElements"; if (rb.containsKey(numElemKey)) { dfsdata[0] = rb.getStringArray(numElemKey); } } // Last resort. No need to check the availability. // Just let it throw MissingResourceException when needed. if (dfsdata[0] == null) { dfsdata[0] = rb.getStringArray("NumberElements"); } cache.put(DECIMAL_FORMAT_SYMBOLS_DATA_CACHEKEY, new ResourceReference(DECIMAL_FORMAT_SYMBOLS_DATA_CACHEKEY, (Object) dfsdata, referenceQueue)); } return dfsdata; }
Example 10
Source File: TransliteratorRegistry.java From j2objc with Apache License 2.0 | 4 votes |
/** * Attempt to find an entry in a single resource bundle. This is * a one-sided lookup. findInStaticStore() performs up to two such * lookups, one for the source, and one for the target. * * Do not perform fallback. Return 0 on failure. * * On success, create a new Entry object, populate it, and return it. * The caller owns the returned object. */ private Object[] findInBundle(Spec specToOpen, Spec specToFind, String variant, int direction) { // assert(specToOpen.isLocale()); ResourceBundle res = specToOpen.getBundle(); if (res == null) { // This means that the bundle's locale does not match // the current level of iteration for the spec. return null; } for (int pass=0; pass<2; ++pass) { StringBuilder tag = new StringBuilder(); // First try either TransliteratorTo_xxx or // TransliterateFrom_xxx, then try the bidirectional // Transliterate_xxx. This precedence order is arbitrary // but must be consistent and documented. if (pass == 0) { tag.append(direction == Transliterator.FORWARD ? "TransliterateTo" : "TransliterateFrom"); } else { tag.append("Transliterate"); } tag.append(specToFind.get().toUpperCase(Locale.ENGLISH)); try { // The Transliterate*_xxx resource is an array of // strings of the format { <v0>, <r0>, ... }. Each // <vi> is a variant name, and each <ri> is a rule. String[] subres = res.getStringArray(tag.toString()); // assert(subres != null); // assert(subres.length % 2 == 0); int i = 0; if (variant.length() != 0) { for (i=0; i<subres.length; i+= 2) { if (subres[i].equalsIgnoreCase(variant)) { break; } } } if (i < subres.length) { // We have a match, or there is no variant and i == 0. // We have succeeded in loading a string from the // locale resources. Return the rule string which // will itself become the registry entry. // The direction is always forward for the // TransliterateTo_xxx and TransliterateFrom_xxx // items; those are unidirectional forward rules. // For the bidirectional Transliterate_xxx items, // the direction is the value passed in to this // function. int dir = (pass == 0) ? Transliterator.FORWARD : direction; return new Object[] { new LocaleEntry(subres[i+1], dir) }; } } catch (MissingResourceException e) { ///CLOVER:OFF if (DEBUG) System.out.println("missing resource: " + e); ///CLOVER:ON } } // If we get here we had a missing resource exception or we // failed to find a desired variant. return null; }
Example 11
Source File: DateFormatSymbols.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
private void initializeData(Locale desiredLocale) { locale = desiredLocale; // Copy values of a cached instance if any. SoftReference<DateFormatSymbols> ref = cachedInstances.get(locale); DateFormatSymbols dfs; if (ref != null && (dfs = ref.get()) != null) { copyMembers(dfs, this); return; } // Initialize the fields from the ResourceBundle for locale. LocaleProviderAdapter adapter = LocaleProviderAdapter.getAdapter(DateFormatSymbolsProvider.class, locale); // Avoid any potential recursions if (!(adapter instanceof ResourceBundleBasedAdapter)) { adapter = LocaleProviderAdapter.getResourceBundleBased(); } ResourceBundle resource = ((ResourceBundleBasedAdapter)adapter).getLocaleData().getDateFormatData(locale); // JRE and CLDR use different keys // JRE: Eras, short.Eras and narrow.Eras // CLDR: long.Eras, Eras and narrow.Eras if (resource.containsKey("Eras")) { eras = resource.getStringArray("Eras"); } else if (resource.containsKey("long.Eras")) { eras = resource.getStringArray("long.Eras"); } else if (resource.containsKey("short.Eras")) { eras = resource.getStringArray("short.Eras"); } months = resource.getStringArray("MonthNames"); shortMonths = resource.getStringArray("MonthAbbreviations"); ampms = resource.getStringArray("AmPmMarkers"); localPatternChars = resource.getString("DateTimePatternChars"); // Day of week names are stored in a 1-based array. weekdays = toOneBasedArray(resource.getStringArray("DayNames")); shortWeekdays = toOneBasedArray(resource.getStringArray("DayAbbreviations")); // Put a clone in the cache ref = new SoftReference<>((DateFormatSymbols)this.clone()); SoftReference<DateFormatSymbols> x = cachedInstances.putIfAbsent(locale, ref); if (x != null) { DateFormatSymbols y = x.get(); if (y == null) { // Replace the empty SoftReference with ref. cachedInstances.put(locale, ref); } } }
Example 12
Source File: DateFormatSymbols.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
/** * Initializes this DateFormatSymbols with the locale data. This method uses * a cached DateFormatSymbols instance for the given locale if available. If * there's no cached one, this method creates an uninitialized instance and * populates its fields from the resource bundle for the locale, and caches * the instance. Note: zoneStrings isn't initialized in this method. */ private void initializeData(Locale locale) { SoftReference<DateFormatSymbols> ref = cachedInstances.get(locale); DateFormatSymbols dfs; if (ref == null || (dfs = ref.get()) == null) { if (ref != null) { // Remove the empty SoftReference cachedInstances.remove(locale, ref); } dfs = new DateFormatSymbols(false); // Initialize the fields from the ResourceBundle for locale. LocaleProviderAdapter adapter = LocaleProviderAdapter.getAdapter(DateFormatSymbolsProvider.class, locale); // Avoid any potential recursions if (!(adapter instanceof ResourceBundleBasedAdapter)) { adapter = LocaleProviderAdapter.getResourceBundleBased(); } ResourceBundle resource = ((ResourceBundleBasedAdapter)adapter).getLocaleData().getDateFormatData(locale); dfs.locale = locale; // JRE and CLDR use different keys // JRE: Eras, short.Eras and narrow.Eras // CLDR: long.Eras, Eras and narrow.Eras if (resource.containsKey("Eras")) { dfs.eras = resource.getStringArray("Eras"); } else if (resource.containsKey("long.Eras")) { dfs.eras = resource.getStringArray("long.Eras"); } else if (resource.containsKey("short.Eras")) { dfs.eras = resource.getStringArray("short.Eras"); } dfs.months = resource.getStringArray("MonthNames"); dfs.shortMonths = resource.getStringArray("MonthAbbreviations"); dfs.ampms = resource.getStringArray("AmPmMarkers"); dfs.localPatternChars = resource.getString("DateTimePatternChars"); // Day of week names are stored in a 1-based array. dfs.weekdays = toOneBasedArray(resource.getStringArray("DayNames")); dfs.shortWeekdays = toOneBasedArray(resource.getStringArray("DayAbbreviations")); // Put dfs in the cache ref = new SoftReference<>(dfs); SoftReference<DateFormatSymbols> x = cachedInstances.putIfAbsent(locale, ref); if (x != null) { DateFormatSymbols y = x.get(); if (y == null) { // Replace the empty SoftReference with ref. cachedInstances.replace(locale, x, ref); } else { ref = x; dfs = y; } } // If the bundle's locale isn't the target locale, put another cache // entry for the bundle's locale. Locale bundleLocale = resource.getLocale(); if (!bundleLocale.equals(locale)) { SoftReference<DateFormatSymbols> z = cachedInstances.putIfAbsent(bundleLocale, ref); if (z != null && z.get() == null) { cachedInstances.replace(bundleLocale, z, ref); } } } // Copy the field values from dfs to this instance. copyMembers(dfs, this); }
Example 13
Source File: DateFormatSymbols.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
/** * Initializes this DateFormatSymbols with the locale data. This method uses * a cached DateFormatSymbols instance for the given locale if available. If * there's no cached one, this method creates an uninitialized instance and * populates its fields from the resource bundle for the locale, and caches * the instance. Note: zoneStrings isn't initialized in this method. */ private void initializeData(Locale locale) { SoftReference<DateFormatSymbols> ref = cachedInstances.get(locale); DateFormatSymbols dfs; if (ref == null || (dfs = ref.get()) == null) { if (ref != null) { // Remove the empty SoftReference cachedInstances.remove(locale, ref); } dfs = new DateFormatSymbols(false); // Initialize the fields from the ResourceBundle for locale. LocaleProviderAdapter adapter = LocaleProviderAdapter.getAdapter(DateFormatSymbolsProvider.class, locale); // Avoid any potential recursions if (!(adapter instanceof ResourceBundleBasedAdapter)) { adapter = LocaleProviderAdapter.getResourceBundleBased(); } ResourceBundle resource = ((ResourceBundleBasedAdapter)adapter).getLocaleData().getDateFormatData(locale); dfs.locale = locale; // JRE and CLDR use different keys // JRE: Eras, short.Eras and narrow.Eras // CLDR: long.Eras, Eras and narrow.Eras if (resource.containsKey("Eras")) { dfs.eras = resource.getStringArray("Eras"); } else if (resource.containsKey("long.Eras")) { dfs.eras = resource.getStringArray("long.Eras"); } else if (resource.containsKey("short.Eras")) { dfs.eras = resource.getStringArray("short.Eras"); } dfs.months = resource.getStringArray("MonthNames"); dfs.shortMonths = resource.getStringArray("MonthAbbreviations"); dfs.ampms = resource.getStringArray("AmPmMarkers"); dfs.localPatternChars = resource.getString("DateTimePatternChars"); // Day of week names are stored in a 1-based array. dfs.weekdays = toOneBasedArray(resource.getStringArray("DayNames")); dfs.shortWeekdays = toOneBasedArray(resource.getStringArray("DayAbbreviations")); // Put dfs in the cache ref = new SoftReference<>(dfs); SoftReference<DateFormatSymbols> x = cachedInstances.putIfAbsent(locale, ref); if (x != null) { DateFormatSymbols y = x.get(); if (y == null) { // Replace the empty SoftReference with ref. cachedInstances.replace(locale, x, ref); } else { ref = x; dfs = y; } } // If the bundle's locale isn't the target locale, put another cache // entry for the bundle's locale. Locale bundleLocale = resource.getLocale(); if (!bundleLocale.equals(locale)) { SoftReference<DateFormatSymbols> z = cachedInstances.putIfAbsent(bundleLocale, ref); if (z != null && z.get() == null) { cachedInstances.replace(bundleLocale, z, ref); } } } // Copy the field values from dfs to this instance. copyMembers(dfs, this); }
Example 14
Source File: DateFormatSymbols.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 4 votes |
private void initializeData(Locale desiredLocale) { locale = desiredLocale; // Copy values of a cached instance if any. SoftReference<DateFormatSymbols> ref = cachedInstances.get(locale); DateFormatSymbols dfs; if (ref != null && (dfs = ref.get()) != null) { copyMembers(dfs, this); return; } // Initialize the fields from the ResourceBundle for locale. LocaleProviderAdapter adapter = LocaleProviderAdapter.getAdapter(DateFormatSymbolsProvider.class, locale); // Avoid any potential recursions if (!(adapter instanceof ResourceBundleBasedAdapter)) { adapter = LocaleProviderAdapter.getResourceBundleBased(); } ResourceBundle resource = ((ResourceBundleBasedAdapter)adapter).getLocaleData().getDateFormatData(locale); // JRE and CLDR use different keys // JRE: Eras, short.Eras and narrow.Eras // CLDR: long.Eras, Eras and narrow.Eras if (resource.containsKey("Eras")) { eras = resource.getStringArray("Eras"); } else if (resource.containsKey("long.Eras")) { eras = resource.getStringArray("long.Eras"); } else if (resource.containsKey("short.Eras")) { eras = resource.getStringArray("short.Eras"); } months = resource.getStringArray("MonthNames"); shortMonths = resource.getStringArray("MonthAbbreviations"); ampms = resource.getStringArray("AmPmMarkers"); localPatternChars = resource.getString("DateTimePatternChars"); // Day of week names are stored in a 1-based array. weekdays = toOneBasedArray(resource.getStringArray("DayNames")); shortWeekdays = toOneBasedArray(resource.getStringArray("DayAbbreviations")); // Put a clone in the cache ref = new SoftReference<>((DateFormatSymbols)this.clone()); SoftReference<DateFormatSymbols> x = cachedInstances.putIfAbsent(locale, ref); if (x != null) { DateFormatSymbols y = x.get(); if (y == null) { // Replace the empty SoftReference with ref. cachedInstances.put(locale, ref); } } }
Example 15
Source File: DateFormatSymbols.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
/** * Initializes this DateFormatSymbols with the locale data. This method uses * a cached DateFormatSymbols instance for the given locale if available. If * there's no cached one, this method creates an uninitialized instance and * populates its fields from the resource bundle for the locale, and caches * the instance. Note: zoneStrings isn't initialized in this method. */ private void initializeData(Locale locale) { SoftReference<DateFormatSymbols> ref = cachedInstances.get(locale); DateFormatSymbols dfs; if (ref == null || (dfs = ref.get()) == null) { if (ref != null) { // Remove the empty SoftReference cachedInstances.remove(locale, ref); } dfs = new DateFormatSymbols(false); // Initialize the fields from the ResourceBundle for locale. LocaleProviderAdapter adapter = LocaleProviderAdapter.getAdapter(DateFormatSymbolsProvider.class, locale); // Avoid any potential recursions if (!(adapter instanceof ResourceBundleBasedAdapter)) { adapter = LocaleProviderAdapter.getResourceBundleBased(); } ResourceBundle resource = ((ResourceBundleBasedAdapter)adapter).getLocaleData().getDateFormatData(locale); dfs.locale = locale; // JRE and CLDR use different keys // JRE: Eras, short.Eras and narrow.Eras // CLDR: long.Eras, Eras and narrow.Eras if (resource.containsKey("Eras")) { dfs.eras = resource.getStringArray("Eras"); } else if (resource.containsKey("long.Eras")) { dfs.eras = resource.getStringArray("long.Eras"); } else if (resource.containsKey("short.Eras")) { dfs.eras = resource.getStringArray("short.Eras"); } dfs.months = resource.getStringArray("MonthNames"); dfs.shortMonths = resource.getStringArray("MonthAbbreviations"); dfs.ampms = resource.getStringArray("AmPmMarkers"); dfs.localPatternChars = resource.getString("DateTimePatternChars"); // Day of week names are stored in a 1-based array. dfs.weekdays = toOneBasedArray(resource.getStringArray("DayNames")); dfs.shortWeekdays = toOneBasedArray(resource.getStringArray("DayAbbreviations")); // Put dfs in the cache ref = new SoftReference<>(dfs); SoftReference<DateFormatSymbols> x = cachedInstances.putIfAbsent(locale, ref); if (x != null) { DateFormatSymbols y = x.get(); if (y == null) { // Replace the empty SoftReference with ref. cachedInstances.replace(locale, x, ref); } else { ref = x; dfs = y; } } } // Copy the field values from dfs to this instance. copyMembers(dfs, this); }
Example 16
Source File: DateFormatSymbols.java From JDKSourceCode1.8 with MIT License | 4 votes |
/** * Initializes this DateFormatSymbols with the locale data. This method uses * a cached DateFormatSymbols instance for the given locale if available. If * there's no cached one, this method creates an uninitialized instance and * populates its fields from the resource bundle for the locale, and caches * the instance. Note: zoneStrings isn't initialized in this method. */ private void initializeData(Locale locale) { SoftReference<DateFormatSymbols> ref = cachedInstances.get(locale); DateFormatSymbols dfs; if (ref == null || (dfs = ref.get()) == null) { if (ref != null) { // Remove the empty SoftReference cachedInstances.remove(locale, ref); } dfs = new DateFormatSymbols(false); // Initialize the fields from the ResourceBundle for locale. LocaleProviderAdapter adapter = LocaleProviderAdapter.getAdapter(DateFormatSymbolsProvider.class, locale); // Avoid any potential recursions if (!(adapter instanceof ResourceBundleBasedAdapter)) { adapter = LocaleProviderAdapter.getResourceBundleBased(); } ResourceBundle resource = ((ResourceBundleBasedAdapter)adapter).getLocaleData().getDateFormatData(locale); dfs.locale = locale; // JRE and CLDR use different keys // JRE: Eras, short.Eras and narrow.Eras // CLDR: long.Eras, Eras and narrow.Eras if (resource.containsKey("Eras")) { dfs.eras = resource.getStringArray("Eras"); } else if (resource.containsKey("long.Eras")) { dfs.eras = resource.getStringArray("long.Eras"); } else if (resource.containsKey("short.Eras")) { dfs.eras = resource.getStringArray("short.Eras"); } dfs.months = resource.getStringArray("MonthNames"); dfs.shortMonths = resource.getStringArray("MonthAbbreviations"); dfs.ampms = resource.getStringArray("AmPmMarkers"); dfs.localPatternChars = resource.getString("DateTimePatternChars"); // Day of week names are stored in a 1-based array. dfs.weekdays = toOneBasedArray(resource.getStringArray("DayNames")); dfs.shortWeekdays = toOneBasedArray(resource.getStringArray("DayAbbreviations")); // Put dfs in the cache ref = new SoftReference<>(dfs); SoftReference<DateFormatSymbols> x = cachedInstances.putIfAbsent(locale, ref); if (x != null) { DateFormatSymbols y = x.get(); if (y == null) { // Replace the empty SoftReference with ref. cachedInstances.replace(locale, x, ref); } else { ref = x; dfs = y; } } // If the bundle's locale isn't the target locale, put another cache // entry for the bundle's locale. Locale bundleLocale = resource.getLocale(); if (!bundleLocale.equals(locale)) { SoftReference<DateFormatSymbols> z = cachedInstances.putIfAbsent(bundleLocale, ref); if (z != null && z.get() == null) { cachedInstances.replace(bundleLocale, z, ref); } } } // Copy the field values from dfs to this instance. copyMembers(dfs, this); }
Example 17
Source File: DateFormatSymbols.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
/** * Initializes this DateFormatSymbols with the locale data. This method uses * a cached DateFormatSymbols instance for the given locale if available. If * there's no cached one, this method creates an uninitialized instance and * populates its fields from the resource bundle for the locale, and caches * the instance. Note: zoneStrings isn't initialized in this method. */ private void initializeData(Locale locale) { SoftReference<DateFormatSymbols> ref = cachedInstances.get(locale); DateFormatSymbols dfs; if (ref == null || (dfs = ref.get()) == null) { if (ref != null) { // Remove the empty SoftReference cachedInstances.remove(locale, ref); } dfs = new DateFormatSymbols(false); // Initialize the fields from the ResourceBundle for locale. LocaleProviderAdapter adapter = LocaleProviderAdapter.getAdapter(DateFormatSymbolsProvider.class, locale); // Avoid any potential recursions if (!(adapter instanceof ResourceBundleBasedAdapter)) { adapter = LocaleProviderAdapter.getResourceBundleBased(); } ResourceBundle resource = ((ResourceBundleBasedAdapter)adapter).getLocaleData().getDateFormatData(locale); dfs.locale = locale; // JRE and CLDR use different keys // JRE: Eras, short.Eras and narrow.Eras // CLDR: long.Eras, Eras and narrow.Eras if (resource.containsKey("Eras")) { dfs.eras = resource.getStringArray("Eras"); } else if (resource.containsKey("long.Eras")) { dfs.eras = resource.getStringArray("long.Eras"); } else if (resource.containsKey("short.Eras")) { dfs.eras = resource.getStringArray("short.Eras"); } dfs.months = resource.getStringArray("MonthNames"); dfs.shortMonths = resource.getStringArray("MonthAbbreviations"); dfs.ampms = resource.getStringArray("AmPmMarkers"); dfs.localPatternChars = resource.getString("DateTimePatternChars"); // Day of week names are stored in a 1-based array. dfs.weekdays = toOneBasedArray(resource.getStringArray("DayNames")); dfs.shortWeekdays = toOneBasedArray(resource.getStringArray("DayAbbreviations")); // Put dfs in the cache ref = new SoftReference<>(dfs); SoftReference<DateFormatSymbols> x = cachedInstances.putIfAbsent(locale, ref); if (x != null) { DateFormatSymbols y = x.get(); if (y == null) { // Replace the empty SoftReference with ref. cachedInstances.replace(locale, x, ref); } else { ref = x; dfs = y; } } // If the bundle's locale isn't the target locale, put another cache // entry for the bundle's locale. Locale bundleLocale = resource.getLocale(); if (!bundleLocale.equals(locale)) { SoftReference<DateFormatSymbols> z = cachedInstances.putIfAbsent(bundleLocale, ref); if (z != null && z.get() == null) { cachedInstances.replace(bundleLocale, z, ref); } } } // Copy the field values from dfs to this instance. copyMembers(dfs, this); }
Example 18
Source File: LocaleResources.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
public Object[] getDecimalFormatSymbolsData() { Object[] dfsdata; removeEmptyReferences(); ResourceReference data = cache.get(DECIMAL_FORMAT_SYMBOLS_DATA_CACHEKEY); if (data == null || ((dfsdata = (Object[]) data.get()) == null)) { // Note that only dfsdata[0] is prepared here in this method. Other // elements are provided by the caller, yet they are cached here. ResourceBundle rb = localeData.getNumberFormatData(locale); dfsdata = new Object[3]; // NumberElements look up. First, try the Unicode extension String numElemKey; String numberType = locale.getUnicodeLocaleType("nu"); if (numberType != null) { numElemKey = numberType + ".NumberElements"; if (rb.containsKey(numElemKey)) { dfsdata[0] = rb.getStringArray(numElemKey); } } // Next, try DefaultNumberingSystem value if (dfsdata[0] == null && rb.containsKey("DefaultNumberingSystem")) { numElemKey = rb.getString("DefaultNumberingSystem") + ".NumberElements"; if (rb.containsKey(numElemKey)) { dfsdata[0] = rb.getStringArray(numElemKey); } } // Last resort. No need to check the availability. // Just let it throw MissingResourceException when needed. if (dfsdata[0] == null) { dfsdata[0] = rb.getStringArray("NumberElements"); } cache.put(DECIMAL_FORMAT_SYMBOLS_DATA_CACHEKEY, new ResourceReference(DECIMAL_FORMAT_SYMBOLS_DATA_CACHEKEY, (Object) dfsdata, referenceQueue)); } return dfsdata; }
Example 19
Source File: LocaleData.java From mpxj with GNU Lesser General Public License v2.1 | 2 votes |
/** * Convenience method for retrieving a String[] resource. * * @param locale locale identifier * @param key resource key * @return resource value */ public static final String[] getStringArray(Locale locale, String key) { ResourceBundle bundle = ResourceBundle.getBundle(LocaleData.class.getName(), locale); return (bundle.getStringArray(key)); }
Example 20
Source File: LocaleData.java From mpxj with GNU Lesser General Public License v2.1 | 2 votes |
/** * Convenience method for retrieving a String[] resource. * * @param locale locale identifier * @param key resource key * @return resource value */ public static final String[] getStringArray(Locale locale, String key) { ResourceBundle bundle = ResourceBundle.getBundle(LocaleData.class.getName(), locale); return (bundle.getStringArray(key)); }