Java Code Examples for sun.util.locale.provider.LocaleProviderAdapter#Type

The following examples show how to use sun.util.locale.provider.LocaleProviderAdapter#Type . 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: LocaleData.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
@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 2
Source File: LocaleData.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
@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 3
Source File: LocaleProviders.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
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 4
Source File: LocaleProviders.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
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 5
Source File: LocaleProviders.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
static void bug7198834Test() {
    LocaleProviderAdapter lda = LocaleProviderAdapter.getAdapter(DateFormatProvider.class, Locale.US);
    LocaleProviderAdapter.Type type = lda.getAdapterType();
    if (type == LocaleProviderAdapter.Type.HOST && System.getProperty("os.name").startsWith("Windows")) {
        DateFormat df = DateFormat.getDateInstance(DateFormat.FULL, Locale.US);
        String date = df.format(new Date());
        if (date.charAt(date.length()-1) == ' ') {
            throw new RuntimeException("Windows Host Locale Provider returns a trailing space.");
        }
    } else {
        System.out.println("Windows HOST locale adapter not found. Ignoring this test.");
    }
}
 
Example 6
Source File: Bug8004240.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
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 7
Source File: LocaleProviders.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
static void bug7198834Test() {
    LocaleProviderAdapter lda = LocaleProviderAdapter.getAdapter(DateFormatProvider.class, Locale.US);
    LocaleProviderAdapter.Type type = lda.getAdapterType();
    if (type == LocaleProviderAdapter.Type.HOST && System.getProperty("os.name").startsWith("Windows")) {
        DateFormat df = DateFormat.getDateInstance(DateFormat.FULL, Locale.US);
        String date = df.format(new Date());
        if (date.charAt(date.length()-1) == ' ') {
            throw new RuntimeException("Windows Host Locale Provider returns a trailing space.");
        }
    } else {
        System.out.println("Windows HOST locale adapter not found. Ignoring this test.");
    }
}
 
Example 8
Source File: Bug8004240.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
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 9
Source File: LocaleProviders.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
static void bug7198834Test() {
    LocaleProviderAdapter lda = LocaleProviderAdapter.getAdapter(DateFormatProvider.class, Locale.US);
    LocaleProviderAdapter.Type type = lda.getAdapterType();
    if (type == LocaleProviderAdapter.Type.HOST && System.getProperty("os.name").startsWith("Windows")) {
        DateFormat df = DateFormat.getDateInstance(DateFormat.FULL, Locale.US);
        String date = df.format(new Date());
        if (date.charAt(date.length()-1) == ' ') {
            throw new RuntimeException("Windows Host Locale Provider returns a trailing space.");
        }
    } else {
        System.out.println("Windows HOST locale adapter not found. Ignoring this test.");
    }
}
 
Example 10
Source File: LocaleProviders.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
static void bug7198834Test() {
    LocaleProviderAdapter lda = LocaleProviderAdapter.getAdapter(DateFormatProvider.class, Locale.US);
    LocaleProviderAdapter.Type type = lda.getAdapterType();
    if (type == LocaleProviderAdapter.Type.HOST && System.getProperty("os.name").startsWith("Windows")) {
        DateFormat df = DateFormat.getDateInstance(DateFormat.FULL, Locale.US);
        String date = df.format(new Date());
        if (date.charAt(date.length()-1) == ' ') {
            throw new RuntimeException("Windows Host Locale Provider returns a trailing space.");
        }
    } else {
        System.out.println("Windows HOST locale adapter not found. Ignoring this test.");
    }
}
 
Example 11
Source File: Bug8004240.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
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 12
Source File: LocaleProviders.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
static void bug7198834Test() {
    LocaleProviderAdapter lda = LocaleProviderAdapter.getAdapter(DateFormatProvider.class, Locale.US);
    LocaleProviderAdapter.Type type = lda.getAdapterType();
    if (type == LocaleProviderAdapter.Type.HOST && System.getProperty("os.name").startsWith("Windows")) {
        DateFormat df = DateFormat.getDateInstance(DateFormat.FULL, Locale.US);
        String date = df.format(new Date());
        if (date.charAt(date.length()-1) == ' ') {
            throw new RuntimeException("Windows Host Locale Provider returns a trailing space.");
        }
    } else {
        System.out.println("Windows HOST locale adapter not found. Ignoring this test.");
    }
}
 
