Mercurial > dive4elements > gnv-client
annotate gnv-artifacts/src/main/java/de/intevation/gnv/utils/InputValidator.java @ 117:ef157bd2fa92
LanguageSupport integrated
gnv-artifacts/trunk@178 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Tim Englich <tim.englich@intevation.de> |
---|---|
date | Fri, 02 Oct 2009 14:24:47 +0000 |
parents | 820238357bab |
children | 7fb9441dd8af |
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 |
116
820238357bab
Added Horizontal-Profile-Support for Meshes.
Tim Englich <tim.englich@intevation.de>
parents:
115
diff
changeset
|
6 import org.apache.commons.validator.GenericValidator; |
101
e01c163ea5b0
Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
7 import org.apache.log4j.Logger; |
e01c163ea5b0
Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
8 |
e01c163ea5b0
Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
9 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
|
10 |
e01c163ea5b0
Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
11 /** |
e01c163ea5b0
Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
12 * @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
|
13 * |
e01c163ea5b0
Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
14 */ |
e01c163ea5b0
Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
15 public class InputValidator { |
e01c163ea5b0
Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
16 /** |
e01c163ea5b0
Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
17 * 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
|
18 */ |
e01c163ea5b0
Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
19 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
|
20 |
e01c163ea5b0
Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
21 /** |
e01c163ea5b0
Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
22 * Constructor |
e01c163ea5b0
Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
23 */ |
e01c163ea5b0
Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
24 public InputValidator() { |
e01c163ea5b0
Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
25 super(); |
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 |
e01c163ea5b0
Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
28 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
|
29 log.debug("InputValidator.isInputValid " + input+ " "+type); |
e01c163ea5b0
Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
30 boolean returnValue = false; |
e01c163ea5b0
Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
31 String[] values = input.split(","); |
e01c163ea5b0
Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
32 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
|
33 boolean valid; |
e01c163ea5b0
Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
34 if ("Integer".equalsIgnoreCase(type)){ |
115
158e89c2263b
Removed needless imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
113
diff
changeset
|
35 valid = GenericValidator.isInt(values[i].trim()); |
113
a16f5267803e
Added Basic-Support for HorizontalProfiles
Tim Englich <tim.englich@intevation.de>
parents:
111
diff
changeset
|
36 }else if ("Double".equalsIgnoreCase(type)){ |
115
158e89c2263b
Removed needless imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
113
diff
changeset
|
37 valid = GenericValidator.isDouble(values[i].trim()); |
101
e01c163ea5b0
Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
38 }else if ("String".equalsIgnoreCase(type)){ |
115
158e89c2263b
Removed needless imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
113
diff
changeset
|
39 valid = 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
|
40 }else if ("Date".equalsIgnoreCase(type)){ |
115
158e89c2263b
Removed needless imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
113
diff
changeset
|
41 valid = 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
|
42 }else if ("Point".equalsIgnoreCase(type)){ |
115
158e89c2263b
Removed needless imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
113
diff
changeset
|
43 valid = GenericValidator.matchRegexp(values[i], "[0-9]"); // TODO: FIXME: VALIDATE REGEXP |
116
820238357bab
Added Horizontal-Profile-Support for Meshes.
Tim Englich <tim.englich@intevation.de>
parents:
115
diff
changeset
|
44 }else if ("AttributeName".equalsIgnoreCase(type)){ |
820238357bab
Added Horizontal-Profile-Support for Meshes.
Tim Englich <tim.englich@intevation.de>
parents:
115
diff
changeset
|
45 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
|
46 }else{ |
e01c163ea5b0
Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
47 valid = false; |
e01c163ea5b0
Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
48 } |
e01c163ea5b0
Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
49 if (!valid){ |
e01c163ea5b0
Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
50 returnValue = false; |
e01c163ea5b0
Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
51 break; |
e01c163ea5b0
Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
52 }else{ |
e01c163ea5b0
Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
53 returnValue = true; |
e01c163ea5b0
Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
54 } |
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 log.debug("Is valid? "+returnValue); |
e01c163ea5b0
Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
57 return returnValue; |
e01c163ea5b0
Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
58 } |
e01c163ea5b0
Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
59 |
e01c163ea5b0
Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
60 } |