comparison 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
comparison
equal deleted inserted replaced
258:4bae15d560d3 259:8fe9ccc77962
1 /*
2 * Copyright (c) 2011 by Intevation GmbH, Germany <info@intevation.de>
3 *
4 * This file is part of MXD2map.
5 *
6 * This program is free software under the LGPL (>=v2.1)
7 * Read the file LICENCE.txt coming with the software for details
8 * or visit http://www.gnu.org/licenses/ if it does not exist.
9 *
10 * MXD2map has been developed on behalf of the
11 * Bundesamt fuer Seeschifffahrt und Hydrographie (BSH) in Hamburg
12 * by Intevation GmbH.
13 *
14 * Authors:
15 * Raimund Renkert <raimund.renkert@intevation.de>
16 * Bjoern Schilberg <bjoern.schilberg@intevation.de>
17 * Stephan Holl <stephan.holl@intevation.de>
18 */
19
20 package de.intevation.mxd.utils;
21
22 import org.apache.log4j.Logger;
23
24 import edu.umn.gis.mapscript.mapObj;
25
26 /**
27 * MapScript utilities.
28 * This utility class provides some useful functions when working with the
29 * MapScript Java API.
30 *
31 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
32 */
33 public class MapScriptUtils
34 {
35 /**
36 * The Logger.
37 */
38 private static final Logger logger = Logger.getLogger(MapScriptUtils.class);
39
40
41 /**
42 * This function is a wrapper for mapObj.getMetaData.
43 * The mapObj.getMetaData raises a not catchable error if the metadata key
44 * can not be found in the map. To avoid this, use this function instead.
45 *
46 * @param map The map object.
47 * @param key The metadata key.
48 *
49 * @return Empty string if the key was not found, else the value.
50 */
51 public String getMetaData (mapObj map, String key) {
52 logger.debug("getMetaData(mapObj, String)");
53 String meta = map.getFirstMetaDataKey();
54 if(meta.equals("")) {
55 return "";
56 }
57 while(meta != null && !meta.equals(key)) {
58 meta = map.getNextMetaDataKey(meta);
59 }
60 if(meta == null || meta.equals("")) {
61 return "";
62 }
63 else {
64 return map.getMetaData(meta);
65 }
66 }
67
68
69 /**
70 * Removes special characters and whitespaces.
71 *
72 * @param s The input string.
73 *
74 * @return The input string without special chars.
75 */
76 public String removeSpecialChars (String s) {
77 if(s.equals("")) {
78 return "";
79 }
80
81 String tmp = s.trim();
82 tmp = tmp.replace(" ", "");
83 tmp = tmp.replace("/", "");
84 tmp = tmp.replace(",", "");
85 tmp = tmp.replace("#", "");
86 tmp = tmp.replace("+", "");
87 tmp = tmp.replace("~", "");
88 tmp = tmp.replace("(", "");
89 tmp = tmp.replace(")", "");
90 tmp = tmp.replace("{", "");
91 tmp = tmp.replace("}", "");
92 tmp = tmp.replace("[", "");
93 tmp = tmp.replace("]", "");
94 tmp = tmp.replace("<", "");
95 tmp = tmp.replace(">", "");
96 tmp = tmp.replace("*", "");
97 tmp = tmp.replace("\\\\", "");
98 tmp = tmp.replace("^", "");
99 if(!s.equals(tmp)) {
100 logger.info("Renamed \"" + s +"\" to \"" + tmp +"\".");
101 }
102 return tmp;
103 }
104
105
106 /**
107 * Replaces german umlauts and removes leading and trailing whitespaces.
108 *
109 * @param s The input string.
110 *
111 * @return The string without german umlauts.
112 */
113 public String replaceUmlauts (String s) {
114 if (s.equals("")) {
115 return "";
116 }
117 String tmp = s.trim();
118 tmp = tmp.replace ("ö", "oe");
119 tmp = tmp.replace ("ä", "ae");
120 tmp = tmp.replace ("ü", "ue");
121 tmp = tmp.replace ("ß", "ss");
122 if(!s.equals(tmp)) {
123 logger.info("Renamed \"" + s + "\" to \"" + tmp + "\".");
124 }
125 return tmp;
126 }
127 }
128 // 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)