changeset 29:77cfa8092611

Write FeatureLayer attributes to XML document.
author Raimund Renkert <rrenkert@intevation.de>
date Fri, 08 Apr 2011 17:36:22 +0200
parents 0e71a1f71ec0
children c34c450edb06
files ChangeLog src/java/de/intevation/mxd/reader/FeatureLayerReader.java src/java/de/intevation/mxd/reader/MXDReader.java
diffstat 3 files changed, 57 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Fri Apr 08 17:33:04 2011 +0200
+++ b/ChangeLog	Fri Apr 08 17:36:22 2011 +0200
@@ -1,3 +1,11 @@
+2011-04-08  Raimund Renkert <raimund.renkert@intevation.de>
+
+	* src/java/de/intevation/mxd/reader/FeatureLayerReader.java:
+	  Write Attributes to the XML document.
+
+	* src/java/de/intevation/mxd/reader/MXDReader.java: Set XML document to
+	  layer reader and print the document.
+
 2011-04-08  Raimund Renkert <raimund.renkert@intevation.de>
 
 	* build.xml: Added parameter for MXD filename.
--- 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{
--- a/src/java/de/intevation/mxd/reader/MXDReader.java	Fri Apr 08 17:33:04 2011 +0200
+++ b/src/java/de/intevation/mxd/reader/MXDReader.java	Fri Apr 08 17:36:22 2011 +0200
@@ -107,7 +107,8 @@
             for(int i = 0; i < map.getLayerCount();i++){
                 ILayer layer = map.getLayer(i);
                 try{
-                    ILayerReader lr = new FeatureLayerReader(layer);
+                    FeatureLayerReader lr = new FeatureLayerReader(layer);
+                    lr.setDocument(mapInfo);
                     lr.read();
                     if (layer instanceof FeatureLayer){
                         IFeatureRenderer renderer = ((FeatureLayer)layer).getRenderer();
@@ -135,6 +136,7 @@
                     e.printStackTrace();
                 }
             }
+            XMLUtils.toStream(mapInfo, System.out);
         }
         return true;
     }
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)