Mercurial > mxd2map
diff src/java/de/intevation/mxd/reader/GdbRasterCatalogLayerReader.java @ 117:6c3d880db7c5
Improved exception handling for layer reader.
author | Raimund Renkert <rrenkert@intevation.de> |
---|---|
date | Thu, 16 Jun 2011 12:05:34 +0200 |
parents | 59e06c405a9a |
children | 39957898c694 |
line wrap: on
line diff
--- a/src/java/de/intevation/mxd/reader/GdbRasterCatalogLayerReader.java Wed Jun 15 18:37:27 2011 +0200 +++ b/src/java/de/intevation/mxd/reader/GdbRasterCatalogLayerReader.java Thu Jun 16 12:05:34 2011 +0200 @@ -6,7 +6,7 @@ import com.esri.arcgis.carto.GdbRasterCatalogLayer; import org.w3c.dom.Element; - +import java.io.IOException; import de.intevation.mxd.utils.MapToXMLUtils; /** @@ -55,26 +55,77 @@ * * @return The layer XML element. */ - public Element read() - throws Exception { + public Element read() { logger.debug("read()"); - Element layerElement = util.addLayer(); - layerElement.setAttribute("name", layer.getName()); - layerElement.setAttribute("min_scale", - String.valueOf(layer.getMinimumScale())); - layerElement.setAttribute("max_scale", - String.valueOf(layer.getMaximumScale())); - if(layer.isVisible()) { + Element layerElement; + try { + layerElement = util.addLayer(); + } + catch(Exception e) { + logger.error( + "Could not create DOM element for layer." + + "Stopped reading layer."); + return null; + } + + try { + layerElement.setAttribute("name", layer.getName()); + } + catch(IOException ioe) { + logger.warn( + "Could not read layer name. " + + "Setting layer name to \"default\"."); + layerElement.setAttribute("name", "default"); + } + + try { + layerElement.setAttribute("min_scale", + String.valueOf(layer.getMinimumScale())); + } + catch(IOException ioe) { + logger.warn( + "Could not read minimum layer scale." + + "Setting minimum layer scale to 1000"); + layerElement.setAttribute("min_scale", "1000"); + } + + try { + layerElement.setAttribute("max_scale", + String.valueOf(layer.getMaximumScale())); + } + catch(IOException ioe) { + logger.warn( + "Could not read maximum layer scale." + + "Setting maximum layer scale to 1000000"); + layerElement.setAttribute("max_scale", "1000000"); + } + + try { + if(layer.isVisible()) { + layerElement.setAttribute("status", "on"); + } + else { + layerElement.setAttribute("status", "off"); + } + } + catch(IOException ioe) { + logger.warn( + "Could not read layer status." + + " Setting layer status to \"on\""); layerElement.setAttribute("status", "on"); } - else { - layerElement.setAttribute("status", "off"); + + try { + layerElement.setAttribute("definition_query", + layer.getDefinitionExpression()); } - - layerElement.setAttribute("definition_query", - layer.getDefinitionExpression()); - + catch(IOException ioe) { + logger.warn( + "Could not read layer definition query." + + "Setting empty definition query."); + layerElement.setAttribute("definition_query", ""); + } return layerElement; } }