001: /**
002: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
003: *
004: * Permission is hereby granted, free of charge, to any person obtaining a copy
005: * of this software and associated documentation files (the "Software"), to deal
006: * in the Software without restriction, including without limitation the rights
007: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008: * copies of the Software, and to permit persons to whom the Software is
009: * furnished to do so, subject to the following conditions:
010: *
011: * The above copyright notice and this permission notice shall be included in
012: * all copies or substantial portions of the Software.
013: *
014: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
020: * SOFTWARE.
021: */package com.liferay.portal.kernel.util;
022:
023: import javax.portlet.PortletPreferences;
024:
025: import javax.servlet.ServletRequest;
026:
027: /**
028: * <a href="PrefsParamUtil.java.html"><b><i>View Source</i></b></a>
029: *
030: * @author Brian Wing Shun Chan
031: *
032: */
033: public class PrefsParamUtil {
034:
035: public static boolean getBoolean(PortletPreferences prefs,
036: ServletRequest req, String param) {
037:
038: return getBoolean(prefs, req, param, GetterUtil.DEFAULT_BOOLEAN);
039: }
040:
041: public static boolean getBoolean(PortletPreferences prefs,
042: ServletRequest req, String param, boolean defaultValue) {
043:
044: String prefsValue = prefs.getValue(param, null);
045:
046: boolean getterUtilValue = GetterUtil.getBoolean(prefsValue,
047: defaultValue);
048:
049: return ParamUtil.get(req, param, getterUtilValue);
050: }
051:
052: public static double getDouble(PortletPreferences prefs,
053: ServletRequest req, String param) {
054:
055: return getDouble(prefs, req, param, GetterUtil.DEFAULT_DOUBLE);
056: }
057:
058: public static double getDouble(PortletPreferences prefs,
059: ServletRequest req, String param, double defaultValue) {
060:
061: String prefsValue = prefs.getValue(param, null);
062:
063: double getterUtilValue = GetterUtil.getDouble(prefsValue,
064: defaultValue);
065:
066: return ParamUtil.get(req, param, getterUtilValue);
067: }
068:
069: public static int getInteger(PortletPreferences prefs,
070: ServletRequest req, String param) {
071:
072: return getInteger(prefs, req, param, GetterUtil.DEFAULT_INTEGER);
073: }
074:
075: public static int getInteger(PortletPreferences prefs,
076: ServletRequest req, String param, int defaultValue) {
077:
078: String prefsValue = prefs.getValue(param, null);
079:
080: int getterUtilValue = GetterUtil.getInteger(prefsValue,
081: defaultValue);
082:
083: return ParamUtil.get(req, param, getterUtilValue);
084: }
085:
086: public static long getLong(PortletPreferences prefs,
087: ServletRequest req, String param) {
088:
089: return getLong(prefs, req, param, GetterUtil.DEFAULT_LONG);
090: }
091:
092: public static long getLong(PortletPreferences prefs,
093: ServletRequest req, String param, long defaultValue) {
094:
095: String prefsValue = prefs.getValue(param, null);
096:
097: long getterUtilValue = GetterUtil.getLong(prefsValue,
098: defaultValue);
099:
100: return ParamUtil.get(req, param, getterUtilValue);
101: }
102:
103: public static String getString(PortletPreferences prefs,
104: ServletRequest req, String param) {
105:
106: return getString(prefs, req, param, GetterUtil.DEFAULT_STRING);
107: }
108:
109: public static String getString(PortletPreferences prefs,
110: ServletRequest req, String param, String defaultValue) {
111:
112: String prefsValue = prefs.getValue(param, null);
113:
114: String getterUtilValue = GetterUtil.getString(prefsValue,
115: defaultValue);
116:
117: return ParamUtil.get(req, param, getterUtilValue);
118: }
119:
120: }
|