Mercurial > dive4elements > gnv-client
comparison 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 |
comparison
equal
deleted
inserted
replaced
251:113b06ab2110 | 252:f1e7ddeef5bc |
---|---|
1 /** | 1 /** |
2 * | 2 * |
3 */ | 3 */ |
4 package de.intevation.gnv.utils; | 4 package de.intevation.gnv.utils; |
5 | |
6 import java.util.Date; | |
5 | 7 |
6 import org.apache.commons.validator.GenericValidator; | 8 import org.apache.commons.validator.GenericValidator; |
7 import org.apache.log4j.Logger; | 9 import org.apache.log4j.Logger; |
8 | 10 |
9 import com.vividsolutions.jts.geom.Coordinate; | 11 import com.vividsolutions.jts.geom.Coordinate; |
31 */ | 33 */ |
32 public InputValidator() { | 34 public InputValidator() { |
33 super(); | 35 super(); |
34 } | 36 } |
35 | 37 |
38 public boolean isInputValid(String minInput, String maxInput, String type) { | |
39 log.debug("InputValidator.isInputValid " + minInput + " " + maxInput + " " +type); | |
40 boolean returnValue = false; | |
41 if ("Date".equalsIgnoreCase(type)) { | |
42 try { | |
43 Date min = DateUtils.getDateFromString(minInput,DateUtils.DATE_PATTERN); | |
44 Date max = DateUtils.getDateFromString(maxInput,DateUtils.DATE_PATTERN); | |
45 int value = max.compareTo(min); | |
46 returnValue = value >= 0; | |
47 } catch (Exception e) { | |
48 log.error(e,e); | |
49 } | |
50 } else if ("Double".equalsIgnoreCase(type)) { | |
51 try { | |
52 double min = Double.parseDouble(minInput); | |
53 double max = Double.parseDouble(maxInput); | |
54 returnValue = max >= min; | |
55 } catch (Exception e) { | |
56 log.error(e,e); | |
57 } | |
58 } | |
59 log.debug("Is valid? " + returnValue); | |
60 return returnValue; | |
61 } | |
62 | |
36 public boolean isInputValid(String input, String type) { | 63 public boolean isInputValid(String input, String type) { |
37 log.debug("InputValidator.isInputValid " + input + " " + type); | 64 log.debug("InputValidator.isInputValid " + input + " " + type); |
38 boolean returnValue = false; | 65 boolean returnValue = false; |
39 String[] values = input.split(","); | 66 String[] values = input.split(","); |
40 for (int i = 0; i < values.length; i++) { | 67 for (int i = 0; i < values.length; i++) { |