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

changeset 173
1dc56ab7845e
parent 168
1c3694ae224c
equal deleted inserted replaced
172:89b3320557e2 173:1dc56ab7845e
273 } 273 }
274 274
275 private <T> Optional<T> parseParameter(String paramValue, Class<T> clazz) { 275 private <T> Optional<T> parseParameter(String paramValue, Class<T> clazz) {
276 if (paramValue == null) return Optional.empty(); 276 if (paramValue == null) return Optional.empty();
277 if (clazz.equals(Boolean.class)) { 277 if (clazz.equals(Boolean.class)) {
278 if (paramValue.toLowerCase().equals("false") || paramValue.equals("0")) { 278 if (paramValue.equalsIgnoreCase("false") || paramValue.equals("0")) {
279 return Optional.of((T) Boolean.FALSE); 279 return Optional.of((T) Boolean.FALSE);
280 } else { 280 } else {
281 return Optional.of((T) Boolean.TRUE); 281 return Optional.of((T) Boolean.TRUE);
282 } 282 }
283 } 283 }
344 final var param = getParameter(req, clazz, name); 344 final var param = getParameter(req, clazz, name);
345 if (param.isPresent()) { 345 if (param.isPresent()) {
346 return Optional.ofNullable(find.apply(param.get())); 346 return Optional.ofNullable(find.apply(param.get()));
347 } else { 347 } else {
348 return Optional.empty(); 348 return Optional.empty();
349 }
350 }
351
352 protected void setAttributeFromParameter(HttpServletRequest req, String name) {
353 final var parm = req.getParameter(name);
354 if (parm != null) {
355 req.setAttribute(name, parm);
349 } 356 }
350 } 357 }
351 358
352 private String sanitizeRequestPath(HttpServletRequest req) { 359 private String sanitizeRequestPath(HttpServletRequest req) {
353 return Optional.ofNullable(req.getPathInfo()).orElse("/"); 360 return Optional.ofNullable(req.getPathInfo()).orElse("/");

mercurial