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