Mercurial > dive4elements > gnv-client
annotate gnv-artifacts/src/main/java/de/intevation/gnv/utils/InputValidator.java @ 113:a16f5267803e
Added Basic-Support for HorizontalProfiles
gnv-artifacts/trunk@163 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Tim Englich <tim.englich@intevation.de> |
---|---|
date | Wed, 30 Sep 2009 13:42:51 +0000 |
parents | 065ec0a29394 |
children | 158e89c2263b |
rev | line source |
---|---|
101
e01c163ea5b0
Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
1 /** |
e01c163ea5b0
Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
2 * |
e01c163ea5b0
Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
3 */ |
e01c163ea5b0
Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
4 package de.intevation.gnv.utils; |
e01c163ea5b0
Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
5 |
e01c163ea5b0
Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
6 import org.apache.log4j.Logger; |
e01c163ea5b0
Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
7 |
e01c163ea5b0
Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
8 import de.intevation.gnv.geobackend.util.DateUtils; |
e01c163ea5b0
Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
9 |
e01c163ea5b0
Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
10 /** |
e01c163ea5b0
Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
11 * @author Tim Englich <tim.englich@intevation.de> |
e01c163ea5b0
Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
12 * |
e01c163ea5b0
Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
13 */ |
e01c163ea5b0
Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
14 public class InputValidator { |
e01c163ea5b0
Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
15 /** |
e01c163ea5b0
Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
16 * the logger, used to log exceptions and additonaly information |
e01c163ea5b0
Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
17 */ |
e01c163ea5b0
Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
18 private static Logger log = Logger.getLogger(InputValidator.class); |
e01c163ea5b0
Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
19 |
e01c163ea5b0
Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
20 /** |
e01c163ea5b0
Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
21 * Constructor |
e01c163ea5b0
Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
22 */ |
e01c163ea5b0
Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
23 public InputValidator() { |
e01c163ea5b0
Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
24 super(); |
e01c163ea5b0
Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
25 } |
e01c163ea5b0
Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
26 |
e01c163ea5b0
Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
27 public boolean isInputValid(String input, String type){ |
e01c163ea5b0
Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
28 log.debug("InputValidator.isInputValid " + input+ " "+type); |
e01c163ea5b0
Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
29 boolean returnValue = false; |
e01c163ea5b0
Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
30 String[] values = input.split(","); |
e01c163ea5b0
Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
31 for (int i = 0; i < values.length; i++){ |
e01c163ea5b0
Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
32 boolean valid; |
e01c163ea5b0
Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
33 if ("Integer".equalsIgnoreCase(type)){ |
104
5e086156e3d1
Bugfix: Remove leading- and trailingwhitespaces from Date- and Integervalues
Tim Englich <tim.englich@intevation.de>
parents:
101
diff
changeset
|
34 valid = org.apache.commons.validator.GenericValidator.isInt(values[i].trim()); |
113
a16f5267803e
Added Basic-Support for HorizontalProfiles
Tim Englich <tim.englich@intevation.de>
parents:
111
diff
changeset
|
35 }else if ("Double".equalsIgnoreCase(type)){ |
a16f5267803e
Added Basic-Support for HorizontalProfiles
Tim Englich <tim.englich@intevation.de>
parents:
111
diff
changeset
|
36 valid = org.apache.commons.validator.GenericValidator.isDouble(values[i].trim()); |
101
e01c163ea5b0
Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
37 }else if ("String".equalsIgnoreCase(type)){ |
111
065ec0a29394
Integrate the type Point into the ArtifactMethod.
Tim Englich <tim.englich@intevation.de>
parents:
104
diff
changeset
|
38 valid = org.apache.commons.validator.GenericValidator.matchRegexp(values[i], "[a-zA-Z0-9]"); // TODO: FIXME: VALIDATE REGEXP |
101
e01c163ea5b0
Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
39 }else if ("Date".equalsIgnoreCase(type)){ |
104
5e086156e3d1
Bugfix: Remove leading- and trailingwhitespaces from Date- and Integervalues
Tim Englich <tim.englich@intevation.de>
parents:
101
diff
changeset
|
40 valid = org.apache.commons.validator.GenericValidator.isDate(values[i].trim(), DateUtils.DATE_PATTERN, true); |
111
065ec0a29394
Integrate the type Point into the ArtifactMethod.
Tim Englich <tim.englich@intevation.de>
parents:
104
diff
changeset
|
41 }else if ("Point".equalsIgnoreCase(type)){ |
065ec0a29394
Integrate the type Point into the ArtifactMethod.
Tim Englich <tim.englich@intevation.de>
parents:
104
diff
changeset
|
42 valid = org.apache.commons.validator.GenericValidator.matchRegexp(values[i], "[0-9]"); // TODO: FIXME: VALIDATE REGEXP |
101
e01c163ea5b0
Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
43 }else{ |
e01c163ea5b0
Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
44 valid = false; |
e01c163ea5b0
Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
45 } |
e01c163ea5b0
Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
46 if (!valid){ |
e01c163ea5b0
Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
47 returnValue = false; |
e01c163ea5b0
Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
48 break; |
e01c163ea5b0
Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
49 }else{ |
e01c163ea5b0
Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
50 returnValue = true; |
e01c163ea5b0
Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
51 } |
e01c163ea5b0
Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
52 } |
e01c163ea5b0
Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
53 log.debug("Is valid? "+returnValue); |
e01c163ea5b0
Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
54 return returnValue; |
e01c163ea5b0
Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
55 } |
e01c163ea5b0
Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
56 |
e01c163ea5b0
Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
57 } |