changeset 121:9f74f4d36822

Set default values and improved logging and exception handling for map reader.
author Raimund Renkert <rrenkert@intevation.de>
date Thu, 16 Jun 2011 18:36:48 +0200
parents 11d63bf00326
children f0a72d232aa8
files ChangeLog src/java/de/intevation/mxd/reader/IReader.java src/java/de/intevation/mxd/reader/MXDReader.java src/java/de/intevation/mxd/reader/MapReader.java
diffstat 4 files changed, 113 insertions(+), 50 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Thu Jun 16 14:49:45 2011 +0200
+++ b/ChangeLog	Thu Jun 16 18:36:48 2011 +0200
@@ -1,3 +1,10 @@
+2011-06-16  Raimund Renkert  <raimund.renkert@intevation.de>
+
+	* src/java/de/intevation/mxd/reader/IReader.java,
+	  src/java/de/intevation/mxd/reader/MXDReader.java,
+	  src/java/de/intevation/mxd/reader/MapReader.java:
+	  Exceptionhandling, default values and logging for map reader.
+
 2011-06-16  Raimund Renkert  <raimund.renkert@intevation.de>
 
 	* conf/log4j.properties: Set console log level to INFO.
--- a/src/java/de/intevation/mxd/reader/IReader.java	Thu Jun 16 14:49:45 2011 +0200
+++ b/src/java/de/intevation/mxd/reader/IReader.java	Thu Jun 16 18:36:48 2011 +0200
@@ -28,7 +28,7 @@
     /**
      * Read the content.
      */
-    boolean read() throws IOException;
+    boolean read() throws Exception;
 
     /**
      * Request DOM Document containing the map data.
--- a/src/java/de/intevation/mxd/reader/MXDReader.java	Thu Jun 16 14:49:45 2011 +0200
+++ b/src/java/de/intevation/mxd/reader/MXDReader.java	Thu Jun 16 18:36:48 2011 +0200
@@ -103,7 +103,7 @@
      * Read the MXD file content.
      */
     public boolean read()
