diff gnv-artifacts/src/main/java/de/intevation/gnv/utils/InputValidator.java @ 252:f1e7ddeef5bc

Added Validation if a given maxvalue is greater than a given minvalue issue19 gnv-artifacts/trunk@323 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Tim Englich <tim.englich@intevation.de>
date Wed, 11 Nov 2009 15:54:31 +0000
parents 3e82b4f1c455
children 3ddc22aab764
line wrap: on
line diff
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/utils/InputValidator.java	Wed Nov 11 12:16:15 2009 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/utils/InputValidator.java	Wed Nov 11 15:54:31 2009 +0000
@@ -3,6 +3,8 @@
  */
 package de.intevation.gnv.utils;
 
+import java.util.Date;
+
 import org.apache.commons.validator.GenericValidator;
 import org.apache.log4j.Logger;
 
@@ -33,6 +35,31 @@
         super();
     }
 
+    public boolean isInputValid(String minInput, String maxInput, String type) {
+        log.debug("InputValidator.isInputValid " + minInput + " " + maxInput + " " +type);
+        boolean returnValue = false;
+        if ("Date".equalsIgnoreCase(type)) {
+            try {
+                Date min = DateUtils.getDateFromString(minInput,DateUtils.DATE_PATTERN);
+                Date max = DateUtils.getDateFromString(maxInput,DateUtils.DATE_PATTERN);
+                int value = max.compareTo(min);
+                returnValue = value >= 0;
+            } catch (Exception e) {
+                log.error(e,e);
+            }
+        } else if ("Double".equalsIgnoreCase(type)) {
+            try {
+                double min = Double.parseDouble(minInput);
+                double max = Double.parseDouble(maxInput);
+                returnValue = max >= min;
+            } catch (Exception e) {
+                log.error(e,e);
+            }
+        }
+        log.debug("Is valid? " + returnValue);
+        return returnValue;
+    }
+    
     public boolean isInputValid(String input, String type) {
         log.debug("InputValidator.isInputValid " + input + " " + type);
         boolean returnValue = false;

http://dive4elements.wald.intevation.org