rrenkert@33: package de.intevation.mxd.reader; rrenkert@25: rrenkert@25: import java.io.IOException; rrenkert@25: rrenkert@25: import org.apache.log4j.Logger; rrenkert@25: rrenkert@25: import com.esri.arcgis.carto.ILayer; rrenkert@25: import com.esri.arcgis.carto.IMap; rrenkert@25: import com.esri.arcgis.carto.MapDocument; rrenkert@25: import com.esri.arcgis.carto.FeatureLayer; rrenkert@36: import com.esri.arcgis.carto.GdbRasterCatalogLayer; rrenkert@25: import com.esri.arcgis.carto.IFeatureRenderer; rrenkert@25: import com.esri.arcgis.carto.SimpleRenderer; rrenkert@25: import com.esri.arcgis.carto.ClassBreaksRenderer; rrenkert@25: import com.esri.arcgis.carto.UniqueValueRenderer; rrenkert@25: rrenkert@27: import org.w3c.dom.Document; rrenkert@27: import org.w3c.dom.Element; rrenkert@27: rrenkert@33: import de.intevation.mxd.ArcGISInitializer; rrenkert@33: import de.intevation.mxd.utils.MapToXMLUtils; rrenkert@33: rrenkert@25: /** rrenkert@25: * The MXD file reader. rrenkert@25: * rrenkert@25: * @author Raimund Renkert rrenkert@25: */ rrenkert@25: public class MXDReader implements IReader { rrenkert@25: rrenkert@25: //Member rrenkert@25: private String filename = ""; rrenkert@25: private ArcGISInitializer initializer = null; rrenkert@25: private IMap map; rrenkert@25: rrenkert@25: private static final Logger logger = Logger.getLogger(MXDReader.class); rrenkert@25: rrenkert@25: //Constructor rrenkert@25: public MXDReader() throws IOException{ rrenkert@25: logger.debug("constructor()"); rrenkert@25: initializer = new ArcGISInitializer(); rrenkert@25: } rrenkert@25: rrenkert@25: rrenkert@25: //Methods rrenkert@25: rrenkert@25: /** rrenkert@25: * Initialize the ArcGIS Objects. rrenkert@25: */ rrenkert@25: public boolean init() throws IOException{ rrenkert@25: logger.debug("init()"); rrenkert@25: initializer.initArcGIS(); rrenkert@25: initializer.initArcGISLicenses(); rrenkert@25: return true; rrenkert@25: } rrenkert@25: rrenkert@25: /** rrenkert@25: * Shutdown the ArcGIS Objects. rrenkert@25: */ rrenkert@25: public boolean shutdown() throws IOException{ rrenkert@25: logger.debug("shutdown()"); rrenkert@25: if(initializer == null){ rrenkert@25: throw new IOException("Faild to shutdown!"); rrenkert@25: } rrenkert@25: else{ rrenkert@25: initializer.shutdownArcGIS(); rrenkert@25: return true; rrenkert@25: } rrenkert@25: } rrenkert@25: rrenkert@25: /** rrenkert@25: * Set the path and filename to the MXD-File. rrenkert@25: */ rrenkert@25: public void setFilename(String name){ rrenkert@25: logger.debug("setFilename()"); rrenkert@25: filename = name; rrenkert@25: } rrenkert@25: rrenkert@27: rrenkert@27: private void openMapDocument() throws IOException{ rrenkert@27: MapDocument m = new MapDocument(); rrenkert@27: if(!m.isMapDocument(filename)){ rrenkert@27: throw new IOException(filename + " is not a map!"); rrenkert@27: } rrenkert@27: m.open(filename, null); rrenkert@27: map = m.getMap(0); rrenkert@27: } rrenkert@25: /** rrenkert@25: * Read the MXD file content. rrenkert@25: */ rrenkert@25: public boolean read() throws IOException{ rrenkert@25: logger.debug("read()"); rrenkert@25: if(filename == ""){ rrenkert@25: throw new IOException("Please set filename!"); rrenkert@25: } rrenkert@25: else{ rrenkert@27: openMapDocument(); rrenkert@25: MapReader mreader = new MapReader (map); rrenkert@31: MapToXMLUtils util = new MapToXMLUtils(); rrenkert@31: mreader.setUtil(util); rrenkert@25: mreader.read(); rrenkert@27: rrenkert@25: for(int i = 0; i < map.getLayerCount();i++){ rrenkert@27: ILayer layer = map.getLayer(i); rrenkert@27: try{ rrenkert@27: if (layer instanceof FeatureLayer){ rrenkert@36: FeatureLayerReader lr = new FeatureLayerReader(layer); rrenkert@36: lr.setUtil(util); rrenkert@36: Element layerElement = lr.read(); rrenkert@27: IFeatureRenderer renderer = ((FeatureLayer)layer).getRenderer(); rrenkert@27: IRendererReader rreader; rrenkert@25: if(renderer instanceof SimpleRenderer){ rrenkert@25: rreader = new SimpleRendererReader(renderer); rrenkert@31: rreader.setParent(layerElement); rrenkert@31: rreader.setUtil(util); rrenkert@25: rreader.read(); rrenkert@25: } rrenkert@25: else if(renderer instanceof ClassBreaksRenderer){ rrenkert@25: rreader = new ClassBreakRendererReader(renderer); rrenkert@31: rreader.setParent(layerElement); rrenkert@31: rreader.setUtil(util); rrenkert@25: rreader.read(); rrenkert@25: } rrenkert@25: else if(renderer instanceof UniqueValueRenderer){ rrenkert@25: rreader = new UniqueValueRendererReader(renderer); rrenkert@31: rreader.setParent(layerElement); rrenkert@31: rreader.setUtil(util); rrenkert@25: rreader.read(); rrenkert@25: } rrenkert@25: else{ rrenkert@25: System.out.println("No known renderer!"); rrenkert@25: System.out.println("Implement new renderer for " + rrenkert@25: renderer.getClass().toString()); rrenkert@25: } rrenkert@25: } rrenkert@36: else if(layer instanceof GdbRasterCatalogLayer) { rrenkert@36: GdbRasterCatalogLayerReader gclr = rrenkert@36: new GdbRasterCatalogLayerReader(layer); rrenkert@36: gclr.setUtil(util); rrenkert@36: Element layerElement = gclr.read(); rrenkert@36: IFeatureRenderer renderer = ((GdbRasterCatalogLayer)layer).getRenderer(); rrenkert@36: IRendererReader rreader; rrenkert@36: if(renderer instanceof SimpleRenderer){ rrenkert@36: rreader = new SimpleRendererReader(renderer); rrenkert@36: rreader.setParent(layerElement); rrenkert@36: rreader.setUtil(util); rrenkert@36: rreader.read(); rrenkert@36: } rrenkert@36: else if(renderer instanceof ClassBreaksRenderer){ rrenkert@36: rreader = new ClassBreakRendererReader(renderer); rrenkert@36: rreader.setParent(layerElement); rrenkert@36: rreader.setUtil(util); rrenkert@36: rreader.read(); rrenkert@36: } rrenkert@36: else if(renderer instanceof UniqueValueRenderer){ rrenkert@36: rreader = new UniqueValueRendererReader(renderer); rrenkert@36: rreader.setParent(layerElement); rrenkert@36: rreader.setUtil(util); rrenkert@36: rreader.read(); rrenkert@36: } rrenkert@36: else{ rrenkert@36: System.out.println("No known renderer!"); rrenkert@36: System.out.println("Implement new renderer for " + rrenkert@36: renderer.getClass().toString()); rrenkert@36: } rrenkert@36: } rrenkert@27: } rrenkert@27: catch(Exception e){ rrenkert@27: e.printStackTrace(); rrenkert@25: } rrenkert@25: } rrenkert@31: util.print(); rrenkert@25: } rrenkert@25: return true; rrenkert@25: } rrenkert@25: rrenkert@27: rrenkert@27: public Document getMapDocument(){ rrenkert@27: logger.debug("getMapDocument()"); rrenkert@31: return null; rrenkert@25: } rrenkert@25: } rrenkert@25: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :