001
014
015 package com.liferay.portal.kernel.util;
016
017 import javax.portlet.PortletRequest;
018 import javax.portlet.PortletSession;
019
020 import javax.servlet.http.HttpServletRequest;
021 import javax.servlet.http.HttpSession;
022
023
026 public class SessionParamUtil {
027
028 public static boolean getBoolean(HttpServletRequest request, String param) {
029 return getBoolean(request, param, GetterUtil.DEFAULT_BOOLEAN);
030 }
031
032 public static boolean getBoolean(
033 HttpServletRequest request, String param, boolean defaultValue) {
034
035 HttpSession session = request.getSession();
036
037 String requestValue = request.getParameter(param);
038
039 if (requestValue != null) {
040 boolean value = GetterUtil.getBoolean(requestValue);
041
042 session.setAttribute(param, value);
043
044 return value;
045 }
046
047 Boolean sessionValue = (Boolean)session.getAttribute(param);
048
049 if (sessionValue != null) {
050 return sessionValue;
051 }
052
053 return defaultValue;
054 }
055
056 public static boolean getBoolean(
057 PortletRequest portletRequest, String param) {
058
059 return getBoolean(portletRequest, param, GetterUtil.DEFAULT_BOOLEAN);
060 }
061
062 public static boolean getBoolean(
063 PortletRequest portletRequest, String param, boolean defaultValue) {
064
065 PortletSession portletSession = portletRequest.getPortletSession();
066
067 String portletRequestValue = portletRequest.getParameter(param);
068
069 if (portletRequestValue != null) {
070 boolean value = GetterUtil.getBoolean(portletRequestValue);
071
072 portletSession.setAttribute(param, value);
073
074 return value;
075 }
076
077 Boolean portletSessionValue = (Boolean)portletSession.getAttribute(
078 param);
079
080 if (portletSessionValue != null) {
081 return portletSessionValue;
082 }
083
084 return defaultValue;
085 }
086
087 public static double getDouble(HttpServletRequest request, String param) {
088 return getDouble(request, param, GetterUtil.DEFAULT_DOUBLE);
089 }
090
091 public static double getDouble(
092 HttpServletRequest request, String param, double defaultValue) {
093
094 HttpSession session = request.getSession();
095
096 String requestValue = request.getParameter(param);
097
098 if (requestValue != null) {
099 double value = GetterUtil.getDouble(requestValue);
100
101 session.setAttribute(param, value);
102
103 return value;
104 }
105
106 Double sessionValue = (Double)session.getAttribute(param);
107
108 if (sessionValue != null) {
109 return sessionValue;
110 }
111
112 return defaultValue;
113 }
114
115 public static double getDouble(
116 PortletRequest portletRequest, String param) {
117
118 return getDouble(portletRequest, param, GetterUtil.DEFAULT_DOUBLE);
119 }
120
121 public static double getDouble(
122 PortletRequest portletRequest, String param, double defaultValue) {
123
124 PortletSession portletSession = portletRequest.getPortletSession();
125
126 String portletRequestValue = portletRequest.getParameter(param);
127
128 if (portletRequestValue != null) {
129 double value = GetterUtil.getDouble(portletRequestValue);
130
131 portletSession.setAttribute(param, value);
132
133 return value;
134 }
135
136 Double portletSessionValue = (Double)portletSession.getAttribute(param);
137
138 if (portletSessionValue != null) {
139 return portletSessionValue;
140 }
141
142 return defaultValue;
143 }
144
145 public static int getInteger(HttpServletRequest request, String param) {
146 return getInteger(request, param, GetterUtil.DEFAULT_INTEGER);
147 }
148
149 public static int getInteger(
150 HttpServletRequest request, String param, int defaultValue) {
151
152 HttpSession session = request.getSession();
153
154 String requestValue = request.getParameter(param);
155
156 if (requestValue != null) {
157 int value = GetterUtil.getInteger(requestValue);
158
159 session.setAttribute(param, value);
160
161 return value;
162 }
163
164 Integer sessionValue = (Integer)session.getAttribute(param);
165
166 if (sessionValue != null) {
167 return sessionValue;
168 }
169
170 return defaultValue;
171 }
172
173 public static int getInteger(PortletRequest portletRequest, String param) {
174 return getInteger(portletRequest, param, GetterUtil.DEFAULT_INTEGER);
175 }
176
177 public static int getInteger(
178 PortletRequest portletRequest, String param, int defaultValue) {
179
180 PortletSession portletSession = portletRequest.getPortletSession();
181
182 String portletRequestValue = portletRequest.getParameter(param);
183
184 if (portletRequestValue != null) {
185 int value = GetterUtil.getInteger(portletRequestValue);
186
187 portletSession.setAttribute(param, value);
188
189 return value;
190 }
191
192 Integer portletSessionValue = (Integer)portletSession.getAttribute(
193 param);
194
195 if (portletSessionValue != null) {
196 return portletSessionValue;
197 }
198
199 return defaultValue;
200 }
201
202 public static long getLong(HttpServletRequest request, String param) {
203 return getLong(request, param, GetterUtil.DEFAULT_LONG);
204 }
205
206 public static long getLong(
207 HttpServletRequest request, String param, long defaultValue) {
208
209 HttpSession session = request.getSession();
210
211 String requestValue = request.getParameter(param);
212
213 if (requestValue != null) {
214 long value = GetterUtil.getLong(requestValue);
215
216 session.setAttribute(param, value);
217
218 return value;
219 }
220
221 Long sessionValue = (Long)session.getAttribute(param);
222
223 if (sessionValue != null) {
224 return sessionValue;
225 }
226
227 return defaultValue;
228 }
229
230 public static long getLong(PortletRequest portletRequest, String param) {
231 return getLong(portletRequest, param, GetterUtil.DEFAULT_LONG);
232 }
233
234 public static long getLong(
235 PortletRequest portletRequest, String param, long defaultValue) {
236
237 PortletSession portletSession = portletRequest.getPortletSession();
238
239 String portletRequestValue = portletRequest.getParameter(param);
240
241 if (portletRequestValue != null) {
242 long value = GetterUtil.getLong(portletRequestValue);
243
244 portletSession.setAttribute(param, value);
245
246 return value;
247 }
248
249 Long portletSessionValue = (Long)portletSession.getAttribute(param);
250
251 if (portletSessionValue != null) {
252 return portletSessionValue;
253 }
254
255 return defaultValue;
256 }
257
258 public static short getShort(HttpServletRequest request, String param) {
259 return getShort(request, param, GetterUtil.DEFAULT_SHORT);
260 }
261
262 public static short getShort(
263 HttpServletRequest request, String param, short defaultValue) {
264
265 HttpSession session = request.getSession();
266
267 String requestValue = request.getParameter(param);
268
269 if (requestValue != null) {
270 short value = GetterUtil.getShort(requestValue);
271
272 session.setAttribute(param, value);
273
274 return value;
275 }
276
277 Short sessionValue = (Short)session.getAttribute(param);
278
279 if (sessionValue != null) {
280 return sessionValue;
281 }
282
283 return defaultValue;
284 }
285
286 public static short getShort(PortletRequest portletRequest, String param) {
287 return getShort(portletRequest, param, GetterUtil.DEFAULT_SHORT);
288 }
289
290 public static short getShort(
291 PortletRequest portletRequest, String param, short defaultValue) {
292
293 PortletSession portletSession = portletRequest.getPortletSession();
294
295 String portletRequestValue = portletRequest.getParameter(param);
296
297 if (portletRequestValue != null) {
298 short value = GetterUtil.getShort(portletRequestValue);
299
300 portletSession.setAttribute(param, value);
301
302 return value;
303 }
304
305 Short portletSessionValue = (Short)portletSession.getAttribute(param);
306
307 if (portletSessionValue != null) {
308 return portletSessionValue;
309 }
310
311 return defaultValue;
312 }
313
314 public static String getString(HttpServletRequest request, String param) {
315 return getString(request, param, GetterUtil.DEFAULT_STRING);
316 }
317
318 public static String getString(
319 HttpServletRequest request, String param, String defaultValue) {
320
321 HttpSession session = request.getSession();
322
323 String requestValue = request.getParameter(param);
324
325 if (requestValue != null) {
326 String value = GetterUtil.getString(requestValue);
327
328 session.setAttribute(param, value);
329
330 return value;
331 }
332
333 String sessionValue = (String)session.getAttribute(param);
334
335 if (sessionValue != null) {
336 return sessionValue;
337 }
338
339 return defaultValue;
340 }
341
342 public static String getString(
343 PortletRequest portletRequest, String param) {
344
345 return getString(portletRequest, param, GetterUtil.DEFAULT_STRING);
346 }
347
348 public static String getString(
349 PortletRequest portletRequest, String param, String defaultValue) {
350
351 PortletSession portletSession = portletRequest.getPortletSession();
352
353 String portletRequestValue = portletRequest.getParameter(param);
354
355 if (portletRequestValue != null) {
356 String value = GetterUtil.getString(portletRequestValue);
357
358 portletSession.setAttribute(param, value);
359
360 return value;
361 }
362
363 String portletSessionValue = (String)portletSession.getAttribute(param);
364
365 if (portletSessionValue != null) {
366 return portletSessionValue;
367 }
368
369 return defaultValue;
370 }
371
372 }