annotate src/java/de/intevation/mxd/utils/MapScriptUtils.java @ 300:215ae6199b95

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