changeset 787:6cd8492019d8

Validate wkt string and display error messages if the validation failed (issue214). gnv-artifacts/trunk@869 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Tue, 30 Mar 2010 16:51:20 +0000
parents c907636c0288
children e8a9e84a0328
files gnv-artifacts/ChangeLog gnv-artifacts/doc/conf/products/horizontalcrosssection/conf_mesh.xml gnv-artifacts/doc/conf/products/verticalcrosssection/conf_mesh.xml gnv-artifacts/src/main/java/de/intevation/gnv/utils/InputValidator.java
diffstat 4 files changed, 35 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/gnv-artifacts/ChangeLog	Tue Mar 30 14:16:07 2010 +0000
+++ b/gnv-artifacts/ChangeLog	Tue Mar 30 16:51:20 2010 +0000
@@ -1,3 +1,17 @@
+2010-03-30  Ingo Weinzierl <ingo.weinzierl@intevation.de>
+
+	  Issue214
+
+	* src/main/java/de/intevation/gnv/utils/InputValidator.java: Added code for
+	  validating polygons and linestrings. The input type needs to be 'polygon'
+	  or 'linestring'.
+
+	* doc/conf/products/horizontalcrosssection/conf_mesh.xml: Changed the input
+	  type of the wkt string from 'string' to 'polygon'.
+
+	* doc/conf/products/verticalcrosssection/conf_mesh.xml: Changed the input
+	  type of the wkt string from 'string' to 'linestring'.
+
 2010-03-30  Ingo Weinzierl <ingo.weinzierl@intevation.de>
 
 	* src/main/java/de/intevation/gnv/state/ExtendedInputData.java: Added a
--- a/gnv-artifacts/doc/conf/products/horizontalcrosssection/conf_mesh.xml	Tue Mar 30 14:16:07 2010 +0000
+++ b/gnv-artifacts/doc/conf/products/horizontalcrosssection/conf_mesh.xml	Tue Mar 30 16:51:20 2010 +0000
@@ -134,7 +134,7 @@
            <inputvalues>
                 <inputvalue name="meshid" type="Integer" multiselect="false"/>
                 <inputvalue name="fisname" type="String" multiselect="false" usedinquery="0"/>
-                <inputvalue name="mesh_polygon" type="String" multiselect="false" usedinquery="0"/>
+                <inputvalue name="mesh_polygon" type="Polygon" multiselect="false" usedinquery="0"/>
            </inputvalues>
         </state>
         
--- a/gnv-artifacts/doc/conf/products/verticalcrosssection/conf_mesh.xml	Tue Mar 30 14:16:07 2010 +0000
+++ b/gnv-artifacts/doc/conf/products/verticalcrosssection/conf_mesh.xml	Tue Mar 30 16:51:20 2010 +0000
@@ -135,7 +135,7 @@
            <inputvalues>
                 <inputvalue name="meshid" type="Integer" multiselect="false"/>
                 <inputvalue name="fisname" type="String" multiselect="false" usedinquery="0"/>
-                <inputvalue name="mesh_linestring" type="String" multiselect="false" usedinquery="0"/>
+                <inputvalue name="mesh_linestring" type="Linestring" multiselect="false" usedinquery="0"/>
            </inputvalues>
         </state>
          
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/utils/InputValidator.java	Tue Mar 30 14:16:07 2010 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/utils/InputValidator.java	Tue Mar 30 16:51:20 2010 +0000
@@ -65,8 +65,27 @@
 
     public static boolean isInputValid(String input, String type) {
         log.debug("InputValidator.isInputValid " + input + " " + type);
+
+        // Let's check polygons and linestrings first, because they might 
+        // contain comma. A splitting at comma characters wouldn't be good here.
+        if ("Polygon".equalsIgnoreCase(type) || "Linestring".equalsIgnoreCase(type))
+        {
+            try {
+                WKTReader reader = new WKTReader();
+                reader.read(input);
+
+                return true;
+            }
+            catch (ParseException pe) {
+                log.warn(pe, pe);
+                return false;
+            }
+        }
+
+        // Check all the other input here
         boolean returnValue = false;
         String[] values = input.split(",");
+
         for (int i = 0; i < values.length; i++) {
             boolean valid;
 

http://dive4elements.wald.intevation.org