Mercurial > dive4elements > gnv-client
comparison gnv-artifacts/src/main/java/de/intevation/gnv/utils/InputValidator.java @ 173:1b2fc94766c9
Added real Coordinate-Query to TimeSeries-Mesh
gnv-artifacts/trunk@212 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Tim Englich <tim.englich@intevation.de> |
---|---|
date | Tue, 13 Oct 2009 09:11:23 +0000 |
parents | 7fb9441dd8af |
children | 3e82b4f1c455 |
comparison
equal
deleted
inserted
replaced
172:b5e55f460f0b | 173:1b2fc94766c9 |
---|---|
4 package de.intevation.gnv.utils; | 4 package de.intevation.gnv.utils; |
5 | 5 |
6 import org.apache.commons.validator.GenericValidator; | 6 import org.apache.commons.validator.GenericValidator; |
7 import org.apache.log4j.Logger; | 7 import org.apache.log4j.Logger; |
8 | 8 |
9 import com.vividsolutions.jts.geom.Coordinate; | |
10 import com.vividsolutions.jts.geom.GeometryFactory; | |
11 import com.vividsolutions.jts.geom.Point; | |
12 | |
9 import de.intevation.gnv.geobackend.util.DateUtils; | 13 import de.intevation.gnv.geobackend.util.DateUtils; |
14 import de.intevation.gnv.utils.exception.ValidationException; | |
10 | 15 |
11 /** | 16 /** |
12 * @author Tim Englich <tim.englich@intevation.de> | 17 * @author Tim Englich <tim.englich@intevation.de> |
13 * | 18 * |
14 */ | 19 */ |
51 } else if ("AttributeName".equalsIgnoreCase(type)) { | 56 } else if ("AttributeName".equalsIgnoreCase(type)) { |
52 valid = org.apache.commons.validator.GenericValidator | 57 valid = org.apache.commons.validator.GenericValidator |
53 .matchRegexp(values[i], "[a-zA-Z0-9]"); // TODO: FIXME: | 58 .matchRegexp(values[i], "[a-zA-Z0-9]"); // TODO: FIXME: |
54 // VALIDATE | 59 // VALIDATE |
55 // REGEXP | 60 // REGEXP |
61 } else if ("Coordinate".equalsIgnoreCase(type)) { | |
62 try { | |
63 valid = this.getPointValue(values[i]) != null; | |
64 } catch (ValidationException e) { | |
65 log.debug(e.getMessage()); | |
66 valid = false; | |
67 } | |
56 } else { | 68 } else { |
57 valid = false; | 69 valid = false; |
58 } | 70 } |
59 if (!valid) { | 71 if (!valid) { |
60 returnValue = false; | 72 returnValue = false; |
64 } | 76 } |
65 } | 77 } |
66 log.debug("Is valid? " + returnValue); | 78 log.debug("Is valid? " + returnValue); |
67 return returnValue; | 79 return returnValue; |
68 } | 80 } |
81 | |
82 | |
83 public Point getPointValue(String value) throws ValidationException{ | |
84 log.debug("InputValidator.getPointValue " + value); | |
85 String[] s, p; | |
86 | |
87 double x=0,y=0; | |
88 log.info("Position :"+value); | |
89 s = value.split(" "); | |
90 if (s.length != 2) { | |
91 throw new ValidationException("Kein Blank separiert Breite und Länge"); | |
92 } | |
93 p = s[0].split("[nNsS]"); | |
94 try { | |
95 if (p.length == 1) | |
96 y = new Double(p[0]); | |
97 else | |
98 y = new Double(p[0]) + new Double(p[1]) / new Double(60.); | |
99 if (s[0].toLowerCase().contains("s")) | |
100 y = -y; | |
101 } | |
102 catch (Exception e) { | |
103 throw new ValidationException("Kein N|S oder nicht im ersten Substring, zB 56n42"); | |
104 | |
105 } | |
106 p = s[1].split("[eEwW]"); | |
107 try { | |
108 if (p.length ==1) | |
109 x = new Double(p[0]); | |
110 else | |
111 x = new Double(p[0]) + new Double(p[1]) / new Double(60.) ; | |
112 if (s[1].toLowerCase().contains("w")) | |
113 x = -x; | |
114 } | |
115 catch (Exception e) { | |
116 throw new ValidationException("Kein E|W oder nicht im zweiten Substring"); | |
117 } | |
118 return new GeometryFactory().createPoint(new Coordinate(x,y)); | |
119 } | |
69 | 120 |
70 } | 121 } |