changeset 244:276f63c86f1c

Refactored group layer handling and "wms_title" metadata.
author raimund renkert <raimund.renkert@intevation.de>
date Tue, 09 Aug 2011 17:27:18 +0200
parents df4e0946ef02
children 2eeeae07aaa2
files ChangeLog src/java/de/intevation/mxd/reader/GroupLayerReader.java src/java/de/intevation/mxd/reader/MXDReader.java src/java/de/intevation/mxd/writer/MapScriptWriter.java
diffstat 4 files changed, 79 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Tue Aug 09 14:24:51 2011 +0200
+++ b/ChangeLog	Tue Aug 09 17:27:18 2011 +0200
@@ -1,3 +1,16 @@
+2011-08-09  Raimund Renkert  <raimund.renkert@intevation.de>
+
+	* src/java/de/intevation/mxd/reader/MXDReader.java:
+	  Added parameter for group layer reader.
+
+	* src/java/de/intevation/mxd/reader/GroupLayerReader.java:
+	  Read Grouplayer recursively and set the groupname as "/"-separated
+	  string.
+
+	* src/java/de/intevation/mxd/writer/MapScriptWriter.java:
+	  Removed GROUP tag. Added group names to the "wms_title" metadata.
+	  Added method to remove special chars from layer names.
+
 2011-08-09  Raimund Renkert  <raimund.renkert@intevation.de>
 
 	* src/java/de/intevation/mxd/ArcGISInitializer.java,
--- a/src/java/de/intevation/mxd/reader/GroupLayerReader.java	Tue Aug 09 14:24:51 2011 +0200
+++ b/src/java/de/intevation/mxd/reader/GroupLayerReader.java	Tue Aug 09 17:27:18 2011 +0200
@@ -44,8 +44,7 @@
  *
  * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
  */
-public class GroupLayerReader
-implements ILayerReader {
+public class GroupLayerReader {
 
     /**
      * The logger.
@@ -91,7 +90,7 @@
      *
      * @return The layer XML element.
      */
-    public Element read()
+    public Element read(String group)
     throws IOException{
         logger.debug("read()");
         Element layerElement = null;
@@ -105,7 +104,7 @@
                     if (layerElement == null) {
                         continue;
                     }
-                    layerElement.setAttribute("group", layer.getName());
+                    layerElement.setAttribute("group", group + "/" + layer.getName());
                     IFeatureRenderer renderer =
                         ((FeatureLayer)lay).getRenderer();
                     IRendererReader rreader;
@@ -164,6 +163,11 @@
                                      renderer.getClass().toString());
                     }
                 }
+                else if(lay instanceof GroupLayer) {
+                    GroupLayerReader glr = new GroupLayerReader (lay);
+                    glr.setUtil(this.util);
+                    layerElement = glr.read("/" + layer.getName());
+                }
             }
             catch(Exception e) {
                 invalidLayerCount++;
--- a/src/java/de/intevation/mxd/reader/MXDReader.java	Tue Aug 09 14:24:51 2011 +0200
+++ b/src/java/de/intevation/mxd/reader/MXDReader.java	Tue Aug 09 17:27:18 2011 +0200
@@ -219,7 +219,7 @@
                     else if(layer instanceof GroupLayer) {
                         GroupLayerReader gl = new GroupLayerReader(layer);
                         gl.setUtil(util);
-                        Element layerElement = gl.read();
+                        Element layerElement = gl.read("");
                         if(layerElement == null) {
                             throw new IOException ("Error reading grouplayer.");
                         }
--- a/src/java/de/intevation/mxd/writer/MapScriptWriter.java	Tue Aug 09 14:24:51 2011 +0200
+++ b/src/java/de/intevation/mxd/writer/MapScriptWriter.java	Tue Aug 09 17:27:18 2011 +0200
@@ -221,18 +221,29 @@
 	    String group = "";
             if(layerElement.hasAttribute("group")) {
 		group = layerElement.getAttribute("group");
-		group = validateString(group);
-		group = group.replaceAll (" ", "");
-                layer.setGroup(group);
-		group = group + ".";
+		String[] splitted = group.split("/");
+		String cleangroup = "";
+		for(int j = 0; j < splitted.length; j++) {
+		    if(!splitted[j].equals("")) {
+		        cleangroup += "/" + validateLayerName(splitted[j]);
+		    }
+		}
+		group = cleangroup;
             }
 	    String lname = layerElement.getAttribute("name");
-            lname = lname.replaceAll(" ", "");
-	    lname = group + lname;
-            layer.setName(validateString(lname));
+	    lname = validateLayerName(lname);
+	    String ulname = group.replaceAll("/", ".") + "." + lname;
+	    if(ulname.startsWith(".")) {
+	        ulname = ulname.substring(1);
+	    }
+            layer.setName(ulname);
             layer.setUnits(units.swigValue());
-            layer.setMetaData("wms_title", validateString(lname));
-
+	    if(!group.equals("")) {
+                layer.setMetaData("wms_title", group + "/" + lname);
+	    }
+	    else {
+	    	layer.setMetaData("wms_title", lname);
+	    }
 
             //The layer status.
             String stat = layerElement.getAttribute("status");
@@ -630,11 +641,46 @@
         tmp = tmp.replace ("ä", "ae");
         tmp = tmp.replace ("ü", "ue");
         tmp = tmp.replace ("ß", "ss");
-	tmp = tmp.replace ("/", "");
-	tmp = tmp.replace (",", "");
 	if(!s.equals(tmp)) {
 	    logger.info("Renamed \"" + s + "\" to \"" + tmp + "\".");
 	}
         return tmp;
     }
+
+
+    /**
+     * Replaces special characters and removes leading and trailing whitespaces.
+     *
+     * @param s String
+     *
+     * @return the input string without special chars.
+     */
+    private String validateLayerName (String s) {
+    	if(s.equals("")) {
+	    return "";
+	}
+
+	String tmp = s.trim();
+	tmp = tmp.replace(" ", "");
+	tmp = tmp.replace("/", "");
+	tmp = tmp.replace(",", "");
+	tmp = tmp.replace("#", "");
+	tmp = tmp.replace("+", "");
+	tmp = tmp.replace("~", "");
+	tmp = tmp.replace("(", "");
+	tmp = tmp.replace(")", "");
+	tmp = tmp.replace("{", "");
+	tmp = tmp.replace("}", "");
+	tmp = tmp.replace("[", "");
+	tmp = tmp.replace("]", "");
+	tmp = tmp.replace("<", "");
+	tmp = tmp.replace(">", "");
+	tmp = tmp.replace("*", "");
+	tmp = tmp.replace("\\\\", "");
+	tmp = tmp.replace("^", "");
+	if(!s.equals(tmp)) {
+	    logger.info("Renamed \"" + s +"\" to \"" + tmp +"\".");
+	}
+	return tmp;
+    }
 }
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)