280 * @return the parameter value or an empty optional, if no parameter with the specified name was found |
280 * @return the parameter value or an empty optional, if no parameter with the specified name was found |
281 */ |
281 */ |
282 protected <T> Optional<T> getParameter(HttpServletRequest req, Class<T> clazz, String name) { |
282 protected <T> Optional<T> getParameter(HttpServletRequest req, Class<T> clazz, String name) { |
283 final String paramValue = req.getParameter(name); |
283 final String paramValue = req.getParameter(name); |
284 if (paramValue == null) return Optional.empty(); |
284 if (paramValue == null) return Optional.empty(); |
|
285 if (clazz.equals(Boolean.class)) { |
|
286 if (paramValue.toLowerCase().equals("false") || paramValue.equals("0")) { |
|
287 return Optional.of((T)Boolean.FALSE); |
|
288 } else { |
|
289 return Optional.of((T)Boolean.TRUE); |
|
290 } |
|
291 } |
285 if (clazz.equals(String.class)) return Optional.of((T) paramValue); |
292 if (clazz.equals(String.class)) return Optional.of((T) paramValue); |
286 if (java.sql.Date.class.isAssignableFrom(clazz)) { |
293 if (java.sql.Date.class.isAssignableFrom(clazz)) { |
287 try { |
294 try { |
288 return Optional.of((T)java.sql.Date.valueOf(paramValue)); |
295 return Optional.of((T)java.sql.Date.valueOf(paramValue)); |
289 } catch (IllegalArgumentException ex) { |
296 } catch (IllegalArgumentException ex) { |