comparison gnv-artifacts/src/main/java/de/intevation/gnv/utils/InputValidator.java @ 101:e01c163ea5b0

Inputvalidation for String, Integer and Date Values added. gnv-artifacts/trunk@149 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Tim Englich <tim.englich@intevation.de>
date Tue, 29 Sep 2009 09:50:25 +0000
parents
children 5e086156e3d1
comparison
equal deleted inserted replaced
100:f07637f96312 101:e01c163ea5b0
1 /**
2 *
3 */
4 package de.intevation.gnv.utils;
5
6 import org.apache.log4j.Logger;
7
8 import de.intevation.gnv.geobackend.util.DateUtils;
9
10 /**
11 * @author Tim Englich <tim.englich@intevation.de>
12 *
13 */
14 public class InputValidator {
15 /**
16 * the logger, used to log exceptions and additonaly information
17 */
18 private static Logger log = Logger.getLogger(InputValidator.class);
19
20 /**
21 * Constructor
22 */
23 public InputValidator() {
24 super();
25 }
26
27 public boolean isInputValid(String input, String type){
28 log.debug("InputValidator.isInputValid " + input+ " "+type);
29 boolean returnValue = false;
30 String[] values = input.split(",");
31 for (int i = 0; i < values.length; i++){
32 boolean valid;
33 if ("Integer".equalsIgnoreCase(type)){
34 valid = org.apache.commons.validator.GenericValidator.isInt(values[i]);
35 }else if ("String".equalsIgnoreCase(type)){
36 valid = org.apache.commons.validator.GenericValidator.matchRegexp(values[i], "[a-zA-Z0-9]");
37 }else if ("Date".equalsIgnoreCase(type)){
38 valid = org.apache.commons.validator.GenericValidator.isDate(values[i], DateUtils.DATE_PATTERN, true);
39 }else{
40 valid = false;
41 }
42 if (!valid){
43 returnValue = false;
44 break;
45 }else{
46 returnValue = true;
47 }
48 }
49 log.debug("Is valid? "+returnValue);
50 return returnValue;
51 }
52
53 }

http://dive4elements.wald.intevation.org