diff src/java/de/intevation/mxd/writer/MapScriptWriter.java @ 259:8fe9ccc77962

Introduced a MapScript helper class and improved metadata handling.
author raimund renkert <raimund.renkert@intevation.de>
date Tue, 16 Aug 2011 13:09:57 +0200
parents 4bae15d560d3
children efab4d62ad3c
line wrap: on
line diff
--- a/src/java/de/intevation/mxd/writer/MapScriptWriter.java	Mon Aug 15 15:52:30 2011 +0200
+++ b/src/java/de/intevation/mxd/writer/MapScriptWriter.java	Tue Aug 16 13:09:57 2011 +0200
@@ -46,6 +46,7 @@
 import edu.umn.gis.mapscript.MS_POSITIONS_ENUM;
 
 import de.intevation.mxd.utils.XMLUtils;
+import de.intevation.mxd.utils.MapScriptUtils;
 
 /**
  * The Mapfile Writer.
@@ -66,6 +67,7 @@
      */
     private Document root;
     private mapObj map;
+    private MapScriptUtils msutils;
     private String mapFilename;
     private String MS_BINDIR = "c:/ms_6.1-dev/bin";
     private String prefix = "";
@@ -77,6 +79,7 @@
      */
     public MapScriptWriter() {
         map = new mapObj("");
+	msutils = new MapScriptUtils();
         mapFilename = "";
     }
 
@@ -91,6 +94,7 @@
     public MapScriptWriter(String templ, String filename) {
         String path = System.getProperty("user.dir");
         map = new mapObj(templ);
+	msutils = new MapScriptUtils();
         File f = new File(filename);
         mapFilename = filename;
         if(f.isAbsolute()) {
@@ -206,11 +210,31 @@
         }
         map.setUnits(units);
 
-	String srs = map.getMetaData("ows_srs");
 	String mproj = mapNode.getAttribute("projection");
-	if(srs.indexOf(mproj) < 0) {
-	    srs += " EPSG:" + mproj;
-	    map.setMetaData("ows_srs", srs);
+	if(mproj != null && !mproj.equals("") && ! mproj.equals("0")) {
+	    MapScriptUtils msu = new MapScriptUtils();
+	    String wmssrs = msu.getMetaData(map, "wms_srs");
+	    String owssrs = msu.getMetaData(map, "ows_srs");
+	    if(wmssrs.indexOf(mproj) < 0) {
+		if(wmssrs.equals("")) {
+		    wmssrs = "EPSG:";
+		}
+		else {
+		    wmssrs += " EPSG:";
+		}
+	    	wmssrs += mproj;
+	    }
+	    if(owssrs.indexOf(mproj) < 0) {
+	        if(owssrs.equals("")) {
+		    owssrs = "EPSG:"; 
+		}
+		else {
+		    owssrs += " EPSG:";
+		}
+                owssrs += mproj;
+	    }
+            map.setMetaData("ows_srs", owssrs);
+	    map.setMetaData("wms_srs", wmssrs);
 	}
     }
 
@@ -244,14 +268,15 @@
 		String cleangroup = "";
 		for(int j = 0; j < splitted.length; j++) {
 		    if(!splitted[j].equals("")) {
-			splitted[j] = validateString(splitted[j]);
-		        cleangroup += "/" + validateLayerName(splitted[j]);
+			splitted[j] = msutils.replaceUmlauts(splitted[j]);
+		        cleangroup += "/" + 
+				      msutils.removeSpecialChars(splitted[j]);
 		    }
 		}
 		group = cleangroup;
             }
 	    String lname = layerElement.getAttribute("name");
-	    lname = validateLayerName(lname);
+	    lname = msutils.removeSpecialChars(lname);
 	    String ulname = group.replaceAll("/", ".") + "." + lname;
 	    if(ulname.startsWith(".")) {
 	        ulname = ulname.substring(1);
@@ -263,6 +288,30 @@
 	    }
             layer.setMetaData("wms_title", ulname);
 
+	    // Projection metadata.
+	    String mproj = mapNode.getAttribute("projection");
+	    if(mproj != null && !mproj.equals("") && !mproj.equals("0")) {
+	        String wmssrs = layer.getMetaData("wms_srs");
+	        String owssrs = layer.getMetaData("ows_srs");
+                if(wmssrs == null) {
+		    wmssrs = "EPSG:";
+	        }
+		else {
+		    wmssrs += " EPSG:";
+		}
+		if(owssrs == null) {
+		    owssrs = "EPSG:";
+		}
+		else {
+		    owssrs += " EPSG:";
+		}
+		wmssrs += mproj;
+		owssrs += mproj;
+		layer.setMetaData("wms_srs", wmssrs);
+		layer.setMetaData("ows_srs", owssrs);
+	    }
+
+	    // The layer extent metadata.
 	    if(layerElement.hasAttribute("extent_min_x") &&
 	       layerElement.hasAttribute("extent_max_x") &&
 	       layerElement.hasAttribute("extent_min_y") &&
@@ -475,10 +524,10 @@
             Element classElement = (Element)list.item(i);
             classObj co = new classObj(layer);
             String name = classElement.getAttribute("label");
-	    name = validateString(name);
+	    name = msutils.replaceUmlauts(name);
             if (name.equals("")) {
                 name = layerElement.getAttribute("name");
-		name = validateString(name);
+		name = msutils.replaceUmlauts(name);
                 if (list.getLength() > 1) {
                     name += "-" + i;
                 }
@@ -703,61 +752,4 @@
         }
         return expression;
     }
-
-    /**
-     * Replaces german umlauts and removes leading and trailing whitespaces.
-     *
-     * @param s String
-     */
-    private String validateString (String s) {
-        if (s.equals("")) {
-            return "";
-        }
-        String tmp = s.trim();
-        tmp = tmp.replace ("ö", "oe");
-        tmp = tmp.replace ("ä", "ae");
-        tmp = tmp.replace ("ü", "ue");
-        tmp = tmp.replace ("ß", "ss");
-	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)