annotate gnv-artifacts/src/main/java/de/intevation/gnv/utils/InputValidator.java @ 852:b5f4b6073cde

Calculate the depth in an odv export of a 'Profilschnitt' properly (issue217). gnv-artifacts/trunk@968 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Thu, 22 Apr 2010 08:54:36 +0000
parents 05bf8534a35a
children f94a95009423
rev   line source
101
e01c163ea5b0 Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
1 package de.intevation.gnv.utils;
e01c163ea5b0 Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
2
779
b1f5f2a8840f Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
3 import com.vividsolutions.jts.geom.Coordinate;
b1f5f2a8840f Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
4 import com.vividsolutions.jts.geom.GeometryFactory;
b1f5f2a8840f Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
5 import com.vividsolutions.jts.geom.Point;
b1f5f2a8840f Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
6
b1f5f2a8840f Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
7 import com.vividsolutions.jts.io.ParseException;
b1f5f2a8840f Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
8 import com.vividsolutions.jts.io.WKTReader;
b1f5f2a8840f Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
9
b1f5f2a8840f Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
10 import de.intevation.gnv.geobackend.util.DateUtils;
b1f5f2a8840f Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
11
b1f5f2a8840f Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
12 import de.intevation.gnv.utils.exception.ValidationException;
b1f5f2a8840f Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
13
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
14 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
15
116
820238357bab Added Horizontal-Profile-Support for Meshes.
Tim Englich <tim.englich@intevation.de>
parents: 115
diff changeset
16 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
17
779
b1f5f2a8840f Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
18 import org.apache.log4j.Logger;
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 /**
780
c4156275c1e1 Bring @author javadoc tags in form '@author <a href="john.doe@example.com">John Doe</a>'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 779
diff changeset
21 * @author <a href="mailto:tim.englich@intevation.de">Tim Englich</a>
785
e764cab8c885 Save the relation between selected measurement and the parameter it belongs to (issue210). TODO: Adapt sql statements.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 784
diff changeset
22 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
778
9a828e5a2390 Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 746
diff changeset
23 *
101
e01c163ea5b0 Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
24 */
e01c163ea5b0 Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
25 public class InputValidator {
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 * 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
28 */
e01c163ea5b0 Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
29 private static Logger log = Logger.getLogger(InputValidator.class);
778
9a828e5a2390 Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 746
diff changeset
30
9a828e5a2390 Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 746
diff changeset
31
222
3e82b4f1c455 Removed some Compilation-Errors according to API-Changes in the ArtifactDatabase.
Tim Englich <tim.englich@intevation.de>
parents: 173
diff changeset
32 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
33
e01c163ea5b0 Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
34 /**
e01c163ea5b0 Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
35 * Constructor
e01c163ea5b0 Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
36 */
e01c163ea5b0 Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
37 public InputValidator() {
e01c163ea5b0 Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
38 super();
e01c163ea5b0 Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
39 }
171
7fb9441dd8af Format Code to max 80 Chars per Row and Cleanup
Tim Englich <tim.englich@intevation.de>
parents: 116
diff changeset
40
806
2cea76f1112e Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 803
diff changeset
41 /**
2cea76f1112e Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 803
diff changeset
42 * Validates the input of a range of double or date values. The input values
2cea76f1112e Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 803
diff changeset
43 * need to be valid double or date values. <i>minInput</i> needs to be
2cea76f1112e Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 803
diff changeset
44 * smaller or equal <i>maxInput</i>.
2cea76f1112e Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 803
diff changeset
45 *
2cea76f1112e Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 803
diff changeset
46 * @param minInput The lower bound.
2cea76f1112e Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 803
diff changeset
47 * @param maxInput The upper bound.
2cea76f1112e Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 803
diff changeset
48 * @param type One of 'Date' or 'Double'.
2cea76f1112e Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 803
diff changeset
49 * @return true, if the input is valid, otherwise false.
2cea76f1112e Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 803
diff changeset
50 */
785
e764cab8c885 Save the relation between selected measurement and the parameter it belongs to (issue210). TODO: Adapt sql statements.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 784
diff changeset
51 public static boolean isInputValid(String minInput, String maxInput, String type) {
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
52 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
53 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
54 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
55 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
56 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
57 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
58 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
59 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
60 } 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
61 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
62 }
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 } 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
64 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
65 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
66 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
67 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
68 } 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
69 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
70 }
f1e7ddeef5bc Added Validation if a given maxvalue is greater than a given minvalue issue19
Tim Englich <tim.englich@intevation.de>
parents: 222
diff changeset
71 }
f1e7ddeef5bc Added Validation if a given maxvalue is greater than a given minvalue issue19
Tim Englich <tim.englich@intevation.de>
parents: 222
diff changeset
72 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
73 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
74 }
778
9a828e5a2390 Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 746
diff changeset
75
806
2cea76f1112e Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 803
diff changeset
76 /**
2cea76f1112e Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 803
diff changeset
77 * Validates an input.
2cea76f1112e Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 803
diff changeset
78 *
2cea76f1112e Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 803
diff changeset
79 * @param input The input value.
2cea76f1112e Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 803
diff changeset
80 * @param type The input value type.
2cea76f1112e Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 803
diff changeset
81 * @return true if the input is valid, otherwise false.
2cea76f1112e Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 803
diff changeset
82 */
785
e764cab8c885 Save the relation between selected measurement and the parameter it belongs to (issue210). TODO: Adapt sql statements.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 784
diff changeset
83 public static boolean isInputValid(String input, String type) {
171
7fb9441dd8af Format Code to max 80 Chars per Row and Cleanup
Tim Englich <tim.englich@intevation.de>
parents: 116
diff changeset
84 log.debug("InputValidator.isInputValid " + input + " " + type);
787
6cd8492019d8 Validate wkt string and display error messages if the validation failed (issue214).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 785
diff changeset
85
803
feae2f9d6c6f Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 787
diff changeset
86 // Let's check polygons and linestrings first, because they might
787
6cd8492019d8 Validate wkt string and display error messages if the validation failed (issue214).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 785
diff changeset
87 // contain comma. A splitting at comma characters wouldn't be good here.
6cd8492019d8 Validate wkt string and display error messages if the validation failed (issue214).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 785
diff changeset
88 if ("Polygon".equalsIgnoreCase(type) || "Linestring".equalsIgnoreCase(type))
6cd8492019d8 Validate wkt string and display error messages if the validation failed (issue214).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 785
diff changeset
89 {
6cd8492019d8 Validate wkt string and display error messages if the validation failed (issue214).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 785
diff changeset
90 try {
6cd8492019d8 Validate wkt string and display error messages if the validation failed (issue214).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 785
diff changeset
91 WKTReader reader = new WKTReader();
6cd8492019d8 Validate wkt string and display error messages if the validation failed (issue214).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 785
diff changeset
92 reader.read(input);
6cd8492019d8 Validate wkt string and display error messages if the validation failed (issue214).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 785
diff changeset
93
6cd8492019d8 Validate wkt string and display error messages if the validation failed (issue214).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 785
diff changeset
94 return true;
6cd8492019d8 Validate wkt string and display error messages if the validation failed (issue214).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 785
diff changeset
95 }
6cd8492019d8 Validate wkt string and display error messages if the validation failed (issue214).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 785
diff changeset
96 catch (ParseException pe) {
6cd8492019d8 Validate wkt string and display error messages if the validation failed (issue214).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 785
diff changeset
97 log.warn(pe, pe);
6cd8492019d8 Validate wkt string and display error messages if the validation failed (issue214).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 785
diff changeset
98 return false;
6cd8492019d8 Validate wkt string and display error messages if the validation failed (issue214).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 785
diff changeset
99 }
6cd8492019d8 Validate wkt string and display error messages if the validation failed (issue214).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 785
diff changeset
100 }
6cd8492019d8 Validate wkt string and display error messages if the validation failed (issue214).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 785
diff changeset
101
6cd8492019d8 Validate wkt string and display error messages if the validation failed (issue214).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 785
diff changeset
102 // Check all the other input here
101
e01c163ea5b0 Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
103 boolean returnValue = false;
e01c163ea5b0 Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
104 String[] values = input.split(",");
787
6cd8492019d8 Validate wkt string and display error messages if the validation failed (issue214).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 785
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 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
107 boolean valid;
778
9a828e5a2390 Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 746
diff changeset
108
222
3e82b4f1c455 Removed some Compilation-Errors according to API-Changes in the ArtifactDatabase.
Tim Englich <tim.englich@intevation.de>
parents: 173
diff changeset
109 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
110 valid = true;
3e82b4f1c455 Removed some Compilation-Errors according to API-Changes in the ArtifactDatabase.
Tim Englich <tim.englich@intevation.de>
parents: 173
diff changeset
111 } else if ("Integer".equalsIgnoreCase(type)) {
115
158e89c2263b Removed needless imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 113
diff changeset
112 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
113 } 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
114 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
115 } 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
116 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
117 // FIXME:
7fb9441dd8af Format Code to max 80 Chars per Row and Cleanup
Tim Englich <tim.englich@intevation.de>
parents: 116
diff changeset
118 // VALIDATE
7fb9441dd8af Format Code to max 80 Chars per Row and Cleanup
Tim Englich <tim.englich@intevation.de>
parents: 116
diff changeset
119 // REGEXP
7fb9441dd8af Format Code to max 80 Chars per Row and Cleanup
Tim Englich <tim.englich@intevation.de>
parents: 116
diff changeset
120 } 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
121 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
122 DateUtils.DATE_PATTERN, true);
731
1efb6a66c7d9 Added Objecttype Geometry for the Validation of Inputdata.
Tim Englich <tim.englich@intevation.de>
parents: 461
diff changeset
123 } 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
124 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
125 // FIXME:
7fb9441dd8af Format Code to max 80 Chars per Row and Cleanup
Tim Englich <tim.englich@intevation.de>
parents: 116
diff changeset
126 // VALIDATE
7fb9441dd8af Format Code to max 80 Chars per Row and Cleanup
Tim Englich <tim.englich@intevation.de>
parents: 116
diff changeset
127 // REGEXP
7fb9441dd8af Format Code to max 80 Chars per Row and Cleanup
Tim Englich <tim.englich@intevation.de>
parents: 116
diff changeset
128 } 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
129 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
130 .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
131 // VALIDATE
7fb9441dd8af Format Code to max 80 Chars per Row and Cleanup
Tim Englich <tim.englich@intevation.de>
parents: 116
diff changeset
132 // REGEXP
173
1b2fc94766c9 Added real Coordinate-Query to TimeSeries-Mesh
Tim Englich <tim.englich@intevation.de>
parents: 171
diff changeset
133 } else if ("Coordinate".equalsIgnoreCase(type)) {
1b2fc94766c9 Added real Coordinate-Query to TimeSeries-Mesh
Tim Englich <tim.englich@intevation.de>
parents: 171
diff changeset
134 try {
785
e764cab8c885 Save the relation between selected measurement and the parameter it belongs to (issue210). TODO: Adapt sql statements.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 784
diff changeset
135 valid = getPointValue(values[i]) != null;
173
1b2fc94766c9 Added real Coordinate-Query to TimeSeries-Mesh
Tim Englich <tim.englich@intevation.de>
parents: 171
diff changeset
136 } catch (ValidationException e) {
1b2fc94766c9 Added real Coordinate-Query to TimeSeries-Mesh
Tim Englich <tim.englich@intevation.de>
parents: 171
diff changeset
137 log.debug(e.getMessage());
1b2fc94766c9 Added real Coordinate-Query to TimeSeries-Mesh
Tim Englich <tim.englich@intevation.de>
parents: 171
diff changeset
138 valid = false;
1b2fc94766c9 Added real Coordinate-Query to TimeSeries-Mesh
Tim Englich <tim.englich@intevation.de>
parents: 171
diff changeset
139 }
171
7fb9441dd8af Format Code to max 80 Chars per Row and Cleanup
Tim Englich <tim.englich@intevation.de>
parents: 116
diff changeset
140 } else {
101
e01c163ea5b0 Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
141 valid = false;
e01c163ea5b0 Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
142 }
171
7fb9441dd8af Format Code to max 80 Chars per Row and Cleanup
Tim Englich <tim.englich@intevation.de>
parents: 116
diff changeset
143 if (!valid) {
7fb9441dd8af Format Code to max 80 Chars per Row and Cleanup
Tim Englich <tim.englich@intevation.de>
parents: 116
diff changeset
144 returnValue = false;
101
e01c163ea5b0 Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
145 break;
171
7fb9441dd8af Format Code to max 80 Chars per Row and Cleanup
Tim Englich <tim.englich@intevation.de>
parents: 116
diff changeset
146 } else {
101
e01c163ea5b0 Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
147 returnValue = true;
e01c163ea5b0 Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
148 }
e01c163ea5b0 Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
149 }
171
7fb9441dd8af Format Code to max 80 Chars per Row and Cleanup
Tim Englich <tim.englich@intevation.de>
parents: 116
diff changeset
150 log.debug("Is valid? " + returnValue);
101
e01c163ea5b0 Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
151 return returnValue;
e01c163ea5b0 Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
152 }
778
9a828e5a2390 Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 746
diff changeset
153
9a828e5a2390 Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 746
diff changeset
154
806
2cea76f1112e Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 803
diff changeset
155 /**
2cea76f1112e Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 803
diff changeset
156 * Returns a point from wkt string.
2cea76f1112e Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 803
diff changeset
157 *
2cea76f1112e Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 803
diff changeset
158 * @param value The wkt string.
2cea76f1112e Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 803
diff changeset
159 * @return a point.
2cea76f1112e Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 803
diff changeset
160 * @throws ValidationException if <i>value</i> is not valid.
2cea76f1112e Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 803
diff changeset
161 */
785
e764cab8c885 Save the relation between selected measurement and the parameter it belongs to (issue210). TODO: Adapt sql statements.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 784
diff changeset
162 public static Point getPointValue(String value) throws ValidationException{
173
1b2fc94766c9 Added real Coordinate-Query to TimeSeries-Mesh
Tim Englich <tim.englich@intevation.de>
parents: 171
diff changeset
163 log.debug("InputValidator.getPointValue " + value);
778
9a828e5a2390 Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 746
diff changeset
164
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
165 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
166 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
167 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
168 } 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
169 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
170 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
171 }
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
172 }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
173 String[] s, p;
778
9a828e5a2390 Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 746
diff changeset
174
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
175 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
176 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
177 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
178 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
179 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
180 }
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
181 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
182 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
183 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
184 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
185 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
186 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
187 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
188 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
189 }
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
190 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
191 throw new ValidationException("Kein N|S oder nicht im ersten Substring, zB 56n42");
778
9a828e5a2390 Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 746
diff changeset
192
9a828e5a2390 Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 746
diff changeset
193 }
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
194 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
195 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
196 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
197 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
198 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
199 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
200 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
201 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
202 }
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
203 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
204 throw new ValidationException("Kein E|W oder nicht im zweiten Substring");
778
9a828e5a2390 Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 746
diff changeset
205 }
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
206 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
207 }
1b2fc94766c9 Added real Coordinate-Query to TimeSeries-Mesh
Tim Englich <tim.englich@intevation.de>
parents: 171
diff changeset
208 }
101
e01c163ea5b0 Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
209
784
7b81d563c8c0 Improved date input validation. A given date needs to be in a specific range (issue212).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 780
diff changeset
210
806
2cea76f1112e Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 803
diff changeset
211 /**
2cea76f1112e Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 803
diff changeset
212 * Makes sure that <i>tmp</i> is between <i>lo</i> and <i>up</i>.
2cea76f1112e Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 803
diff changeset
213 *
2cea76f1112e Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 803
diff changeset
214 * @param tmp The value to validate.
2cea76f1112e Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 803
diff changeset
215 * @param lo The lower range bound.
2cea76f1112e Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 803
diff changeset
216 * @param up The upper range bound.
2cea76f1112e Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 803
diff changeset
217 * @return true, if tmp is valid, otherwise false.
2cea76f1112e Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 803
diff changeset
218 */
785
e764cab8c885 Save the relation between selected measurement and the parameter it belongs to (issue210). TODO: Adapt sql statements.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 784
diff changeset
219 public static boolean isDateValid(Date tmp, Date lo, Date up) {
784
7b81d563c8c0 Improved date input validation. A given date needs to be in a specific range (issue212).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 780
diff changeset
220 // we need to transform the given dates into seconds, because
7b81d563c8c0 Improved date input validation. A given date needs to be in a specific range (issue212).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 780
diff changeset
221 // they differ in milliseconds -> that's why we cannot use the
7b81d563c8c0 Improved date input validation. A given date needs to be in a specific range (issue212).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 780
diff changeset
222 // Date.compareTo(Date) method.
7b81d563c8c0 Improved date input validation. A given date needs to be in a specific range (issue212).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 780
diff changeset
223 long tmpTime = tmp.getTime() / 1000;
7b81d563c8c0 Improved date input validation. A given date needs to be in a specific range (issue212).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 780
diff changeset
224 long tmpLow = lo.getTime() / 1000;
7b81d563c8c0 Improved date input validation. A given date needs to be in a specific range (issue212).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 780
diff changeset
225 long tmpUp = up.getTime() / 1000;
7b81d563c8c0 Improved date input validation. A given date needs to be in a specific range (issue212).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 780
diff changeset
226
7b81d563c8c0 Improved date input validation. A given date needs to be in a specific range (issue212).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 780
diff changeset
227 if (tmpTime < tmpLow || tmpTime > tmpUp) {
7b81d563c8c0 Improved date input validation. A given date needs to be in a specific range (issue212).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 780
diff changeset
228 log.warn(
7b81d563c8c0 Improved date input validation. A given date needs to be in a specific range (issue212).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 780
diff changeset
229 "Date [" + tmp.toString() + "] is out of range ["
7b81d563c8c0 Improved date input validation. A given date needs to be in a specific range (issue212).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 780
diff changeset
230 + lo.toString() + " to "+ up.toString() + "].");
7b81d563c8c0 Improved date input validation. A given date needs to be in a specific range (issue212).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 780
diff changeset
231 return false;
7b81d563c8c0 Improved date input validation. A given date needs to be in a specific range (issue212).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 780
diff changeset
232 }
7b81d563c8c0 Improved date input validation. A given date needs to be in a specific range (issue212).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 780
diff changeset
233
7b81d563c8c0 Improved date input validation. A given date needs to be in a specific range (issue212).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 780
diff changeset
234 return true;
7b81d563c8c0 Improved date input validation. A given date needs to be in a specific range (issue212).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 780
diff changeset
235 }
101
e01c163ea5b0 Inputvalidation for String, Integer and Date Values added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
236 }
836
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 806
diff changeset
237 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org