1   /**
2    * Copyright (c) 2000-2009 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.kernel.util;
24  
25  import javax.portlet.PortletPreferences;
26  
27  import javax.servlet.http.HttpServletRequest;
28  
29  /**
30   * <a href="PrefsParamUtil.java.html"><b><i>View Source</i></b></a>
31   *
32   * @author Brian Wing Shun Chan
33   *
34   */
35  public class PrefsParamUtil {
36  
37      public static boolean getBoolean(
38          PortletPreferences preferences, HttpServletRequest request,
39          String param) {
40  
41          return getBoolean(
42              preferences, request, param, GetterUtil.DEFAULT_BOOLEAN);
43      }
44  
45      public static boolean getBoolean(
46          PortletPreferences preferences, HttpServletRequest request,
47          String param, boolean defaultValue) {
48  
49          String preferencesValue = preferences.getValue(param, null);
50  
51          boolean getterUtilValue = GetterUtil.getBoolean(
52              preferencesValue, defaultValue);
53  
54          return ParamUtil.get(request, param, getterUtilValue);
55      }
56  
57      public static double getDouble(
58          PortletPreferences preferences, HttpServletRequest request,
59          String param) {
60  
61          return getDouble(
62              preferences, request, param, GetterUtil.DEFAULT_DOUBLE);
63      }
64  
65      public static double getDouble(
66          PortletPreferences preferences, HttpServletRequest request,
67          String param, double defaultValue) {
68  
69          String preferencesValue = preferences.getValue(param, null);
70  
71          double getterUtilValue = GetterUtil.getDouble(
72              preferencesValue, defaultValue);
73  
74          return ParamUtil.get(request, param, getterUtilValue);
75      }
76  
77      public static int getInteger(
78          PortletPreferences preferences, HttpServletRequest request,
79          String param) {
80  
81          return getInteger(
82              preferences, request, param, GetterUtil.DEFAULT_INTEGER);
83      }
84  
85      public static int getInteger(
86          PortletPreferences preferences, HttpServletRequest request,
87          String param, int defaultValue) {
88  
89          String preferencesValue = preferences.getValue(param, null);
90  
91          int getterUtilValue = GetterUtil.getInteger(
92              preferencesValue, defaultValue);
93  
94          return ParamUtil.get(request, param, getterUtilValue);
95      }
96  
97      public static long getLong(
98          PortletPreferences preferences, HttpServletRequest request,
99          String param) {
100 
101         return getLong(preferences, request, param, GetterUtil.DEFAULT_LONG);
102     }
103 
104     public static long getLong(
105         PortletPreferences preferences, HttpServletRequest request,
106         String param, long defaultValue) {
107 
108         String preferencesValue = preferences.getValue(param, null);
109 
110         long getterUtilValue = GetterUtil.getLong(
111             preferencesValue, defaultValue);
112 
113         return ParamUtil.get(request, param, getterUtilValue);
114     }
115 
116     public static String getString(
117         PortletPreferences preferences, HttpServletRequest request,
118         String param) {
119 
120         return getString(
121             preferences, request, param, GetterUtil.DEFAULT_STRING);
122     }
123 
124     public static String getString(
125         PortletPreferences preferences, HttpServletRequest request,
126         String param, String defaultValue) {
127 
128         String preferencesValue = preferences.getValue(param, null);
129 
130         String getterUtilValue = GetterUtil.getString(
131             preferencesValue, defaultValue);
132 
133         return ParamUtil.get(request, param, getterUtilValue);
134     }
135 
136 }