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