-    throws IOException {
+    throws Exception {
         logger.debug("read()");
         if(filename == "") {
             throw new IOException("Please set filename!");
@@ -119,13 +119,12 @@
 
             }
             catch(Exception e) {
-                e.printStackTrace();
+                throw e;
             }
 
             for(int i = 0; i < map.getLayerCount();i++) {
                 ILayer layer = map.getLayer(i);
                 try {
-                    //TODO Implement wrapper for renderer reader
                     if (layer instanceof FeatureLayer) {
                         FeatureLayerReader lr = new FeatureLayerReader(layer);
                         lr.setUtil(util);
--- a/src/java/de/intevation/mxd/reader/MapReader.java	Thu Jun 16 14:49:45 2011 +0200
+++ b/src/java/de/intevation/mxd/reader/MapReader.java	Thu Jun 16 18:36:48 2011 +0200
@@ -62,71 +62,128 @@
             mapElement = util.createMap();
         }
         catch(Exception e){
-            e.printStackTrace();
-            return;
+            logger.error("Could not create DOM element. Aborting.");
+            throw new IOException("Error creating DOM element.");
         }
 
         //Read map name.
-        mapElement.setAttribute("name", map.getName());
+        try {
+            mapElement.setAttribute("name", map.getName());
+        }
+        catch(IOException ioe) {
+            logger.warn(
+                "Could not read map name." +
+                " Setting map name to \"default-map\"");
+            mapElement.setAttribute("name", "default-map");
+        }
 
         //Read map extent.
-        IEnvelope ext = map.getExtent();
-        mapElement.setAttribute(
-            "extent_max_x",
-            String.valueOf(ext.getXMax()));
-        mapElement.setAttribute(
-            "extent_max_y",
-            String.valueOf(ext.getYMax()));
-        mapElement.setAttribute(
-            "extent_min_x",
-            String.valueOf(ext.getXMin()));
-        mapElement.setAttribute(
-            "extent_min_y",
-            String.valueOf(ext.getYMin()));
+        try {
+            IEnvelope ext = map.getExtent();
+            mapElement.setAttribute(
+                "extent_max_x",
+                String.valueOf(ext.getXMax()));
+            mapElement.setAttribute(
+                "extent_max_y",
+                String.valueOf(ext.getYMax()));
+            mapElement.setAttribute(
+                "extent_min_x",
+                String.valueOf(ext.getXMin()));
+            mapElement.setAttribute(
+                "extent_min_y",
+                String.valueOf(ext.getYMin()));
+        }
+        catch(IOException ioe) {
+            logger.warn("Could not read map extend. Setting to 0, 0, 0, 0.");
+            mapElement.setAttribute("extend_max_x", "0");
+            mapElement.setAttribute("extend_min_x", "0");
+            mapElement.setAttribute("extend_max_y", "0");
+            mapElement.setAttribute("extend_min_y", "0");
+        }
 
         //Read map units.
-        int units = map.getMapUnits();
+        int units = 0;
+        try {
+            units = map.getMapUnits();
+        }
+        catch(IOException ioe) {
+            logger.warn(
+                "Could not read map units." +
+                " Setting map units to unknown.");
+            units = 0;
+        }
+
         String s_units;
         switch(units) {
-            case   3: s_units = "feet"; break;
             case   1: s_units = "inches"; break;
-            case  10: s_units = "kilometers"; break;
-            case   9: s_units = "meters"; break;
+            case   2: s_units = "points"; break;
+            case   3: s_units = "feet"; break;
+            case   4: s_units = "yards"; break;
             case   5: s_units = "miles"; break;
             case   6: s_units = "nauticalmiles"; break;
-            case   2: s_units = "points"; break;
-            default : s_units = "meters"; break;
+            case   7: s_units = "millimeters"; break;
+            case   8: s_units = "centimeters"; break;
+            case   9: s_units = "meters"; break;
+            case  10: s_units = "kilometers"; break;
+            case  11: s_units = "degree"; break;
+            case  12: s_units = "decimeters"; break;
+            case  13: s_units = "units_last"; break;
+            default : s_units = "unknown"; break;
         }
         mapElement.setAttribute("units", s_units);
 
+        if(units == 0) {
+            logger.warn(
+                "Unknown units." +
+                " Please edit units in resulting mapfile.");
+        }
+
         //TODO: Find out whats the correct scale value.
-        mapElement.setAttribute(
-            "scale",
-            String.valueOf(map.getMaxScale()));
+        try {
+            mapElement.setAttribute(
+                "scale",
+                String.valueOf(map.getMaxScale()));
+        }
+        catch(IOException ioe) {
+            logger.warn("Could not read map scale. Setting map scale to 1000");
+            mapElement.setAttribute("scale", "1000");
+        }
 
         //Read the projection.
-        ISpatialReference sr = map.getSpatialReference();
-        if(sr instanceof ProjectedCoordinateSystem) {
-            ProjectedCoordinateSystem pcs = (ProjectedCoordinateSystem)sr;
-            Projection p = (Projection)pcs.getProjection();
-            mapElement.setAttribute("projection", p.getName());
-        }
-        else if(sr instanceof GeographicCoordinateSystem) {
-            GeographicCoordinateSystem gcs = (GeographicCoordinateSystem)sr;
-            mapElement.setAttribute("projection", gcs.getName());
+        try {
+            ISpatialReference sr = map.getSpatialReference();
+            String projection = "";
+            if(sr instanceof ProjectedCoordinateSystem) {
+                ProjectedCoordinateSystem pcs = (ProjectedCoordinateSystem)sr;
+                Projection p = (Projection)pcs.getProjection();
+                projection = p.getName();
+            }
+            else if(sr instanceof GeographicCoordinateSystem) {
+                GeographicCoordinateSystem gcs = (GeographicCoordinateSystem)sr;
+                projection = gcs.getName();
+            }
+            else if(sr instanceof UnknownCoordinateSystem) {
+                UnknownCoordinateSystem ucs = (UnknownCoordinateSystem)sr;
+                projection = ucs.getName();
+            }
+            else{
+                logger.debug(
+                    "Unknown SpatialReference: " +
+                    sr.getClass().toString());
+            }
+
+            if(projection.equals("Unknown")) {
+                logger.warn(
+                    "Unknown projection." +
+                    " Please edit projection in resulting mapfile.");
+            }
+            mapElement.setAttribute("projection", projection);
         }
-        else if(sr instanceof UnknownCoordinateSystem) {
-            UnknownCoordinateSystem ucs = (UnknownCoordinateSystem)sr;
-            if (sr.getName().equals("Unknown")) {
-                mapElement.setAttribute ("projection", "EPSG:31467");
-            }
-            else {
-                mapElement.setAttribute("projection", sr.getName());
-            }
-        }
-        else{
-            throw new IOException("Unknown SpatialReference: " +
-                                  sr.getClass().toString());
+        catch(IOException ioe) {
+            logger.warn(
+                "Could not read map projection." +
+                " Setting map projection to unknown.");
+            mapElement.setAttribute("projection", "Unknown");
         }
     }
 
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)