[MXD2map-commits] r244:276f63c86f1c

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Tue Aug 9 17:51:03 CEST 2011


details:   http://hg.intevation.org/geospatial/mxd2map/rev/276f63c86f1c

changeset: 244:276f63c86f1c

user:      raimund renkert <raimund.renkert at intevation.de>

date:      Tue Aug 09 17:27:18 2011 +0200

description:
Refactored group layer handling and "wms_title" metadata.


diffstat:

 ChangeLog                                               |  13 +++
 src/java/de/intevation/mxd/reader/GroupLayerReader.java |  12 ++-
 src/java/de/intevation/mxd/reader/MXDReader.java        |   2 +-
 src/java/de/intevation/mxd/writer/MapScriptWriter.java  |  68 ++++++++++++++--
 4 files changed, 79 insertions(+), 16 deletions(-)

diffs (166 lines):

diff -r df4e0946ef02 -r 276f63c86f1c ChangeLog
--- 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 at 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 at intevation.de>
 
 	* src/java/de/intevation/mxd/ArcGISInitializer.java,
diff -r df4e0946ef02 -r 276f63c86f1c src/java/de/intevation/mxd/reader/GroupLayerReader.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 at 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++;
diff -r df4e0946ef02 -r 276f63c86f1c src/java/de/intevation/mxd/reader/MXDReader.java
--- 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.");
                         }
diff -r df4e0946ef02 -r 276f63c86f1c src/java/de/intevation/mxd/writer/MapScriptWriter.java
--- 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;
+    }
 }


More information about the MXD2map-commits mailing list