sun.util.locale.provider.LocaleProviderAdapter Java Examples
The following examples show how to use
sun.util.locale.provider.LocaleProviderAdapter.
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: LocaleProviders.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 6 votes |
static void adapterTest(String expected, String lang, String ctry) { Locale testLocale = new Locale(lang, ctry); LocaleProviderAdapter ldaExpected = LocaleProviderAdapter.forType(LocaleProviderAdapter.Type.valueOf(expected)); if (!ldaExpected.getDateFormatProvider().isSupportedLocale(testLocale)) { System.out.println("test locale: "+testLocale+" is not supported by the expected provider: "+ldaExpected+". Ignoring the test."); return; } String preference = System.getProperty("java.locale.providers", ""); LocaleProviderAdapter lda = LocaleProviderAdapter.getAdapter(DateFormatProvider.class, testLocale); LocaleProviderAdapter.Type type = lda.getAdapterType(); System.out.printf("testLocale: %s, got: %s, expected: %s\n", testLocale, type, expected); if (!type.toString().equals(expected)) { throw new RuntimeException("Returned locale data adapter is not correct."); } }
Example #2
Source File: DateFormat.java From Bytecoder with Apache License 2.0 | 6 votes |
/** * Creates a DateFormat with the given time and/or date style in the given * locale. * @param timeStyle a value from 0 to 3 indicating the time format, * ignored if flags is 2 * @param dateStyle a value from 0 to 3 indicating the time format, * ignored if flags is 1 * @param flags either 1 for a time format, 2 for a date format, * or 3 for a date/time format * @param loc the locale for the format */ private static DateFormat get(int timeStyle, int dateStyle, int flags, Locale loc) { if ((flags & 1) != 0) { if (timeStyle < 0 || timeStyle > 3) { throw new IllegalArgumentException("Illegal time style " + timeStyle); } } else { timeStyle = -1; } if ((flags & 2) != 0) { if (dateStyle < 0 || dateStyle > 3) { throw new IllegalArgumentException("Illegal date style " + dateStyle); } } else { dateStyle = -1; } LocaleProviderAdapter adapter = LocaleProviderAdapter.getAdapter(DateFormatProvider.class, loc); DateFormat dateFormat = get(adapter, timeStyle, dateStyle, loc); if (dateFormat == null) { dateFormat = get(LocaleProviderAdapter.forJRE(), timeStyle, dateStyle, loc); } return dateFormat; }
Example #3
Source File: BreakIterator.java From Java8CN with Apache License 2.0 | 6 votes |
private static BreakIterator createBreakInstance(LocaleProviderAdapter adapter, Locale locale, int type) { BreakIteratorProvider breakIteratorProvider = adapter.getBreakIteratorProvider(); BreakIterator iterator = null; switch (type) { case CHARACTER_INDEX: iterator = breakIteratorProvider.getCharacterInstance(locale); break; case WORD_INDEX: iterator = breakIteratorProvider.getWordInstance(locale); break; case LINE_INDEX: iterator = breakIteratorProvider.getLineInstance(locale); break; case SENTENCE_INDEX: iterator = breakIteratorProvider.getSentenceInstance(locale); break; } return iterator; }
Example #4
Source File: BreakIterator.java From jdk1.8-source-analysis with Apache License 2.0 | 6 votes |
private static BreakIterator createBreakInstance(LocaleProviderAdapter adapter, Locale locale, int type) { BreakIteratorProvider breakIteratorProvider = adapter.getBreakIteratorProvider(); BreakIterator iterator = null; switch (type) { case CHARACTER_INDEX: iterator = breakIteratorProvider.getCharacterInstance(locale); break; case WORD_INDEX: iterator = breakIteratorProvider.getWordInstance(locale); break; case LINE_INDEX: iterator = breakIteratorProvider.getLineInstance(locale); break; case SENTENCE_INDEX: iterator = breakIteratorProvider.getSentenceInstance(locale); break; } return iterator; }
Example #5
Source File: LocaleData.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
@Override public List<Locale> getCandidateLocales(String baseName, Locale locale) { List<Locale> candidates = super.getCandidateLocales(baseName, locale); // Weed out Locales which are known to have no resource bundles int lastDot = baseName.lastIndexOf('.'); String category = (lastDot >= 0) ? baseName.substring(lastDot + 1) : baseName; LocaleProviderAdapter.Type type = baseName.contains(DOTCLDR) ? CLDR : JRE; LocaleProviderAdapter adapter = LocaleProviderAdapter.forType(type); Set<String> langtags = ((JRELocaleProviderAdapter)adapter).getLanguageTagSet(category); if (!langtags.isEmpty()) { for (Iterator<Locale> itr = candidates.iterator(); itr.hasNext();) { if (!LocaleProviderAdapter.isSupportedLocale(itr.next(), type, langtags)) { itr.remove(); } } } // Force fallback to Locale.ENGLISH for CLDR time zone names support if (locale.getLanguage() != "en" && type == CLDR && category.equals("TimeZoneNames")) { candidates.add(candidates.size() - 1, Locale.ENGLISH); } return candidates; }
Example #6
Source File: LocaleData.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
@Override public List<Locale> getCandidateLocales(String baseName, Locale locale) { List<Locale> candidates = super.getCandidateLocales(baseName, locale); // Weed out Locales which are known to have no resource bundles int lastDot = baseName.lastIndexOf('.'); String category = (lastDot >= 0) ? baseName.substring(lastDot + 1) : baseName; LocaleProviderAdapter.Type type = baseName.contains(DOTCLDR) ? CLDR : JRE; LocaleProviderAdapter adapter = LocaleProviderAdapter.forType(type); Set<String> langtags = ((JRELocaleProviderAdapter)adapter).getLanguageTagSet(category); if (!langtags.isEmpty()) { for (Iterator<Locale> itr = candidates.iterator(); itr.hasNext();) { if (!LocaleProviderAdapter.isSupportedLocale(itr.next(), type, langtags)) { itr.remove(); } } } // Force fallback to Locale.ENGLISH for CLDR time zone names support if (locale.getLanguage() != "en" && type == CLDR && category.equals("TimeZoneNames")) { candidates.add(candidates.size() - 1, Locale.ENGLISH); } return candidates; }
Example #7
Source File: BreakIterator.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
private static BreakIterator createBreakInstance(LocaleProviderAdapter adapter, Locale locale, int type) { BreakIteratorProvider breakIteratorProvider = adapter.getBreakIteratorProvider(); BreakIterator iterator = null; switch (type) { case CHARACTER_INDEX: iterator = breakIteratorProvider.getCharacterInstance(locale); break; case WORD_INDEX: iterator = breakIteratorProvider.getWordInstance(locale); break; case LINE_INDEX: iterator = breakIteratorProvider.getLineInstance(locale); break; case SENTENCE_INDEX: iterator = breakIteratorProvider.getSentenceInstance(locale); break; } return iterator; }
Example #8
Source File: LocaleProviders.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 6 votes |
static void bug8013903Test() { if (System.getProperty("os.name").startsWith("Windows")) { Date sampleDate = new Date(0x10000000000L); String fallbackResult = "Heisei 16.Nov.03 (Wed) AM 11:53:47"; String jreResult = "\u5e73\u6210 16.11.03 (\u6c34) \u5348\u524d 11:53:47"; Locale l = new Locale("ja", "JP", "JP"); SimpleDateFormat sdf = new SimpleDateFormat("GGGG yyyy.MMM.dd '('E')' a hh:mm:ss", l); sdf.setTimeZone(TimeZone.getTimeZone("America/Los_Angeles")); String result = sdf.format(sampleDate); System.out.println(result); if (LocaleProviderAdapter.getAdapterPreference() .contains(LocaleProviderAdapter.Type.JRE)) { if (!jreResult.equals(result)) { throw new RuntimeException("Format failed. result: \"" + result + "\", expected: \"" + jreResult); } } else { // should be FALLBACK, as Windows HOST does not return // display names if (!fallbackResult.equals(result)) { throw new RuntimeException("Format failed. result: \"" + result + "\", expected: \"" + fallbackResult); } } } }
Example #9
Source File: LocaleProviders.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
static void adapterTest(String expected, String lang, String ctry) { Locale testLocale = new Locale(lang, ctry); LocaleProviderAdapter ldaExpected = LocaleProviderAdapter.forType(LocaleProviderAdapter.Type.valueOf(expected)); if (!ldaExpected.getDateFormatProvider().isSupportedLocale(testLocale)) { System.out.println("test locale: "+testLocale+" is not supported by the expected provider: "+ldaExpected+". Ignoring the test."); return; } String preference = System.getProperty("java.locale.providers", ""); LocaleProviderAdapter lda = LocaleProviderAdapter.getAdapter(DateFormatProvider.class, testLocale); LocaleProviderAdapter.Type type = lda.getAdapterType(); System.out.printf("testLocale: %s, got: %s, expected: %s\n", testLocale, type, expected); if (!type.toString().equals(expected)) { throw new RuntimeException("Returned locale data adapter is not correct."); } }
Example #10
Source File: CLDRLocaleProviderAdapter.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
public CLDRLocaleProviderAdapter() { LocaleDataMetaInfo nbmi = null; try { nbmi = AccessController.doPrivileged(new PrivilegedExceptionAction<LocaleDataMetaInfo>() { @Override public LocaleDataMetaInfo run() { for (LocaleDataMetaInfo ldmi : ServiceLoader.loadInstalled(LocaleDataMetaInfo.class)) { if (ldmi.getType() == LocaleProviderAdapter.Type.CLDR) { return ldmi; } } return null; } }); } catch (Exception e) { // Catch any exception, and continue as if only CLDR's base locales exist. } nonBaseMetaInfo = nbmi; }
Example #11
Source File: LocaleProviders.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
static void adapterTest(String expected, String lang, String ctry) { Locale testLocale = new Locale(lang, ctry); LocaleProviderAdapter ldaExpected = LocaleProviderAdapter.forType(LocaleProviderAdapter.Type.valueOf(expected)); if (!ldaExpected.getDateFormatProvider().isSupportedLocale(testLocale)) { System.out.println("test locale: "+testLocale+" is not supported by the expected provider: "+ldaExpected+". Ignoring the test."); return; } String preference = System.getProperty("java.locale.providers", ""); LocaleProviderAdapter lda = LocaleProviderAdapter.getAdapter(DateFormatProvider.class, testLocale); LocaleProviderAdapter.Type type = lda.getAdapterType(); System.out.printf("testLocale: %s, got: %s, expected: %s\n", testLocale, type, expected); if (!type.toString().equals(expected)) { throw new RuntimeException("Returned locale data adapter is not correct."); } }
Example #12
Source File: CLDRCalendarNameProviderImpl.java From Bytecoder with Apache License 2.0 | 6 votes |
@Override public boolean isSupportedLocale(Locale locale) { if (Locale.ROOT.equals(locale)) { return true; } String calendarType = null; if (locale.hasExtensions()) { calendarType = locale.getUnicodeLocaleType("ca"); locale = locale.stripExtensions(); } if (calendarType != null) { switch (calendarType) { case "buddhist": case "japanese": case "gregory": case "islamic": case "roc": break; default: // Unknown calendar type return false; } } return LocaleProviderAdapter.forType(Type.CLDR).isSupportedProviderLocale(locale, langtags); }
Example #13
Source File: LocaleProviders.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
static void bug8013903Test() { if (System.getProperty("os.name").startsWith("Windows")) { Date sampleDate = new Date(0x10000000000L); String hostResult = "\u5e73\u6210 16.11.03 (Wed) AM 11:53:47"; String jreResult = "\u5e73\u6210 16.11.03 (\u6c34) \u5348\u524d 11:53:47"; Locale l = new Locale("ja", "JP", "JP"); SimpleDateFormat sdf = new SimpleDateFormat("GGGG yyyy.MMM.dd '('E')' a hh:mm:ss", l); sdf.setTimeZone(TimeZone.getTimeZone("America/Los_Angeles")); String result = sdf.format(sampleDate); System.out.println(result); if (LocaleProviderAdapter.getAdapterPreference() .contains(LocaleProviderAdapter.Type.JRE)) { if (!jreResult.equals(result)) { throw new RuntimeException("Format failed. result: \"" + result + "\", expected: \"" + jreResult); } } else { // Windows display names. Subject to change if Windows changes its format. if (!hostResult.equals(result)) { throw new RuntimeException("Format failed. result: \"" + result + "\", expected: \"" + hostResult); } } } }
Example #14
Source File: LocaleData.java From jdk8u_jdk with GNU General Public License v2.0 | 6 votes |
@Override public List<Locale> getCandidateLocales(String baseName, Locale locale) { List<Locale> candidates = super.getCandidateLocales(baseName, locale); // Weed out Locales which are known to have no resource bundles int lastDot = baseName.lastIndexOf('.'); String category = (lastDot >= 0) ? baseName.substring(lastDot + 1) : baseName; LocaleProviderAdapter.Type type = baseName.contains(DOTCLDR) ? CLDR : JRE; LocaleProviderAdapter adapter = LocaleProviderAdapter.forType(type); Set<String> langtags = ((JRELocaleProviderAdapter)adapter).getLanguageTagSet(category); if (!langtags.isEmpty()) { for (Iterator<Locale> itr = candidates.iterator(); itr.hasNext();) { if (!LocaleProviderAdapter.isSupportedLocale(itr.next(), type, langtags)) { itr.remove(); } } } // Force fallback to Locale.ENGLISH for CLDR time zone names support if (locale.getLanguage() != "en" && type == CLDR && category.equals("TimeZoneNames")) { candidates.add(candidates.size() - 1, Locale.ENGLISH); } return candidates; }
Example #15
Source File: LocaleProviders.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
static void bug8013903Test() { if (System.getProperty("os.name").startsWith("Windows")) { Date sampleDate = new Date(0x10000000000L); String fallbackResult = "Heisei 16.Nov.03 (Wed) AM 11:53:47"; String jreResult = "\u5e73\u6210 16.11.03 (\u6c34) \u5348\u524d 11:53:47"; Locale l = new Locale("ja", "JP", "JP"); SimpleDateFormat sdf = new SimpleDateFormat("GGGG yyyy.MMM.dd '('E')' a hh:mm:ss", l); sdf.setTimeZone(TimeZone.getTimeZone("America/Los_Angeles")); String result = sdf.format(sampleDate); System.out.println(result); if (LocaleProviderAdapter.getAdapterPreference() .contains(LocaleProviderAdapter.Type.JRE)) { if (!jreResult.equals(result)) { throw new RuntimeException("Format failed. result: \"" + result + "\", expected: \"" + jreResult); } } else { // should be FALLBACK, as Windows HOST does not return // display names if (!fallbackResult.equals(result)) { throw new RuntimeException("Format failed. result: \"" + result + "\", expected: \"" + fallbackResult); } } } }
Example #16
Source File: BreakIterator.java From openjdk-8 with GNU General Public License v2.0 | 6 votes |
private static BreakIterator createBreakInstance(LocaleProviderAdapter adapter, Locale locale, int type) { BreakIteratorProvider breakIteratorProvider = adapter.getBreakIteratorProvider(); BreakIterator iterator = null; switch (type) { case CHARACTER_INDEX: iterator = breakIteratorProvider.getCharacterInstance(locale); break; case WORD_INDEX: iterator = breakIteratorProvider.getWordInstance(locale); break; case LINE_INDEX: iterator = breakIteratorProvider.getLineInstance(locale); break; case SENTENCE_INDEX: iterator = breakIteratorProvider.getSentenceInstance(locale); break; } return iterator; }
Example #17
Source File: IsoFields.java From jdk1.8-source-analysis with Apache License 2.0 | 5 votes |
@Override public String getDisplayName(Locale locale) { Objects.requireNonNull(locale, "locale"); LocaleResources lr = LocaleProviderAdapter.getResourceBundleBased() .getLocaleResources(locale); ResourceBundle rb = lr.getJavaTimeFormatData(); return rb.containsKey("field.week") ? rb.getString("field.week") : toString(); }
Example #18
Source File: DateFormatSymbols.java From hottub with GNU General Public License v2.0 | 5 votes |
private static DateFormatSymbols getProviderInstance(Locale locale) { LocaleProviderAdapter adapter = LocaleProviderAdapter.getAdapter(DateFormatSymbolsProvider.class, locale); DateFormatSymbolsProvider provider = adapter.getDateFormatSymbolsProvider(); DateFormatSymbols dfsyms = provider.getInstance(locale); if (dfsyms == null) { provider = LocaleProviderAdapter.forJRE().getDateFormatSymbolsProvider(); dfsyms = provider.getInstance(locale); } return dfsyms; }
Example #19
Source File: IsoFields.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
@Override public String getDisplayName(Locale locale) { Objects.requireNonNull(locale, "locale"); LocaleResources lr = LocaleProviderAdapter.getResourceBundleBased() .getLocaleResources(locale); ResourceBundle rb = lr.getJavaTimeFormatData(); return rb.containsKey("field.week") ? rb.getString("field.week") : toString(); }
Example #20
Source File: JSpinner.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
private static String getDefaultPattern(Locale locale) { // Get the pattern for the default locale. LocaleProviderAdapter adapter; adapter = LocaleProviderAdapter.getAdapter(NumberFormatProvider.class, locale); LocaleResources lr = adapter.getLocaleResources(locale); if (lr == null) { lr = LocaleProviderAdapter.forJRE().getLocaleResources(locale); } String[] all = lr.getNumberPatterns(); return all[0]; }
Example #21
Source File: WeekFields.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
@Override public String getDisplayName(Locale locale) { Objects.requireNonNull(locale, "locale"); if (rangeUnit == YEARS) { // only have values for week-of-year LocaleResources lr = LocaleProviderAdapter.getResourceBundleBased() .getLocaleResources(locale); ResourceBundle rb = lr.getJavaTimeFormatData(); return rb.containsKey("field.week") ? rb.getString("field.week") : name; } return name; }
Example #22
Source File: DateFormat.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
private static DateFormat get(LocaleProviderAdapter adapter, int timeStyle, int dateStyle, Locale loc) { DateFormatProvider provider = adapter.getDateFormatProvider(); DateFormat dateFormat; if (timeStyle == -1) { dateFormat = provider.getDateInstance(dateStyle, loc); } else { if (dateStyle == -1) { dateFormat = provider.getTimeInstance(timeStyle, loc); } else { dateFormat = provider.getDateTimeInstance(dateStyle, timeStyle, loc); } } return dateFormat; }
Example #23
Source File: JSpinner.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
private static String getDefaultPattern(Locale loc) { LocaleProviderAdapter adapter = LocaleProviderAdapter.getAdapter(DateFormatProvider.class, loc); LocaleResources lr = adapter.getLocaleResources(loc); if (lr == null) { lr = LocaleProviderAdapter.forJRE().getLocaleResources(loc); } return lr.getDateTimePattern(DateFormat.SHORT, DateFormat.SHORT, null); }
Example #24
Source File: JSpinner.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
private static String getDefaultPattern(Locale loc) { LocaleProviderAdapter adapter = LocaleProviderAdapter.getAdapter(DateFormatProvider.class, loc); LocaleResources lr = adapter.getLocaleResources(loc); if (lr == null) { lr = LocaleProviderAdapter.forJRE().getLocaleResources(loc); } return lr.getDateTimePattern(DateFormat.SHORT, DateFormat.SHORT, null); }
Example #25
Source File: BreakIterator.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
private static BreakIterator createBreakInstance(Locale locale, int type) { LocaleProviderAdapter adapter = LocaleProviderAdapter.getAdapter(BreakIteratorProvider.class, locale); BreakIterator iterator = createBreakInstance(adapter, locale, type); if (iterator == null) { iterator = createBreakInstance(LocaleProviderAdapter.forJRE(), locale, type); } return iterator; }
Example #26
Source File: Locale.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
/** * Returns a name for the locale's variant code that is appropriate for display to the * user. If possible, the name will be localized for inLocale. If the locale * doesn't specify a variant code, this function returns the empty string. * * @param inLocale The locale for which to retrieve the display variant code. * @return The name of the display variant code appropriate to the given locale. * @exception NullPointerException if <code>inLocale</code> is <code>null</code> */ public String getDisplayVariant(Locale inLocale) { if (baseLocale.getVariant().length() == 0) return ""; LocaleResources lr = LocaleProviderAdapter.forJRE().getLocaleResources(inLocale); String names[] = getDisplayVariantArray(inLocale); // Get the localized patterns for formatting a list, and use // them to format the list. return formatList(names, lr.getLocaleName("ListPattern"), lr.getLocaleName("ListCompositionPattern")); }
Example #27
Source File: Locale.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
/** * Returns a name for the locale's variant code that is appropriate for display to the * user. If possible, the name will be localized for inLocale. If the locale * doesn't specify a variant code, this function returns the empty string. * * @param inLocale The locale for which to retrieve the display variant code. * @return The name of the display variant code appropriate to the given locale. * @exception NullPointerException if <code>inLocale</code> is <code>null</code> */ public String getDisplayVariant(Locale inLocale) { if (baseLocale.getVariant().length() == 0) return ""; LocaleResources lr = LocaleProviderAdapter.forJRE().getLocaleResources(inLocale); String names[] = getDisplayVariantArray(inLocale); // Get the localized patterns for formatting a list, and use // them to format the list. return formatList(names, lr.getLocaleName("ListPattern"), lr.getLocaleName("ListCompositionPattern")); }
Example #28
Source File: Collator.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
/** * Gets the Collator for the desired locale. * @param desiredLocale the desired locale. * @return the Collator for the desired locale. * @see java.util.Locale * @see java.util.ResourceBundle */ public static Collator getInstance(Locale desiredLocale) { SoftReference<Collator> ref = cache.get(desiredLocale); Collator result = (ref != null) ? ref.get() : null; if (result == null) { LocaleProviderAdapter adapter; adapter = LocaleProviderAdapter.getAdapter(CollatorProvider.class, desiredLocale); CollatorProvider provider = adapter.getCollatorProvider(); result = provider.getInstance(desiredLocale); if (result == null) { result = LocaleProviderAdapter.forJRE() .getCollatorProvider().getInstance(desiredLocale); } while (true) { if (ref != null) { // Remove the empty SoftReference if any cache.remove(desiredLocale, ref); } ref = cache.putIfAbsent(desiredLocale, new SoftReference<>(result)); if (ref == null) { break; } Collator cachedColl = ref.get(); if (cachedColl != null) { result = cachedColl; break; } } } return (Collator) result.clone(); // make the world safe }
Example #29
Source File: Bug8004240.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) { List<LocaleProviderAdapter.Type> types = LocaleProviderAdapter.getAdapterPreference(); try { types.set(0, null); } catch (UnsupportedOperationException e) { // success return; } throw new RuntimeException("LocaleProviderAdapter.getAdapterPrefence() returned a modifiable list."); }
Example #30
Source File: IsoFields.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
@Override public String getDisplayName(Locale locale) { Objects.requireNonNull(locale, "locale"); LocaleResources lr = LocaleProviderAdapter.getResourceBundleBased() .getLocaleResources(locale); ResourceBundle rb = lr.getJavaTimeFormatData(); return rb.containsKey("field.week") ? rb.getString("field.week") : toString(); }