1   /**
2    * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portal.util;
24  
25  import com.liferay.portal.configuration.ConfigurationImpl;
26  import com.liferay.portal.kernel.configuration.Configuration;
27  import com.liferay.portal.kernel.configuration.Filter;
28  import com.liferay.util.SystemProperties;
29  
30  import java.util.Properties;
31  
32  /**
33   * <a href="PropsUtil.java.html"><b><i>View Source</i></b></a>
34   *
35   * @author Brian Wing Shun Chan
36   *
37   */
38  public class PropsUtil {
39  
40      /*static {
41          InitUtil.init();
42      }*/
43  
44      public static void addProperties(Properties properties) {
45          _instance._addProperties(properties);
46      }
47  
48      public static boolean contains(String key) {
49          return _instance._contains(key);
50      }
51  
52      public static String get(String key) {
53          return _instance._get(key);
54      }
55  
56      public static String get(String key, Filter filter) {
57          return _instance._get(key, filter);
58      }
59  
60      public static String[] getArray(String key) {
61          return _instance._getArray(key);
62      }
63  
64      public static String[] getArray(String key, Filter filter) {
65          return _instance._getArray(key, filter);
66      }
67  
68      public static Properties getProperties() {
69          return _instance._getProperties();
70      }
71  
72      public static void removeProperties(Properties properties) {
73          _instance._removeProperties(properties);
74      }
75  
76      public static void set(String key, String value) {
77          _instance._set(key, value);
78      }
79  
80      private PropsUtil() {
81          _configuration = new ConfigurationImpl(
82              PropsUtil.class.getClassLoader(), PropsFiles.PORTAL);
83  
84          // Set the portal property "resource.repositories.root" as a system
85          // property as well so it can be referenced by Ehcache.
86  
87          SystemProperties.set(
88              PropsKeys.RESOURCE_REPOSITORIES_ROOT,
89              _get(PropsKeys.RESOURCE_REPOSITORIES_ROOT));
90      }
91  
92      private void _addProperties(Properties properties) {
93          _configuration.addProperties(properties);
94      }
95  
96      private boolean _contains(String key) {
97          return _configuration.contains(key);
98      }
99  
100     private String _get(String key) {
101         return _configuration.get(key);
102     }
103 
104     private String _get(String key, Filter filter) {
105         return _configuration.get(key, filter);
106     }
107 
108     private String[] _getArray(String key) {
109         return _configuration.getArray(key);
110     }
111 
112     private String[] _getArray(String key, Filter filter) {
113         return _configuration.getArray(key, filter);
114     }
115 
116     private Properties _getProperties() {
117         return _configuration.getProperties();
118     }
119 
120     private void _removeProperties(Properties properties) {
121         _configuration.removeProperties(properties);
122     }
123 
124     private void _set(String key, String value) {
125         _configuration.set(key, value);
126     }
127 
128     private static PropsUtil _instance = new PropsUtil();
129 
130     private Configuration _configuration;
131 
132 }