Example 13
Source File: LocaleProviders.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
static void bug8010666Test() {
    if (System.getProperty("os.name").startsWith("Windows")) {
        NumberFormat nf = NumberFormat.getInstance(Locale.US);
        try {
            double ver = nf.parse(System.getProperty("os.version"))
                           .doubleValue();
            System.out.printf("Windows version: %.1f\n", ver);
            if (ver >= 6.0) {
                LocaleProviderAdapter lda =
                    LocaleProviderAdapter.getAdapter(
                        LocaleNameProvider.class, Locale.ENGLISH);
                LocaleProviderAdapter.Type type = lda.getAdapterType();
                if (type == LocaleProviderAdapter.Type.HOST) {
                    LocaleNameProvider lnp = lda.getLocaleNameProvider();
                    Locale mkmk = Locale.forLanguageTag("mk-MK");
                    String result = mkmk.getDisplayLanguage(Locale.ENGLISH);
                    String hostResult =
                        lnp.getDisplayLanguage(mkmk.getLanguage(),
                                               Locale.ENGLISH);
                    System.out.printf("  Display language name for" +
                        " (mk_MK): result(HOST): \"%s\", returned: \"%s\"\n",
                        hostResult, result);
                    if (result == null ||
                        hostResult != null &&
                        !result.equals(hostResult)) {
                        throw new RuntimeException("Display language name" +
                            " mismatch for \"mk\". Returned name was" +
                            " \"" + result + "\", result(HOST): \"" +
                            hostResult + "\"");
                    }
                    result = Locale.US.getDisplayLanguage(Locale.ENGLISH);
                    hostResult =
                        lnp.getDisplayLanguage(Locale.US.getLanguage(),
                                               Locale.ENGLISH);
                    System.out.printf("  Display language name for" +
                        " (en_US): result(HOST): \"%s\", returned: \"%s\"\n",
                        hostResult, result);
                    if (result == null ||
                        hostResult != null &&
                        !result.equals(hostResult)) {
                        throw new RuntimeException("Display language name" +
                            " mismatch for \"en\". Returned name was" +
                            " \"" + result + "\", result(HOST): \"" +
                            hostResult + "\"");
                    }
                    if (ver >= 6.1) {
                        result = Locale.US.getDisplayCountry(Locale.ENGLISH);
                        hostResult = lnp.getDisplayCountry(
                            Locale.US.getCountry(), Locale.ENGLISH);
                        System.out.printf("  Display country name for" +
                            " (en_US): result(HOST): \"%s\", returned: \"%s\"\n",
                            hostResult, result);
                        if (result == null ||
                            hostResult != null &&
                            !result.equals(hostResult)) {
                            throw new RuntimeException("Display country name" +
                                " mismatch for \"US\". Returned name was" +
                                " \"" + result + "\", result(HOST): \"" +
                                hostResult + "\"");
                        }
                    }
                } else {
                    throw new RuntimeException("Windows Host" +
                        " LocaleProviderAdapter was not selected for" +
                        " English locale.");
                }
            }
        } catch (ParseException pe) {
            throw new RuntimeException("Parsing Windows version failed: "+pe.toString());
        }
    }
}
 
Example 14
Source File: CLDRLocaleProviderAdapter.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns the type of this LocaleProviderAdapter
 * @return the type of this
 */
@Override
public LocaleProviderAdapter.Type getAdapterType() {
    return LocaleProviderAdapter.Type.CLDR;
}
 
