Mercurial > dive4elements > gnv-client
view gnv-artifacts/src/main/java/de/intevation/gnv/utils/InputValidator.java @ 145:92faade399e4 0.1
merged geo-backend/0.1
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Fri, 28 Sep 2012 12:13:42 +0200 |
parents | 820238357bab |
children | 7fb9441dd8af |
line wrap: on
line source
/** * */ package de.intevation.gnv.utils; import org.apache.commons.validator.GenericValidator; import org.apache.log4j.Logger; import de.intevation.gnv.geobackend.util.DateUtils; /** * @author Tim Englich <tim.englich@intevation.de> * */ public class InputValidator { /** * the logger, used to log exceptions and additonaly information */ private static Logger log = Logger.getLogger(InputValidator.class); /** * Constructor */ public InputValidator() { super(); } public boolean isInputValid(String input, String type){ log.debug("InputValidator.isInputValid " + input+ " "+type); boolean returnValue = false; String[] values = input.split(","); for (int i = 0; i < values.length; i++){ boolean valid; if ("Integer".equalsIgnoreCase(type)){ valid = GenericValidator.isInt(values[i].trim()); }else if ("Double".equalsIgnoreCase(type)){ valid = GenericValidator.isDouble(values[i].trim()); }else if ("String".equalsIgnoreCase(type)){ valid = GenericValidator.matchRegexp(values[i], "[a-zA-Z0-9]"); // TODO: FIXME: VALIDATE REGEXP }else if ("Date".equalsIgnoreCase(type)){ valid = GenericValidator.isDate(values[i].trim(), DateUtils.DATE_PATTERN, true); }else if ("Point".equalsIgnoreCase(type)){ valid = GenericValidator.matchRegexp(values[i], "[0-9]"); // TODO: FIXME: VALIDATE REGEXP }else if ("AttributeName".equalsIgnoreCase(type)){ valid = org.apache.commons.validator.GenericValidator.matchRegexp(values[i], "[a-zA-Z0-9]"); // TODO: FIXME: VALIDATE REGEXP }else{ valid = false; } if (!valid){ returnValue = false; break; }else{ returnValue = true; } } log.debug("Is valid? "+returnValue); return returnValue; } }