1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    *
5    *
6    *
7    * The contents of this file are subject to the terms of the Liferay Enterprise
8    * Subscription License ("License"). You may not use this file except in
9    * compliance with the License. You can obtain a copy of the License by
10   * contacting Liferay, Inc. See the License for the specific language governing
11   * permissions and limitations under the License, including but not limited to
12   * distribution rights 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.bean;
24  
25  import com.liferay.portal.kernel.util.GetterUtil;
26  import com.liferay.portal.kernel.util.ParamUtil;
27  
28  import javax.servlet.http.HttpServletRequest;
29  
30  /**
31   * <a href="BeanParamUtil.java.html"><b><i>View Source</i></b></a>
32   *
33   * @author Brian Wing Shun Chan
34   */
35  public class BeanParamUtil {
36  
37      public static boolean getBoolean(
38          Object bean, HttpServletRequest request, String param) {
39  
40          return getBoolean(bean, request, param, GetterUtil.DEFAULT_BOOLEAN);
41      }
42  
43      public static boolean getBoolean(
44          Object bean, HttpServletRequest request, String param,
45          boolean defaultValue) {
46  
47          defaultValue = BeanPropertiesUtil.getBoolean(bean, param, defaultValue);
48  
49          return ParamUtil.get(request, param, defaultValue);
50      }
51  
52      public static double getDouble(
53          Object bean, HttpServletRequest request, String param) {
54  
55          return getDouble(bean, request, param, GetterUtil.DEFAULT_DOUBLE);
56      }
57  
58      public static double getDouble(
59          Object bean, HttpServletRequest request, String param,
60          double defaultValue) {
61  
62          defaultValue = BeanPropertiesUtil.getDouble(bean, param, defaultValue);
63  
64          return ParamUtil.get(request, param, defaultValue);
65      }
66  
67      public static int getInteger(
68          Object bean, HttpServletRequest request, String param) {
69  
70          return getInteger(bean, request, param, GetterUtil.DEFAULT_INTEGER);
71      }
72  
73      public static int getInteger(
74          Object bean, HttpServletRequest request, String param,
75          int defaultValue) {
76  
77          defaultValue = BeanPropertiesUtil.getInteger(bean, param, defaultValue);
78  
79          return ParamUtil.get(request, param, defaultValue);
80      }
81  
82      public static long getLong(
83          Object bean, HttpServletRequest request, String param) {
84  
85          return getLong(bean, request, param, GetterUtil.DEFAULT_LONG);
86      }
87  
88      public static long getLong(
89          Object bean, HttpServletRequest request, String param,
90          long defaultValue) {
91  
92          defaultValue = BeanPropertiesUtil.getLong(bean, param, defaultValue);
93  
94          return ParamUtil.get(request, param, defaultValue);
95  
96      }
97  
98      public static String getString(
99          Object bean, HttpServletRequest request, String param) {
100 
101         return getString(bean, request, param, GetterUtil.DEFAULT_STRING);
102     }
103 
104     public static String getString(
105         Object bean, HttpServletRequest request, String param,
106         String defaultValue) {
107 
108         defaultValue = BeanPropertiesUtil.getString(bean, param, defaultValue);
109 
110         return ParamUtil.get(request, param, defaultValue);
111 
112     }
113 
114 }