001
014
015 package com.liferay.portal.kernel.util;
016
017 import java.util.Map;
018 import java.util.Properties;
019
020 import javax.portlet.PortletRequest;
021
022 import javax.servlet.http.HttpServletRequest;
023
024
027 public class PropertiesParamUtil {
028
029 public static boolean getBoolean(
030 Properties properties, HttpServletRequest request, String param) {
031
032 return getBoolean(
033 properties, request, param, GetterUtil.DEFAULT_BOOLEAN);
034 }
035
036 public static boolean getBoolean(
037 Properties properties, HttpServletRequest request, String param,
038 boolean defaultValue) {
039
040 String propertiesValue = properties.getProperty(param, null);
041
042 boolean getterUtilValue = GetterUtil.getBoolean(
043 propertiesValue, defaultValue);
044
045 return ParamUtil.get(request, param, getterUtilValue);
046 }
047
048 public static boolean getBoolean(
049 Properties properties, PortletRequest portletRequest, String param) {
050
051 return getBoolean(
052 properties, portletRequest, param, GetterUtil.DEFAULT_BOOLEAN);
053 }
054
055 public static boolean getBoolean(
056 Properties properties, PortletRequest portletRequest, String param,
057 boolean defaultValue) {
058
059 String propertiesValue = properties.getProperty(param, null);
060
061 boolean getterUtilValue = GetterUtil.getBoolean(
062 propertiesValue, defaultValue);
063
064 return ParamUtil.get(portletRequest, param, getterUtilValue);
065 }
066
067 public static boolean getBoolean(
068 UnicodeProperties properties, HttpServletRequest request,
069 String param) {
070
071 return getBoolean(
072 properties, request, param, GetterUtil.DEFAULT_BOOLEAN);
073 }
074
075 public static boolean getBoolean(
076 UnicodeProperties properties, HttpServletRequest request, String param,
077 boolean defaultValue) {
078
079 String propertiesValue = properties.getProperty(param, null);
080
081 boolean getterUtilValue = GetterUtil.getBoolean(
082 propertiesValue, defaultValue);
083
084 return ParamUtil.get(request, param, getterUtilValue);
085 }
086
087 public static boolean getBoolean(
088 UnicodeProperties properties, PortletRequest portletRequest,
089 String param) {
090
091 return getBoolean(
092 properties, portletRequest, param, GetterUtil.DEFAULT_BOOLEAN);
093 }
094
095 public static boolean getBoolean(
096 UnicodeProperties properties, PortletRequest portletRequest,
097 String param, boolean defaultValue) {
098
099 String propertiesValue = properties.getProperty(param, null);
100
101 boolean getterUtilValue = GetterUtil.getBoolean(
102 propertiesValue, defaultValue);
103
104 return ParamUtil.get(portletRequest, param, getterUtilValue);
105 }
106
107 public static double getDouble(
108 Properties properties, HttpServletRequest request, String param) {
109
110 return getDouble(properties, request, param, GetterUtil.DEFAULT_DOUBLE);
111 }
112
113 public static double getDouble(
114 Properties properties, HttpServletRequest request, String param,
115 double defaultValue) {
116
117 String propertiesValue = properties.getProperty(param, null);
118
119 double getterUtilValue = GetterUtil.getDouble(
120 propertiesValue, defaultValue);
121
122 return ParamUtil.get(request, param, getterUtilValue);
123 }
124
125 public static double getDouble(
126 Properties properties, PortletRequest portletRequest, String param) {
127
128 return getDouble(
129 properties, portletRequest, param, GetterUtil.DEFAULT_DOUBLE);
130 }
131
132 public static double getDouble(
133 Properties properties, PortletRequest portletRequest, String param,
134 double defaultValue) {
135
136 String propertiesValue = properties.getProperty(param, null);
137
138 double getterUtilValue = GetterUtil.getDouble(
139 propertiesValue, defaultValue);
140
141 return ParamUtil.get(portletRequest, param, getterUtilValue);
142 }
143
144 public static double getDouble(
145 UnicodeProperties properties, HttpServletRequest request,
146 String param) {
147
148 return getDouble(properties, request, param, GetterUtil.DEFAULT_DOUBLE);
149 }
150
151 public static double getDouble(
152 UnicodeProperties properties, HttpServletRequest request, String param,
153 double defaultValue) {
154
155 String propertiesValue = properties.getProperty(param, null);
156
157 double getterUtilValue = GetterUtil.getDouble(
158 propertiesValue, defaultValue);
159
160 return ParamUtil.get(request, param, getterUtilValue);
161 }
162
163 public static double getDouble(
164 UnicodeProperties properties, PortletRequest portletRequest,
165 String param) {
166
167 return getDouble(
168 properties, portletRequest, param, GetterUtil.DEFAULT_DOUBLE);
169 }
170
171 public static double getDouble(
172 UnicodeProperties properties, PortletRequest portletRequest,
173 String param, double defaultValue) {
174
175 String propertiesValue = properties.getProperty(param, null);
176
177 double getterUtilValue = GetterUtil.getDouble(
178 propertiesValue, defaultValue);
179
180 return ParamUtil.get(portletRequest, param, getterUtilValue);
181 }
182
183 public static int getInteger(
184 Properties properties, HttpServletRequest request, String param) {
185
186 return getInteger(
187 properties, request, param, GetterUtil.DEFAULT_INTEGER);
188 }
189
190 public static int getInteger(
191 Properties properties, HttpServletRequest request, String param,
192 int defaultValue) {
193
194 String propertiesValue = properties.getProperty(param, null);
195
196 int getterUtilValue = GetterUtil.getInteger(
197 propertiesValue, defaultValue);
198
199 return ParamUtil.get(request, param, getterUtilValue);
200 }
201
202 public static int getInteger(
203 Properties properties, PortletRequest portletRequest, String param) {
204
205 return getInteger(
206 properties, portletRequest, param, GetterUtil.DEFAULT_INTEGER);
207 }
208
209 public static int getInteger(
210 Properties properties, PortletRequest portletRequest, String param,
211 int defaultValue) {
212
213 String propertiesValue = properties.getProperty(param, null);
214
215 int getterUtilValue = GetterUtil.getInteger(
216 propertiesValue, defaultValue);
217
218 return ParamUtil.get(portletRequest, param, getterUtilValue);
219 }
220
221 public static int getInteger(
222 UnicodeProperties properties, HttpServletRequest request,
223 String param) {
224
225 return getInteger(
226 properties, request, param, GetterUtil.DEFAULT_INTEGER);
227 }
228
229 public static int getInteger(
230 UnicodeProperties properties, HttpServletRequest request, String param,
231 int defaultValue) {
232
233 String propertiesValue = properties.getProperty(param, null);
234
235 int getterUtilValue = GetterUtil.getInteger(
236 propertiesValue, defaultValue);
237
238 return ParamUtil.get(request, param, getterUtilValue);
239 }
240
241 public static int getInteger(
242 UnicodeProperties properties, PortletRequest portletRequest,
243 String param) {
244
245 return getInteger(
246 properties, portletRequest, param, GetterUtil.DEFAULT_INTEGER);
247 }
248
249 public static int getInteger(
250 UnicodeProperties properties, PortletRequest portletRequest,
251 String param, int defaultValue) {
252
253 String propertiesValue = properties.getProperty(param, null);
254
255 int getterUtilValue = GetterUtil.getInteger(
256 propertiesValue, defaultValue);
257
258 return ParamUtil.get(portletRequest, param, getterUtilValue);
259 }
260
261 public static long getLong(
262 Properties properties, HttpServletRequest request, String param) {
263
264 return getLong(properties, request, param, GetterUtil.DEFAULT_LONG);
265 }
266
267 public static long getLong(
268 Properties properties, HttpServletRequest request, String param,
269 long defaultValue) {
270
271 String propertiesValue = properties.getProperty(param, null);
272
273 long getterUtilValue = GetterUtil.getLong(
274 propertiesValue, defaultValue);
275
276 return ParamUtil.get(request, param, getterUtilValue);
277 }
278
279 public static long getLong(
280 Properties properties, PortletRequest portletRequest, String param) {
281
282 return getLong(
283 properties, portletRequest, param, GetterUtil.DEFAULT_LONG);
284 }
285
286 public static long getLong(
287 Properties properties, PortletRequest portletRequest, String param,
288 long defaultValue) {
289
290 String propertiesValue = properties.getProperty(param, null);
291
292 long getterUtilValue = GetterUtil.getLong(
293 propertiesValue, defaultValue);
294
295 return ParamUtil.get(portletRequest, param, getterUtilValue);
296 }
297
298 public static long getLong(
299 UnicodeProperties properties, HttpServletRequest request,
300 String param) {
301
302 return getLong(properties, request, param, GetterUtil.DEFAULT_LONG);
303 }
304
305 public static long getLong(
306 UnicodeProperties properties, HttpServletRequest request, String param,
307 long defaultValue) {
308
309 String propertiesValue = properties.getProperty(param, null);
310
311 long getterUtilValue = GetterUtil.getLong(
312 propertiesValue, defaultValue);
313
314 return ParamUtil.get(request, param, getterUtilValue);
315 }
316
317 public static long getLong(
318 UnicodeProperties properties, PortletRequest portletRequest,
319 String param) {
320
321 return getLong(
322 properties, portletRequest, param, GetterUtil.DEFAULT_LONG);
323 }
324
325 public static long getLong(
326 UnicodeProperties properties, PortletRequest portletRequest,
327 String param, long defaultValue) {
328
329 String propertiesValue = properties.getProperty(param, null);
330
331 long getterUtilValue = GetterUtil.getLong(
332 propertiesValue, defaultValue);
333
334 return ParamUtil.get(portletRequest, param, getterUtilValue);
335 }
336
337 public static UnicodeProperties getProperties(
338 HttpServletRequest request, String prefix) {
339
340 UnicodeProperties properties = new UnicodeProperties(true);
341
342 Map<String, String[]> parameterMap = request.getParameterMap();
343
344 for (String param : parameterMap.keySet()) {
345 if (param.startsWith(prefix) && !param.endsWith("--Checkbox")) {
346 String key = param.substring(
347 prefix.length(), param.length() - 2);
348
349 String value = request.getParameter(param);
350
351 properties.setProperty(key, value);
352 }
353 }
354
355 return properties;
356 }
357
358 public static UnicodeProperties getProperties(
359 PortletRequest portletRequest, String prefix) {
360
361 UnicodeProperties properties = new UnicodeProperties(true);
362
363 for (String param : portletRequest.getParameterMap().keySet()) {
364 if (param.startsWith(prefix) && !param.endsWith("--Checkbox")) {
365 String key = param.substring(
366 prefix.length(), param.length() - 2);
367
368 String[] values = portletRequest.getParameterValues(param);
369
370 String value = StringUtil.merge(values);
371
372 properties.setProperty(key, value);
373 }
374 }
375
376 return properties;
377 }
378
379 public static String getString(
380 Properties properties, HttpServletRequest request, String param) {
381
382 return getString(properties, request, param, GetterUtil.DEFAULT_STRING);
383 }
384
385 public static String getString(
386 Properties properties, HttpServletRequest request, String param,
387 String defaultValue) {
388
389 String propertiesValue = properties.getProperty(param, null);
390
391 String getterUtilValue = GetterUtil.getString(
392 propertiesValue, defaultValue);
393
394 return ParamUtil.get(request, param, getterUtilValue);
395 }
396
397 public static String getString(
398 Properties properties, PortletRequest portletRequest, String param) {
399
400 return getString(
401 properties, portletRequest, param, GetterUtil.DEFAULT_STRING);
402 }
403
404 public static String getString(
405 Properties properties, PortletRequest portletRequest, String param,
406 String defaultValue) {
407
408 String propertiesValue = properties.getProperty(param, null);
409
410 String getterUtilValue = GetterUtil.getString(
411 propertiesValue, defaultValue);
412
413 return ParamUtil.get(portletRequest, param, getterUtilValue);
414 }
415
416 public static String getString(
417 UnicodeProperties properties, HttpServletRequest request,
418 String param) {
419
420 return getString(properties, request, param, GetterUtil.DEFAULT_STRING);
421 }
422
423 public static String getString(
424 UnicodeProperties properties, HttpServletRequest request, String param,
425 String defaultValue) {
426
427 String propertiesValue = properties.getProperty(param, null);
428
429 String getterUtilValue = GetterUtil.getString(
430 propertiesValue, defaultValue);
431
432 return ParamUtil.get(request, param, getterUtilValue);
433 }
434
435 public static String getString(
436 UnicodeProperties properties, PortletRequest portletRequest,
437 String param) {
438
439 return getString(
440 properties, portletRequest, param, GetterUtil.DEFAULT_STRING);
441 }
442
443 public static String getString(
444 UnicodeProperties properties, PortletRequest portletRequest,
445 String param, String defaultValue) {
446
447 String propertiesValue = properties.getProperty(param, null);
448
449 String getterUtilValue = GetterUtil.getString(
450 propertiesValue, defaultValue);
451
452 return ParamUtil.get(portletRequest, param, getterUtilValue);
453 }
454
455 }