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 void removeProperties(Properties properties) {
69          _instance._removeProperties(properties);
70      }
71  
72      public static void set(String key, String value) {
73          _instance._set(key, value);
74      }
75  
76      private PropsUtil() {
77          _configuration = new ConfigurationImpl(
78              PropsUtil.class.getClassLoader(), PropsFiles.PORTAL);
79  
80          // Set the portal property "resource.repositories.root" as a system
81          // property as well so it can be referenced by Ehcache.
82  
83          SystemProperties.set(
84              PropsKeys.RESOURCE_REPOSITORIES_ROOT,
85              _get(PropsKeys.RESOURCE_REPOSITORIES_ROOT));
86      }
87  
88      private void _addProperties(Properties properties) {
89          _configuration.addProperties(properties);
90      }
91  
92      private boolean _contains(String key) {
93          return _configuration.contains(key);
94      }
95  
96      private String _get(String key) {
97          return _configuration.get(key);
98      }
99  
100     private String _get(String key, Filter filter) {
101         return _configuration.get(key, filter);
102     }
103 
104     private String[] _getArray(String key) {
105         return _configuration.getArray(key);
106     }
107 
108     private String[] _getArray(String key, Filter filter) {
109         return _configuration.getArray(key, filter);
110     }
111 
112     private Properties _getProperties() {
113         return _configuration.getProperties();
114     }
115 
116     private void _removeProperties(Properties properties) {
117         _configuration.removeProperties(properties);
118     }
119 
120     private void _set(String key, String value) {
121         _configuration.set(key, value);
122     }
123 
124     private static PropsUtil _instance = new PropsUtil();
125 
126     private Configuration _configuration;
127 
128 }