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

Print this page
rev 5957 : imported patch 8000245.8000273.8000615


  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 /*
  24  *
  25  */
  26 
  27 package com.bar;
  28 
  29 import java.text.*;
  30 import java.util.*;
  31 import java.util.spi.*;
  32 
  33 import com.foobar.Utils;
  34 
  35 public class LocaleNameProviderImpl extends LocaleNameProvider {
  36     static Locale[] avail = {Locale.JAPANESE,
  37                              Locale.JAPAN,
  38                              new Locale("ja", "JP", "osaka"),
  39                              new Locale("ja", "JP", "kyoto"),
  40                              new Locale("xx")};

  41     static List<Locale> availList = Arrays.asList(avail);
  42     public Locale[] getAvailableLocales() {
  43         return avail;
  44     }
  45 

  46     public String getDisplayLanguage(String lang, Locale target) {
  47         if (!Utils.supportsLocale(availList, target)) {
  48             throw new IllegalArgumentException("locale is not supported: "+target);
  49         }
  50 
  51         String ret = null;
  52 
  53         try {
  54             ResourceBundle rb = ResourceBundle.getBundle("com.bar.LocaleNames", target);
  55             ret = rb.getString(lang);
  56         } catch (MissingResourceException mre) {
  57         }
  58 
  59         return ret;


  60     }
  61 
  62     public String getDisplayCountry(String ctry, Locale target) {
  63         if (!Utils.supportsLocale(availList, target)) {
  64             throw new IllegalArgumentException("locale is not supported: "+target);
  65         }
  66 
  67         String ret = null;
  68 
  69         try {
  70             ResourceBundle rb = ResourceBundle.getBundle("LocaleNames", target);
  71             ret = rb.getString(ctry);
  72         } catch (MissingResourceException mre) {
  73         }




  74 
  75         return ret;





  76     }
  77 
  78     public String getDisplayVariant(String vrnt, Locale target) {
  79         if (!Utils.supportsLocale(availList, target)) {
  80             throw new IllegalArgumentException("locale is not supported: "+target);
  81         }
  82 
  83         String ret = null;
  84 
  85         try {
  86             ResourceBundle rb = ResourceBundle.getBundle("LocaleNames", target);
  87             ret = rb.getString(vrnt);
  88         } catch (MissingResourceException mre) {
  89         }

  90 
  91         return ret;
  92     }
  93 }


  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 /*
  24  *
  25  */
  26 
  27 package com.bar;
  28 
  29 import java.text.*;
  30 import java.util.*;
  31 import java.util.spi.*;
  32 
  33 import com.foobar.Utils;
  34 
  35 public class LocaleNameProviderImpl extends LocaleNameProvider {
  36     static Locale[] avail = {Locale.JAPANESE,
  37                              Locale.JAPAN,
  38                              new Locale("ja", "JP", "osaka"),
  39                              new Locale("ja", "JP", "kyoto"),
  40                              new Locale("xx"),
  41                              new Locale("yy", "YY", "YYYY")};
  42     static List<Locale> availList = Arrays.asList(avail);
  43     public Locale[] getAvailableLocales() {
  44         return avail;
  45     }
  46 
  47     @Override
  48     public String getDisplayLanguage(String lang, Locale target) {
  49         return getDisplayString(lang, target);

  50     }
  51 
  52     @Override
  53     public String getDisplayCountry(String ctry, Locale target) {
  54         return getDisplayString(ctry, target);



  55     }
  56 
  57     @Override
  58     public String getDisplayVariant(String vrnt, Locale target) {
  59         return getDisplayString(vrnt, target);
  60     }
  61 
  62     private String getDisplayString(String key, Locale target) {
  63         if (!Utils.supportsLocale(availList, target)) {
  64             throw new IllegalArgumentException("locale is not supported: "+target);
  65         }
  66 
  67         String ret = null;
  68 
  69         if (target.getLanguage().equals("yy") &&
  70             target.getCountry().equals("YY")) {
  71             String vrnt = target.getVariant();
  72             if (vrnt.startsWith("YYYY")) {
  73                 switch (key) {
  74                     case "yy":
  75                     case "YY":
  76                         ret = "waiwai";
  77                         break;
  78 
  79                     case "YYYY":
  80                         if (vrnt.equals("YYYY_suffix")) {
  81                             // for LocaleNameProviderTest.variantFallbackTest()
  82                             throw new RuntimeException(vrnt);
  83                         } else {
  84                             ret = "waiwai";
  85                         }
  86                         break;



  87                 }
  88             }
  89         } else {
  90             // resource bundle based (allows fallback)
  91             try {
  92                 ResourceBundle rb = ResourceBundle.getBundle("com.bar.LocaleNames", target);
  93                 ret = rb.getString(key);
  94             } catch (MissingResourceException mre) {
  95             }
  96         }
  97 
  98         return ret;
  99     }
 100 }