src/main/java/de/uapcore/lightpit/AbstractLightPITServlet.java

changeset 80
27a25f32048e
parent 79
f64255a88d66
child 83
24a3596b8f98
equal deleted inserted replaced
79:f64255a88d66 80:27a25f32048e
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) {

mercurial