Example 15
Source File: LocaleProviders.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
static void bug8010666Test() {
    if (System.getProperty("os.name").startsWith("Windows")) {
        NumberFormat nf = NumberFormat.getInstance(Locale.US);
        try {
            double ver = nf.parse(System.getProperty("os.version"))
                           .doubleValue();
            System.out.printf("Windows version: %.1f\n", ver);
            if (ver >= 6.0) {
                LocaleProviderAdapter lda =
                    LocaleProviderAdapter.getAdapter(
                        LocaleNameProvider.class, Locale.ENGLISH);
                LocaleProviderAdapter.Type type = lda.getAdapterType();
                if (type == LocaleProviderAdapter.Type.HOST) {
                    LocaleNameProvider lnp = lda.getLocaleNameProvider();
                    Locale mkmk = Locale.forLanguageTag("mk-MK");
                    String result = mkmk.getDisplayLanguage(Locale.ENGLISH);
                    String hostResult =
                        lnp.getDisplayLanguage(mkmk.getLanguage(),
                                               Locale.ENGLISH);
                    System.out.printf("  Display language name for" +
                        " (mk_MK): result(HOST): \"%s\", returned: \"%s\"\n",
                        hostResult, result);
                    if (result == null ||
                        hostResult != null &&
                        !result.equals(hostResult)) {
                        throw new RuntimeException("Display language name" +
                            " mismatch for \"mk\". Returned name was" +
                            " \"" + result + "\", result(HOST): \"" +
                            hostResult + "\"");
                    }
                    result = Locale.US.getDisplayLanguage(Locale.ENGLISH);
                    hostResult =
                        lnp.getDisplayLanguage(Locale.US.getLanguage(),
                                               Locale.ENGLISH);
                    System.out.printf("  Display language name for" +
                        " (en_US): result(HOST): \"%s\", returned: \"%s\"\n",
                        hostResult, result);
                    if (result == null ||
                        hostResult != null &&
                        !result.equals(hostResult)) {
                        throw new RuntimeException("Display language name" +
                            " mismatch for \"en\". Returned name was" +
                            " \"" + result + "\", result(HOST): \"" +
                            hostResult + "\"");
                    }
                    if (ver >= 6.1) {
                        result = Locale.US.getDisplayCountry(Locale.ENGLISH);
                        hostResult = lnp.getDisplayCountry(
                            Locale.US.getCountry(), Locale.ENGLISH);
                        System.out.printf("  Display country name for" +
                            " (en_US): result(HOST): \"%s\", returned: \"%s\"\n",
                            hostResult, result);
                        if (result == null ||
                            hostResult != null &&
                            !result.equals(hostResult)) {
                            throw new RuntimeException("Display country name" +
                                " mismatch for \"US\". Returned name was" +
                                " \"" + result + "\", result(HOST): \"" +
                                hostResult + "\"");
                        }
                    }
                } else {
                    throw new RuntimeException("Windows Host" +
                        " LocaleProviderAdapter was not selected for" +
                        " English locale.");
                }
            }
        } catch (ParseException pe) {
            throw new RuntimeException("Parsing Windows version failed: "+pe.toString());
        }
    }
}
 
Example 16
Source File: LocaleProviders.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
static void bug8010666Test() {
    if (System.getProperty("os.name").startsWith("Windows")) {
        NumberFormat nf = NumberFormat.getInstance(Locale.US);
        try {
            double ver = nf.parse(System.getProperty("os.version"))
                           .doubleValue();
            System.out.printf("Windows version: %.1f\n", ver);
            if (ver >= 6.0) {
                LocaleProviderAdapter lda =
                    LocaleProviderAdapter.getAdapter(
                        LocaleNameProvider.class, Locale.ENGLISH);
                LocaleProviderAdapter.Type type = lda.getAdapterType();
                if (type == LocaleProviderAdapter.Type.HOST) {
                    LocaleNameProvider lnp = lda.getLocaleNameProvider();
                    Locale mkmk = Locale.forLanguageTag("mk-MK");
                    String result = mkmk.getDisplayLanguage(Locale.ENGLISH);
                    String hostResult =
                        lnp.getDisplayLanguage(mkmk.getLanguage(),
                                               Locale.ENGLISH);
                    System.out.printf("  Display language name for" +
                        " (mk_MK): result(HOST): \"%s\", returned: \"%s\"\n",
                        hostResult, result);
                    if (result == null ||
                        hostResult != null &&
                        !result.equals(hostResult)) {
                        throw new RuntimeException("Display language name" +
                            " mismatch for \"mk\". Returned name was" +
                            " \"" + result + "\", result(HOST): \"" +
                            hostResult + "\"");
                    }
                    result = Locale.US.getDisplayLanguage(Locale.ENGLISH);
                    hostResult =
                        lnp.getDisplayLanguage(Locale.US.getLanguage(),
                                               Locale.ENGLISH);
                    System.out.printf("  Display language name for" +
                        " (en_US): result(HOST): \"%s\", returned: \"%s\"\n",
                        hostResult, result);
                    if (result == null ||
                        hostResult != null &&
                        !result.equals(hostResult)) {
                        throw new RuntimeException("Display language name" +
                            " mismatch for \"en\". Returned name was" +
                            " \"" + result + "\", result(HOST): \"" +
                            hostResult + "\"");
                    }
                    if (ver >= 6.1) {
                        result = Locale.US.getDisplayCountry(Locale.ENGLISH);
                        hostResult = lnp.getDisplayCountry(
                            Locale.US.getCountry(), Locale.ENGLISH);
                        System.out.printf("  Display country name for" +
                            " (en_US): result(HOST): \"%s\", returned: \"%s\"\n",
                            hostResult, result);
                        if (result == null ||
                            hostResult != null &&
                            !result.equals(hostResult)) {
                            throw new RuntimeException("Display country name" +
                                " mismatch for \"US\". Returned name was" +
                                " \"" + result + "\", result(HOST): \"" +
                                hostResult + "\"");
                        }
                    }
                } else {
                    throw new RuntimeException("Windows Host" +
                        " LocaleProviderAdapter was not selected for" +
                        " English locale.");
                }
            }
        } catch (ParseException pe) {
            throw new RuntimeException("Parsing Windows version failed: "+pe.toString());
        }
    }
}
 
