1 /* GENERATED SOURCE. DO NOT MODIFY. */ 2 /* 3 ******************************************************************************* 4 * Copyright (C) 2008-2015, International Business Machines Corporation and 5 * others. All Rights Reserved. 6 ******************************************************************************* 7 */ 8 package android.icu.impl; 9 10 import java.io.IOException; 11 import java.io.InputStream; 12 import java.security.AccessControlException; 13 import java.security.AccessController; 14 import java.security.PrivilegedAction; 15 import java.util.MissingResourceException; 16 import java.util.Properties; 17 18 /** 19 * ICUConfig is a class used for accessing ICU4J runtime configuration. 20 * @hide Only a subset of ICU is exposed in Android 21 */ 22 public class ICUConfig { 23 public static final String CONFIG_PROPS_FILE = "/android/icu/ICUConfig.properties"; 24 private static final Properties CONFIG_PROPS; 25 26 static { 27 CONFIG_PROPS = new Properties(); 28 try { 29 InputStream is = ICUData.getStream(CONFIG_PROPS_FILE); 30 if (is != null) { 31 try { 32 CONFIG_PROPS.load(is); 33 } finally { is.close()34 is.close(); 35 } 36 } 37 } catch (MissingResourceException mre) { 38 // If it does not exist, ignore. 39 } catch (IOException ioe) { 40 // Any IO errors, ignore 41 } 42 } 43 44 /** 45 * Get ICU configuration property value for the given name. 46 * @param name The configuration property name 47 * @return The configuration property value, or null if it does not exist. 48 */ get(String name)49 public static String get(String name) { 50 return get(name, null); 51 } 52 53 /** 54 * Get ICU configuration property value for the given name. 55 * @param name The configuration property name 56 * @param def The default value 57 * @return The configuration property value. If the property does not 58 * exist, <code>def</code> is returned. 59 */ get(String name, String def)60 public static String get(String name, String def) { 61 String val = null; 62 final String fname = name; 63 if (System.getSecurityManager() != null) { 64 try { 65 val = AccessController.doPrivileged(new PrivilegedAction<String>() { 66 public String run() { 67 return System.getProperty(fname); 68 } 69 }); 70 } catch (AccessControlException e) { 71 // ignore 72 // TODO log this message 73 } 74 } else { 75 val = System.getProperty(name); 76 } 77 78 if (val == null) { 79 val = CONFIG_PROPS.getProperty(name, def); 80 } 81 return val; 82 } 83 } 84