Mercurial > mxd2map
changeset 133:6b80d2c7536e
Improved broken layer handling.
author | vc11884admin@VC11884.win.bsh.de |
---|---|
date | Tue, 21 Jun 2011 15:22:06 +0200 |
parents | 02df1dbc2166 |
children | acc9e5430177 |
files | ChangeLog src/java/de/intevation/mxd/reader/FeatureLayerReader.java src/java/de/intevation/mxd/reader/MXDReader.java src/java/de/intevation/mxd/utils/MapToXMLUtils.java |
diffstat | 4 files changed, 79 insertions(+), 31 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog Mon Jun 20 17:54:09 2011 +0200 +++ b/ChangeLog Tue Jun 21 15:22:06 2011 +0200 @@ -1,3 +1,14 @@ +2011-06-21 Raimund Renkert <raimund.renkert@intevation.de> + + * src/java/de/intevation/mxd/reader/FeatureLayerReader.java: + Abort layer reading and remove layer element on error. + + * src/java/de/intevation/mxd/reader/MXDReader.java: + Handle empty layer. + + * src/java/de/intevation/mxd/utils/MapToXMLUtils.java: + Added removeLayer method to remove a broken layer from DOM. + 2011-06-20 Raimund Renkert <raimund.renkert@intevation.de> * src/java/de/intevation/mxd/writer/MapscriptWriter.java:
--- a/src/java/de/intevation/mxd/reader/FeatureLayerReader.java Mon Jun 20 17:54:09 2011 +0200 +++ b/src/java/de/intevation/mxd/reader/FeatureLayerReader.java Tue Jun 21 15:22:06 2011 +0200 @@ -11,7 +11,7 @@ import de.intevation.mxd.utils.MapToXMLUtils; import java.io.IOException; - +import com.esri.arcgis.interop.AutomationException; /** * Reads Layer information. * @@ -67,9 +67,7 @@ } catch(Exception e) { logger.error("Failed to create DOM-Element for Layer."); - throw new IOException( - this.getClass()+toString() + - "Error creating dom element"); + return null; } try { @@ -159,29 +157,32 @@ } } catch(IOException ioe) { - logger.warn("Could not read datasource. Stopped reading layer."); - throw new IOException( - this.getClass().toString() + - "Error reading datasource."); + logger.warn( + "Could not read datasource." + + " Stopped reading layer " + layer.getName() + "."); + util.removeLayer(layerElement); + return null; } try { String datatype = layer.getDataSourceType(); - if(datatype.equals("Shapefile Feature Class")) { + if(layer.getWorkspace().getType() == 0) { layerElement.setAttribute("connection_type", "local"); layerElement.setAttribute( "workspace", layer.getWorkspace().getPathName()); } - else if(datatype.equals("File Geodatabase Feature Class")){ + else if(layer.getWorkspace().getType() == 1){ layerElement.setAttribute("connection_type", "ogr"); - layerElement.setAttribute("data", layer.getFeatureClass().getFeatureDataset().getName()); + layerElement.setAttribute( + "data", + layer.getFeatureClass().getFeatureDataset().getName()); layerElement.setAttribute( "workspace", layer.getWorkspace().getPathName()); } - else if(datatype.equals("SDE Feature Class")) { + else if(layer.getWorkspace().getType() == 2) { IPropertySet set = layer.getWorkspace().getConnectionProperties(); Object names[] = new Object[set.getCount()]; Object prop[] = new Object[set.getCount()]; @@ -197,29 +198,39 @@ } } } - layerElement.setAttribute( - "join_table", - layer.getRelationshipClass() - .getOriginClass().getAliasName()); - layerElement.setAttribute( - "join_field", - layer.getRelationshipClass().getOriginPrimaryKey()); - layerElement.setAttribute( - "join_table_target", - layer.getRelationshipClass() - .getDestinationClass().getAliasName()); - layerElement.setAttribute( - "join_field_target", - layer.getRelationshipClass().getOriginForeignKey()); + try { + layerElement.setAttribute( + "join_table", + layer.getRelationshipClass() + .getOriginClass().getAliasName()); + layerElement.setAttribute( + "join_field", + layer.getRelationshipClass().getOriginPrimaryKey()); + layerElement.setAttribute( + "join_table_target", + layer.getRelationshipClass() + .getDestinationClass().getAliasName()); + layerElement.setAttribute( + "join_field_target", + layer.getRelationshipClass().getOriginForeignKey()); + } + catch(AutomationException ioe) { + //Do nothing, cause no jointable defined. + } + catch(IOException ae) { + //Do nothing, cause no jointable defined. + } + catch(NullPointerException npe) { + //Do nothing, cause no jointable defined. + } } } catch(Exception e) { logger.error( "Could not read layer datasource." + - " Stopped reading layer."); - throw new IOException( - this.getClass().toString() + - " Error reading data source."); + " Stopped reading layer " + layer.getName() + "."); + util.removeLayer(layerElement); + return null; } return layerElement; }
--- a/src/java/de/intevation/mxd/reader/MXDReader.java Mon Jun 20 17:54:09 2011 +0200 +++ b/src/java/de/intevation/mxd/reader/MXDReader.java Tue Jun 21 15:22:06 2011 +0200 @@ -129,6 +129,9 @@ FeatureLayerReader lr = new FeatureLayerReader(layer); lr.setUtil(util); Element layerElement = lr.read(); + if (layerElement == null) { + continue; + } IFeatureRenderer renderer = ((FeatureLayer)layer).getRenderer(); IRendererReader rreader; @@ -189,7 +192,7 @@ } catch(Exception e) { invalidLayerCount++; - if(i == 0 && (i + 1) < map.getLayerCount() || + if(i == 0 && (i + 1) == map.getLayerCount() || invalidLayerCount == map.getLayerCount()) { throw new IOException( "No valid layer in MXD file." +
--- a/src/java/de/intevation/mxd/utils/MapToXMLUtils.java Mon Jun 20 17:54:09 2011 +0200 +++ b/src/java/de/intevation/mxd/utils/MapToXMLUtils.java Tue Jun 21 15:22:06 2011 +0200 @@ -12,6 +12,7 @@ import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.NodeList; +import org.w3c.dom.DOMException; /** * Utility class to store map information in a XML structure. @@ -96,6 +97,28 @@ } /** + * Remove a layer element from map. + * @param name The layer name. + */ + public void removeLayer(Element layerElement) { + NodeList list = root.getElementsByTagName("map"); + if(list == null || list.getLength() == 0){ + return; + } + else if(list.getLength() > 1) { + return; + } + else { + try { + list.item(0).removeChild(layerElement); + } + catch(DOMException de) { + return; + } + } + } + + /** * Add a renderer element to the map. * @param layer The parent layer element. * @return The renderer element.