diff src/java/de/intevation/mxd/writer/MapScriptWriter.java @ 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
line wrap: on
line diff
--- 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)