Mercurial > mxd2map
changeset 43:ef7ca23c4233
Added comments, done some code styling and removed typos.
author | Raimund Renkert <rrenkert@intevation.de> |
---|---|
date | Fri, 15 Apr 2011 15:44:54 +0200 |
parents | 395307e8b7ee |
children | 9b5fb5e5914d |
files | ChangeLog src/java/de/intevation/mxd/ArcGISInitializer.java src/java/de/intevation/mxd/Converter.java src/java/de/intevation/mxd/reader/FeatureClassReader.java src/java/de/intevation/mxd/reader/FeatureLayerReader.java src/java/de/intevation/mxd/reader/GdbRasterCatalogLayerReader.java src/java/de/intevation/mxd/reader/MXDReader.java src/java/de/intevation/mxd/reader/MapReader.java src/java/de/intevation/mxd/reader/SimpleFillSymbolReader.java src/java/de/intevation/mxd/reader/SimpleMarkerSymbolReader.java src/java/de/intevation/mxd/reader/SimpleRendererReader.java src/java/de/intevation/mxd/utils/MapToXMLUtils.java src/java/de/intevation/mxd/writer/IWriter.java src/java/de/intevation/mxd/writer/MapScriptWriter.java |
diffstat | 14 files changed, 215 insertions(+), 105 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog Fri Apr 15 14:14:49 2011 +0200 +++ b/ChangeLog Fri Apr 15 15:44:54 2011 +0200 @@ -1,3 +1,20 @@ +2011-04-15 Raimund Renkert <raimund.renkert@intevation.de> + + * src/java/de/intevation/mxd/ArcGISInitializer.java, + src/java/de/intevation/mxd/Converter.java, + src/java/de/intevation/mxd/reader/FeatureClassReader.java, + src/java/de/intevation/mxd/reader/FeatureLayerReader.java + src/java/de/intevation/mxd/reader/GdbRasterCatalogLayerReader.java, + src/java/de/intevation/mxd/reader/MXDReader.java, + src/java/de/intevation/mxd/reader/MapReader.java, + src/java/de/intevation/mxd/reader/SimpleFillSymbolReader.java, + src/java/de/intevation/mxd/reader/SimpleMarkerSymbolReader.java, + src/java/de/intevation/mxd/reader/SimpleRendererReader.java, + src/java/de/intevation/mxd/utils/MapToXMLUtils.java, + src/java/de/intevation/mxd/writer/IWriter.java, + src/java/de/intevation/mxd/writer/MapScriptWriter.java: + Added comments, done some code styling and removed typos. + 2011-04-15 Raimund Renkert <raimund.renkert@intevation.de> * src/java/de/intevation/mxd/reader/FeatureLayerReader.java:
--- a/src/java/de/intevation/mxd/ArcGISInitializer.java Fri Apr 15 14:14:49 2011 +0200 +++ b/src/java/de/intevation/mxd/ArcGISInitializer.java Fri Apr 15 15:44:54 2011 +0200 @@ -12,18 +12,20 @@ * * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> */ -public class ArcGISInitializer{ +public class ArcGISInitializer { - //Member + /** + * Private member. + */ private AoInitialize aoInit; private String engineInstallDir = ""; - //Methods /** * Init ArcGIS Java Objects. */ - public boolean initArcGIS () throws IOException{ + public boolean initArcGIS () + throws IOException { EngineInitializer.initializeEngine(); aoInit = new AoInitialize(); engineInstallDir = System.getenv("AGSENGINEJAVA"); @@ -33,21 +35,23 @@ /** * Init ArcGIS License. */ - public void initArcGISLicenses() throws IOException{ + public void initArcGISLicenses() + throws IOException { if(aoInit.isProductCodeAvailable (esriLicenseProductCode.esriLicenseProductCodeEngine) == - esriLicenseStatus.esriLicenseAvailable){ + esriLicenseStatus.esriLicenseAvailable) { aoInit.initialize (esriLicenseProductCode.esriLicenseProductCodeEngine); } else if (aoInit.isProductCodeAvailable (esriLicenseProductCode.esriLicenseProductCodeArcView) == - esriLicenseStatus.esriLicenseAvailable){ + esriLicenseStatus.esriLicenseAvailable) { aoInit.initialize (esriLicenseProductCode.esriLicenseProductCodeArcView); } - else{ - System.err.println("Engine Runtime or ArcView license not initialized."); + else { + System.err.println("Engine Runtime or ArcView" + + " license not initialized."); System.err.println("Exiting application."); System.exit(-1); } @@ -56,12 +60,13 @@ /** * Shutdown the ArcGIS Objects. */ - public boolean shutdownArcGIS() throws IOException{ - if(aoInit != null){ + public boolean shutdownArcGIS() + throws IOException { + if(aoInit != null) { aoInit.shutdown(); return true; } - else{ + else { return false; } } @@ -69,10 +74,13 @@ /** * Get the ArcGIS Engine Directory. */ - public String getEngineDirectory() throws Exception{ - if(engineInstallDir == "") + public String getEngineDirectory() + throws Exception { + if(engineInstallDir == "") { throw new Exception("Call initArcGIS() first!"); - else + } + else { return engineInstallDir; + } } }
--- a/src/java/de/intevation/mxd/Converter.java Fri Apr 15 14:14:49 2011 +0200 +++ b/src/java/de/intevation/mxd/Converter.java Fri Apr 15 15:44:54 2011 +0200 @@ -84,7 +84,7 @@ writer.write(reader.getMapDocument()); reader.shutdown(); } - catch(IOException e){ + catch(IOException e) { e.printStackTrace(); } }
--- a/src/java/de/intevation/mxd/reader/FeatureClassReader.java Fri Apr 15 14:14:49 2011 +0200 +++ b/src/java/de/intevation/mxd/reader/FeatureClassReader.java Fri Apr 15 15:44:54 2011 +0200 @@ -14,33 +14,46 @@ * * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> */ -public class FeatureClassReader implements IClassReader{ - - private static final Logger logger = Logger.getLogger(FeatureClassReader.class); - - private IClass fclass; +public class FeatureClassReader +implements IClassReader { + /** + * The Logger. + */ + private static final Logger logger = + Logger.getLogger(FeatureClassReader.class); + + /** + * Private member. + */ + private IClass fclass; private Node parent; - //Constructor - public FeatureClassReader(IClass cl) throws Exception{ - if(cl instanceof FeatureClass) + + + public FeatureClassReader(IClass cl) + throws Exception { + if(cl instanceof FeatureClass) { this.fclass = cl; - else + } + else { throw new Exception("Not a FeatureClass object!" + cl.getClass().toString()); + } } - //Methods /** * Reads the Layer content. + * + * @return Currently always false. */ - public boolean read() throws IOException{ - - logger.debug("read()"); + public boolean read() + throws IOException { + logger.debug("read() -> not implemented jet."); return false; } - public void getClassDoc() throws IOException{ + public void getClassDoc() + throws IOException { logger.debug("getLayer() -> not implemented jet."); return; }
--- a/src/java/de/intevation/mxd/reader/FeatureLayerReader.java Fri Apr 15 14:14:49 2011 +0200 +++ b/src/java/de/intevation/mxd/reader/FeatureLayerReader.java Fri Apr 15 15:44:54 2011 +0200 @@ -14,11 +14,12 @@ import de.intevation.mxd.utils.MapToXMLUtils; /** - * Reads Layer information.. + * Reads Layer information. * * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> */ -public class FeatureLayerReader implements ILayerReader{ +public class FeatureLayerReader +implements ILayerReader { /** * The logger. @@ -35,11 +36,13 @@ public FeatureLayerReader(ILayer layer) throws Exception { - if(layer instanceof FeatureLayer) + if(layer instanceof FeatureLayer) { this.layer = (FeatureLayer)layer; - else + } + else { throw new Exception("Not an instance of FeatureLayer: " + layer.getClass().toString()); + } } /** @@ -47,7 +50,7 @@ * * @param util The helper for storing map information. */ - public void setUtil(MapToXMLUtils util){ + public void setUtil(MapToXMLUtils util) { this.util = util; }
--- a/src/java/de/intevation/mxd/reader/GdbRasterCatalogLayerReader.java Fri Apr 15 14:14:49 2011 +0200 +++ b/src/java/de/intevation/mxd/reader/GdbRasterCatalogLayerReader.java Fri Apr 15 15:44:54 2011 +0200 @@ -12,11 +12,12 @@ import de.intevation.mxd.utils.MapToXMLUtils; /** - * Reads Layer information.. + * Reads Layer information. * * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> */ -public class GdbRasterCatalogLayerReader implements ILayerReader{ +public class GdbRasterCatalogLayerReader +implements ILayerReader { /** * The logger. @@ -33,11 +34,13 @@ public GdbRasterCatalogLayerReader(ILayer layer) throws Exception { - if(layer instanceof GdbRasterCatalogLayer) + if(layer instanceof GdbRasterCatalogLayer) { this.layer = (GdbRasterCatalogLayer)layer; - else + } + else { throw new Exception("Not an instance of GdbRastaCatalogLayer: " + layer.getClass().toString()); + } } /** @@ -45,7 +48,7 @@ * * @param util The helper for storing map information. */ - public void setUtil(MapToXMLUtils util){ + public void setUtil(MapToXMLUtils util) { this.util = util; }
--- a/src/java/de/intevation/mxd/reader/MXDReader.java Fri Apr 15 14:14:49 2011 +0200 +++ b/src/java/de/intevation/mxd/reader/MXDReader.java Fri Apr 15 15:44:54 2011 +0200 @@ -25,30 +25,35 @@ * * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> */ -public class MXDReader implements IReader { +public class MXDReader +implements IReader { + /** + * The Logger. + */ + private static final Logger logger = Logger.getLogger(MXDReader.class); - //Member + /** + * Private member. + */ private String filename = ""; private ArcGISInitializer initializer = null; private MapToXMLUtils util; private IMap map; - private static final Logger logger = Logger.getLogger(MXDReader.class); - //Constructor - public MXDReader() throws IOException{ + public MXDReader() + throws IOException { logger.debug("constructor()"); initializer = new ArcGISInitializer(); util = new MapToXMLUtils(); } - //Methods - /** * Initialize the ArcGIS Objects. */ - public boolean init() throws IOException{ + public boolean init() + throws IOException { logger.debug("init()"); initializer.initArcGIS(); initializer.initArcGISLicenses(); @@ -58,12 +63,13 @@ /** * Shutdown the ArcGIS Objects. */ - public boolean shutdown() throws IOException{ + public boolean shutdown() + throws IOException { logger.debug("shutdown()"); - if(initializer == null){ + if(initializer == null) { throw new IOException("Faild to shutdown!"); } - else{ + else { initializer.shutdownArcGIS(); return true; } @@ -72,29 +78,32 @@ /** * Set the path and filename to the MXD-File. */ - public void setFilename(String name){ + public void setFilename(String name) { logger.debug("setFilename()"); filename = name; } - private void openMapDocument() throws IOException{ + private void openMapDocument() + throws IOException { MapDocument m = new MapDocument(); - if(!m.isMapDocument(filename)){ + if(!m.isMapDocument(filename)) { throw new IOException(filename + " is not a map!"); } m.open(filename, null); map = m.getMap(0); } + /** * Read the MXD file content. */ - public boolean read() throws IOException{ + public boolean read() + throws IOException { logger.debug("read()"); - if(filename == ""){ + if(filename == "") { throw new IOException("Please set filename!"); } - else{ + else { util.addFilename(filename); openMapDocument(); MapReader mreader; @@ -108,28 +117,29 @@ e.printStackTrace(); } - for(int i = 0; i < map.getLayerCount();i++){ + for(int i = 0; i < map.getLayerCount();i++) { ILayer layer = map.getLayer(i); - try{ - if (layer instanceof FeatureLayer){ + try { + if (layer instanceof FeatureLayer) { FeatureLayerReader lr = new FeatureLayerReader(layer); lr.setUtil(util); Element layerElement = lr.read(); - IFeatureRenderer renderer = ((FeatureLayer)layer).getRenderer(); + IFeatureRenderer renderer = + ((FeatureLayer)layer).getRenderer(); IRendererReader rreader; - if(renderer instanceof SimpleRenderer){ + if(renderer instanceof SimpleRenderer) { rreader = new SimpleRendererReader(renderer); rreader.setParent(layerElement); rreader.setUtil(util); rreader.read(); } - else if(renderer instanceof ClassBreaksRenderer){ + else if(renderer instanceof ClassBreaksRenderer) { rreader = new ClassBreakRendererReader(renderer); rreader.setParent(layerElement); rreader.setUtil(util); rreader.read(); } - else if(renderer instanceof UniqueValueRenderer){ + else if(renderer instanceof UniqueValueRenderer) { rreader = new UniqueValueRendererReader(renderer); rreader.setParent(layerElement); rreader.setUtil(util); @@ -146,34 +156,35 @@ new GdbRasterCatalogLayerReader(layer); gclr.setUtil(util); Element layerElement = gclr.read(); - IFeatureRenderer renderer = ((GdbRasterCatalogLayer)layer).getRenderer(); + IFeatureRenderer renderer = + ((GdbRasterCatalogLayer)layer).getRenderer(); IRendererReader rreader; - if(renderer instanceof SimpleRenderer){ + if(renderer instanceof SimpleRenderer) { rreader = new SimpleRendererReader(renderer); rreader.setParent(layerElement); rreader.setUtil(util); rreader.read(); } - else if(renderer instanceof ClassBreaksRenderer){ + else if(renderer instanceof ClassBreaksRenderer) { rreader = new ClassBreakRendererReader(renderer); rreader.setParent(layerElement); rreader.setUtil(util); rreader.read(); } - else if(renderer instanceof UniqueValueRenderer){ + else if(renderer instanceof UniqueValueRenderer) { rreader = new UniqueValueRendererReader(renderer); rreader.setParent(layerElement); rreader.setUtil(util); rreader.read(); } - else{ + else { System.out.println("No known renderer!"); System.out.println("Implement new renderer for " + renderer.getClass().toString()); } } } - catch(Exception e){ + catch(Exception e) { e.printStackTrace(); } } @@ -182,8 +193,10 @@ return true; } - - public Document getMapDocument(){ + /** + * Get the root DOM document. + */ + public Document getMapDocument() { logger.debug("getMapDocument()"); return util.getDocument(); }
--- a/src/java/de/intevation/mxd/reader/MapReader.java Fri Apr 15 14:14:49 2011 +0200 +++ b/src/java/de/intevation/mxd/reader/MapReader.java Fri Apr 15 15:44:54 2011 +0200 @@ -22,15 +22,19 @@ * * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> */ -public class MapReader{ +public class MapReader { + /** + * The Logger. + */ + private static final Logger logger = Logger.getLogger(MapReader.class); - //Member + /** + * Private member. + */ private Map map; private MapToXMLUtils util; - private static final Logger logger = Logger.getLogger(MapReader.class); - //Constructor public MapReader(IMap map) throws Exception { logger.debug("constructor()"); @@ -42,16 +46,15 @@ } } - - //Methods - /** * Reads the Map attributes. */ - public void read() throws IOException{ + public void read() + throws IOException { logger.debug("read()"); - if(util == null) + if(util == null) { throw new IOException("Can not write to document."); + } //Create XML Element for map. Element mapElement; @@ -103,12 +106,12 @@ //Read the projection. ISpatialReference sr = map.getSpatialReference(); - if(sr instanceof ProjectedCoordinateSystem){ + if(sr instanceof ProjectedCoordinateSystem) { ProjectedCoordinateSystem pcs = (ProjectedCoordinateSystem)sr; Projection p = (Projection)pcs.getProjection(); mapElement.setAttribute("projection", p.getName()); } - else if(sr instanceof GeographicCoordinateSystem){ + else if(sr instanceof GeographicCoordinateSystem) { GeographicCoordinateSystem gcs = (GeographicCoordinateSystem)sr; mapElement.setAttribute("projection", gcs.getName()); } @@ -122,7 +125,10 @@ } } - public void setUtil(MapToXMLUtils util){ + /** + * Set the utilities. + */ + public void setUtil(MapToXMLUtils util) { this.util = util; } }
--- a/src/java/de/intevation/mxd/reader/SimpleFillSymbolReader.java Fri Apr 15 14:14:49 2011 +0200 +++ b/src/java/de/intevation/mxd/reader/SimpleFillSymbolReader.java Fri Apr 15 15:44:54 2011 +0200 @@ -19,7 +19,8 @@ * * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> */ -public class SimpleFillSymbolReader implements ISymbolReader{ +public class SimpleFillSymbolReader +implements ISymbolReader { /** * The logger. @@ -37,10 +38,12 @@ public SimpleFillSymbolReader(ISymbol symbol) throws Exception{ logger.debug("contructor()"); - if(symbol instanceof SimpleFillSymbol) + if(symbol instanceof SimpleFillSymbol) { this.symbol = (SimpleFillSymbol)symbol; - else + } + else { throw new Exception("Not a SimpleFillSymbol!"); + } } /** @@ -79,8 +82,9 @@ } symbolElement.setAttribute("name", symbol.getNameString()); - if(symbol.getStyle() == esriSimpleMarkerStyle.esriSMSCircle) + if(symbol.getStyle() == esriSimpleMarkerStyle.esriSMSCircle) { symbolElement.setAttribute("style", "point"); + } if(symbol.getColor() instanceof IRgbColor) { IRgbColor color = (IRgbColor)symbol.getColor();
--- a/src/java/de/intevation/mxd/reader/SimpleMarkerSymbolReader.java Fri Apr 15 14:14:49 2011 +0200 +++ b/src/java/de/intevation/mxd/reader/SimpleMarkerSymbolReader.java Fri Apr 15 15:44:54 2011 +0200 @@ -36,12 +36,15 @@ private MapToXMLUtils util; - public SimpleMarkerSymbolReader(ISymbol symbol) throws Exception{ + public SimpleMarkerSymbolReader(ISymbol symbol) + throws Exception { logger.debug("contructor()"); - if(symbol instanceof SimpleMarkerSymbol) + if(symbol instanceof SimpleMarkerSymbol) { this.symbol = (SimpleMarkerSymbol)symbol; - else + } + else { throw new Exception("Not a SimpleMarkerSymbol!"); + } } /**
--- a/src/java/de/intevation/mxd/reader/SimpleRendererReader.java Fri Apr 15 14:14:49 2011 +0200 +++ b/src/java/de/intevation/mxd/reader/SimpleRendererReader.java Fri Apr 15 15:44:54 2011 +0200 @@ -86,7 +86,7 @@ rendererElement.setAttribute("label", renderer.getLabel()); rendererElement.setAttribute("description", renderer.getDescription()); symbol = renderer.getSymbol(); - try{ + try { if(symbol instanceof SimpleMarkerSymbol){ ISymbolReader isr= new SimpleMarkerSymbolReader(symbol); isr.setParent(rendererElement); @@ -101,7 +101,7 @@ } return rendererElement; } - catch(Exception e){ + catch(Exception e) { e.printStackTrace(); } return rendererElement;
--- a/src/java/de/intevation/mxd/utils/MapToXMLUtils.java Fri Apr 15 14:14:49 2011 +0200 +++ b/src/java/de/intevation/mxd/utils/MapToXMLUtils.java Fri Apr 15 15:44:54 2011 +0200 @@ -20,10 +20,19 @@ */ public class MapToXMLUtils { + /** + * The logger. + */ + private static final Logger logger = Logger.getLogger(MapToXMLUtils.class); + + /** + * Private member. + */ private Document root; private Element rootElement; private XMLUtils.ElementCreator creator; + public MapToXMLUtils() { this.root = XMLUtils.newDocument(); creator = new XMLUtils.ElementCreator(root, "", ""); @@ -31,6 +40,11 @@ root.appendChild(rootElement); } + /** + * Add the mxd filename to the dom. + * @param path Path to the mxdfile. + * @return Currently always true. + */ public boolean addFilename(String path) { Element file = creator.create("file"); file.setAttribute("name", path); @@ -40,7 +54,6 @@ /** * Create the top level map element. - * * @return The new map element. */ public Element createMap() @@ -111,6 +124,10 @@ XMLUtils.toStream(root, System.out); } + /** + * Get the DOM document. + * @return The root document. + */ public Document getDocument() { return root; }
--- a/src/java/de/intevation/mxd/writer/IWriter.java Fri Apr 15 14:14:49 2011 +0200 +++ b/src/java/de/intevation/mxd/writer/IWriter.java Fri Apr 15 15:44:54 2011 +0200 @@ -5,13 +5,13 @@ import org.w3c.dom.Document; /** - * The interface to the MXD-Reader. + * The interface to the mapfile writer. * * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> */ public interface IWriter { /** - * write the content. + * Write the content. */ boolean write(Document doc) throws IOException; }
--- a/src/java/de/intevation/mxd/writer/MapScriptWriter.java Fri Apr 15 14:14:49 2011 +0200 +++ b/src/java/de/intevation/mxd/writer/MapScriptWriter.java Fri Apr 15 15:44:54 2011 +0200 @@ -26,17 +26,25 @@ import de.intevation.mxd.utils.XMLUtils; /** - * The MXD file reader. + * The Mapfile Writer. + * This Writer uses the MapScript Java API to create Mapfiles from a DOM. * * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> */ public class MapScriptWriter implements IWriter { + /** + * The Logger. + */ + private static final Logger logger = Logger.getLogger(MapScriptWriter.class); + + /** + * Private member. + */ private Document root; private mapObj map; - private static final Logger logger = Logger.getLogger(MapScriptWriter.class); public MapScriptWriter() { map = new mapObj(""); @@ -46,6 +54,12 @@ map = new mapObj(path); } + /** + * Write the mapfile. + * @param doc The root document containin the map attributes. + * + * @return Currently always true. + */ public boolean write(Document doc) { logger.debug("write()"); this.root = doc; @@ -69,6 +83,9 @@ return true; } + /** + * Create the map object and set the attributes. + */ private void writeMap() { logger.debug("writeMap()"); //Get the map. @@ -126,6 +143,9 @@ //map.setScaledenom(Double.parseDouble(mapNode.getAttribute("scale"))); } + /** + * Create layer objects and set the attributes. + */ private void writeLayer() { logger.debug("writeLayer()"); Element mapNode = (Element)XMLUtils.xpath( @@ -194,7 +214,7 @@ } /** - * Adds teh symbols and styles to the mapfile. + * Adds the symbols and styles to the mapfile. * @param co Mapscript class object. * @param classElement Dom element containing the style and symbol * attributes. @@ -220,7 +240,8 @@ col.getBlue(), -4); style.setColor(color); - style.setSize(Double.parseDouble(symbolElement.getAttribute("size"))); + style.setSize(Double.parseDouble( + symbolElement.getAttribute("size"))); Color oCol = Color.decode( symbolElement.getAttribute("outline_color")); colorObj outlineColor = new colorObj( @@ -229,11 +250,13 @@ oCol.getBlue(), -4); style.setOutlinecolor(outlineColor); - style.setOutlinewidth( - Double.parseDouble(symbolElement.getAttribute("outline_size"))); - style.setSymbolByName(map, symbolElement.getAttribute("name")); + style.setOutlinewidth(Double.parseDouble( + symbolElement.getAttribute("outline_size"))); - symbolObj sym = symbolSet.getSymbolByName(symbolElement.getAttribute("name")); + String name = symbolElement.getAttribute("name"); + style.setSymbolByName(map, name); + symbolObj sym = symbolSet.getSymbolByName(name); + String symType = symbolElement.getAttribute("style"); if(symType.equals("point")) { lineObj points = new lineObj(); @@ -248,7 +271,7 @@ /** * Save the symbol set. - * @param + * @param symbols The symbol set. */ private void saveSymbolSet(symbolSetObj symbols) { Element fileNode = (Element)XMLUtils.xpath(