diff src/java/de/intevation/mxd/utils/MapScriptUtils.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
children 84ab3afc5610
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/java/de/intevation/mxd/utils/MapScriptUtils.java	Tue Aug 16 13:09:57 2011 +0200
@@ -0,0 +1,128 @@
+/*
+ * Copyright (c) 2011 by Intevation GmbH, Germany <info@intevation.de>
+ *
+ * This file is part of MXD2map.
+ *
+ * This program is free software under the LGPL (>=v2.1)
+ * Read the file LICENCE.txt coming with the software for details
+ * or visit http://www.gnu.org/licenses/ if it does not exist.
+ *
+ * MXD2map has been developed on behalf of the
+ * Bundesamt fuer Seeschifffahrt und Hydrographie (BSH) in Hamburg
+ * by Intevation GmbH.
+ *
+ * Authors:
+ * Raimund Renkert <raimund.renkert@intevation.de>
+ * Bjoern Schilberg <bjoern.schilberg@intevation.de>
+ * Stephan Holl <stephan.holl@intevation.de>
+ */
+
+package de.intevation.mxd.utils;
+
+import org.apache.log4j.Logger;
+
+import edu.umn.gis.mapscript.mapObj;
+
+/**
+ * MapScript utilities.
+ * This utility class provides some useful functions when working with the
+ * MapScript Java API.
+ *
+ * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
+ */
+public class MapScriptUtils
+{
+    /**
+     * The Logger.
+     */
+    private static final Logger logger = Logger.getLogger(MapScriptUtils.class);
+
+    
+    /**
+     * This function is a wrapper for mapObj.getMetaData.
+     * The mapObj.getMetaData raises a not catchable error if the metadata key
+     * can not be found in the map. To avoid this, use this function instead.
+     *
+     * @param map The map object.
+     * @param key The metadata key.
+     *
+     * @return Empty string if the key was not found, else the value.
+     */
+    public String getMetaData (mapObj map, String key) {
+	logger.debug("getMetaData(mapObj, String)");
+        String meta = map.getFirstMetaDataKey();
+	if(meta.equals("")) {
+	    return "";
+	}
+        while(meta != null && !meta.equals(key)) {
+	    meta = map.getNextMetaDataKey(meta);
+	}
+	if(meta == null || meta.equals("")) {
+	    return "";
+	}
+	else {
+	    return map.getMetaData(meta);
+	}
+    }
+
+
+    /**
+     * Removes special characters and whitespaces.
+     *
+     * @param s The input string.
+     *
+     * @return The input string without special chars.
+     */
+    public String removeSpecialChars (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;
+    }
+
+
+    /**
+     * Replaces german umlauts and removes leading and trailing whitespaces.
+     *
+     * @param s The input string.
+     *
+     * @return The string without german umlauts.
+     */
+    public String replaceUmlauts (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;
+    }
+}
+// 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)