diff src/java/de/intevation/mxd/reader/FeatureLayerReader.java @ 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 77cfa8092611
children c51376f8e24c
line wrap: on
line diff
--- 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 :
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)