Mercurial > dive4elements > gnv-client
annotate gnv-artifacts/src/main/java/de/intevation/gnv/utils/InputValidator.java @ 763:e4d1fded433b
Bugfix: The Description of an InputData-Object will now only be fetched if
the Name of the data of the Current State is equal to the Name of the
InputData-Object.
gnv-artifacts/trunk@818 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Tim Englich <tim.englich@intevation.de> |
---|---|
date | Mon, 22 Mar 2010 12:52:09 +0000 |
parents | b81f6f896668 |
children | 9a828e5a2390 |
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 |
252
f1e7ddeef5bc
Added Validation if a given maxvalue is greater than a given minvalue issue19
Tim Englich <tim.englich@intevation.de>
parents:
222
diff
changeset
|
6 import java.util.Date; |
f1e7ddeef5bc
Added Validation if a given maxvalue is greater than a given minvalue issue19
Tim Englich <tim.englich@intevation.de>
parents:
222
diff
changeset
|
7 |
116
820238357bab
Added Horizontal-Profile-Support for Meshes.
Tim Englich <tim.englich@intevation.de>
parents:
115
diff
changeset
|
8 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
|
9 import org.apache.log4j.Logger; |
e01c163ea5b0
Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
10 |
173
1b2fc94766c9
Added real Coordinate-Query to TimeSeries-Mesh
Tim Englich <tim.englich@intevation.de>
parents:
171
diff
changeset
|
11 import com.vividsolutions.jts.geom.Coordinate; |
1b2fc94766c9
Added real Coordinate-Query to TimeSeries-Mesh
Tim Englich <tim.englich@intevation.de>
parents:
171
diff
changeset
|
12 import com.vividsolutions.jts.geom.GeometryFactory; |
1b2fc94766c9
Added real Coordinate-Query to TimeSeries-Mesh
Tim Englich <tim.englich@intevation.de>
parents:
171
diff
changeset
|
13 import com.vividsolutions.jts.geom.Point; |
746
b81f6f896668
Integrated handling of WKT-Strings for Points to extract Points from a given Inputstring.
Tim Englich <tim.englich@intevation.de>
parents:
731
diff
changeset
|
14 import com.vividsolutions.jts.io.ParseException; |
b81f6f896668
Integrated handling of WKT-Strings for Points to extract Points from a given Inputstring.
Tim Englich <tim.englich@intevation.de>
parents:
731
diff
changeset
|
15 import com.vividsolutions.jts.io.WKTReader; |
173
1b2fc94766c9
Added real Coordinate-Query to TimeSeries-Mesh
Tim Englich <tim.englich@intevation.de>
parents:
171
diff
changeset
|
16 |
101
e01c163ea5b0
Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
17 import de.intevation.gnv.geobackend.util.DateUtils; |
173
1b2fc94766c9
Added real Coordinate-Query to TimeSeries-Mesh
Tim Englich <tim.englich@intevation.de>
parents:
171
diff
changeset
|
18 import de.intevation.gnv.utils.exception.ValidationException; |
101
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 * @author Tim Englich <tim.englich@intevation.de> |
171
7fb9441dd8af
Format Code to max 80 Chars per Row and Cleanup
Tim Englich <tim.englich@intevation.de>
parents:
116
diff
changeset
|
22 * |
101
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 class InputValidator { |
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 * 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
|
27 */ |
e01c163ea5b0
Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
28 private static Logger log = Logger.getLogger(InputValidator.class); |
222
3e82b4f1c455
Removed some Compilation-Errors according to API-Changes in the ArtifactDatabase.
Tim Englich <tim.englich@intevation.de>
parents:
173
diff
changeset
|
29 |
3e82b4f1c455
Removed some Compilation-Errors according to API-Changes in the ArtifactDatabase.
Tim Englich <tim.englich@intevation.de>
parents:
173
diff
changeset
|
30 |
3e82b4f1c455
Removed some Compilation-Errors according to API-Changes in the ArtifactDatabase.
Tim Englich <tim.englich@intevation.de>
parents:
173
diff
changeset
|
31 public final static String NODATASELECTEDVALUE = "n/n"; |
101
e01c163ea5b0
Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
32 |
e01c163ea5b0
Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
33 /** |
e01c163ea5b0
Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
34 * Constructor |
e01c163ea5b0
Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
35 */ |
e01c163ea5b0
Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
36 public InputValidator() { |
e01c163ea5b0
Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
37 super(); |
e01c163ea5b0
Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
38 } |
171
7fb9441dd8af
Format Code to max 80 Chars per Row and Cleanup
Tim Englich <tim.englich@intevation.de>
parents:
116
diff
changeset
|
39 |
252
f1e7ddeef5bc
Added Validation if a given maxvalue is greater than a given minvalue issue19
Tim Englich <tim.englich@intevation.de>
parents:
222
diff
changeset
|
40 public boolean isInputValid(String minInput, String maxInput, String type) { |
f1e7ddeef5bc
Added Validation if a given maxvalue is greater than a given minvalue issue19
Tim Englich <tim.englich@intevation.de>
parents:
222
diff
changeset
|
41 log.debug("InputValidator.isInputValid " + minInput + " " + maxInput + " " +type); |
f1e7ddeef5bc
Added Validation if a given maxvalue is greater than a given minvalue issue19
Tim Englich <tim.englich@intevation.de>
parents:
222
diff
changeset
|
42 boolean returnValue = false; |
f1e7ddeef5bc
Added Validation if a given maxvalue is greater than a given minvalue issue19
Tim Englich <tim.englich@intevation.de>
parents:
222
diff
changeset
|
43 if ("Date".equalsIgnoreCase(type)) { |
f1e7ddeef5bc
Added Validation if a given maxvalue is greater than a given minvalue issue19
Tim Englich <tim.englich@intevation.de>
parents:
222
diff
changeset
|
44 try { |
f1e7ddeef5bc
Added Validation if a given maxvalue is greater than a given minvalue issue19
Tim Englich <tim.englich@intevation.de>
parents:
222
diff
changeset
|
45 Date min = DateUtils.getDateFromString(minInput,DateUtils.DATE_PATTERN); |
f1e7ddeef5bc
Added Validation if a given maxvalue is greater than a given minvalue issue19
Tim Englich <tim.englich@intevation.de>
parents:
222
diff
changeset
|
46 Date max = DateUtils.getDateFromString(maxInput,DateUtils.DATE_PATTERN); |
f1e7ddeef5bc
Added Validation if a given maxvalue is greater than a given minvalue issue19
Tim Englich <tim.englich@intevation.de>
parents:
222
diff
changeset
|
47 int value = max.compareTo(min); |
f1e7ddeef5bc
Added Validation if a given maxvalue is greater than a given minvalue issue19
Tim Englich <tim.englich@intevation.de>
parents:
222
diff
changeset
|
48 returnValue = value >= 0; |
f1e7ddeef5bc
Added Validation if a given maxvalue is greater than a given minvalue issue19
Tim Englich <tim.englich@intevation.de>
parents:
222
diff
changeset
|
49 } catch (Exception e) { |
f1e7ddeef5bc
Added Validation if a given maxvalue is greater than a given minvalue issue19
Tim Englich <tim.englich@intevation.de>
parents:
222
diff
changeset
|
50 log.error(e,e); |
f1e7ddeef5bc
Added Validation if a given maxvalue is greater than a given minvalue issue19
Tim Englich <tim.englich@intevation.de>
parents:
222
diff
changeset
|
51 } |
f1e7ddeef5bc
Added Validation if a given maxvalue is greater than a given minvalue issue19
Tim Englich <tim.englich@intevation.de>
parents:
222
diff
changeset
|
52 } else if ("Double".equalsIgnoreCase(type)) { |
f1e7ddeef5bc
Added Validation if a given maxvalue is greater than a given minvalue issue19
Tim Englich <tim.englich@intevation.de>
parents:
222
diff
changeset
|
53 try { |
f1e7ddeef5bc
Added Validation if a given maxvalue is greater than a given minvalue issue19
Tim Englich <tim.englich@intevation.de>
parents:
222
diff
changeset
|
54 double min = Double.parseDouble(minInput); |
f1e7ddeef5bc
Added Validation if a given maxvalue is greater than a given minvalue issue19
Tim Englich <tim.englich@intevation.de>
parents:
222
diff
changeset
|
55 double max = Double.parseDouble(maxInput); |
f1e7ddeef5bc
Added Validation if a given maxvalue is greater than a given minvalue issue19
Tim Englich <tim.englich@intevation.de>
parents:
222
diff
changeset
|
56 returnValue = max >= min; |
f1e7ddeef5bc
Added Validation if a given maxvalue is greater than a given minvalue issue19
Tim Englich <tim.englich@intevation.de>
parents:
222
diff
changeset
|
57 } catch (Exception e) { |
f1e7ddeef5bc
Added Validation if a given maxvalue is greater than a given minvalue issue19
Tim Englich <tim.englich@intevation.de>
parents:
222
diff
changeset
|
58 log.error(e,e); |
f1e7ddeef5bc
Added Validation if a given maxvalue is greater than a given minvalue issue19
Tim Englich <tim.englich@intevation.de>
parents:
222
diff
changeset
|
59 } |
f1e7ddeef5bc
Added Validation if a given maxvalue is greater than a given minvalue issue19
Tim Englich <tim.englich@intevation.de>
parents:
222
diff
changeset
|
60 } |
f1e7ddeef5bc
Added Validation if a given maxvalue is greater than a given minvalue issue19
Tim Englich <tim.englich@intevation.de>
parents:
222
diff
changeset
|
61 log.debug("Is valid? " + returnValue); |
f1e7ddeef5bc
Added Validation if a given maxvalue is greater than a given minvalue issue19
Tim Englich <tim.englich@intevation.de>
parents:
222
diff
changeset
|
62 return returnValue; |
f1e7ddeef5bc
Added Validation if a given maxvalue is greater than a given minvalue issue19
Tim Englich <tim.englich@intevation.de>
parents:
222
diff
changeset
|
63 } |
f1e7ddeef5bc
Added Validation if a given maxvalue is greater than a given minvalue issue19
Tim Englich <tim.englich@intevation.de>
parents:
222
diff
changeset
|
64 |
171
7fb9441dd8af
Format Code to max 80 Chars per Row and Cleanup
Tim Englich <tim.englich@intevation.de>
parents:
116
diff
changeset
|
65 public boolean isInputValid(String input, String type) { |
7fb9441dd8af
Format Code to max 80 Chars per Row and Cleanup
Tim Englich <tim.englich@intevation.de>
parents:
116
diff
changeset
|
66 log.debug("InputValidator.isInputValid " + input + " " + type); |
101
e01c163ea5b0
Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
67 boolean returnValue = false; |
e01c163ea5b0
Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
68 String[] values = input.split(","); |
171
7fb9441dd8af
Format Code to max 80 Chars per Row and Cleanup
Tim Englich <tim.englich@intevation.de>
parents:
116
diff
changeset
|
69 for (int i = 0; i < values.length; i++) { |
101
e01c163ea5b0
Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
70 boolean valid; |
222
3e82b4f1c455
Removed some Compilation-Errors according to API-Changes in the ArtifactDatabase.
Tim Englich <tim.englich@intevation.de>
parents:
173
diff
changeset
|
71 |
3e82b4f1c455
Removed some Compilation-Errors according to API-Changes in the ArtifactDatabase.
Tim Englich <tim.englich@intevation.de>
parents:
173
diff
changeset
|
72 if (NODATASELECTEDVALUE.equals(values[i].trim())){ |
3e82b4f1c455
Removed some Compilation-Errors according to API-Changes in the ArtifactDatabase.
Tim Englich <tim.englich@intevation.de>
parents:
173
diff
changeset
|
73 valid = true; |
3e82b4f1c455
Removed some Compilation-Errors according to API-Changes in the ArtifactDatabase.
Tim Englich <tim.englich@intevation.de>
parents:
173
diff
changeset
|
74 } else if ("Integer".equalsIgnoreCase(type)) { |
115
158e89c2263b
Removed needless imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
113
diff
changeset
|
75 valid = GenericValidator.isInt(values[i].trim()); |
171
7fb9441dd8af
Format Code to max 80 Chars per Row and Cleanup
Tim Englich <tim.englich@intevation.de>
parents:
116
diff
changeset
|
76 } else if ("Double".equalsIgnoreCase(type)) { |
7fb9441dd8af
Format Code to max 80 Chars per Row and Cleanup
Tim Englich <tim.englich@intevation.de>
parents:
116
diff
changeset
|
77 valid = GenericValidator.isDouble(values[i].trim()); |
7fb9441dd8af
Format Code to max 80 Chars per Row and Cleanup
Tim Englich <tim.englich@intevation.de>
parents:
116
diff
changeset
|
78 } else if ("String".equalsIgnoreCase(type)) { |
7fb9441dd8af
Format Code to max 80 Chars per Row and Cleanup
Tim Englich <tim.englich@intevation.de>
parents:
116
diff
changeset
|
79 valid = GenericValidator.matchRegexp(values[i], "[a-zA-Z0-9]"); // TODO: |
7fb9441dd8af
Format Code to max 80 Chars per Row and Cleanup
Tim Englich <tim.englich@intevation.de>
parents:
116
diff
changeset
|
80 // FIXME: |
7fb9441dd8af
Format Code to max 80 Chars per Row and Cleanup
Tim Englich <tim.englich@intevation.de>
parents:
116
diff
changeset
|
81 // VALIDATE |
7fb9441dd8af
Format Code to max 80 Chars per Row and Cleanup
Tim Englich <tim.englich@intevation.de>
parents:
116
diff
changeset
|
82 // REGEXP |
7fb9441dd8af
Format Code to max 80 Chars per Row and Cleanup
Tim Englich <tim.englich@intevation.de>
parents:
116
diff
changeset
|
83 } else if ("Date".equalsIgnoreCase(type)) { |
7fb9441dd8af
Format Code to max 80 Chars per Row and Cleanup
Tim Englich <tim.englich@intevation.de>
parents:
116
diff
changeset
|
84 valid = GenericValidator.isDate(values[i].trim(), |
7fb9441dd8af
Format Code to max 80 Chars per Row and Cleanup
Tim Englich <tim.englich@intevation.de>
parents:
116
diff
changeset
|
85 DateUtils.DATE_PATTERN, true); |
731
1efb6a66c7d9
Added Objecttype Geometry for the Validation of Inputdata.
Tim Englich <tim.englich@intevation.de>
parents:
461
diff
changeset
|
86 } else if ("Point".equalsIgnoreCase(type) || "Geometry".equals(type)) { |
171
7fb9441dd8af
Format Code to max 80 Chars per Row and Cleanup
Tim Englich <tim.englich@intevation.de>
parents:
116
diff
changeset
|
87 valid = GenericValidator.matchRegexp(values[i], "[0-9]"); // TODO: |
7fb9441dd8af
Format Code to max 80 Chars per Row and Cleanup
Tim Englich <tim.englich@intevation.de>
parents:
116
diff
changeset
|
88 // FIXME: |
7fb9441dd8af
Format Code to max 80 Chars per Row and Cleanup
Tim Englich <tim.englich@intevation.de>
parents:
116
diff
changeset
|
89 // VALIDATE |
7fb9441dd8af
Format Code to max 80 Chars per Row and Cleanup
Tim Englich <tim.englich@intevation.de>
parents:
116
diff
changeset
|
90 // REGEXP |
7fb9441dd8af
Format Code to max 80 Chars per Row and Cleanup
Tim Englich <tim.englich@intevation.de>
parents:
116
diff
changeset
|
91 } else if ("AttributeName".equalsIgnoreCase(type)) { |
7fb9441dd8af
Format Code to max 80 Chars per Row and Cleanup
Tim Englich <tim.englich@intevation.de>
parents:
116
diff
changeset
|
92 valid = org.apache.commons.validator.GenericValidator |
7fb9441dd8af
Format Code to max 80 Chars per Row and Cleanup
Tim Englich <tim.englich@intevation.de>
parents:
116
diff
changeset
|
93 .matchRegexp(values[i], "[a-zA-Z0-9]"); // TODO: FIXME: |
7fb9441dd8af
Format Code to max 80 Chars per Row and Cleanup
Tim Englich <tim.englich@intevation.de>
parents:
116
diff
changeset
|
94 // VALIDATE |
7fb9441dd8af
Format Code to max 80 Chars per Row and Cleanup
Tim Englich <tim.englich@intevation.de>
parents:
116
diff
changeset
|
95 // REGEXP |
173
1b2fc94766c9
Added real Coordinate-Query to TimeSeries-Mesh
Tim Englich <tim.englich@intevation.de>
parents:
171
diff
changeset
|
96 } else if ("Coordinate".equalsIgnoreCase(type)) { |
1b2fc94766c9
Added real Coordinate-Query to TimeSeries-Mesh
Tim Englich <tim.englich@intevation.de>
parents:
171
diff
changeset
|
97 try { |
1b2fc94766c9
Added real Coordinate-Query to TimeSeries-Mesh
Tim Englich <tim.englich@intevation.de>
parents:
171
diff
changeset
|
98 valid = this.getPointValue(values[i]) != null; |
1b2fc94766c9
Added real Coordinate-Query to TimeSeries-Mesh
Tim Englich <tim.englich@intevation.de>
parents:
171
diff
changeset
|
99 } catch (ValidationException e) { |
1b2fc94766c9
Added real Coordinate-Query to TimeSeries-Mesh
Tim Englich <tim.englich@intevation.de>
parents:
171
diff
changeset
|
100 log.debug(e.getMessage()); |
1b2fc94766c9
Added real Coordinate-Query to TimeSeries-Mesh
Tim Englich <tim.englich@intevation.de>
parents:
171
diff
changeset
|
101 valid = false; |
1b2fc94766c9
Added real Coordinate-Query to TimeSeries-Mesh
Tim Englich <tim.englich@intevation.de>
parents:
171
diff
changeset
|
102 } |
171
7fb9441dd8af
Format Code to max 80 Chars per Row and Cleanup
Tim Englich <tim.englich@intevation.de>
parents:
116
diff
changeset
|
103 } else { |
101
e01c163ea5b0
Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
104 valid = false; |
e01c163ea5b0
Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
105 } |
171
7fb9441dd8af
Format Code to max 80 Chars per Row and Cleanup
Tim Englich <tim.englich@intevation.de>
parents:
116
diff
changeset
|
106 if (!valid) { |
7fb9441dd8af
Format Code to max 80 Chars per Row and Cleanup
Tim Englich <tim.englich@intevation.de>
parents:
116
diff
changeset
|
107 returnValue = false; |
101
e01c163ea5b0
Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
108 break; |
171
7fb9441dd8af
Format Code to max 80 Chars per Row and Cleanup
Tim Englich <tim.englich@intevation.de>
parents:
116
diff
changeset
|
109 } else { |
101
e01c163ea5b0
Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
110 returnValue = true; |
e01c163ea5b0
Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
111 } |
e01c163ea5b0
Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
112 } |
171
7fb9441dd8af
Format Code to max 80 Chars per Row and Cleanup
Tim Englich <tim.englich@intevation.de>
parents:
116
diff
changeset
|
113 log.debug("Is valid? " + returnValue); |
101
e01c163ea5b0
Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
114 return returnValue; |
e01c163ea5b0
Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
115 } |
173
1b2fc94766c9
Added real Coordinate-Query to TimeSeries-Mesh
Tim Englich <tim.englich@intevation.de>
parents:
171
diff
changeset
|
116 |
1b2fc94766c9
Added real Coordinate-Query to TimeSeries-Mesh
Tim Englich <tim.englich@intevation.de>
parents:
171
diff
changeset
|
117 |
1b2fc94766c9
Added real Coordinate-Query to TimeSeries-Mesh
Tim Englich <tim.englich@intevation.de>
parents:
171
diff
changeset
|
118 public Point getPointValue(String value) throws ValidationException{ |
1b2fc94766c9
Added real Coordinate-Query to TimeSeries-Mesh
Tim Englich <tim.englich@intevation.de>
parents:
171
diff
changeset
|
119 log.debug("InputValidator.getPointValue " + value); |
1b2fc94766c9
Added real Coordinate-Query to TimeSeries-Mesh
Tim Englich <tim.englich@intevation.de>
parents:
171
diff
changeset
|
120 |
746
b81f6f896668
Integrated handling of WKT-Strings for Points to extract Points from a given Inputstring.
Tim Englich <tim.englich@intevation.de>
parents:
731
diff
changeset
|
121 if (value.toLowerCase().startsWith("point")){ |
b81f6f896668
Integrated handling of WKT-Strings for Points to extract Points from a given Inputstring.
Tim Englich <tim.englich@intevation.de>
parents:
731
diff
changeset
|
122 try { |
b81f6f896668
Integrated handling of WKT-Strings for Points to extract Points from a given Inputstring.
Tim Englich <tim.englich@intevation.de>
parents:
731
diff
changeset
|
123 return (Point)new WKTReader().read(value); |
b81f6f896668
Integrated handling of WKT-Strings for Points to extract Points from a given Inputstring.
Tim Englich <tim.englich@intevation.de>
parents:
731
diff
changeset
|
124 } catch (ParseException e) { |
b81f6f896668
Integrated handling of WKT-Strings for Points to extract Points from a given Inputstring.
Tim Englich <tim.englich@intevation.de>
parents:
731
diff
changeset
|
125 log.error(e,e); |
b81f6f896668
Integrated handling of WKT-Strings for Points to extract Points from a given Inputstring.
Tim Englich <tim.englich@intevation.de>
parents:
731
diff
changeset
|
126 throw new ValidationException(e); |
b81f6f896668
Integrated handling of WKT-Strings for Points to extract Points from a given Inputstring.
Tim Englich <tim.englich@intevation.de>
parents:
731
diff
changeset
|
127 } |
b81f6f896668
Integrated handling of WKT-Strings for Points to extract Points from a given Inputstring.
Tim Englich <tim.englich@intevation.de>
parents:
731
diff
changeset
|
128 }else{ |
b81f6f896668
Integrated handling of WKT-Strings for Points to extract Points from a given Inputstring.
Tim Englich <tim.englich@intevation.de>
parents:
731
diff
changeset
|
129 String[] s, p; |
b81f6f896668
Integrated handling of WKT-Strings for Points to extract Points from a given Inputstring.
Tim Englich <tim.englich@intevation.de>
parents:
731
diff
changeset
|
130 |
b81f6f896668
Integrated handling of WKT-Strings for Points to extract Points from a given Inputstring.
Tim Englich <tim.englich@intevation.de>
parents:
731
diff
changeset
|
131 double x=0,y=0; |
b81f6f896668
Integrated handling of WKT-Strings for Points to extract Points from a given Inputstring.
Tim Englich <tim.englich@intevation.de>
parents:
731
diff
changeset
|
132 log.info("Position :"+value); |
b81f6f896668
Integrated handling of WKT-Strings for Points to extract Points from a given Inputstring.
Tim Englich <tim.englich@intevation.de>
parents:
731
diff
changeset
|
133 s = value.split(" "); |
b81f6f896668
Integrated handling of WKT-Strings for Points to extract Points from a given Inputstring.
Tim Englich <tim.englich@intevation.de>
parents:
731
diff
changeset
|
134 if (s.length != 2) { |
b81f6f896668
Integrated handling of WKT-Strings for Points to extract Points from a given Inputstring.
Tim Englich <tim.englich@intevation.de>
parents:
731
diff
changeset
|
135 throw new ValidationException("Kein Blank separiert Breite und Länge"); |
b81f6f896668
Integrated handling of WKT-Strings for Points to extract Points from a given Inputstring.
Tim Englich <tim.englich@intevation.de>
parents:
731
diff
changeset
|
136 } |
b81f6f896668
Integrated handling of WKT-Strings for Points to extract Points from a given Inputstring.
Tim Englich <tim.englich@intevation.de>
parents:
731
diff
changeset
|
137 p = s[0].split("[nNsS]"); |
b81f6f896668
Integrated handling of WKT-Strings for Points to extract Points from a given Inputstring.
Tim Englich <tim.englich@intevation.de>
parents:
731
diff
changeset
|
138 try { |
b81f6f896668
Integrated handling of WKT-Strings for Points to extract Points from a given Inputstring.
Tim Englich <tim.englich@intevation.de>
parents:
731
diff
changeset
|
139 if (p.length == 1) |
b81f6f896668
Integrated handling of WKT-Strings for Points to extract Points from a given Inputstring.
Tim Englich <tim.englich@intevation.de>
parents:
731
diff
changeset
|
140 y = new Double(p[0]); |
b81f6f896668
Integrated handling of WKT-Strings for Points to extract Points from a given Inputstring.
Tim Englich <tim.englich@intevation.de>
parents:
731
diff
changeset
|
141 else |
b81f6f896668
Integrated handling of WKT-Strings for Points to extract Points from a given Inputstring.
Tim Englich <tim.englich@intevation.de>
parents:
731
diff
changeset
|
142 y = new Double(p[0]) + new Double(p[1]) / new Double(60.); |
b81f6f896668
Integrated handling of WKT-Strings for Points to extract Points from a given Inputstring.
Tim Englich <tim.englich@intevation.de>
parents:
731
diff
changeset
|
143 if (s[0].toLowerCase().contains("s")) |
b81f6f896668
Integrated handling of WKT-Strings for Points to extract Points from a given Inputstring.
Tim Englich <tim.englich@intevation.de>
parents:
731
diff
changeset
|
144 y = -y; |
b81f6f896668
Integrated handling of WKT-Strings for Points to extract Points from a given Inputstring.
Tim Englich <tim.englich@intevation.de>
parents:
731
diff
changeset
|
145 } |
b81f6f896668
Integrated handling of WKT-Strings for Points to extract Points from a given Inputstring.
Tim Englich <tim.englich@intevation.de>
parents:
731
diff
changeset
|
146 catch (Exception e) { |
b81f6f896668
Integrated handling of WKT-Strings for Points to extract Points from a given Inputstring.
Tim Englich <tim.englich@intevation.de>
parents:
731
diff
changeset
|
147 throw new ValidationException("Kein N|S oder nicht im ersten Substring, zB 56n42"); |
b81f6f896668
Integrated handling of WKT-Strings for Points to extract Points from a given Inputstring.
Tim Englich <tim.englich@intevation.de>
parents:
731
diff
changeset
|
148 |
b81f6f896668
Integrated handling of WKT-Strings for Points to extract Points from a given Inputstring.
Tim Englich <tim.englich@intevation.de>
parents:
731
diff
changeset
|
149 } |
b81f6f896668
Integrated handling of WKT-Strings for Points to extract Points from a given Inputstring.
Tim Englich <tim.englich@intevation.de>
parents:
731
diff
changeset
|
150 p = s[1].split("[eEwW]"); |
b81f6f896668
Integrated handling of WKT-Strings for Points to extract Points from a given Inputstring.
Tim Englich <tim.englich@intevation.de>
parents:
731
diff
changeset
|
151 try { |
b81f6f896668
Integrated handling of WKT-Strings for Points to extract Points from a given Inputstring.
Tim Englich <tim.englich@intevation.de>
parents:
731
diff
changeset
|
152 if (p.length ==1) |
b81f6f896668
Integrated handling of WKT-Strings for Points to extract Points from a given Inputstring.
Tim Englich <tim.englich@intevation.de>
parents:
731
diff
changeset
|
153 x = new Double(p[0]); |
b81f6f896668
Integrated handling of WKT-Strings for Points to extract Points from a given Inputstring.
Tim Englich <tim.englich@intevation.de>
parents:
731
diff
changeset
|
154 else |
b81f6f896668
Integrated handling of WKT-Strings for Points to extract Points from a given Inputstring.
Tim Englich <tim.englich@intevation.de>
parents:
731
diff
changeset
|
155 x = new Double(p[0]) + new Double(p[1]) / new Double(60.) ; |
b81f6f896668
Integrated handling of WKT-Strings for Points to extract Points from a given Inputstring.
Tim Englich <tim.englich@intevation.de>
parents:
731
diff
changeset
|
156 if (s[1].toLowerCase().contains("w")) |
b81f6f896668
Integrated handling of WKT-Strings for Points to extract Points from a given Inputstring.
Tim Englich <tim.englich@intevation.de>
parents:
731
diff
changeset
|
157 x = -x; |
b81f6f896668
Integrated handling of WKT-Strings for Points to extract Points from a given Inputstring.
Tim Englich <tim.englich@intevation.de>
parents:
731
diff
changeset
|
158 } |
b81f6f896668
Integrated handling of WKT-Strings for Points to extract Points from a given Inputstring.
Tim Englich <tim.englich@intevation.de>
parents:
731
diff
changeset
|
159 catch (Exception e) { |
b81f6f896668
Integrated handling of WKT-Strings for Points to extract Points from a given Inputstring.
Tim Englich <tim.englich@intevation.de>
parents:
731
diff
changeset
|
160 throw new ValidationException("Kein E|W oder nicht im zweiten Substring"); |
b81f6f896668
Integrated handling of WKT-Strings for Points to extract Points from a given Inputstring.
Tim Englich <tim.englich@intevation.de>
parents:
731
diff
changeset
|
161 } |
b81f6f896668
Integrated handling of WKT-Strings for Points to extract Points from a given Inputstring.
Tim Englich <tim.englich@intevation.de>
parents:
731
diff
changeset
|
162 return new GeometryFactory().createPoint(new Coordinate(x,y)); |
173
1b2fc94766c9
Added real Coordinate-Query to TimeSeries-Mesh
Tim Englich <tim.englich@intevation.de>
parents:
171
diff
changeset
|
163 } |
1b2fc94766c9
Added real Coordinate-Query to TimeSeries-Mesh
Tim Englich <tim.englich@intevation.de>
parents:
171
diff
changeset
|
164 } |
101
e01c163ea5b0
Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
165 |
e01c163ea5b0
Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
166 } |