]> gitweb.fperrin.net Git - Dictionary.git/blob - jars/icu4j-4_2_1-src/src/com/ibm/icu/impl/ICUConfig.java
icu4jsrc
[Dictionary.git] / jars / icu4j-4_2_1-src / src / com / ibm / icu / impl / ICUConfig.java
1 /*\r
2  *******************************************************************************\r
3  * Copyright (C) 2008, International Business Machines Corporation and         *\r
4  * others. All Rights Reserved.                                                *\r
5  *******************************************************************************\r
6  */\r
7 package com.ibm.icu.impl;\r
8 \r
9 import java.io.IOException;\r
10 import java.io.InputStream;\r
11 import java.util.MissingResourceException;\r
12 import java.util.Properties;\r
13 \r
14 /**\r
15  * ICUConfig is a class used for accessing ICU4J runtime configuration.\r
16  */\r
17 public class ICUConfig {\r
18     public static final String CONFIG_PROPS_FILE = "/com/ibm/icu/ICUConfig.properties";\r
19     private static final Properties CONFIG_PROPS;\r
20 \r
21     static {\r
22         CONFIG_PROPS = new Properties();\r
23         try {\r
24             InputStream is = ICUData.getStream(CONFIG_PROPS_FILE);\r
25             if (is != null) {\r
26                 CONFIG_PROPS.load(is);\r
27             }\r
28         } catch (MissingResourceException mre) {\r
29             // If it does not exist, ignore.\r
30         } catch (IOException ioe) {\r
31             // Any IO errors, ignore\r
32         }\r
33     }\r
34 \r
35     /**\r
36      * Get ICU configuration property value for the given name.\r
37      * @param name The configuration property name\r
38      * @return The configuration property value, or null if it does not exist.\r
39      */\r
40     public static String get(String name) {\r
41         return get(name, null);\r
42     }\r
43 \r
44     /**\r
45      * Get ICU configuration property value for the given name.\r
46      * @param name The configuration property name\r
47      * @param def The default value\r
48      * @return The configuration property value.  If the property does not\r
49      * exist, <code>def</code> is returned.\r
50      */\r
51     public static String get(String name, String def) {\r
52         String val = null;\r
53         // Try the system property first\r
54         try {\r
55             val = System.getProperty(name);\r
56         } catch (SecurityException e) {\r
57             // Ignore and fall through\r
58         }\r
59 \r
60         if (val == null) {\r
61             val = CONFIG_PROPS.getProperty(name, def);\r
62         }\r
63         return val;\r
64     }\r
65 }\r