001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portal.kernel.util;
016    
017    import com.liferay.portal.kernel.configuration.Filter;
018    import com.liferay.portal.kernel.log.Log;
019    import com.liferay.portal.kernel.log.LogFactoryUtil;
020    
021    import java.util.Properties;
022    
023    /**
024     * @author Brian Wing Shun Chan
025     */
026    public class PropsUtil {
027    
028            public static String get(String key) {
029                    String value = null;
030    
031                    try {
032                            Object returnObj = PortalClassInvoker.invoke(
033                                    false, _getMethodKey1, key);
034    
035                            if (returnObj != null) {
036                                    value = (String)returnObj;
037                            }
038                    }
039                    catch (Exception e) {
040                            _log.error(e, e);
041                    }
042    
043                    return value;
044            }
045    
046            public static String get(String key, Filter filter) {
047                    String value = null;
048    
049                    try {
050                            Object returnObj = PortalClassInvoker.invoke(
051                                    false, _getMethodKey2, key, filter);
052    
053                            if (returnObj != null) {
054                                    value = (String)returnObj;
055                            }
056                    }
057                    catch (Exception e) {
058                            _log.error(e, e);
059                    }
060    
061                    return value;
062            }
063    
064            public static String[] getArray(String key) {
065                    String[] value = null;
066    
067                    try {
068                            Object returnObj = PortalClassInvoker.invoke(
069                                    false, _getArrayMethodKey, key);
070    
071                            if (returnObj != null) {
072                                    value = (String[])returnObj;
073                            }
074                    }
075                    catch (Exception e) {
076                            _log.error(e, e);
077                    }
078    
079                    return value;
080            }
081    
082            public static Properties getProperties() {
083                    Properties properties = null;
084    
085                    try {
086                            Object returnObj = PortalClassInvoker.invoke(
087                                    false, _getPropertiesMethodKey1);
088    
089                            if (returnObj != null) {
090                                    properties = (Properties)returnObj;
091                            }
092                    }
093                    catch (Exception e) {
094                            _log.error(e, e);
095                    }
096    
097                    return properties;
098            }
099    
100            public static Properties getProperties(
101                    String prefix, boolean removePrefix) {
102    
103                    Properties properties = null;
104    
105                    try {
106                            Object returnObj = PortalClassInvoker.invoke(
107                                    false, _getPropertiesMethodKey2, prefix, removePrefix);
108    
109                            if (returnObj != null) {
110                                    properties = (Properties)returnObj;
111                            }
112                    }
113                    catch (Exception e) {
114                            _log.error(e, e);
115                    }
116    
117                    return properties;
118            }
119    
120            private static final String _CLASS_NAME =
121                    "com.liferay.portal.util.PropsUtil";
122    
123            private static Log _log = LogFactoryUtil.getLog(PropsUtil.class);
124    
125            private static MethodKey _getArrayMethodKey = new MethodKey(
126                    _CLASS_NAME, "getArray", String.class);
127            private static MethodKey _getMethodKey1 = new MethodKey(
128                    _CLASS_NAME, "get", String.class);
129            private static MethodKey _getMethodKey2 = new MethodKey(
130                    _CLASS_NAME, "get", String.class, Filter.class);
131            private static MethodKey _getPropertiesMethodKey1 = new MethodKey(
132                    _CLASS_NAME, "getProperties");
133            private static MethodKey _getPropertiesMethodKey2 = new MethodKey(
134                    _CLASS_NAME, "getProperties", String.class, boolean.class);
135    
136    }