diff 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
line wrap: on
line diff
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/utils/InputValidator.java	Mon Oct 12 09:19:16 2009 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/utils/InputValidator.java	Tue Oct 13 09:11:23 2009 +0000
@@ -6,7 +6,12 @@
 import org.apache.commons.validator.GenericValidator;
 import org.apache.log4j.Logger;
 
+import com.vividsolutions.jts.geom.Coordinate;
+import com.vividsolutions.jts.geom.GeometryFactory;
+import com.vividsolutions.jts.geom.Point;
+
 import de.intevation.gnv.geobackend.util.DateUtils;
+import de.intevation.gnv.utils.exception.ValidationException;
 
 /**
  * @author Tim Englich <tim.englich@intevation.de>
@@ -53,6 +58,13 @@
                         .matchRegexp(values[i], "[a-zA-Z0-9]"); // TODO: FIXME:
                                                                 // VALIDATE
                                                                 // REGEXP
+            } else if ("Coordinate".equalsIgnoreCase(type)) {
+                    try {
+                        valid = this.getPointValue(values[i]) != null;
+                    } catch (ValidationException e) {
+                        log.debug(e.getMessage());
+                        valid = false;
+                    }
             } else {
                 valid = false;
             }
@@ -66,5 +78,44 @@
         log.debug("Is valid? " + returnValue);
         return returnValue;
     }
+    
+    
+    public Point getPointValue(String value) throws ValidationException{
+        log.debug("InputValidator.getPointValue " + value);
+        String[] s, p;
+        
+        double x=0,y=0;
+        log.info("Position :"+value);
+        s = value.split(" ");
+        if (s.length != 2) {
+              throw new ValidationException("Kein Blank separiert Breite und Länge");
+        }
+        p = s[0].split("[nNsS]");
+        try {
+            if (p.length == 1)
+                y = new Double(p[0]);
+            else
+                y = new Double(p[0]) +   new Double(p[1]) / new Double(60.);
+            if (s[0].toLowerCase().contains("s"))
+                y = -y;
+        }
+        catch (Exception e) {
+            throw new ValidationException("Kein N|S oder nicht im ersten Substring, zB 56n42");
+        
+        } 
+        p = s[1].split("[eEwW]");
+        try {
+            if (p.length ==1)
+                x = new Double(p[0]);
+            else
+                x = new Double(p[0]) +  new Double(p[1]) / new Double(60.) ;
+            if (s[1].toLowerCase().contains("w"))
+                x = -x;
+        }
+        catch (Exception e) {
+            throw new ValidationException("Kein E|W oder nicht im zweiten Substring");
+        } 
+        return new GeometryFactory().createPoint(new Coordinate(x,y));
+    }
 
 }

http://dive4elements.wald.intevation.org