jdk/src/java.base/share/classes/java/util/Locale.java
changeset 38339 65b26013c786
parent 37593 824750ada3d6
child 37781 71ed5645f17c
equal deleted inserted replaced
38338:f3909e996a6a 38339:65b26013c786
    43 import java.io.IOException;
    43 import java.io.IOException;
    44 import java.io.ObjectInputStream;
    44 import java.io.ObjectInputStream;
    45 import java.io.ObjectOutputStream;
    45 import java.io.ObjectOutputStream;
    46 import java.io.ObjectStreamField;
    46 import java.io.ObjectStreamField;
    47 import java.io.Serializable;
    47 import java.io.Serializable;
    48 import java.security.AccessController;
       
    49 import java.text.MessageFormat;
    48 import java.text.MessageFormat;
    50 import java.util.spi.LocaleNameProvider;
    49 import java.util.spi.LocaleNameProvider;
    51 
    50 
    52 import sun.security.action.GetPropertyAction;
    51 import sun.security.action.GetPropertyAction;
    53 import sun.util.locale.BaseLocale;
    52 import sun.util.locale.BaseLocale;
   857         return getDefault();
   856         return getDefault();
   858     }
   857     }
   859 
   858 
   860     private static Locale initDefault() {
   859     private static Locale initDefault() {
   861         String language, region, script, country, variant;
   860         String language, region, script, country, variant;
   862         language = AccessController.doPrivileged(
   861         Properties props = GetPropertyAction.getProperties();
   863             new GetPropertyAction("user.language", "en"));
   862         language = props.getProperty("user.language", "en");
   864         // for compatibility, check for old user.region property
   863         // for compatibility, check for old user.region property
   865         region = AccessController.doPrivileged(
   864         region = props.getProperty("user.region");
   866             new GetPropertyAction("user.region"));
       
   867         if (region != null) {
   865         if (region != null) {
   868             // region can be of form country, country_variant, or _variant
   866             // region can be of form country, country_variant, or _variant
   869             int i = region.indexOf('_');
   867             int i = region.indexOf('_');
   870             if (i >= 0) {
   868             if (i >= 0) {
   871                 country = region.substring(0, i);
   869                 country = region.substring(0, i);
   874                 country = region;
   872                 country = region;
   875                 variant = "";
   873                 variant = "";
   876             }
   874             }
   877             script = "";
   875             script = "";
   878         } else {
   876         } else {
   879             script = AccessController.doPrivileged(
   877             script = props.getProperty("user.script", "");
   880                 new GetPropertyAction("user.script", ""));
   878             country = props.getProperty("user.country", "");
   881             country = AccessController.doPrivileged(
   879             variant = props.getProperty("user.variant", "");
   882                 new GetPropertyAction("user.country", ""));
       
   883             variant = AccessController.doPrivileged(
       
   884                 new GetPropertyAction("user.variant", ""));
       
   885         }
   880         }
   886 
   881 
   887         return getInstance(language, script, country, variant, null);
   882         return getInstance(language, script, country, variant, null);
   888     }
   883     }
   889 
   884 
   890     private static Locale initDefault(Locale.Category category) {
   885     private static Locale initDefault(Locale.Category category) {
       
   886         Properties props = GetPropertyAction.getProperties();
   891         return getInstance(
   887         return getInstance(
   892             AccessController.doPrivileged(
   888             props.getProperty(category.languageKey,
   893                 new GetPropertyAction(category.languageKey, defaultLocale.getLanguage())),
   889                     defaultLocale.getLanguage()),
   894             AccessController.doPrivileged(
   890             props.getProperty(category.scriptKey,
   895                 new GetPropertyAction(category.scriptKey, defaultLocale.getScript())),
   891                     defaultLocale.getScript()),
   896             AccessController.doPrivileged(
   892             props.getProperty(category.countryKey,
   897                 new GetPropertyAction(category.countryKey, defaultLocale.getCountry())),
   893                     defaultLocale.getCountry()),
   898             AccessController.doPrivileged(
   894             props.getProperty(category.variantKey,
   899                 new GetPropertyAction(category.variantKey, defaultLocale.getVariant())),
   895                     defaultLocale.getVariant()),
   900             null);
   896             null);
   901     }
   897     }
   902 
   898 
   903     /**
   899     /**
   904      * Sets the default locale for this instance of the Java Virtual Machine.
   900      * Sets the default locale for this instance of the Java Virtual Machine.