Mercurial > dive4elements > gnv-client
comparison gnv-artifacts/src/main/java/de/intevation/gnv/utils/InputValidator.java @ 778:9a828e5a2390
Removed trailing whitespace
gnv-artifacts/trunk@851 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Mon, 29 Mar 2010 07:58:51 +0000 |
parents | b81f6f896668 |
children | b1f5f2a8840f |
comparison
equal
deleted
inserted
replaced
777:8009961db1cb | 778:9a828e5a2390 |
---|---|
17 import de.intevation.gnv.geobackend.util.DateUtils; | 17 import de.intevation.gnv.geobackend.util.DateUtils; |
18 import de.intevation.gnv.utils.exception.ValidationException; | 18 import de.intevation.gnv.utils.exception.ValidationException; |
19 | 19 |
20 /** | 20 /** |
21 * @author Tim Englich <tim.englich@intevation.de> | 21 * @author Tim Englich <tim.englich@intevation.de> |
22 * | 22 * |
23 */ | 23 */ |
24 public class InputValidator { | 24 public class InputValidator { |
25 /** | 25 /** |
26 * the logger, used to log exceptions and additonaly information | 26 * the logger, used to log exceptions and additonaly information |
27 */ | 27 */ |
28 private static Logger log = Logger.getLogger(InputValidator.class); | 28 private static Logger log = Logger.getLogger(InputValidator.class); |
29 | 29 |
30 | 30 |
31 public final static String NODATASELECTEDVALUE = "n/n"; | 31 public final static String NODATASELECTEDVALUE = "n/n"; |
32 | 32 |
33 /** | 33 /** |
34 * Constructor | 34 * Constructor |
35 */ | 35 */ |
59 } | 59 } |
60 } | 60 } |
61 log.debug("Is valid? " + returnValue); | 61 log.debug("Is valid? " + returnValue); |
62 return returnValue; | 62 return returnValue; |
63 } | 63 } |
64 | 64 |
65 public boolean isInputValid(String input, String type) { | 65 public boolean isInputValid(String input, String type) { |
66 log.debug("InputValidator.isInputValid " + input + " " + type); | 66 log.debug("InputValidator.isInputValid " + input + " " + type); |
67 boolean returnValue = false; | 67 boolean returnValue = false; |
68 String[] values = input.split(","); | 68 String[] values = input.split(","); |
69 for (int i = 0; i < values.length; i++) { | 69 for (int i = 0; i < values.length; i++) { |
70 boolean valid; | 70 boolean valid; |
71 | 71 |
72 if (NODATASELECTEDVALUE.equals(values[i].trim())){ | 72 if (NODATASELECTEDVALUE.equals(values[i].trim())){ |
73 valid = true; | 73 valid = true; |
74 } else if ("Integer".equalsIgnoreCase(type)) { | 74 } else if ("Integer".equalsIgnoreCase(type)) { |
75 valid = GenericValidator.isInt(values[i].trim()); | 75 valid = GenericValidator.isInt(values[i].trim()); |
76 } else if ("Double".equalsIgnoreCase(type)) { | 76 } else if ("Double".equalsIgnoreCase(type)) { |
111 } | 111 } |
112 } | 112 } |
113 log.debug("Is valid? " + returnValue); | 113 log.debug("Is valid? " + returnValue); |
114 return returnValue; | 114 return returnValue; |
115 } | 115 } |
116 | 116 |
117 | 117 |
118 public Point getPointValue(String value) throws ValidationException{ | 118 public Point getPointValue(String value) throws ValidationException{ |
119 log.debug("InputValidator.getPointValue " + value); | 119 log.debug("InputValidator.getPointValue " + value); |
120 | 120 |
121 if (value.toLowerCase().startsWith("point")){ | 121 if (value.toLowerCase().startsWith("point")){ |
122 try { | 122 try { |
123 return (Point)new WKTReader().read(value); | 123 return (Point)new WKTReader().read(value); |
124 } catch (ParseException e) { | 124 } catch (ParseException e) { |
125 log.error(e,e); | 125 log.error(e,e); |
126 throw new ValidationException(e); | 126 throw new ValidationException(e); |
127 } | 127 } |
128 }else{ | 128 }else{ |
129 String[] s, p; | 129 String[] s, p; |
130 | 130 |
131 double x=0,y=0; | 131 double x=0,y=0; |
132 log.info("Position :"+value); | 132 log.info("Position :"+value); |
133 s = value.split(" "); | 133 s = value.split(" "); |
134 if (s.length != 2) { | 134 if (s.length != 2) { |
135 throw new ValidationException("Kein Blank separiert Breite und Länge"); | 135 throw new ValidationException("Kein Blank separiert Breite und Länge"); |
143 if (s[0].toLowerCase().contains("s")) | 143 if (s[0].toLowerCase().contains("s")) |
144 y = -y; | 144 y = -y; |
145 } | 145 } |
146 catch (Exception e) { | 146 catch (Exception e) { |
147 throw new ValidationException("Kein N|S oder nicht im ersten Substring, zB 56n42"); | 147 throw new ValidationException("Kein N|S oder nicht im ersten Substring, zB 56n42"); |
148 | 148 |
149 } | 149 } |
150 p = s[1].split("[eEwW]"); | 150 p = s[1].split("[eEwW]"); |
151 try { | 151 try { |
152 if (p.length ==1) | 152 if (p.length ==1) |
153 x = new Double(p[0]); | 153 x = new Double(p[0]); |
154 else | 154 else |
156 if (s[1].toLowerCase().contains("w")) | 156 if (s[1].toLowerCase().contains("w")) |
157 x = -x; | 157 x = -x; |
158 } | 158 } |
159 catch (Exception e) { | 159 catch (Exception e) { |
160 throw new ValidationException("Kein E|W oder nicht im zweiten Substring"); | 160 throw new ValidationException("Kein E|W oder nicht im zweiten Substring"); |
161 } | 161 } |
162 return new GeometryFactory().createPoint(new Coordinate(x,y)); | 162 return new GeometryFactory().createPoint(new Coordinate(x,y)); |
163 } | 163 } |
164 } | 164 } |
165 | 165 |
166 } | 166 } |