Mercurial > mxd2map
view src/java/de/intevation/mxd/utils/MapScriptUtils.java @ 316:5e3a40a84539
Some minor cleanups
* src/java/de/intevation/mxd/reader/FeatureLayerReader.java:
Add Debug output if Layer class is not implemented
* src/java/de/intevation/mxd/reader/RasterLayerReader.java:
Remove unused import
* src/java/de/intevation/mxd/reader/WMSLayerReader.java:
Tune down warnings about min/max scale
author | Andre Heinecke <aheinecke@intevation.de> |
---|---|
date | Mon, 17 Sep 2012 17:10:44 +0200 |
parents | 8fe9ccc77962 |
children | 84ab3afc5610 |
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 ("�", "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 :