home *** CD-ROM | disk | FTP | other *** search
/ Dynamic HTML Construction Kit / Dynamic HTML Construction Kit.iso / earthlink / nscomm / java40.jar / java / util / Locale.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-11-03  |  5.2 KB  |  262 lines

  1. package java.util;
  2.  
  3. import java.io.Serializable;
  4.  
  5. public final class Locale implements Cloneable, Serializable {
  6.    public static final Locale ENGLISH = new Locale("en", "", "");
  7.    public static final Locale FRENCH = new Locale("fr", "", "");
  8.    public static final Locale GERMAN = new Locale("de", "", "");
  9.    public static final Locale ITALIAN = new Locale("it", "", "");
  10.    public static final Locale JAPANESE = new Locale("ja", "", "");
  11.    public static final Locale KOREAN = new Locale("ko", "", "");
  12.    public static final Locale CHINESE = new Locale("zh", "", "");
  13.    public static final Locale SIMPLIFIED_CHINESE = new Locale("zh", "CN", "");
  14.    public static final Locale TRADITIONAL_CHINESE = new Locale("zh", "TW", "");
  15.    public static final Locale FRANCE = new Locale("fr", "FR", "");
  16.    public static final Locale GERMANY = new Locale("de", "DE", "");
  17.    public static final Locale ITALY = new Locale("it", "IT", "");
  18.    public static final Locale JAPAN = new Locale("ja", "JP", "");
  19.    public static final Locale KOREA = new Locale("ko", "KR", "");
  20.    public static final Locale CHINA = new Locale("zh", "CN", "");
  21.    public static final Locale PRC = new Locale("zh", "CN", "");
  22.    public static final Locale TAIWAN = new Locale("zh", "TW", "");
  23.    // $FF: renamed from: UK java.util.Locale
  24.    public static final Locale field_0 = new Locale("en", "GB", "");
  25.    // $FF: renamed from: US java.util.Locale
  26.    public static final Locale field_1 = new Locale("en", "US", "");
  27.    public static final Locale CANADA = new Locale("en", "CA", "");
  28.    public static final Locale CANADA_FRENCH = new Locale("fr", "CA", "");
  29.    private String language = "";
  30.    private String country = "";
  31.    private String variant = "";
  32.    private int hashcode = -1;
  33.    private static Locale defaultLocale = null;
  34.  
  35.    public Locale(String var1, String var2, String var3) {
  36.       this.language = this.toLowerCase(var1);
  37.       this.country = this.toUpperCase(var2);
  38.       this.variant = this.toUpperCase(var3);
  39.    }
  40.  
  41.    public Locale(String var1, String var2) {
  42.       this.language = this.toLowerCase(var1);
  43.       this.country = this.toUpperCase(var2);
  44.       this.variant = "";
  45.    }
  46.  
  47.    public static synchronized Locale getDefault() {
  48.       if (defaultLocale == null) {
  49.          String var0 = System.getProperty("user.language", "EN");
  50.          String var1 = System.getProperty("user.region", "");
  51.          defaultLocale = new Locale(var0, var1);
  52.       }
  53.  
  54.       return defaultLocale;
  55.    }
  56.  
  57.    public static synchronized void setDefault(Locale var0) {
  58.       SecurityManager var1 = System.getSecurityManager();
  59.       if (var1 != null) {
  60.          var1.checkPropertyAccess("user.language");
  61.       }
  62.  
  63.       defaultLocale = var0;
  64.    }
  65.  
  66.    public String getLanguage() {
  67.       return this.language;
  68.    }
  69.  
  70.    public String getCountry() {
  71.       return this.country;
  72.    }
  73.  
  74.    public String getVariant() {
  75.       return this.variant;
  76.    }
  77.  
  78.    public final String toString() {
  79.       StringBuffer var1 = new StringBuffer(this.language);
  80.       if (this.country.length() != 0) {
  81.          var1.append('_');
  82.          var1.append(this.country);
  83.          if (this.variant.length() != 0) {
  84.             var1.append('_');
  85.             var1.append(this.variant);
  86.          }
  87.       }
  88.  
  89.       return var1.toString();
  90.    }
  91.  
  92.    public String getISO3Language() throws MissingResourceException {
  93.       ResourceBundle var1 = ResourceBundle.getBundle("java.text.resources.LocaleElements", this);
  94.       return var1.getString("ShortLanguage");
  95.    }
  96.  
  97.    public String getISO3Country() throws MissingResourceException {
  98.       ResourceBundle var1 = ResourceBundle.getBundle("java.text.resources.LocaleElements", this);
  99.       return var1.getString("ShortCountry");
  100.    }
  101.  
  102.    private int getLCID() throws MissingResourceException {
  103.       ResourceBundle var1 = ResourceBundle.getBundle("java.text.resources.LocaleElements", this);
  104.       String var2 = var1.getString("LocaleID");
  105.       return Integer.parseInt(var2, 16);
  106.    }
  107.  
  108.    public final String getDisplayLanguage() {
  109.       return this.getDisplayLanguage(getDefault());
  110.    }
  111.  
  112.    public String getDisplayLanguage(Locale var1) {
  113.       try {
  114.          ResourceBundle var2 = ResourceBundle.getBundle("java.text.resources.LocaleElements", this);
  115.          return this.findStringMatch((String[][])var2.getObject("Languages"), var1.language, this.language);
  116.       } catch (Exception var3) {
  117.          return this.language;
  118.       }
  119.    }
  120.  
  121.    public final String getDisplayCountry() {
  122.       return this.getDisplayCountry(getDefault());
  123.    }
  124.  
  125.    public String getDisplayCountry(Locale var1) {
  126.       try {
  127.          ResourceBundle var2 = ResourceBundle.getBundle("java.text.resources.LocaleElements", this);
  128.          return this.findStringMatch((String[][])var2.getObject("Countries"), var1.language, this.language);
  129.       } catch (Exception var3) {
  130.          return this.country;
  131.       }
  132.    }
  133.  
  134.    public final String getDisplayVariant() {
  135.       return this.getDisplayVariant(getDefault());
  136.    }
  137.  
  138.    public String getDisplayVariant(Locale var1) {
  139.       try {
  140.          ResourceBundle var2 = ResourceBundle.getBundle("java.text.resources.LocaleElements", var1);
  141.          String[][] var3 = (String[][])var2.getObject("Variants");
  142.          return var3 == null ? this.variant : this.findStringMatch(var3, var1.language, this.language);
  143.       } catch (Exception var4) {
  144.          return this.variant;
  145.       }
  146.    }
  147.  
  148.    public final String getDisplayName() {
  149.       return this.getDisplayName(getDefault());
  150.    }
  151.  
  152.    public String getDisplayName(Locale var1) {
  153.       StringBuffer var2 = new StringBuffer(this.getDisplayLanguage(var1));
  154.       String var3 = this.getDisplayCountry(var1);
  155.       String var4 = this.getDisplayVariant(var1);
  156.       if (var3.length() != 0 || var4.length() != 0) {
  157.          var2.append(" (");
  158.          var2.append(this.getDisplayCountry(var1));
  159.          if (var3.length() != 0 && var4.length() != 0) {
  160.             var2.append(",");
  161.          }
  162.  
  163.          var2.append(this.getDisplayVariant(var1));
  164.          var2.append(")");
  165.       }
  166.  
  167.       return var2.toString();
  168.    }
  169.  
  170.    public Object clone() {
  171.       try {
  172.          Locale var1 = (Locale)super.clone();
  173.          return var1;
  174.       } catch (CloneNotSupportedException var2) {
  175.          throw new InternalError();
  176.       }
  177.    }
  178.  
  179.    public synchronized int hashCode() {
  180.       if (this.hashcode == -1) {
  181.          this.hashcode = this.language.hashCode() ^ this.country.hashCode() ^ this.variant.hashCode();
  182.       }
  183.  
  184.       return this.hashcode;
  185.    }
  186.  
  187.    public boolean equals(Object var1) {
  188.       if (this == var1) {
  189.          return true;
  190.       } else if (!(var1 instanceof Locale)) {
  191.          return false;
  192.       } else {
  193.          Locale var2 = (Locale)var1;
  194.          if (this.hashCode() != var2.hashCode()) {
  195.             return false;
  196.          } else if (!this.language.equals(var2.language)) {
  197.             return false;
  198.          } else if (!this.country.equals(var2.country)) {
  199.             return false;
  200.          } else {
  201.             return this.variant.equals(var2.variant);
  202.          }
  203.       }
  204.    }
  205.  
  206.    private String toLowerCase(String var1) {
  207.       char[] var2 = var1.toCharArray();
  208.  
  209.       for(int var3 = 0; var3 < var2.length; ++var3) {
  210.          var2[var3] = Character.toLowerCase(var2[var3]);
  211.       }
  212.  
  213.       return new String(var2);
  214.    }
  215.  
  216.    private String toUpperCase(String var1) {
  217.       char[] var2 = var1.toCharArray();
  218.  
  219.       for(int var3 = 0; var3 < var2.length; ++var3) {
  220.          var2[var3] = Character.toUpperCase(var2[var3]);
  221.       }
  222.  
  223.       return new String(var2);
  224.    }
  225.  
  226.    private String findStringMatch(String[][] var1, String var2, String var3) {
  227.       for(int var4 = 0; var4 < var1.length; ++var4) {
  228.          if (var2.equals(var1[var4][0])) {
  229.             return var1[var4][1];
  230.          }
  231.       }
  232.  
  233.       if (!var3.equals(var2)) {
  234.          for(int var5 = 0; var5 < var1.length; ++var5) {
  235.             if (var3.equals(var1[var5][0])) {
  236.                return var1[var5][1];
  237.             }
  238.          }
  239.       }
  240.  
  241.       if (!"EN".equals(var2) && "EN".equals(var3)) {
  242.          for(int var6 = 0; var6 < var1.length; ++var6) {
  243.             if ("EN".equals(var1[var6][0])) {
  244.                return var1[var6][1];
  245.             }
  246.          }
  247.       }
  248.  
  249.       return "";
  250.    }
  251.  
  252.    private boolean matches(Locale var1) {
  253.       if (this.language.length() != 0 && !this.language.equals(var1.language)) {
  254.          return false;
  255.       } else if (this.country.length() != 0 && !this.country.equals(var1.country)) {
  256.          return false;
  257.       } else {
  258.          return this.variant.length() == 0 || this.variant.equals(var1.variant);
  259.       }
  260.    }
  261. }
  262.