1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
15   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
17   * SOFTWARE.
18   */
19  
20  package com.liferay.portal.util;
21  
22  import com.liferay.portal.configuration.ConfigurationImpl;
23  import com.liferay.portal.kernel.configuration.Configuration;
24  import com.liferay.portal.kernel.configuration.Filter;
25  import com.liferay.util.SystemProperties;
26  
27  import java.util.Properties;
28  
29  /**
30   * <a href="PropsUtil.java.html"><b><i>View Source</i></b></a>
31   *
32   * @author Brian Wing Shun Chan
33   *
34   */
35  public class PropsUtil {
36  
37      public static void addProperties(Properties properties) {
38          _instance._addProperties(properties);
39      }
40  
41      public static boolean contains(String key) {
42          return _instance._contains(key);
43      }
44  
45      public static String get(String key) {
46          return _instance._get(key);
47      }
48  
49      public static String get(String key, Filter filter) {
50          return _instance._get(key, filter);
51      }
52  
53      public static String[] getArray(String key) {
54          return _instance._getArray(key);
55      }
56  
57      public static String[] getArray(String key, Filter filter) {
58          return _instance._getArray(key, filter);
59      }
60  
61      public static Properties getProperties() {
62          return _instance._getProperties();
63      }
64  
65      public static Properties getProperties(
66          String prefix, boolean removePrefix) {
67  
68          return _instance._getProperties(prefix, removePrefix);
69      }
70  
71      public static void removeProperties(Properties properties) {
72          _instance._removeProperties(properties);
73      }
74  
75      public static void set(String key, String value) {
76          _instance._set(key, value);
77      }
78  
79      private PropsUtil() {
80          _configuration = new ConfigurationImpl(
81              PropsUtil.class.getClassLoader(), PropsFiles.PORTAL);
82  
83          // Set the portal property "resource.repositories.root" and
84          // "ehcache.disk.store.dir" as a system property as well so it can be
85          // referenced by Ehcache. The property "resource.repositories.root" is
86          // deprecated. Please use "ehcache.disk.store.dir" instead.
87  
88          SystemProperties.set(
89              PropsKeys.RESOURCE_REPOSITORIES_ROOT,
90              _get(PropsKeys.RESOURCE_REPOSITORIES_ROOT));
91  
92          SystemProperties.set(
93              "ehcache.disk.store.dir",
94              _get(PropsKeys.RESOURCE_REPOSITORIES_ROOT));
95      }
96  
97      private void _addProperties(Properties properties) {
98          _configuration.addProperties(properties);
99      }
100 
101     private boolean _contains(String key) {
102         return _configuration.contains(key);
103     }
104 
105     private String _get(String key) {
106         return _configuration.get(key);
107     }
108 
109     private String _get(String key, Filter filter) {
110         return _configuration.get(key, filter);
111     }
112 
113     private String[] _getArray(String key) {
114         return _configuration.getArray(key);
115     }
116 
117     private String[] _getArray(String key, Filter filter) {
118         return _configuration.getArray(key, filter);
119     }
120 
121     private Properties _getProperties() {
122         return _configuration.getProperties();
123     }
124 
125     private Properties _getProperties(String prefix, boolean removePrefix) {
126         return _configuration.getProperties(prefix, removePrefix);
127     }
128 
129     private void _removeProperties(Properties properties) {
130         _configuration.removeProperties(properties);
131     }
132 
133     private void _set(String key, String value) {
134         _configuration.set(key, value);
135     }
136 
137     private static PropsUtil _instance = new PropsUtil();
138 
139     private Configuration _configuration;
140 
141 }