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