comparison gnv-artifacts/src/main/java/de/intevation/gnv/utils/InputValidator.java @ 785:e764cab8c885

Save the relation between selected measurement and the parameter it belongs to (issue210). TODO: Adapt sql statements. gnv-artifacts/trunk@867 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Tue, 30 Mar 2010 14:05:22 +0000
parents 7b81d563c8c0
children 6cd8492019d8
comparison
equal deleted inserted replaced
784:7b81d563c8c0 785:e764cab8c885
17 17
18 import org.apache.log4j.Logger; 18 import org.apache.log4j.Logger;
19 19
20 /** 20 /**
21 * @author <a href="mailto:tim.englich@intevation.de">Tim Englich</a> 21 * @author <a href="mailto:tim.englich@intevation.de">Tim Englich</a>
22 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
22 * 23 *
23 */ 24 */
24 public class InputValidator { 25 public class InputValidator {
25 /** 26 /**
26 * the logger, used to log exceptions and additonaly information 27 * the logger, used to log exceptions and additonaly information
35 */ 36 */
36 public InputValidator() { 37 public InputValidator() {
37 super(); 38 super();
38 } 39 }
39 40
40 public boolean isInputValid(String minInput, String maxInput, String type) { 41 public static boolean isInputValid(String minInput, String maxInput, String type) {
41 log.debug("InputValidator.isInputValid " + minInput + " " + maxInput + " " +type); 42 log.debug("InputValidator.isInputValid " + minInput + " " + maxInput + " " +type);
42 boolean returnValue = false; 43 boolean returnValue = false;
43 if ("Date".equalsIgnoreCase(type)) { 44 if ("Date".equalsIgnoreCase(type)) {
44 try { 45 try {
45 Date min = DateUtils.getDateFromString(minInput,DateUtils.DATE_PATTERN); 46 Date min = DateUtils.getDateFromString(minInput,DateUtils.DATE_PATTERN);
60 } 61 }
61 log.debug("Is valid? " + returnValue); 62 log.debug("Is valid? " + returnValue);
62 return returnValue; 63 return returnValue;
63 } 64 }
64 65
65 public boolean isInputValid(String input, String type) { 66 public static boolean isInputValid(String input, String type) {
66 log.debug("InputValidator.isInputValid " + input + " " + type); 67 log.debug("InputValidator.isInputValid " + input + " " + type);
67 boolean returnValue = false; 68 boolean returnValue = false;
68 String[] values = input.split(","); 69 String[] values = input.split(",");
69 for (int i = 0; i < values.length; i++) { 70 for (int i = 0; i < values.length; i++) {
70 boolean valid; 71 boolean valid;
93 .matchRegexp(values[i], "[a-zA-Z0-9]"); // TODO: FIXME: 94 .matchRegexp(values[i], "[a-zA-Z0-9]"); // TODO: FIXME:
94 // VALIDATE 95 // VALIDATE
95 // REGEXP 96 // REGEXP
96 } else if ("Coordinate".equalsIgnoreCase(type)) { 97 } else if ("Coordinate".equalsIgnoreCase(type)) {
97 try { 98 try {
98 valid = this.getPointValue(values[i]) != null; 99 valid = getPointValue(values[i]) != null;
99 } catch (ValidationException e) { 100 } catch (ValidationException e) {
100 log.debug(e.getMessage()); 101 log.debug(e.getMessage());
101 valid = false; 102 valid = false;
102 } 103 }
103 } else { 104 } else {
113 log.debug("Is valid? " + returnValue); 114 log.debug("Is valid? " + returnValue);
114 return returnValue; 115 return returnValue;
115 } 116 }
116 117
117 118
118 public Point getPointValue(String value) throws ValidationException{ 119 public static Point getPointValue(String value) throws ValidationException{
119 log.debug("InputValidator.getPointValue " + value); 120 log.debug("InputValidator.getPointValue " + value);
120 121
121 if (value.toLowerCase().startsWith("point")){ 122 if (value.toLowerCase().startsWith("point")){
122 try { 123 try {
123 return (Point)new WKTReader().read(value); 124 return (Point)new WKTReader().read(value);
162 return new GeometryFactory().createPoint(new Coordinate(x,y)); 163 return new GeometryFactory().createPoint(new Coordinate(x,y));
163 } 164 }
164 } 165 }
165 166
166 167
167 public boolean isDateValid(Date tmp, Date lo, Date up) { 168 public static boolean isDateValid(Date tmp, Date lo, Date up) {
168 // we need to transform the given dates into seconds, because 169 // we need to transform the given dates into seconds, because
169 // they differ in milliseconds -> that's why we cannot use the 170 // they differ in milliseconds -> that's why we cannot use the
170 // Date.compareTo(Date) method. 171 // Date.compareTo(Date) method.
171 long tmpTime = tmp.getTime() / 1000; 172 long tmpTime = tmp.getTime() / 1000;
172 long tmpLow = lo.getTime() / 1000; 173 long tmpLow = lo.getTime() / 1000;

http://dive4elements.wald.intevation.org