2 *******************************************************************************
\r
3 * Copyright (C) 2008-2010, International Business Machines Corporation and *
\r
4 * others. All Rights Reserved. *
\r
5 *******************************************************************************
\r
7 package com.ibm.icu.impl;
\r
9 import java.io.IOException;
\r
10 import java.io.InputStream;
\r
11 import java.security.AccessControlException;
\r
12 import java.security.AccessController;
\r
13 import java.security.PrivilegedAction;
\r
14 import java.util.MissingResourceException;
\r
15 import java.util.Properties;
\r
18 * ICUConfig is a class used for accessing ICU4J runtime configuration.
\r
20 public class ICUConfig {
\r
21 public static final String CONFIG_PROPS_FILE = "/com/ibm/icu/ICUConfig.properties";
\r
22 private static final Properties CONFIG_PROPS;
\r
25 CONFIG_PROPS = new Properties();
\r
27 InputStream is = ICUData.getStream(CONFIG_PROPS_FILE);
\r
29 CONFIG_PROPS.load(is);
\r
31 } catch (MissingResourceException mre) {
\r
32 // If it does not exist, ignore.
\r
33 } catch (IOException ioe) {
\r
34 // Any IO errors, ignore
\r
39 * Get ICU configuration property value for the given name.
\r
40 * @param name The configuration property name
\r
41 * @return The configuration property value, or null if it does not exist.
\r
43 public static String get(String name) {
\r
44 return get(name, null);
\r
48 * Get ICU configuration property value for the given name.
\r
49 * @param name The configuration property name
\r
50 * @param def The default value
\r
51 * @return The configuration property value. If the property does not
\r
52 * exist, <code>def</code> is returned.
\r
54 public static String get(String name, String def) {
\r
56 final String fname = name;
\r
57 if (System.getSecurityManager() != null) {
\r
59 val = AccessController.doPrivileged(new PrivilegedAction<String>() {
\r
60 public String run() {
\r
61 return System.getProperty(fname);
\r
64 } catch (AccessControlException e) {
\r
66 // TODO log this message
\r
69 val = System.getProperty(name);
\r
73 val = CONFIG_PROPS.getProperty(name, def);
\r