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      public static void addProperties(Properties properties) {
41          _instance._addProperties(properties);
42      }
43  
44      public static boolean contains(String key) {
45          return _instance._contains(key);
46      }
47  
48      public static String get(String key) {
49          return _instance._get(key);
50      }
51  
52      public static String get(String key, Filter filter) {
53          return _instance._get(key, filter);
54      }
55  
56      public static String[] getArray(String key) {
57          return _instance._getArray(key);
58      }
59  
60      public static String[] getArray(String key, Filter filter) {
61          return _instance._getArray(key, filter);
62      }
63  
64      public static Properties getProperties() {
65          return _instance._getProperties();
66      }
67  
68      public static Properties getProperties(
69          String prefix, boolean removePrefix) {
70  
71          return _instance._getProperties(prefix, removePrefix);
72      }
73  
74      public static void removeProperties(Properties properties) {
75          _instance._removeProperties(properties);
76      }
77  
78      public static void set(String key, String value) {
79          _instance._set(key, value);
80      }
81  
82      private PropsUtil() {
83          _configuration = new ConfigurationImpl(
84              PropsUtil.class.getClassLoader(), PropsFiles.PORTAL);
85  
86          // Set the portal property "resource.repositories.root" as a system
87          // property as well so it can be referenced by Ehcache.
88  
89          SystemProperties.set(
90              PropsKeys.RESOURCE_REPOSITORIES_ROOT,
91              _get(PropsKeys.RESOURCE_REPOSITORIES_ROOT));
92      }
93  
94      private void _addProperties(Properties properties) {
95          _configuration.addProperties(properties);
96      }
97  
98      private boolean _contains(String key) {
99          return _configuration.contains(key);
100     }
101 
102     private String _get(String key) {
103         return _configuration.get(key);
104     }
105 
106     private String _get(String key, Filter filter) {
107         return _configuration.get(key, filter);
108     }
109 
110     private String[] _getArray(String key) {
111         return _configuration.getArray(key);
112     }
113 
114     private String[] _getArray(String key, Filter filter) {
115         return _configuration.getArray(key, filter);
116     }
117 
118     private Properties _getProperties() {
119         return _configuration.getProperties();
120     }
121 
122     private Properties _getProperties(String prefix, boolean removePrefix) {
123         return _configuration.getProperties(prefix, removePrefix);
124     }
125 
126     private void _removeProperties(Properties properties) {
127         _configuration.removeProperties(properties);
128     }
129 
130     private void _set(String key, String value) {
131         _configuration.set(key, value);
132     }
133 
134     private static PropsUtil _instance = new PropsUtil();
135 
136     private Configuration _configuration;
137 
138 }