changeset 31:40c0b4e5f91a

Added utility class to store map attributes.
author Raimund Renkert <rrenkert@intevation.de>
date Mon, 11 Apr 2011 16:04:03 +0200
parents c34c450edb06
children 8381aa59078e
files ChangeLog src/java/de/intevation/mxd/reader/ClassBreakRendererReader.java src/java/de/intevation/mxd/reader/FeatureClassReader.java src/java/de/intevation/mxd/reader/FeatureLayerReader.java src/java/de/intevation/mxd/reader/ILayerReader.java src/java/de/intevation/mxd/reader/IRendererReader.java src/java/de/intevation/mxd/reader/ISymbolReader.java src/java/de/intevation/mxd/reader/MXDReader.java src/java/de/intevation/mxd/reader/MapReader.java src/java/de/intevation/mxd/reader/SimpleMarkerSymbolReader.java src/java/de/intevation/mxd/reader/SimpleRendererReader.java src/java/de/intevation/mxd/reader/UniqueValueRendererReader.java src/java/de/intevation/mxd/utils/MapToXMLUtils.java
diffstat 13 files changed, 511 insertions(+), 197 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Fri Apr 08 17:58:37 2011 +0200
+++ b/ChangeLog	Mon Apr 11 16:04:03 2011 +0200
@@ -1,3 +1,22 @@
+2011-04-11  Raimund Renkert <raimund.renkert@intevation.de>
+
+	* src/java/de/intevation/mxd/reader/ClassBreakRendererReader.java,
+	  src/java/de/intevation/mxd/reader/FeatureClassReader.java,
+	  src/java/de/intevation/mxd/reader/FeatureLayerReader.java,
+	  src/java/de/intevation/mxd/reader/MXDReader.java,
+	  src/java/de/intevation/mxd/reader/MapReader.java,
+	  src/java/de/intevation/mxd/reader/SimpleMarkerSymbolReader.java,
+	  src/java/de/intevation/mxd/reader/SimpleRendererReader.java,
+	  src/java/de/intevation/mxd/reader/UniqueValueRendererReader.java:
+	  Store all attributes in an XML document using the new utility class.
+
+	* src/java/de/intevation/mxd/reader/ILayerReader.java,
+	  src/java/de/intevation/mxd/reader/IRendererReader.java,
+	  src/java/de/intevation/mxd/reader/ISymbolReader.java: Updated interfaces.
+
+	* src/java/de/intevation/mxd/utils/MapToXMLUtils.java: New. Utility class to
+	  store map information in a XML structure.
+
 2011-04-08  Raimund Renkert <raimund.renkert@intevation.de>
 
 	* src/java/de/intevation/mxd/reader/MXDReader.java: Added class reader.
--- a/src/java/de/intevation/mxd/reader/ClassBreakRendererReader.java	Fri Apr 08 17:58:37 2011 +0200
+++ b/src/java/de/intevation/mxd/reader/ClassBreakRendererReader.java	Mon Apr 11 16:04:03 2011 +0200
@@ -7,21 +7,35 @@
 import com.esri.arcgis.carto.IFeatureRenderer;
 import com.esri.arcgis.carto.ClassBreaksRenderer;
 
+import org.w3c.dom.Node;
+import org.w3c.dom.Element;
+import org.w3c.dom.Document;
+import org.w3c.dom.Attr;
+
 /**
  * Reads the ClassBreaksRender Object Attributes.
  *
  * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
  */
-public class ClassBreakRendererReader implements IRendererReader{
+public class ClassBreakRendererReader
+implements IRendererReader {
 
-    //Member
+    /**
+     * The logger.
+     */
     private static final Logger logger =
         Logger.getLogger(ClassBreakRendererReader.class);
 
+    /**
+     * Private member.
+     */
     private ClassBreaksRenderer renderer;
+    private Element layer;
+    private MapToXMLUtils util;
 
-    //Constructor
-    public ClassBreakRendererReader(IFeatureRenderer renderer) throws Exception{
+
+    public ClassBreakRendererReader(IFeatureRenderer renderer)
+    throws Exception {
         logger.debug("contructor()");
         if(renderer instanceof ClassBreaksRenderer)
             this.renderer = (ClassBreaksRenderer)renderer;
@@ -29,28 +43,57 @@
             throw new Exception("Not a ClassBreaksRenderer!");
     }
 
-
-    //Methods
-    public boolean read() throws IOException{
-        logger.debug("read()");
-        System.out.println("--------------------");
-        System.out.println("Renderer information:");
-        System.out.println("Ramp\t\t = " + renderer.getColorRamp());
-        System.out.println("Class count\t\t = " + renderer.getClassCount());
-
-        for(int i = 0; i < renderer.getClassCount(); i++){
-            System.out.println("Class " + i + "\t\t = " + renderer.esri_getClass(i));
-        }
-        System.out.println("Break count\t\t = " + renderer.getBreakCount());
-        for(int i = 0; i < renderer.getBreakCount(); i++){
-            System.out.println("Break " + i + "\t\t = " + renderer.getBreak(i));
-        }
-        System.out.println("");
-        return true;
+    /**
+     * Setter for the parent XML element.
+     *
+     * @param parent The XML parent node.
+     */
+    public void setParent(Element parent) {
+        this.layer = parent;
     }
 
-    public void getRenderer() throws IOException{
-        logger.debug("getRenderer() -> not implemented jet.");
+    /**
+     * Setter for XML document helper.
+     *
+     * @param util The helper class for storing map information.
+     */
+    public void setUtil(MapToXMLUtils util) {
+        this.util = util;
+    }
+
+    /**
+     * Reads the Renderer attributes.
+     *
+     * @return The XML node.
+     */
+    public Element read()
+    throws IOException {
+        logger.debug("read()");
+        Element rendererElement;
+        try {
+            rendererElement = util.addRenderer(layer);
+        }
+        catch(Exception e) {
+            e.printStackTrace();
+            return null;
+        }
+
+        rendererElement.setAttribute("class_count",
+                String.valueOf(renderer.getClassCount()));
+        for(int i = 0; i < renderer.getClassCount(); i++){
+            rendererElement.setAttribute("class_" + i,
+                renderer.esri_getClass(i));
+        }
+
+        rendererElement.setAttribute("break_count",
+            String.valueOf(renderer.getBreakCount()));
+        for(int i = 0; i < renderer.getBreakCount(); i++){
+            rendererElement.setAttribute("break_" + i,
+                String.valueOf(renderer.getBreak(i)));
+        }
+
+        rendererElement.setAttribute("color_ramp", renderer.getColorRamp());
+        return rendererElement;
     }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/src/java/de/intevation/mxd/reader/FeatureClassReader.java	Fri Apr 08 17:58:37 2011 +0200
+++ b/src/java/de/intevation/mxd/reader/FeatureClassReader.java	Mon Apr 11 16:04:03 2011 +0200
@@ -29,7 +29,8 @@
         if(cl instanceof FeatureClass)
             this.fclass = cl;
         else
-            throw new Exception("Not a FeatureClass object!");
+            throw new Exception("Not a FeatureClass object!" +
+                                cl.getClass().toString());
     }
 
     //Methods
@@ -37,6 +38,7 @@
      * Reads the Layer content.
      */
     public boolean read() throws IOException{
+
         logger.debug("read()");
         return false;
     }
--- a/src/java/de/intevation/mxd/reader/FeatureLayerReader.java	Fri Apr 08 17:58:37 2011 +0200
+++ b/src/java/de/intevation/mxd/reader/FeatureLayerReader.java	Mon Apr 11 16:04:03 2011 +0200
@@ -26,66 +26,70 @@
  */
 public class FeatureLayerReader implements ILayerReader{
 
-    private static final Logger logger = Logger.getLogger(FeatureLayerReader.class);
+    /**
+     * The logger.
+     */
+    private static final Logger logger =
+        Logger.getLogger(FeatureLayerReader.class);
 
+    /**
+     * Privte member.
+     */
     private FeatureLayer  layer;
-    private Document document;
+    private MapToXMLUtils util;
 
-    //Constructor
-    public FeatureLayerReader(ILayer layer) throws Exception{
+
+    public FeatureLayerReader(ILayer layer)
+    throws Exception {
         if(layer instanceof FeatureLayer)
             this.layer = (FeatureLayer)layer;
         else
             throw new Exception("Not an instance of FeatureLayer: " +
-                                layer.getClass().toString());
+                layer.getClass().toString());
     }
 
-    //Methods
     /**
-     * Setter for XML document.
+     * Setter for XML document helper.
+     *
+     * @param util The helper for storing map information.
      */
-    public void setDocument(Document doc){
-        this.document = doc;
+    public void setUtil(MapToXMLUtils util){
+        this.util = util;
     }
 
     /**
      * Reads the Layer content.
+     *
+     * @return The layer XML element.
      */
-    public boolean read() throws IOException{
+    public Element read()
+    throws IOException {
         logger.debug("read()");
-        XMLUtils.ElementCreator creator = new XMLUtils.ElementCreator(document,
-                                                                      "", "");
+        Element layerElement;
+        try {
+            layerElement = util.addLayer();
+        }
+        catch(Exception e) {
+            e.printStackTrace();
+            return null;
+        }
 
-        Element layerElement = creator.create("layer");
-        creator.addAttr(layerElement, "name", layer.getName());
-        creator.addAttr(layerElement,
-                        "min_scale",
-                        String.valueOf(layer.getMinimumScale()));
-        creator.addAttr(layerElement,
-                        "max_scale",
-                        String.valueOf(layer.getMaximumScale()));
-        if(layer.isVisible())
-            creator.addAttr(layerElement, "status", "on");
-        else
-            creator.addAttr(layerElement, "status", "off");
-        creator.addAttr(layerElement,
-                        "definition_query",
-                        layer.getDefinitionExpression());
-        NodeList list = document.getElementsByTagName("map");
-        if(list.getLength() > 1){
-            throw new IOException("Error while creating DOM! Found" +
-                                  " more than one map object!");
+        layerElement.setAttribute("name", layer.getName());
+        layerElement.setAttribute("min_scale",
+            String.valueOf(layer.getMinimumScale()));
+        layerElement.setAttribute("max_scale",
+            String.valueOf(layer.getMaximumScale()));
+        if(layer.isVisible()) {
+            layerElement.setAttribute("status", "on");
         }
-        else{
-            Node map = list.item(0);
-            map.appendChild(layerElement);
+        else {
+            layerElement.setAttribute("status", "off");
         }
-        return true;
-    }
 
-    public void getLayer() throws IOException{
-        logger.debug("getLayer() -> not implemented jet.");
-        return;
+        layerElement.setAttribute("definition_query",
+            layer.getDefinitionExpression());
+
+        return layerElement;
     }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/src/java/de/intevation/mxd/reader/ILayerReader.java	Fri Apr 08 17:58:37 2011 +0200
+++ b/src/java/de/intevation/mxd/reader/ILayerReader.java	Mon Apr 11 16:04:03 2011 +0200
@@ -2,6 +2,7 @@
 
 import java.io.IOException;
 
+import org.w3c.dom.Element;
 /**
  * The interface to the layer reader.
  *
@@ -9,8 +10,8 @@
  */
 public interface ILayerReader{
 
-  public boolean read() throws IOException;
-  public void getLayer() throws IOException;
+    void setUtil(MapToXMLUtils util);
+    Element read() throws IOException;
 
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/src/java/de/intevation/mxd/reader/IRendererReader.java	Fri Apr 08 17:58:37 2011 +0200
+++ b/src/java/de/intevation/mxd/reader/IRendererReader.java	Mon Apr 11 16:04:03 2011 +0200
@@ -2,7 +2,7 @@
 
 import java.io.IOException;
 
-import com.esri.arcgis.carto.IFeatureRenderer;
+import org.w3c.dom.Element;
 
 /**
  * The interface to the renderer reader.
@@ -11,8 +11,10 @@
  */
 public interface IRendererReader{
 
-    public boolean read() throws IOException;
-    public void getRenderer() throws IOException;
+    Element read() throws IOException;
+
+    void setParent(Element parent);
+    void setUtil(MapToXMLUtils util);
 
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/src/java/de/intevation/mxd/reader/ISymbolReader.java	Fri Apr 08 17:58:37 2011 +0200
+++ b/src/java/de/intevation/mxd/reader/ISymbolReader.java	Mon Apr 11 16:04:03 2011 +0200
@@ -2,6 +2,8 @@
 
 import java.io.IOException;
 
+import org.w3c.dom.Element;
+
 /**
  * The interface to the symbol reader.
  *
@@ -9,8 +11,10 @@
  */
 public interface ISymbolReader{
 
-  public boolean read() throws IOException;
-  public void getSymbol() throws IOException;
+    Element read() throws IOException;
+
+    void setParent(Element parent);
+    void setUtil(MapToXMLUtils util);
 
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/src/java/de/intevation/mxd/reader/MXDReader.java	Fri Apr 08 17:58:37 2011 +0200
+++ b/src/java/de/intevation/mxd/reader/MXDReader.java	Mon Apr 11 16:04:03 2011 +0200
@@ -36,7 +36,6 @@
     private String filename = "";
     private ArcGISInitializer initializer = null;
     private IMap map;
-    private Document mapInfo;
 
     private static final Logger logger = Logger.getLogger(MXDReader.class);
 
@@ -44,7 +43,6 @@
     public MXDReader() throws IOException{
         logger.debug("constructor()");
         initializer = new ArcGISInitializer();
-        mapInfo = XMLUtils.newDocument();
     }
 
 
@@ -102,31 +100,35 @@
         else{
             openMapDocument();
             MapReader mreader = new MapReader (map);
-            mreader.setDocument(mapInfo);
+            MapToXMLUtils util = new MapToXMLUtils();
+            mreader.setUtil(util);
             mreader.read();
 
             for(int i = 0; i < map.getLayerCount();i++){
                 ILayer layer = map.getLayer(i);
                 try{
                     FeatureLayerReader lr = new FeatureLayerReader(layer);
-                    lr.setDocument(mapInfo);
-                    lr.read();
+                    lr.setUtil(util);
+                    Element layerElement = lr.read();
                     if (layer instanceof FeatureLayer){
-                        IFeatureClass fc = ((FeatureLayer)layer).getFeatureClass();
-                        IClassReader creader = new FeatureClassReader(fc);
-
                         IFeatureRenderer renderer = ((FeatureLayer)layer).getRenderer();
                         IRendererReader rreader;
                         if(renderer instanceof SimpleRenderer){
                             rreader = new SimpleRendererReader(renderer);
+                            rreader.setParent(layerElement);
+                            rreader.setUtil(util);
                             rreader.read();
                         }
                         else if(renderer instanceof ClassBreaksRenderer){
                             rreader = new ClassBreakRendererReader(renderer);
+                            rreader.setParent(layerElement);
+                            rreader.setUtil(util);
                             rreader.read();
                         }
                         else if(renderer instanceof UniqueValueRenderer){
                             rreader = new UniqueValueRendererReader(renderer);
+                            rreader.setParent(layerElement);
+                            rreader.setUtil(util);
                             rreader.read();
                         }
                         else{
@@ -140,18 +142,15 @@
                     e.printStackTrace();
                 }
             }
-            XMLUtils.toStream(mapInfo, System.out);
+            util.print();
         }
         return true;
     }
 
 
-    /**
-     * Get the mapinformation as DOM document. TODO: implement me!
-     */
     public Document getMapDocument(){
         logger.debug("getMapDocument()");
-        return mapInfo;
+        return null;
     }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/src/java/de/intevation/mxd/reader/MapReader.java	Fri Apr 08 17:58:37 2011 +0200
+++ b/src/java/de/intevation/mxd/reader/MapReader.java	Mon Apr 11 16:04:03 2011 +0200
@@ -9,6 +9,7 @@
 import com.esri.arcgis.geometry.ISpatialReference;
 import com.esri.arcgis.geometry.ProjectedCoordinateSystem;
 import com.esri.arcgis.geometry.GeographicCoordinateSystem;
+import com.esri.arcgis.geometry.UnknownCoordinateSystem;
 import com.esri.arcgis.geometry.IProjection;
 import com.esri.arcgis.geometry.Projection;
 
@@ -24,7 +25,7 @@
 
     //Member
     private IMap map;
-    private Document document;
+    private MapToXMLUtils util;
 
     private static final Logger logger = Logger.getLogger(MapReader.class);
 
@@ -42,32 +43,42 @@
      */
     public void read() throws IOException{
         logger.debug("read()");
-        if(document == null)
+        if(util == null)
             throw new IOException("Can not write to document.");
 
-        XMLUtils.ElementCreator creator = new XMLUtils.ElementCreator(document,
-                                                                      "", "");
-        Element mapElement = creator.create("map");
+//        XMLUtils.ElementCreator creator = new XMLUtils.ElementCreator(document,
+//                                                                      "", "");
+        Element mapElement;
+        try{
+            mapElement = util.createMap();
+        }
+        catch(Exception e){
+            e.printStackTrace();
+            return;
+        }
         ISpatialReference sr = map.getSpatialReference();
         logger.debug("Instance: " + sr.getClass().toString());
         if(sr instanceof ProjectedCoordinateSystem){
             ProjectedCoordinateSystem pcs = (ProjectedCoordinateSystem)sr;
             Projection p = (Projection)pcs.getProjection();
-            creator.addAttr(mapElement, "projection", p.getName());
+            mapElement.setAttribute("projection", p.getName());
         }
         else if(sr instanceof GeographicCoordinateSystem){
             GeographicCoordinateSystem gcs = (GeographicCoordinateSystem)sr;
-            creator.addAttr(mapElement, "projection", gcs.getName());
+            mapElement.setAttribute("projection", gcs.getName());
+        }
+        else if(sr instanceof UnknownCoordinateSystem) {
+            UnknownCoordinateSystem ucs = (UnknownCoordinateSystem)sr;
+            mapElement.setAttribute("projection", sr.getName());
         }
         else{
             throw new IOException("Unknown SpatialReference: " +
                                   sr.getClass().toString());
         }
-        document.appendChild(mapElement);
     }
 
-    public void setDocument(Document doc){
-        this.document = doc;
+    public void setUtil(MapToXMLUtils util){
+        this.util = util;
     }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/src/java/de/intevation/mxd/reader/SimpleMarkerSymbolReader.java	Fri Apr 08 17:58:37 2011 +0200
+++ b/src/java/de/intevation/mxd/reader/SimpleMarkerSymbolReader.java	Mon Apr 11 16:04:03 2011 +0200
@@ -10,6 +10,8 @@
 import com.esri.arcgis.display.IRgbColor;
 import com.esri.arcgis.display.RgbColor;
 
+import org.w3c.dom.Element;
+
 /**
  * Reads simple marker symbol information.
  *
@@ -17,12 +19,20 @@
  */
 public class SimpleMarkerSymbolReader implements ISymbolReader{
 
-    //Member
-    private static final Logger logger = Logger.getLogger(SimpleMarkerSymbolReader.class);
+    /**
+     * The logger.
+     */
+    private static final Logger logger =
+        Logger.getLogger(SimpleMarkerSymbolReader.class);
 
+    /**
+     * Private member.
+     */
+    private Element renderer;
     private SimpleMarkerSymbol symbol;
+    private MapToXMLUtils util;
 
-    //Constructor
+
     public SimpleMarkerSymbolReader(ISymbol symbol) throws Exception{
         logger.debug("contructor()");
         if(symbol instanceof SimpleMarkerSymbol)
@@ -31,50 +41,79 @@
             throw new Exception("Not a SimpleMarkerSymbol!");
     }
 
+    /**
+     * Setter for the parent XML element.
+     *
+     * @param parent The XML parent node.
+     */
+    public void setParent(Element parent) {
+        this.renderer = parent;
+    }
 
-    //Methods
-    public boolean read() throws IOException{
+    /**
+     * Setter for XML document helper.
+     *
+     * @param util The helper class for storing map information.
+     */
+    public void setUtil(MapToXMLUtils util) {
+        this.util = util;
+    }
+
+    /**
+     * Reads the symbol attributes.
+     *
+     * @return The XML node.
+     */
+    public Element read()
+    throws IOException {
         logger.debug("read()");
-        System.out.println("--------------------");
-        System.out.println("Symbol information:");
-        System.out.println("Name\t\t = " + symbol.getNameString());
+        Element symbolElement;
+        try {
+            symbolElement = util.addSymbol(renderer);
+        }
+        catch(Exception e) {
+            e.printStackTrace();
+            return null;
+        }
 
+        symbolElement.setAttribute("name", symbol.getNameString());
         if(symbol.getStyle() == esriSimpleMarkerStyle.esriSMSCircle)
-            System.out.println("Style\t\t = Point");
-        if(symbol.getColor() instanceof IRgbColor){
+            symbolElement.setAttribute("style", "point");
+
+        if(symbol.getColor() instanceof IRgbColor) {
             IRgbColor color = (IRgbColor)symbol.getColor();
-            System.out.println("Color\t\t = (" + color.getRed() + 
-                               "," + color.getGreen() +
-                               "," + color.getBlue() + ")");
-            System.out.println("Transparency\t = " + color.getTransparency());
+            symbolElement.setAttribute("color",  "(" + color.getRed() +
+                "," + color.getGreen() +
+                "," + color.getBlue() + ")");
+            symbolElement.setAttribute("transparency",
+                String.valueOf(color.getTransparency()));
         }
-        else{
+        else {
+            System.out.println("Color type unknown! " +
+                symbol.getColor().getClass().toString());
+        }
+
+        symbolElement.setAttribute("size", String.valueOf(symbol.getSize()));
+        symbolElement.setAttribute("outline_size",
+            String.valueOf(symbol.getOutlineSize()));
+        if(symbol.getOutlineColor() instanceof IRgbColor) {
+            IRgbColor color = (IRgbColor)symbol.getOutlineColor();
+            symbolElement.setAttribute("outline_color",  "(" + color.getRed() +
+                "," + color.getGreen() +
+                "," + color.getBlue() + ")");
+            symbolElement.setAttribute("outline_transparency",
+                String.valueOf(color.getTransparency()));
+        }
+        else {
             System.out.println("Color type unknown! " +
                                symbol.getColor().getClass().toString());
         }
-        if(symbol.getOutlineColor() instanceof RgbColor){
-            RgbColor color = (RgbColor)symbol.getOutlineColor();
-            System.out.println("Outlinecolor\t = (" + color.getRed() +
-                               "," + color.getGreen() +
-                               "," + color.getBlue() + ")");
-            System.out.println("Transparency\t = " + color.getTransparency());
-        }
-        else{
-            System.out.println("Color type unknown! " +
-                               symbol.getOutlineColor().getClass().toString());
-        }
 
-        System.out.println("Size\t\t = " + symbol.getSize());
-        System.out.println("OutlineSize\t\t = " + symbol.getOutlineSize());
-        System.out.println("Angle\t\t = " + symbol.getAngle());
-        System.out.println("Offset\t\t = " + symbol.getXOffset() +
-                           "," + symbol.getYOffset());
-        System.out.println("");
-        return true;
-    }
+        symbolElement.setAttribute("angle", String.valueOf(symbol.getAngle()));
+        symbolElement.setAttribute("offset",
+            symbol.getXOffset() + "," + symbol.getYOffset());
 
-    public void getSymbol() throws IOException{
-        logger.debug("getSymbol() -> not implemented jet.");
+        return symbolElement;
     }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/src/java/de/intevation/mxd/reader/SimpleRendererReader.java	Fri Apr 08 17:58:37 2011 +0200
+++ b/src/java/de/intevation/mxd/reader/SimpleRendererReader.java	Mon Apr 11 16:04:03 2011 +0200
@@ -9,49 +9,91 @@
 import com.esri.arcgis.carto.SimpleRenderer;
 import com.esri.arcgis.display.SimpleMarkerSymbol;
 
+import org.w3c.dom.Element;
+
 /**
  * Reads simple renderer information.
  *
  * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
  */
-public class SimpleRendererReader implements IRendererReader{
+public class SimpleRendererReader
+implements IRendererReader {
 
-    //Member
+    /**
+     * The logger.
+     */
+    private static final Logger logger =
+        Logger.getLogger(FeatureLayerReader.class);
+
+    /**
+     * Private member.
+     */
     private ISymbol symbol;
-    private IFeatureRenderer renderer;
-    private static final Logger logger = Logger.getLogger(FeatureLayerReader.class);
-
-    //Constructor
-    public SimpleRendererReader(IFeatureRenderer renderer){
-        this.renderer = renderer;
-    }
+    private SimpleRenderer renderer;
+    private Element layer;
+    private MapToXMLUtils util;
 
 
-    //Methods
-    public boolean read() throws IOException{
-        logger.debug("read()");
-        if(renderer instanceof SimpleRenderer){
-            SimpleRenderer sr = (SimpleRenderer)renderer;
-            System.out.println("--------------------");
-            System.out.println("Renderer inforamtion:");
-            System.out.println("Label\t\t = " + sr.getLabel());
-            System.out.println("Description\t\t = " + sr.getDescription());
-            System.out.println("");
-            symbol = sr.getSymbol();
-            try{
-                ISymbolReader isr= new SimpleMarkerSymbolReader(symbol);
-                isr.read();
-                return true;
-            }
-            catch(Exception e){
-                e.printStackTrace();
-            }
+    public SimpleRendererReader(IFeatureRenderer renderer)
+    throws Exception {
+        logger.debug("constructor()");
+        if(renderer instanceof SimpleRenderer) {
+            this.renderer = (SimpleRenderer)renderer;
         }
-        return false;
+        else{
+            throw new Exception ("Not an instance of SimpleRenderer!");
+        }
     }
 
-    public void getRenderer() throws IOException{
-        logger.debug("getRenderer() -> not implemented jet.");
+    /**
+     * Setter for the parent XML element.
+     *
+     * @param parent The XML parent node.
+     */
+    public void setParent(Element parent) {
+        this.layer = parent;
+    }
+
+    /**
+     * Setter for the XML document helper.
+     *
+     * @param util The helper class for storing map information.
+     */
+    public void setUtil(MapToXMLUtils util) {
+        this.util = util;
+    }
+
+    /**
+     * Reads the renderer attributes.
+     *
+     * @return The XML node.
+     */
+    public Element read()
+    throws IOException {
+        logger.debug("read()");
+        Element rendererElement;
+        try {
+            rendererElement = util.addRenderer(layer);
+        }
+        catch(Exception e) {
+            e.printStackTrace();
+            return null;
+        }
+
+        rendererElement.setAttribute("label", renderer.getLabel());
+        rendererElement.setAttribute("description", renderer.getDescription());
+        symbol = renderer.getSymbol();
+        try{
+            ISymbolReader isr= new SimpleMarkerSymbolReader(symbol);
+            isr.setParent(rendererElement);
+            isr.setUtil(util);
+            isr.read();
+            return rendererElement;
+        }
+        catch(Exception e){
+            e.printStackTrace();
+        }
+        return rendererElement;
     }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/src/java/de/intevation/mxd/reader/UniqueValueRendererReader.java	Fri Apr 08 17:58:37 2011 +0200
+++ b/src/java/de/intevation/mxd/reader/UniqueValueRendererReader.java	Mon Apr 11 16:04:03 2011 +0200
@@ -8,54 +8,98 @@
 import com.esri.arcgis.display.ISymbol;
 import com.esri.arcgis.carto.UniqueValueRenderer;
 
+import org.w3c.dom.Element;
+
 /**
  * Reads unique vaule renderer information.
  *
  * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
  */
-public class UniqueValueRendererReader implements IRendererReader{
+public class UniqueValueRendererReader
+implements IRendererReader {
 
-    //Member
-    private ISymbol symbol;
-    private IFeatureRenderer renderer;
-    private static final Logger logger = Logger.getLogger(FeatureLayerReader.class);
+    /**
+     * The logger.
+     */
+    private static final Logger logger =
+        Logger.getLogger(FeatureLayerReader.class);
 
-    //Constructor
-    public UniqueValueRendererReader(IFeatureRenderer renderer){
-        this.renderer = renderer;
-    }
+    /**
+     * Private Member.
+     */
+    private UniqueValueRenderer renderer;
+    private Element layer;
+    private MapToXMLUtils util;
 
 
-    //Methods
-    public boolean read() throws IOException{
-        logger.debug("read()");
-        if(renderer instanceof UniqueValueRenderer){
-            UniqueValueRenderer sr = (UniqueValueRenderer)renderer;
-            System.out.println("--------------------");
-            System.out.println("Renderer inforamtion:");
-            System.out.println("Value count\t\t = " + sr.getValueCount());
-            for(int i = 0; i < sr.getValueCount(); i++){
-                String val = sr.getValue(i);
-                System.out.println("Value\t\t = " + val);
-                System.out.println("Label\t\t = " + sr.getLabel(val));
-                System.out.println("Description\t\t = " + sr.getDescription(val));
-            }
-            System.out.println("");
-            symbol = sr.getDefaultSymbol();
-            try{
-                ISymbolReader isr= new SimpleMarkerSymbolReader(symbol);
-                isr.read();
-                return true;
-            }
-            catch(Exception e){
-                e.printStackTrace();
-            }
+    public UniqueValueRendererReader(IFeatureRenderer renderer)
+    throws Exception {
+        logger.debug("constructor()");
+        if (renderer instanceof UniqueValueRenderer) {
+            this.renderer = (UniqueValueRenderer)renderer;
         }
-        return false;
+        else {
+            throw new Exception ("Not an instance of UniqueValueRenderer.");
+        }
     }
 
-    public void getRenderer() throws IOException{
-        logger.debug("getRenderer() -> not implemented jet.");
+    /**
+     * Setter for the parent XML element.
+     *
+     * @param parent The XML parent node.
+     */
+    public void setParent(Element parent) {
+        this.layer = parent;
+    }
+
+    /**
+     * Setter for XML document helper.
+     *
+     * @param util The helper class for storing map information.
+     */
+    public void setUtil(MapToXMLUtils util) {
+        this.util = util;
+    }
+
+    /**
+     * Reads the renderer attributes.
+     *
+     * @return The parent XML node.
+     */
+    public Element read()
+    throws IOException {
+        logger.debug("read()");
+        for(int i = 0; i < renderer.getClassCount() - 1; i++) {
+            Element rendererElement;
+            try {
+                rendererElement = util.addRenderer(layer);
+            }
+            catch(Exception e) {
+                e.printStackTrace();
+                return null;
+            }
+            String value = renderer.getValue(i);
+            rendererElement.setAttribute("name", renderer.esri_getClass(i));
+            rendererElement.setAttribute("description",
+                renderer.getDescription(value));
+            rendererElement.setAttribute("value", value);
+            rendererElement.setAttribute("label", renderer.getLabel(value));
+
+            ISymbol symbol = renderer.getSymbol(value);
+            ISymbolReader symbolReader;
+            try {
+                 symbolReader = new SimpleMarkerSymbolReader(symbol);
+            }
+            catch(Exception e) {
+                e.printStackTrace();
+                return null;
+            }
+            symbolReader.setUtil(util);
+            symbolReader.setParent(rendererElement);
+            symbolReader.read ();
+
+        }
+        return layer;
     }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/java/de/intevation/mxd/utils/MapToXMLUtils.java	Mon Apr 11 16:04:03 2011 +0200
@@ -0,0 +1,104 @@
+/*
+ * Copyright (c) 2010 by Intevation GmbH
+ *
+ * This program is free software under the LGPL (>=v2.1)
+ * Read the file LGPL.txt coming with the software for details
+ * or visit http://www.gnu.org/licenses/ if it does not exist.
+ */
+package de.intevation.mxd.utils;
+
+import org.apache.log4j.Logger;
+
+import org.w3c.dom.Attr;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+
+/**
+ * Utility class to store map information in a XML structure.
+ *
+ * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
+ */
+public class MapToXMLUtils
+{
+    private Document root;
+    private XMLUtils.ElementCreator creator;
+
+    public MapToXMLUtils() {
+        this.root = XMLUtils.newDocument();
+        creator = new XMLUtils.ElementCreator(root, "", "");
+    }
+
+    /**
+     * Create the top level map element.
+     *
+     * @return The new map element.
+     */
+    public Element createMap()
+    throws Exception {
+        Element map;
+        NodeList list = root.getElementsByTagName("map");
+        if(list == null || list.getLength() == 0){
+            map = creator.create("map");
+            root.appendChild(map);
+        }
+        else if(list.getLength() == 1){
+            map = (Element)list.item(0);
+        }
+        else{
+            throw new Exception("Error while creating map node.");
+        }
+        return map;
+    }
+
+    /**
+     * Add a layer element to the map.
+     * @param name The layer name.
+     * @return The layer element.
+     */
+    public Element addLayer()
+    throws Exception {
+        Element node = creator.create("layer");
+        NodeList list = root.getElementsByTagName("map");
+        if(list == null || list.getLength() == 0){
+            throw new Exception("No map node found!");
+        }
+        else if(list.getLength() > 1) {
+            throw new Exception("Found more than one map node." +
+                                " This should never happen!");
+        }
+        else {
+            list.item(0).appendChild(node);
+            return node;
+        }
+    }
+
+    /**
+     * Add a renderer element to the map.
+     * @param layer The parent layer element.
+     * @return The renderer element.
+     */
+    public Element addRenderer(Element layer) {
+        Element node = creator.create("renderer");
+        layer.appendChild(node);
+        return node;
+    }
+
+    /**
+     * Add a symbol element to the map.
+     * @param renderer The parent renderer element.
+     * @return The symbol element.
+     */
+    public Element addSymbol(Element renderer) {
+        Element node = creator.create("symbol");
+        renderer.appendChild(node);
+        return node;
+    }
+
+    /**
+     * Print out the XML document.
+     */
+    public void print() {
+        XMLUtils.toStream(root, System.out);
+    }
+}
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)