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.bean;
21  
22  import com.liferay.portal.kernel.util.GetterUtil;
23  import com.liferay.portal.kernel.util.ParamUtil;
24  
25  import javax.servlet.http.HttpServletRequest;
26  
27  /**
28   * <a href="BeanParamUtil.java.html"><b><i>View Source</i></b></a>
29   *
30   * @author Brian Wing Shun Chan
31   *
32   */
33  public class BeanParamUtil {
34  
35      public static boolean getBoolean(
36          Object bean, HttpServletRequest request, String param) {
37  
38          return getBoolean(bean, request, param, GetterUtil.DEFAULT_BOOLEAN);
39      }
40  
41      public static boolean getBoolean(
42          Object bean, HttpServletRequest request, String param,
43          boolean defaultValue) {
44  
45          defaultValue = BeanPropertiesUtil.getBoolean(bean, param, defaultValue);
46  
47          return ParamUtil.get(request, param, defaultValue);
48      }
49  
50      public static double getDouble(
51          Object bean, HttpServletRequest request, String param) {
52  
53          return getDouble(bean, request, param, GetterUtil.DEFAULT_DOUBLE);
54      }
55  
56      public static double getDouble(
57          Object bean, HttpServletRequest request, String param,
58          double defaultValue) {
59  
60          defaultValue = BeanPropertiesUtil.getDouble(bean, param, defaultValue);
61  
62          return ParamUtil.get(request, param, defaultValue);
63      }
64  
65      public static int getInteger(
66          Object bean, HttpServletRequest request, String param) {
67  
68          return getInteger(bean, request, param, GetterUtil.DEFAULT_INTEGER);
69      }
70  
71      public static int getInteger(
72          Object bean, HttpServletRequest request, String param,
73          int defaultValue) {
74  
75          defaultValue = BeanPropertiesUtil.getInteger(bean, param, defaultValue);
76  
77          return ParamUtil.get(request, param, defaultValue);
78      }
79  
80      public static long getLong(
81          Object bean, HttpServletRequest request, String param) {
82  
83          return getLong(bean, request, param, GetterUtil.DEFAULT_LONG);
84      }
85  
86      public static long getLong(
87          Object bean, HttpServletRequest request, String param,
88          long defaultValue) {
89  
90          defaultValue = BeanPropertiesUtil.getLong(bean, param, defaultValue);
91  
92          return ParamUtil.get(request, param, defaultValue);
93  
94      }
95  
96      public static String getString(
97          Object bean, HttpServletRequest request, String param) {
98  
99          return getString(bean, request, param, GetterUtil.DEFAULT_STRING);
100     }
101 
102     public static String getString(
103         Object bean, HttpServletRequest request, String param,
104         String defaultValue) {
105 
106         defaultValue = BeanPropertiesUtil.getString(bean, param, defaultValue);
107 
108         return ParamUtil.get(request, param, defaultValue);
109 
110     }
111 
112 }