diff src/java/de/intevation/mxd/writer/FillStyleWriter.java @ 145:b2c5a66022f1

Exception handling for number conversions in writer modules.
author Raimund Renkert <rrenkert@intevation.de>
date Mon, 27 Jun 2011 18:22:21 +0200
parents cd18c61cbcf6
children 7b1433d3b574
line wrap: on
line diff
--- a/src/java/de/intevation/mxd/writer/FillStyleWriter.java	Mon Jun 27 17:22:52 2011 +0200
+++ b/src/java/de/intevation/mxd/writer/FillStyleWriter.java	Mon Jun 27 18:22:21 2011 +0200
@@ -69,8 +69,13 @@
                    (i == 1 && type.equals("marker"))) {
                     double gap = 0;
                     if(symbolElement.hasAttribute("xseparation")) {
-                        gap = Double.parseDouble(
-                            symbolElement.getAttribute("xseparation"));
+                        try {
+                            gap = Double.parseDouble(
+                                symbolElement.getAttribute("xseparation"));
+                        }
+                        catch(NumberFormatException nfe) {
+                            gap = 0;
+                        }
                     }
                     writeMarker(nextSym, gap);
                 }
@@ -104,8 +109,14 @@
                     oCol.getBlue(),
                     -4);
                 style.setOutlinecolor(outlineColor);
-                style.setOutlinewidth(Double.parseDouble(
-                    symbolElement.getAttribute("outline_size")));
+                try {
+                    style.setOutlinewidth(Double.parseDouble(
+                        symbolElement.getAttribute("outline_size")));
+                }
+                catch(NumberFormatException nfe) {
+                    logger.warn("Error setting outline width.");
+                    style.setOutlinewidth(0.0);
+                }
             }
 
         }
@@ -121,7 +132,14 @@
         //write transparent outline
         colorObj color = new colorObj(-1, -1, -1, -4);
         if(symbolElement.hasAttribute("width")) {
-            double w = Double.parseDouble(symbolElement.getAttribute("width"));
+            double w = 0;
+            try {
+                w = Double.parseDouble(symbolElement.getAttribute("width"));
+            }
+            catch(NumberFormatException nfe) {
+                logger.warn("Error setting outline width.");
+                w = 0;
+            }
             if (w < 1.0) {
                 return;
             }
@@ -139,8 +157,14 @@
             oCol.getBlue(),
             -4);
         outline.setOutlinecolor(outlinecolor);
-        outline.setOutlinewidth(Double.parseDouble(
-            symbolElement.getAttribute("width")));
+        try {
+            outline.setOutlinewidth(Double.parseDouble(
+                symbolElement.getAttribute("width")));
+        }
+        catch(NumberFormatException nfe) {
+            logger.warn("Error setting outline width.");
+            outline.setOutlinewidth(0.0);
+        }
         if(symbolElement.hasAttribute("linestyle")) {
             String ls = symbolElement.getAttribute("linestyle");
             double[] vals;
@@ -177,8 +201,14 @@
         String name = symbolElement.getAttribute("name");
         String type = symbolElement.getAttribute("type");
         if (symbolElement.hasAttribute("angle")) {
-            style.setAngle(
-                Double.parseDouble(symbolElement.getAttribute("angle")));
+            try {
+               style.setAngle(
+                   Double.parseDouble(symbolElement.getAttribute("angle")));
+            }
+            catch(NumberFormatException nfe) {
+                logger.warn("Error setting angle.");
+                style.setAngle(0.0);
+            }
         }
         if(symbolElement.hasAttribute("color")) {
             String c = symbolElement.getAttribute("color");
@@ -191,8 +221,13 @@
             style.setColor(color);
         }
         if (symbolElement.hasAttribute ("size")) {
-            double size = Double.parseDouble(
-                symbolElement.getAttribute("size"));
+            double size = 1;
+            try {
+                size = Double.parseDouble(symbolElement.getAttribute("size"));
+            }
+            catch(NumberFormatException nfe) {
+                size = 1.0;
+            }
             style.setSize(size);
             //In arcgis the separation goes from center to center, so the gap is
             //the separation - size
@@ -209,8 +244,14 @@
                 oCol.getBlue(),
                 -4);
             style.setOutlinecolor(outlineColor);
-            style.setOutlinewidth(Double.parseDouble(
-                symbolElement.getAttribute("outline_size")));
+            try {
+                style.setOutlinewidth(Double.parseDouble(
+                    symbolElement.getAttribute("outline_size")));
+            }
+            catch(NumberFormatException nfe) {
+                logger.warn("Error setting angle.");
+                style.setOutlinewidth(0.0);
+            }
         }
         if(type.equals("marker")) {
             style.setSymbolByName(map, name);
@@ -255,8 +296,14 @@
     private void writeSimple(Element symbolElement) {
         logger.debug("writeSimple(Element)");
         if(symbolElement.hasAttribute("transparency")) {
-            double value = Double.parseDouble(
-                symbolElement.getAttribute("transparency"));
+            double value = 0;
+            try {
+                value = Double.parseDouble(
+                    symbolElement.getAttribute("transparency"));
+            }
+            catch(NumberFormatException nfe) {
+                value = 0;
+            }
             int opacity = (int)(value/255) * 100;
             if(value >= 0) {
                 style.setOpacity(opacity);
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)