1   /**
2    * Copyright (c) 2000-2009 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   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
15   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
17   * SOFTWARE.
18   */
19  
20  package com.liferay.portal.kernel.util;
21  
22  import javax.portlet.PortletPreferences;
23  
24  import javax.servlet.http.HttpServletRequest;
25  
26  /**
27   * <a href="PrefsParamUtil.java.html"><b><i>View Source</i></b></a>
28   *
29   * @author Brian Wing Shun Chan
30   *
31   */
32  public class PrefsParamUtil {
33  
34      public static boolean getBoolean(
35          PortletPreferences prefs, HttpServletRequest request, String param) {
36  
37          return getBoolean(prefs, request, param, GetterUtil.DEFAULT_BOOLEAN);
38      }
39  
40      public static boolean getBoolean(
41          PortletPreferences prefs, HttpServletRequest request, String param,
42          boolean defaultValue) {
43  
44          String prefsValue = prefs.getValue(param, null);
45  
46          boolean getterUtilValue = GetterUtil.getBoolean(
47              prefsValue, defaultValue);
48  
49          return ParamUtil.get(request, param, getterUtilValue);
50      }
51  
52      public static double getDouble(
53          PortletPreferences prefs, HttpServletRequest request, String param) {
54  
55          return getDouble(prefs, request, param, GetterUtil.DEFAULT_DOUBLE);
56      }
57  
58      public static double getDouble(
59          PortletPreferences prefs, HttpServletRequest request, String param,
60          double defaultValue) {
61  
62          String prefsValue = prefs.getValue(param, null);
63  
64          double getterUtilValue = GetterUtil.getDouble(
65              prefsValue, defaultValue);
66  
67          return ParamUtil.get(request, param, getterUtilValue);
68      }
69  
70      public static int getInteger(
71          PortletPreferences prefs, HttpServletRequest request, String param) {
72  
73          return getInteger(prefs, request, param, GetterUtil.DEFAULT_INTEGER);
74      }
75  
76      public static int getInteger(
77          PortletPreferences prefs, HttpServletRequest request, String param,
78          int defaultValue) {
79  
80          String prefsValue = prefs.getValue(param, null);
81  
82          int getterUtilValue = GetterUtil.getInteger(
83              prefsValue, defaultValue);
84  
85          return ParamUtil.get(request, param, getterUtilValue);
86      }
87  
88      public static long getLong(
89          PortletPreferences prefs, HttpServletRequest request, String param) {
90  
91          return getLong(prefs, request, param, GetterUtil.DEFAULT_LONG);
92      }
93  
94      public static long getLong(
95          PortletPreferences prefs, HttpServletRequest request, String param,
96          long defaultValue) {
97  
98          String prefsValue = prefs.getValue(param, null);
99  
100         long getterUtilValue = GetterUtil.getLong(
101             prefsValue, defaultValue);
102 
103         return ParamUtil.get(request, param, getterUtilValue);
104     }
105 
106     public static String getString(
107         PortletPreferences prefs, HttpServletRequest request, String param) {
108 
109         return getString(prefs, request, param, GetterUtil.DEFAULT_STRING);
110     }
111 
112     public static String getString(
113         PortletPreferences prefs, HttpServletRequest request, String param,
114         String defaultValue) {
115 
116         String prefsValue = prefs.getValue(param, null);
117 
118         String getterUtilValue = GetterUtil.getString(
119             prefsValue, defaultValue);
120 
121         return ParamUtil.get(request, param, getterUtilValue);
122     }
123 
124 }