view gnv-artifacts/src/main/java/de/intevation/gnv/utils/InputValidator.java @ 103:4042844339ee

Testcases for VerticalProfile and VerticalProfile Instantaneouspoint added gnv-artifacts/trunk@152 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Tim Englich <tim.englich@intevation.de>
date Tue, 29 Sep 2009 12:01:41 +0000
parents e01c163ea5b0
children 5e086156e3d1
line wrap: on
line source
/**
 *
 */
package de.intevation.gnv.utils;

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 = org.apache.commons.validator.GenericValidator.isInt(values[i]);
            }else if ("String".equalsIgnoreCase(type)){
                valid = org.apache.commons.validator.GenericValidator.matchRegexp(values[i], "[a-zA-Z0-9]");
            }else if ("Date".equalsIgnoreCase(type)){
                valid = org.apache.commons.validator.GenericValidator.isDate(values[i], DateUtils.DATE_PATTERN, true);
            }else{
                valid = false;
            }
            if (!valid){
                returnValue =  false;
                break;
            }else{
                returnValue = true;
            }
        }
        log.debug("Is valid? "+returnValue);
        return returnValue;
    }

}

http://dive4elements.wald.intevation.org