vc11884admin@148: package de.intevation.mxd.reader; vc11884admin@148: vc11884admin@148: import java.io.IOException; vc11884admin@148: vc11884admin@148: import org.apache.log4j.Logger; vc11884admin@148: vc11884admin@148: import com.esri.arcgis.carto.ILayer; vc11884admin@148: import com.esri.arcgis.carto.FeatureLayer; vc11884admin@148: import com.esri.arcgis.carto.GdbRasterCatalogLayer; vc11884admin@148: import com.esri.arcgis.carto.IFeatureRenderer; vc11884admin@148: import com.esri.arcgis.carto.SimpleRenderer; vc11884admin@148: import com.esri.arcgis.carto.ClassBreaksRenderer; vc11884admin@148: import com.esri.arcgis.carto.UniqueValueRenderer; vc11884admin@148: import com.esri.arcgis.carto.GroupLayer; vc11884admin@148: vc11884admin@148: import org.w3c.dom.Document; vc11884admin@148: import org.w3c.dom.Element; vc11884admin@148: vc11884admin@148: import de.intevation.mxd.ArcGISInitializer; vc11884admin@148: import de.intevation.mxd.utils.MapToXMLUtils; vc11884admin@148: vc11884admin@148: vc11884admin@148: /** vc11884admin@148: * Reads Layer information. vc11884admin@148: * vc11884admin@148: * @author Raimund Renkert vc11884admin@148: */ vc11884admin@148: public class GroupLayerReader vc11884admin@148: implements ILayerReader { vc11884admin@148: vc11884admin@148: /** vc11884admin@148: * The logger. vc11884admin@148: */ vc11884admin@148: private static final Logger logger = vc11884admin@148: Logger.getLogger(FeatureLayerReader.class); vc11884admin@148: vc11884admin@148: /** vc11884admin@148: * Privte member. vc11884admin@148: */ vc11884admin@148: private GroupLayer layer; vc11884admin@148: private MapToXMLUtils util; vc11884admin@148: private int invalidLayerCount; vc11884admin@148: vc11884admin@148: public GroupLayerReader(ILayer layer) vc11884admin@148: throws Exception { vc11884admin@148: if(layer instanceof GroupLayer) { vc11884admin@148: this.layer = (GroupLayer)layer; vc11884admin@148: invalidLayerCount = 0; vc11884admin@148: } vc11884admin@148: else { vc11884admin@148: throw new Exception("Not an instance of GroupLayer: " + vc11884admin@148: layer.getClass().toString()); vc11884admin@148: } vc11884admin@148: } vc11884admin@148: vc11884admin@148: /** vc11884admin@148: * Setter for XML document helper. vc11884admin@148: * vc11884admin@148: * @param util The helper for storing map information. vc11884admin@148: */ vc11884admin@148: public void setUtil(MapToXMLUtils util) { vc11884admin@148: this.util = util; vc11884admin@148: } vc11884admin@148: vc11884admin@148: /** vc11884admin@148: * Reads the Layer content. vc11884admin@148: * vc11884admin@148: * @return The layer XML element. vc11884admin@148: */ vc11884admin@148: public Element read() vc11884admin@148: throws IOException{ vc11884admin@148: logger.debug("read()"); rrenkert@180: Element layerElement = null; vc11884admin@148: for(int i = 0; i < layer.getCount();i++) { vc11884admin@148: ILayer lay = layer.getLayer(i); vc11884admin@148: try { vc11884admin@148: if (lay instanceof FeatureLayer) { vc11884admin@148: FeatureLayerReader lr = new FeatureLayerReader(lay); vc11884admin@148: lr.setUtil(util); vc11884admin@148: layerElement = lr.read(); vc11884admin@148: if (layerElement == null) { vc11884admin@148: continue; vc11884admin@148: } rrenkert@180: layerElement.setAttribute("group", layer.getName()); vc11884admin@148: IFeatureRenderer renderer = vc11884admin@148: ((FeatureLayer)lay).getRenderer(); vc11884admin@148: IRendererReader rreader; vc11884admin@148: if(renderer instanceof SimpleRenderer) { vc11884admin@148: rreader = new SimpleRendererReader(renderer); vc11884admin@148: rreader.setParent(layerElement); vc11884admin@148: rreader.setUtil(util); vc11884admin@148: rreader.read(); vc11884admin@148: } vc11884admin@148: else if(renderer instanceof ClassBreaksRenderer) { vc11884admin@148: rreader = new ClassBreakRendererReader(renderer); vc11884admin@148: rreader.setParent(layerElement); vc11884admin@148: rreader.setUtil(util); vc11884admin@148: rreader.read(); vc11884admin@148: } vc11884admin@148: else if(renderer instanceof UniqueValueRenderer) { vc11884admin@148: rreader = new UniqueValueRendererReader(renderer); vc11884admin@148: rreader.setParent(layerElement); vc11884admin@148: rreader.setUtil(util); vc11884admin@148: rreader.read(); vc11884admin@148: } vc11884admin@148: else{ vc11884admin@148: logger.debug("Not a known renderer type " + vc11884admin@148: renderer.getClass().toString()); vc11884admin@148: } vc11884admin@148: } vc11884admin@148: else if(lay instanceof GdbRasterCatalogLayer) { vc11884admin@148: GdbRasterCatalogLayerReader gclr = vc11884admin@148: new GdbRasterCatalogLayerReader(lay); vc11884admin@148: gclr.setUtil(util); vc11884admin@148: layerElement = gclr.read(); rrenkert@180: layerElement.setAttribute("group", layer.getName()); vc11884admin@148: IFeatureRenderer renderer = vc11884admin@148: ((GdbRasterCatalogLayer)lay).getRenderer(); vc11884admin@148: IRendererReader rreader; vc11884admin@148: if(renderer instanceof SimpleRenderer) { vc11884admin@148: rreader = new SimpleRendererReader(renderer); vc11884admin@148: rreader.setParent(layerElement); vc11884admin@148: rreader.setUtil(util); vc11884admin@148: rreader.read(); vc11884admin@148: } vc11884admin@148: else if(renderer instanceof ClassBreaksRenderer) { vc11884admin@148: rreader = new ClassBreakRendererReader(renderer); vc11884admin@148: rreader.setParent(layerElement); vc11884admin@148: rreader.setUtil(util); vc11884admin@148: rreader.read(); vc11884admin@148: } vc11884admin@148: else if(renderer instanceof UniqueValueRenderer) { vc11884admin@148: rreader = new UniqueValueRendererReader(renderer); vc11884admin@148: rreader.setParent(layerElement); vc11884admin@148: rreader.setUtil(util); vc11884admin@148: rreader.read(); vc11884admin@148: } vc11884admin@148: else { vc11884admin@148: logger.debug("Not a known renderer type " + vc11884admin@148: renderer.getClass().toString()); vc11884admin@148: } vc11884admin@148: } rrenkert@180: } rrenkert@180: catch(Exception e) { rrenkert@180: invalidLayerCount++; vc11884admin@148: if(i == 0 && (i + 1) == layer.getCount() || vc11884admin@148: invalidLayerCount == layer.getCount()) { vc11884admin@148: throw new IOException( vc11884admin@148: "No valid layer in MXD file." + vc11884admin@148: " Aborting."); vc11884admin@148: } rrenkert@180: } rrenkert@180: } rrenkert@180: return layerElement; vc11884admin@148: } vc11884admin@148: } vc11884admin@148: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :