1
14
15 package com.liferay.portal.kernel.util;
16
17 import javax.portlet.PortletRequest;
18 import javax.portlet.PortletSession;
19
20 import javax.servlet.http.HttpServletRequest;
21 import javax.servlet.http.HttpSession;
22
23
28 public class SessionParamUtil {
29
30 public static boolean getBoolean(HttpServletRequest request, String param) {
31 return getBoolean(request, param, GetterUtil.DEFAULT_BOOLEAN);
32 }
33
34 public static boolean getBoolean(
35 HttpServletRequest request, String param, boolean defaultValue) {
36
37 HttpSession session = request.getSession();
38
39 String requestValue = request.getParameter(param);
40
41 if (requestValue != null) {
42 boolean value = GetterUtil.getBoolean(requestValue);
43
44 session.setAttribute(param, value);
45
46 return value;
47 }
48
49 Boolean sessionValue = (Boolean)session.getAttribute(param);
50
51 if (sessionValue != null) {
52 return sessionValue;
53 }
54
55 return defaultValue;
56 }
57
58 public static boolean getBoolean(
59 PortletRequest portletRequest, String param) {
60
61 return getBoolean(portletRequest, param, GetterUtil.DEFAULT_BOOLEAN);
62 }
63
64 public static boolean getBoolean(
65 PortletRequest portletRequest, String param, boolean defaultValue) {
66
67 PortletSession portletSession = portletRequest.getPortletSession();
68
69 String portletRequestValue = portletRequest.getParameter(param);
70
71 if (portletRequestValue != null) {
72 boolean value = GetterUtil.getBoolean(portletRequestValue);
73
74 portletSession.setAttribute(param, value);
75
76 return value;
77 }
78
79 Boolean portletSessionValue = (Boolean)portletSession.getAttribute(
80 param);
81
82 if (portletSessionValue != null) {
83 return portletSessionValue;
84 }
85
86 return defaultValue;
87 }
88
89 public static double getDouble(HttpServletRequest request, String param) {
90 return getDouble(request, param, GetterUtil.DEFAULT_DOUBLE);
91 }
92
93 public static double getDouble(
94 HttpServletRequest request, String param, double defaultValue) {
95
96 HttpSession session = request.getSession();
97
98 String requestValue = request.getParameter(param);
99
100 if (requestValue != null) {
101 double value = GetterUtil.getDouble(requestValue);
102
103 session.setAttribute(param, value);
104
105 return value;
106 }
107
108 Double sessionValue = (Double)session.getAttribute(param);
109
110 if (sessionValue != null) {
111 return sessionValue;
112 }
113
114 return defaultValue;
115 }
116
117 public static double getDouble(
118 PortletRequest portletRequest, String param) {
119
120 return getDouble(portletRequest, param, GetterUtil.DEFAULT_DOUBLE);
121 }
122
123 public static double getDouble(
124 PortletRequest portletRequest, String param, double defaultValue) {
125
126 PortletSession portletSession = portletRequest.getPortletSession();
127
128 String portletRequestValue = portletRequest.getParameter(param);
129
130 if (portletRequestValue != null) {
131 double value = GetterUtil.getDouble(portletRequestValue);
132
133 portletSession.setAttribute(param, value);
134
135 return value;
136 }
137
138 Double portletSessionValue = (Double)portletSession.getAttribute(param);
139
140 if (portletSessionValue != null) {
141 return portletSessionValue;
142 }
143
144 return defaultValue;
145 }
146
147 public static int getInteger(HttpServletRequest request, String param) {
148 return getInteger(request, param, GetterUtil.DEFAULT_INTEGER);
149 }
150
151 public static int getInteger(
152 HttpServletRequest request, String param, int defaultValue) {
153
154 HttpSession session = request.getSession();
155
156 String requestValue = request.getParameter(param);
157
158 if (requestValue != null) {
159 int value = GetterUtil.getInteger(requestValue);
160
161 session.setAttribute(param, value);
162
163 return value;
164 }
165
166 Integer sessionValue = (Integer)session.getAttribute(param);
167
168 if (sessionValue != null) {
169 return sessionValue;
170 }
171
172 return defaultValue;
173 }
174
175 public static int getInteger(PortletRequest portletRequest, String param) {
176 return getInteger(portletRequest, param, GetterUtil.DEFAULT_INTEGER);
177 }
178
179 public static int getInteger(
180 PortletRequest portletRequest, String param, int defaultValue) {
181
182 PortletSession portletSession = portletRequest.getPortletSession();
183
184 String portletRequestValue = portletRequest.getParameter(param);
185
186 if (portletRequestValue != null) {
187 int value = GetterUtil.getInteger(portletRequestValue);
188
189 portletSession.setAttribute(param, value);
190
191 return value;
192 }
193
194 Integer portletSessionValue = (Integer)portletSession.getAttribute(
195 param);
196
197 if (portletSessionValue != null) {
198 return portletSessionValue;
199 }
200
201 return defaultValue;
202 }
203
204 public static long getLong(HttpServletRequest request, String param) {
205 return getLong(request, param, GetterUtil.DEFAULT_LONG);
206 }
207
208 public static long getLong(
209 HttpServletRequest request, String param, long defaultValue) {
210
211 HttpSession session = request.getSession();
212
213 String requestValue = request.getParameter(param);
214
215 if (requestValue != null) {
216 long value = GetterUtil.getLong(requestValue);
217
218 session.setAttribute(param, value);
219
220 return value;
221 }
222
223 Long sessionValue = (Long)session.getAttribute(param);
224
225 if (sessionValue != null) {
226 return sessionValue;
227 }
228
229 return defaultValue;
230 }
231
232 public static long getLong(PortletRequest portletRequest, String param) {
233 return getLong(portletRequest, param, GetterUtil.DEFAULT_LONG);
234 }
235
236 public static long getLong(
237 PortletRequest portletRequest, String param, long defaultValue) {
238
239 PortletSession portletSession = portletRequest.getPortletSession();
240
241 String portletRequestValue = portletRequest.getParameter(param);
242
243 if (portletRequestValue != null) {
244 long value = GetterUtil.getLong(portletRequestValue);
245
246 portletSession.setAttribute(param, value);
247
248 return value;
249 }
250
251 Long portletSessionValue = (Long)portletSession.getAttribute(param);
252
253 if (portletSessionValue != null) {
254 return portletSessionValue;
255 }
256
257 return defaultValue;
258 }
259
260 public static short getShort(HttpServletRequest request, String param) {
261 return getShort(request, param, GetterUtil.DEFAULT_SHORT);
262 }
263
264 public static short getShort(
265 HttpServletRequest request, String param, short defaultValue) {
266
267 HttpSession session = request.getSession();
268
269 String requestValue = request.getParameter(param);
270
271 if (requestValue != null) {
272 short value = GetterUtil.getShort(requestValue);
273
274 session.setAttribute(param, value);
275
276 return value;
277 }
278
279 Short sessionValue = (Short)session.getAttribute(param);
280
281 if (sessionValue != null) {
282 return sessionValue;
283 }
284
285 return defaultValue;
286 }
287
288 public static short getShort(PortletRequest portletRequest, String param) {
289 return getShort(portletRequest, param, GetterUtil.DEFAULT_SHORT);
290 }
291
292 public static short getShort(
293 PortletRequest portletRequest, String param, short defaultValue) {
294
295 PortletSession portletSession = portletRequest.getPortletSession();
296
297 String portletRequestValue = portletRequest.getParameter(param);
298
299 if (portletRequestValue != null) {
300 short value = GetterUtil.getShort(portletRequestValue);
301
302 portletSession.setAttribute(param, value);
303
304 return value;
305 }
306
307 Short portletSessionValue = (Short)portletSession.getAttribute(param);
308
309 if (portletSessionValue != null) {
310 return portletSessionValue;
311 }
312
313 return defaultValue;
314 }
315
316 public static String getString(HttpServletRequest request, String param) {
317 return getString(request, param, GetterUtil.DEFAULT_STRING);
318 }
319
320 public static String getString(
321 HttpServletRequest request, String param, String defaultValue) {
322
323 HttpSession session = request.getSession();
324
325 String requestValue = request.getParameter(param);
326
327 if (requestValue != null) {
328 String value = GetterUtil.getString(requestValue);
329
330 session.setAttribute(param, value);
331
332 return value;
333 }
334
335 String sessionValue = (String)session.getAttribute(param);
336
337 if (sessionValue != null) {
338 return sessionValue;
339 }
340
341 return defaultValue;
342 }
343
344 public static String getString(
345 PortletRequest portletRequest, String param) {
346
347 return getString(portletRequest, param, GetterUtil.DEFAULT_STRING);
348 }
349
350 public static String getString(
351 PortletRequest portletRequest, String param, String defaultValue) {
352
353 PortletSession portletSession = portletRequest.getPortletSession();
354
355 String portletRequestValue = portletRequest.getParameter(param);
356
357 if (portletRequestValue != null) {
358 String value = GetterUtil.getString(portletRequestValue);
359
360 portletSession.setAttribute(param, value);
361
362 return value;
363 }
364
365 String portletSessionValue = (String)portletSession.getAttribute(param);
366
367 if (portletSessionValue != null) {
368 return portletSessionValue;
369 }
370
371 return defaultValue;
372 }
373
374 }