diff src/java/de/intevation/mxd/reader/FeatureLayerReader.java @ 29:77cfa8092611

Write FeatureLayer attributes to XML document.
author Raimund Renkert <rrenkert@intevation.de>
date Fri, 08 Apr 2011 17:36:22 +0200
parents 3e24fffdf2bb
children 40c0b4e5f91a
line wrap: on
line diff
--- a/src/java/de/intevation/mxd/reader/FeatureLayerReader.java	Fri Apr 08 17:33:04 2011 +0200
+++ b/src/java/de/intevation/mxd/reader/FeatureLayerReader.java	Fri Apr 08 17:36:22 2011 +0200
@@ -12,6 +12,13 @@
 import com.esri.arcgis.geometry.Projection;
 import com.esri.arcgis.display.ISymbol;
 import com.esri.arcgis.display.SimpleMarkerSymbol;
+
+import org.w3c.dom.Attr;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
 /**
  * Reads Layer information..
  *
@@ -21,41 +28,59 @@
 
     private static final Logger logger = Logger.getLogger(FeatureLayerReader.class);
 
-    private ILayer layer;
+    private FeatureLayer  layer;
+    private Document document;
 
     //Constructor
-    public FeatureLayerReader(ILayer layer){
-        this.layer = layer;
+    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());
     }
 
     //Methods
     /**
+     * Setter for XML document.
+     */
+    public void setDocument(Document doc){
+        this.document = doc;
+    }
+
+    /**
      * Reads the Layer content.
      */
     public boolean read() throws IOException{
         logger.debug("read()");
-        if(layer instanceof FeatureLayer){
-            FeatureLayer fl = (FeatureLayer)layer;
-            System.out.println("--------------------");
-            System.out.println("Layer information:");
-            System.out.println("Layername\t\t = " + fl.getName());
-            System.out.println("Min-/Maxscale\t = " + fl.getMinimumScale() +
-                               "/" + fl.getMaximumScale());
-            ISymbol symbol = fl.getSelectionSymbol();
-            if(symbol instanceof SimpleMarkerSymbol)
-                System.out.println("Symboltype\t\t = " +
-                                   ((SimpleMarkerSymbol)symbol).getNameString());
+        XMLUtils.ElementCreator creator = new XMLUtils.ElementCreator(document,
+                                                                      "", "");
 
-            System.out.println("Status\t\t = " + fl.isVisible());
-            System.out.println("Definition Query\t = " + fl.getDefinitionExpression());
-            System.out.println("");
-            return true;
+        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!");
         }
         else{
-            System.out.println("Layer type unknown! " + layer.getClass().toString());
+            Node map = list.item(0);
+            map.appendChild(layerElement);
         }
-
-        return false;
+        return true;
     }
 
     public void getLayer() throws IOException{
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)