test/java/util/PluggableLocale/providersrc/LocaleNameProviderImpl.java

Print this page
rev 5957 : imported patch 8000245.8000273.8000615

*** 35,93 **** public class LocaleNameProviderImpl extends LocaleNameProvider { static Locale[] avail = {Locale.JAPANESE, Locale.JAPAN, new Locale("ja", "JP", "osaka"), new Locale("ja", "JP", "kyoto"), ! new Locale("xx")}; static List<Locale> availList = Arrays.asList(avail); public Locale[] getAvailableLocales() { return avail; } public String getDisplayLanguage(String lang, Locale target) { ! if (!Utils.supportsLocale(availList, target)) { ! throw new IllegalArgumentException("locale is not supported: "+target); } ! String ret = null; ! ! try { ! ResourceBundle rb = ResourceBundle.getBundle("com.bar.LocaleNames", target); ! ret = rb.getString(lang); ! } catch (MissingResourceException mre) { } ! return ret; } ! public String getDisplayCountry(String ctry, Locale target) { if (!Utils.supportsLocale(availList, target)) { throw new IllegalArgumentException("locale is not supported: "+target); } String ret = null; ! try { ! ResourceBundle rb = ResourceBundle.getBundle("LocaleNames", target); ! ret = rb.getString(ctry); ! } catch (MissingResourceException mre) { ! } ! return ret; } ! ! public String getDisplayVariant(String vrnt, Locale target) { ! if (!Utils.supportsLocale(availList, target)) { ! throw new IllegalArgumentException("locale is not supported: "+target); } ! ! String ret = null; ! try { ! ResourceBundle rb = ResourceBundle.getBundle("LocaleNames", target); ! ret = rb.getString(vrnt); } catch (MissingResourceException mre) { } return ret; } } --- 35,100 ---- public class LocaleNameProviderImpl extends LocaleNameProvider { static Locale[] avail = {Locale.JAPANESE, Locale.JAPAN, new Locale("ja", "JP", "osaka"), new Locale("ja", "JP", "kyoto"), ! new Locale("xx"), ! new Locale("yy", "YY", "YYYY")}; static List<Locale> availList = Arrays.asList(avail); public Locale[] getAvailableLocales() { return avail; } + @Override public String getDisplayLanguage(String lang, Locale target) { ! return getDisplayString(lang, target); } ! @Override ! public String getDisplayCountry(String ctry, Locale target) { ! return getDisplayString(ctry, target); } ! @Override ! public String getDisplayVariant(String vrnt, Locale target) { ! return getDisplayString(vrnt, target); } ! private String getDisplayString(String key, Locale target) { if (!Utils.supportsLocale(availList, target)) { throw new IllegalArgumentException("locale is not supported: "+target); } String ret = null; ! if (target.getLanguage().equals("yy") && ! target.getCountry().equals("YY")) { ! String vrnt = target.getVariant(); ! if (vrnt.startsWith("YYYY")) { ! switch (key) { ! case "yy": ! case "YY": ! ret = "waiwai"; ! break; ! case "YYYY": ! if (vrnt.equals("YYYY_suffix")) { ! // for LocaleNameProviderTest.variantFallbackTest() ! throw new RuntimeException(vrnt); ! } else { ! ret = "waiwai"; } ! break; } ! } ! } else { ! // resource bundle based (allows fallback) try { ! ResourceBundle rb = ResourceBundle.getBundle("com.bar.LocaleNames", target); ! ret = rb.getString(key); } catch (MissingResourceException mre) { } + } return ret; } }