Example 17
Source File: LocaleData.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
public LocaleData(LocaleProviderAdapter.Type type) {
    this.type = type;
}
 
Example 18
Source File: LocaleData.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
public LocaleData(LocaleProviderAdapter.Type type) {
    this.type = type;
}
 
Example 19
Source File: LocaleProviders.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
static void bug8010666Test() {
    if (System.getProperty("os.name").startsWith("Windows")) {
        NumberFormat nf = NumberFormat.getInstance(Locale.US);
        try {
            double ver = nf.parse(System.getProperty("os.version"))
                           .doubleValue();
            System.out.printf("Windows version: %.1f\n", ver);
            if (ver >= 6.0) {
                LocaleProviderAdapter lda =
                    LocaleProviderAdapter.getAdapter(
                        LocaleNameProvider.class, Locale.ENGLISH);
                LocaleProviderAdapter.Type type = lda.getAdapterType();
                if (type == LocaleProviderAdapter.Type.HOST) {
                    LocaleNameProvider lnp = lda.getLocaleNameProvider();
                    Locale mkmk = Locale.forLanguageTag("mk-MK");
                    String result = mkmk.getDisplayLanguage(Locale.ENGLISH);
                    String hostResult =
                        lnp.getDisplayLanguage(mkmk.getLanguage(),
                                               Locale.ENGLISH);
                    System.out.printf("  Display language name for" +
                        " (mk_MK): result(HOST): \"%s\", returned: \"%s\"\n",
                        hostResult, result);
                    if (result == null ||
                        hostResult != null &&
                        !result.equals(hostResult)) {
                        throw new RuntimeException("Display language name" +
                            " mismatch for \"mk\". Returned name was" +
                            " \"" + result + "\", result(HOST): \"" +
                            hostResult + "\"");
                    }
                    result = Locale.US.getDisplayLanguage(Locale.ENGLISH);
                    hostResult =
                        lnp.getDisplayLanguage(Locale.US.getLanguage(),
                                               Locale.ENGLISH);
                    System.out.printf("  Display language name for" +
                        " (en_US): result(HOST): \"%s\", returned: \"%s\"\n",
                        hostResult, result);
                    if (result == null ||
                        hostResult != null &&
                        !result.equals(hostResult)) {
                        throw new RuntimeException("Display language name" +
                            " mismatch for \"en\". Returned name was" +
                            " \"" + result + "\", result(HOST): \"" +
                            hostResult + "\"");
                    }
                    if (ver >= 6.1) {
                        result = Locale.US.getDisplayCountry(Locale.ENGLISH);
                        hostResult = lnp.getDisplayCountry(
                            Locale.US.getCountry(), Locale.ENGLISH);
                        System.out.printf("  Display country name for" +
                            " (en_US): result(HOST): \"%s\", returned: \"%s\"\n",
                            hostResult, result);
                        if (result == null ||
                            hostResult != null &&
                            !result.equals(hostResult)) {
                            throw new RuntimeException("Display country name" +
                                " mismatch for \"US\". Returned name was" +
                                " \"" + result + "\", result(HOST): \"" +
                                hostResult + "\"");
                        }
                    }
                } else {
                    throw new RuntimeException("Windows Host" +
                        " LocaleProviderAdapter was not selected for" +
                        " English locale.");
                }
            }
        } catch (ParseException pe) {
            throw new RuntimeException("Parsing Windows version failed: "+pe.toString());
        }
    }
}
 
Example 20
Source File: LocaleData.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
public LocaleData(LocaleProviderAdapter.Type type) {
    this.type = type;
}