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.portlet.PortletRequest;
29  
30  import javax.servlet.http.HttpServletRequest;
31  
32  /**
33   * <a href="BeanParamUtil.java.html"><b><i>View Source</i></b></a>
34   *
35   * @author Brian Wing Shun Chan
36   */
37  public class BeanParamUtil {
38  
39      public static boolean getBoolean(
40          Object bean, HttpServletRequest request, String param) {
41  
42          return getBoolean(bean, request, param, GetterUtil.DEFAULT_BOOLEAN);
43      }
44  
45      public static boolean getBoolean(
46          Object bean, HttpServletRequest request, String param,
47          boolean defaultValue) {
48  
49          defaultValue = BeanPropertiesUtil.getBoolean(bean, param, defaultValue);
50  
51          return ParamUtil.get(request, param, defaultValue);
52      }
53  
54      public static boolean getBoolean(
55          Object bean, PortletRequest portletRequest, String param) {
56  
57          return getBoolean(
58              bean, portletRequest, param, GetterUtil.DEFAULT_BOOLEAN);
59      }
60  
61      public static boolean getBoolean(
62          Object bean, PortletRequest portletRequest, String param,
63          boolean defaultValue) {
64  
65          defaultValue = BeanPropertiesUtil.getBoolean(bean, param, defaultValue);
66  
67          return ParamUtil.get(portletRequest, param, defaultValue);
68      }
69  
70      public static double getDouble(
71          Object bean, HttpServletRequest request, String param) {
72  
73          return getDouble(bean, request, param, GetterUtil.DEFAULT_DOUBLE);
74      }
75  
76      public static double getDouble(
77          Object bean, HttpServletRequest request, String param,
78          double defaultValue) {
79  
80          defaultValue = BeanPropertiesUtil.getDouble(bean, param, defaultValue);
81  
82          return ParamUtil.get(request, param, defaultValue);
83      }
84  
85      public static double getDouble(
86          Object bean, PortletRequest portletRequest, String param) {
87  
88          return getDouble(
89              bean, portletRequest, param, GetterUtil.DEFAULT_DOUBLE);
90      }
91  
92      public static double getDouble(
93          Object bean, PortletRequest portletRequest, String param,
94          double defaultValue) {
95  
96          defaultValue = BeanPropertiesUtil.getDouble(bean, param, defaultValue);
97  
98          return ParamUtil.get(portletRequest, param, defaultValue);
99      }
100 
101     public static int getInteger(
102         Object bean, HttpServletRequest request, String param) {
103 
104         return getInteger(bean, request, param, GetterUtil.DEFAULT_INTEGER);
105     }
106 
107     public static int getInteger(
108         Object bean, HttpServletRequest request, String param,
109         int defaultValue) {
110 
111         defaultValue = BeanPropertiesUtil.getInteger(bean, param, defaultValue);
112 
113         return ParamUtil.get(request, param, defaultValue);
114     }
115 
116     public static int getInteger(
117         Object bean, PortletRequest portletRequest, String param) {
118 
119         return getInteger(
120             bean, portletRequest, param, GetterUtil.DEFAULT_INTEGER);
121     }
122 
123     public static int getInteger(
124         Object bean, PortletRequest portletRequest, String param,
125         int defaultValue) {
126 
127         defaultValue = BeanPropertiesUtil.getInteger(bean, param, defaultValue);
128 
129         return ParamUtil.get(portletRequest, param, defaultValue);
130     }
131 
132     public static long getLong(
133         Object bean, HttpServletRequest request, String param) {
134 
135         return getLong(bean, request, param, GetterUtil.DEFAULT_LONG);
136     }
137 
138     public static long getLong(
139         Object bean, HttpServletRequest request, String param,
140         long defaultValue) {
141 
142         defaultValue = BeanPropertiesUtil.getLong(bean, param, defaultValue);
143 
144         return ParamUtil.get(request, param, defaultValue);
145 
146     }
147 
148     public static long getLong(
149         Object bean, PortletRequest portletRequest, String param) {
150 
151         return getLong(bean, portletRequest, param, GetterUtil.DEFAULT_LONG);
152     }
153 
154     public static long getLong(
155         Object bean, PortletRequest portletRequest, String param,
156         long defaultValue) {
157 
158         defaultValue = BeanPropertiesUtil.getLong(bean, param, defaultValue);
159 
160         return ParamUtil.get(portletRequest, param, defaultValue);
161 
162     }
163 
164     public static String getString(
165         Object bean, HttpServletRequest request, String param) {
166 
167         return getString(bean, request, param, GetterUtil.DEFAULT_STRING);
168     }
169 
170     public static String getString(
171         Object bean, HttpServletRequest request, String param,
172         String defaultValue) {
173 
174         defaultValue = BeanPropertiesUtil.getString(bean, param, defaultValue);
175 
176         return ParamUtil.get(request, param, defaultValue);
177 
178     }
179 
180     public static String getString(
181         Object bean, PortletRequest portletRequest, String param) {
182 
183         return getString(
184             bean, portletRequest, param, GetterUtil.DEFAULT_STRING);
185     }
186 
187     public static String getString(
188         Object bean, PortletRequest portletRequest, String param,
189         String defaultValue) {
190 
191         defaultValue = BeanPropertiesUtil.getString(bean, param, defaultValue);
192 
193         return ParamUtil.get(portletRequest, param, defaultValue);
194 
195     }
196 
197 }