1   /**
2    * Copyright (c) 2000-2010 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   *
12   *
13   */
14  
15  package com.liferay.portal.kernel.util;
16  
17  import com.liferay.portal.kernel.configuration.Filter;
18  import com.liferay.portal.kernel.log.Log;
19  import com.liferay.portal.kernel.log.LogFactoryUtil;
20  
21  import java.util.Properties;
22  
23  /**
24   * <a href="PropsUtil.java.html"><b><i>View Source</i></b></a>
25   *
26   * @author Brian Wing Shun Chan
27   */
28  public class PropsUtil {
29  
30      public static String get(String key) {
31          String value = null;
32  
33          try {
34              Object returnObj = PortalClassInvoker.invoke(
35                  false, _getMethodKey1, key);
36  
37              if (returnObj != null) {
38                  value = (String)returnObj;
39              }
40          }
41          catch (Exception e) {
42              _log.error(e, e);
43          }
44  
45          return value;
46      }
47  
48      public static String get(String key, Filter filter) {
49          String value = null;
50  
51          try {
52              Object returnObj = PortalClassInvoker.invoke(
53                  false, _getMethodKey2, key, filter);
54  
55              if (returnObj != null) {
56                  value = (String)returnObj;
57              }
58          }
59          catch (Exception e) {
60              _log.error(e, e);
61          }
62  
63          return value;
64      }
65  
66      public static String[] getArray(String key) {
67          String[] value = null;
68  
69          try {
70              Object returnObj = PortalClassInvoker.invoke(
71                  false, _getArrayMethodKey, key);
72  
73              if (returnObj != null) {
74                  value = (String[])returnObj;
75              }
76          }
77          catch (Exception e) {
78              _log.error(e, e);
79          }
80  
81          return value;
82      }
83  
84      public static Properties getProperties() {
85          Properties properties = null;
86  
87          try {
88              Object returnObj = PortalClassInvoker.invoke(
89                  false, _getPropertiesMethodKey1);
90  
91              if (returnObj != null) {
92                  properties = (Properties)returnObj;
93              }
94          }
95          catch (Exception e) {
96              _log.error(e, e);
97          }
98  
99          return properties;
100     }
101 
102     public static Properties getProperties(
103         String prefix, boolean removePrefix) {
104 
105         Properties properties = null;
106 
107         try {
108             Object returnObj = PortalClassInvoker.invoke(
109                 false, _getPropertiesMethodKey2, prefix, removePrefix);
110 
111             if (returnObj != null) {
112                 properties = (Properties)returnObj;
113             }
114         }
115         catch (Exception e) {
116             _log.error(e, e);
117         }
118 
119         return properties;
120     }
121 
122     private static final String _CLASS_NAME =
123         "com.liferay.portal.util.PropsUtil";
124 
125     private static Log _log = LogFactoryUtil.getLog(PropsUtil.class);
126 
127     private static MethodKey _getArrayMethodKey = new MethodKey(
128         _CLASS_NAME, "getArray", String.class);
129     private static MethodKey _getMethodKey1 = new MethodKey(
130         _CLASS_NAME, "get", String.class);
131     private static MethodKey _getMethodKey2 = new MethodKey(
132         _CLASS_NAME, "get", String.class, Filter.class);
133     private static MethodKey _getPropertiesMethodKey1 = new MethodKey(
134         _CLASS_NAME, "getProperties");
135     private static MethodKey _getPropertiesMethodKey2 = new MethodKey(
136         _CLASS_NAME, "getProperties", String.class, boolean.class);
137 
138 }