view src/java/de/intevation/mxd/utils/MapScriptUtils.java @ 355:5fd9effbfe24

Remove more instances of outdated repository URL
author Tom Gottfried <tom@intevation.de>
date Mon, 04 Jan 2021 15:45:14 +0100
parents 84ab3afc5610
children
line wrap: on
line source
/*
 * 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 ("\u00f6", "oe");
        tmp = tmp.replace ("\u00e4", "ae");
        tmp = tmp.replace ("\u00fc", "ue");
        tmp = tmp.replace ("\u00df", "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)