Mercurial > mxd2map
annotate src/java/de/intevation/mxd/writer/MapScriptWriter.java @ 245:2eeeae07aaa2
Set the group attribute to the correct wms metadata.
author | raimund renkert <raimund.renkert@intevation.de> |
---|---|
date | Tue, 09 Aug 2011 17:42:31 +0200 |
parents | 276f63c86f1c |
children | 87e92debc53f |
rev | line source |
---|---|
243
df4e0946ef02
Added LGPL header.
Raimund Renkert <rrenkert@intevation.de>
parents:
239
diff
changeset
|
1 /* |
df4e0946ef02
Added LGPL header.
Raimund Renkert <rrenkert@intevation.de>
parents:
239
diff
changeset
|
2 * Copyright (c) 2011 by Intevation GmbH, Germany <info@intevation.de> |
df4e0946ef02
Added LGPL header.
Raimund Renkert <rrenkert@intevation.de>
parents:
239
diff
changeset
|
3 * |
df4e0946ef02
Added LGPL header.
Raimund Renkert <rrenkert@intevation.de>
parents:
239
diff
changeset
|
4 * This file is part of MXD2map. |
df4e0946ef02
Added LGPL header.
Raimund Renkert <rrenkert@intevation.de>
parents:
239
diff
changeset
|
5 * |
df4e0946ef02
Added LGPL header.
Raimund Renkert <rrenkert@intevation.de>
parents:
239
diff
changeset
|
6 * This program is free software under the LGPL (>=v2.1) |
df4e0946ef02
Added LGPL header.
Raimund Renkert <rrenkert@intevation.de>
parents:
239
diff
changeset
|
7 * Read the file LICENCE.txt coming with the software for details |
df4e0946ef02
Added LGPL header.
Raimund Renkert <rrenkert@intevation.de>
parents:
239
diff
changeset
|
8 * or visit http://www.gnu.org/licenses/ if it does not exist. |
df4e0946ef02
Added LGPL header.
Raimund Renkert <rrenkert@intevation.de>
parents:
239
diff
changeset
|
9 * |
df4e0946ef02
Added LGPL header.
Raimund Renkert <rrenkert@intevation.de>
parents:
239
diff
changeset
|
10 * MXD2map has been developed on behalf of the |
df4e0946ef02
Added LGPL header.
Raimund Renkert <rrenkert@intevation.de>
parents:
239
diff
changeset
|
11 * Bundesamt fuer Seeschifffahrt und Hydrographie (BSH) in Hamburg |
df4e0946ef02
Added LGPL header.
Raimund Renkert <rrenkert@intevation.de>
parents:
239
diff
changeset
|
12 * by Intevation GmbH. |
df4e0946ef02
Added LGPL header.
Raimund Renkert <rrenkert@intevation.de>
parents:
239
diff
changeset
|
13 * |
df4e0946ef02
Added LGPL header.
Raimund Renkert <rrenkert@intevation.de>
parents:
239
diff
changeset
|
14 * Authors: |
df4e0946ef02
Added LGPL header.
Raimund Renkert <rrenkert@intevation.de>
parents:
239
diff
changeset
|
15 * Raimund Renkert <raimund.renkert@intevation.de> |
df4e0946ef02
Added LGPL header.
Raimund Renkert <rrenkert@intevation.de>
parents:
239
diff
changeset
|
16 * Bjoern Schilberg <bjoern.schilberg@intevation.de> |
df4e0946ef02
Added LGPL header.
Raimund Renkert <rrenkert@intevation.de>
parents:
239
diff
changeset
|
17 * Stephan Holl <stephan.holl@intevation.de> |
df4e0946ef02
Added LGPL header.
Raimund Renkert <rrenkert@intevation.de>
parents:
239
diff
changeset
|
18 */ |
df4e0946ef02
Added LGPL header.
Raimund Renkert <rrenkert@intevation.de>
parents:
239
diff
changeset
|
19 |
41
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
20 package de.intevation.mxd.writer; |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
21 |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
22 import org.apache.log4j.Logger; |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
23 |
179
f3a91cd7440b
Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
175
diff
changeset
|
24 import java.awt.Color; |
f3a91cd7440b
Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
175
diff
changeset
|
25 |
41
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
26 import org.w3c.dom.Document; |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
27 import org.w3c.dom.Element; |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
28 import org.w3c.dom.NodeList; |
42
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
29 |
98
4696d0769f9c
Write the absolute path to the data source of the layer.
Raimund Renkert <rrenkert@intevation.de>
parents:
97
diff
changeset
|
30 import java.io.File; |
4696d0769f9c
Write the absolute path to the data source of the layer.
Raimund Renkert <rrenkert@intevation.de>
parents:
97
diff
changeset
|
31 |
41
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
32 import javax.xml.xpath.XPathConstants; |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
33 |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
34 import edu.umn.gis.mapscript.mapObj; |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
35 import edu.umn.gis.mapscript.layerObj; |
42
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
36 import edu.umn.gis.mapscript.classObj; |
179
f3a91cd7440b
Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
175
diff
changeset
|
37 import edu.umn.gis.mapscript.labelObj; |
f3a91cd7440b
Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
175
diff
changeset
|
38 import edu.umn.gis.mapscript.colorObj; |
f3a91cd7440b
Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
175
diff
changeset
|
39 import edu.umn.gis.mapscript.fontSetObj; |
f3a91cd7440b
Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
175
diff
changeset
|
40 import edu.umn.gis.mapscript.hashTableObj; |
42
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
41 |
41
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
42 import edu.umn.gis.mapscript.MS_UNITS; |
42
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
43 import edu.umn.gis.mapscript.MS_LAYER_TYPE; |
130
5991c1f90f91
Added data source "SDE" to writer.
vc11884admin@VC11884.win.bsh.de
parents:
129
diff
changeset
|
44 import edu.umn.gis.mapscript.MS_CONNECTION_TYPE; |
179
f3a91cd7440b
Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
175
diff
changeset
|
45 import edu.umn.gis.mapscript.MS_FONT_TYPE; |
f3a91cd7440b
Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
175
diff
changeset
|
46 import edu.umn.gis.mapscript.MS_POSITIONS_ENUM; |
41
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
47 |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
48 import de.intevation.mxd.utils.XMLUtils; |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
49 |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
50 /** |
43
ef7ca23c4233
Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents:
42
diff
changeset
|
51 * The Mapfile Writer. |
ef7ca23c4233
Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents:
42
diff
changeset
|
52 * This Writer uses the MapScript Java API to create Mapfiles from a DOM. |
41
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
53 * |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
54 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
55 */ |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
56 public class MapScriptWriter |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
57 implements IWriter |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
58 { |
43
ef7ca23c4233
Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents:
42
diff
changeset
|
59 /** |
ef7ca23c4233
Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents:
42
diff
changeset
|
60 * The Logger. |
ef7ca23c4233
Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents:
42
diff
changeset
|
61 */ |
ef7ca23c4233
Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents:
42
diff
changeset
|
62 private static final Logger logger = Logger.getLogger(MapScriptWriter.class); |
ef7ca23c4233
Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents:
42
diff
changeset
|
63 |
ef7ca23c4233
Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents:
42
diff
changeset
|
64 /** |
ef7ca23c4233
Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents:
42
diff
changeset
|
65 * Private member. |
ef7ca23c4233
Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents:
42
diff
changeset
|
66 */ |
41
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
67 private Document root; |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
68 private mapObj map; |
55
f0c02ff120d6
Read filenames from properties file or commandline arguments.
Raimund Renkert <rrenkert@intevation.de>
parents:
53
diff
changeset
|
69 private String mapFilename; |
130
5991c1f90f91
Added data source "SDE" to writer.
vc11884admin@VC11884.win.bsh.de
parents:
129
diff
changeset
|
70 private String MS_BINDIR = "c:/ms_6.1-dev/bin"; |
134
acc9e5430177
Handle SDE connection attributes and expressions.
vc11884admin@VC11884.win.bsh.de
parents:
132
diff
changeset
|
71 private String prefix = ""; |
170
b9ee44070056
Manage projections and units.
vc11884admin@VC11884.win.bsh.de
parents:
169
diff
changeset
|
72 private MS_UNITS units = MS_UNITS.MS_METERS; |
41
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
73 |
181 | 74 /** |
75 * Default constructor. | |
76 * Creates a mapscript writer object with an empty map. | |
77 */ | |
41
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
78 public MapScriptWriter() { |
55
f0c02ff120d6
Read filenames from properties file or commandline arguments.
Raimund Renkert <rrenkert@intevation.de>
parents:
53
diff
changeset
|
79 map = new mapObj(""); |
f0c02ff120d6
Read filenames from properties file or commandline arguments.
Raimund Renkert <rrenkert@intevation.de>
parents:
53
diff
changeset
|
80 mapFilename = ""; |
41
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
81 } |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
82 |
181 | 83 /** |
84 * Contructor with template and output filename. | |
85 * Creates a mapscript writer object with the given template that saves the | |
86 * map to the filename. | |
87 * | |
88 * @param templ Mapfile template. | |
89 * @param filename Output file name. | |
90 */ | |
55
f0c02ff120d6
Read filenames from properties file or commandline arguments.
Raimund Renkert <rrenkert@intevation.de>
parents:
53
diff
changeset
|
91 public MapScriptWriter(String templ, String filename) { |
180
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
92 String path = System.getProperty("user.dir"); |
55
f0c02ff120d6
Read filenames from properties file or commandline arguments.
Raimund Renkert <rrenkert@intevation.de>
parents:
53
diff
changeset
|
93 map = new mapObj(templ); |
180
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
94 File f = new File(filename); |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
95 mapFilename = filename; |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
96 if(f.isAbsolute()) { |
174
707f13cfba74
Improved the commandline arguments and save the mapfile in the correct directory.
raimund.renkert@intevation.de
parents:
172
diff
changeset
|
97 map.setMappath(mapFilename); |
180
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
98 } |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
99 else { |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
100 map.setMappath( |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
101 System.getProperty("user.dir") + |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
102 File.separator + |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
103 mapFilename); |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
104 mapFilename = System.getProperty("user.dir") + |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
105 File.separator + |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
106 mapFilename; |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
107 } |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
108 String fontSetPath = map.getFontset().getFilename(); |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
109 File fonts = new File(fontSetPath); |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
110 String fontSet = fonts.getAbsolutePath(); |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
111 fontSet = fontSet.replaceAll("\\\\", "/"); |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
112 map.setFontSet(fontSet); |
41
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
113 } |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
114 |
43
ef7ca23c4233
Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents:
42
diff
changeset
|
115 /** |
ef7ca23c4233
Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents:
42
diff
changeset
|
116 * Write the mapfile. |
ef7ca23c4233
Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents:
42
diff
changeset
|
117 * @param doc The root document containin the map attributes. |
ef7ca23c4233
Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents:
42
diff
changeset
|
118 * |
ef7ca23c4233
Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents:
42
diff
changeset
|
119 * @return Currently always true. |
ef7ca23c4233
Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents:
42
diff
changeset
|
120 */ |
120
11d63bf00326
Changed exception handling and logging in writer classes.
Raimund Renkert <rrenkert@intevation.de>
parents:
102
diff
changeset
|
121 public boolean write(Document doc) { |
41
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
122 logger.debug("write()"); |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
123 this.root = doc; |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
124 |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
125 //Get the filename. |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
126 Element fileNode = (Element)XMLUtils.xpath( |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
127 root, |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
128 "/mxd/file", |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
129 XPathConstants.NODE); |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
130 //Write the map attributes. |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
131 writeMap(); |
42
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
132 //Write the layers. |
196
5350621a0294
Verify the SDE databse jointable attribute.
raimund renkert <raimund.renkert@intevation.de>
parents:
190
diff
changeset
|
133 boolean ret = writeLayer(); |
41
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
134 //Save the map. |
196
5350621a0294
Verify the SDE databse jointable attribute.
raimund renkert <raimund.renkert@intevation.de>
parents:
190
diff
changeset
|
135 if (ret) { |
5350621a0294
Verify the SDE databse jointable attribute.
raimund renkert <raimund.renkert@intevation.de>
parents:
190
diff
changeset
|
136 mapObj cloneMap = map.cloneMap(); |
5350621a0294
Verify the SDE databse jointable attribute.
raimund renkert <raimund.renkert@intevation.de>
parents:
190
diff
changeset
|
137 cloneMap.save(mapFilename); |
5350621a0294
Verify the SDE databse jointable attribute.
raimund renkert <raimund.renkert@intevation.de>
parents:
190
diff
changeset
|
138 logger.info("Mapfile created: " + mapFilename); |
5350621a0294
Verify the SDE databse jointable attribute.
raimund renkert <raimund.renkert@intevation.de>
parents:
190
diff
changeset
|
139 return true; |
5350621a0294
Verify the SDE databse jointable attribute.
raimund renkert <raimund.renkert@intevation.de>
parents:
190
diff
changeset
|
140 } |
5350621a0294
Verify the SDE databse jointable attribute.
raimund renkert <raimund.renkert@intevation.de>
parents:
190
diff
changeset
|
141 return false; |
41
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
142 } |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
143 |
43
ef7ca23c4233
Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents:
42
diff
changeset
|
144 /** |
ef7ca23c4233
Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents:
42
diff
changeset
|
145 * Create the map object and set the attributes. |
ef7ca23c4233
Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents:
42
diff
changeset
|
146 */ |
41
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
147 private void writeMap() { |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
148 logger.debug("writeMap()"); |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
149 //Get the map. |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
150 Element mapNode = (Element)XMLUtils.xpath( |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
151 root, |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
152 "/mxd/map", |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
153 XPathConstants.NODE); |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
154 |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
155 //Set the name. |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
156 map.setName(mapNode.getAttribute("name")); |
42
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
157 map.setMetaData("wms_title", mapNode.getAttribute("name")); |
41
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
158 //Set the extent. |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
159 map.setExtent( |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
160 Double.parseDouble(mapNode.getAttribute("extent_min_x")), |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
161 Double.parseDouble(mapNode.getAttribute("extent_min_y")), |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
162 Double.parseDouble(mapNode.getAttribute("extent_max_x")), |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
163 Double.parseDouble(mapNode.getAttribute("extent_max_y"))); |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
164 |
172
929e09649b08
Handle unknown projections.
vc11884admin@VC11884.win.bsh.de
parents:
170
diff
changeset
|
165 //Set the units and projection. |
180
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
166 int proj = Integer.parseInt(mapNode.getAttribute("projection")); |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
167 if(proj != 0) { |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
168 map.setProjection("epsg:" + mapNode.getAttribute("projection")); |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
169 } |
170
b9ee44070056
Manage projections and units.
vc11884admin@VC11884.win.bsh.de
parents:
169
diff
changeset
|
170 String u = mapNode.getAttribute("units"); |
b9ee44070056
Manage projections and units.
vc11884admin@VC11884.win.bsh.de
parents:
169
diff
changeset
|
171 if(u.equals("feet")) { |
b9ee44070056
Manage projections and units.
vc11884admin@VC11884.win.bsh.de
parents:
169
diff
changeset
|
172 units = MS_UNITS.MS_FEET; |
41
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
173 } |
170
b9ee44070056
Manage projections and units.
vc11884admin@VC11884.win.bsh.de
parents:
169
diff
changeset
|
174 else if(u.equals("inches")) { |
b9ee44070056
Manage projections and units.
vc11884admin@VC11884.win.bsh.de
parents:
169
diff
changeset
|
175 units = MS_UNITS.MS_INCHES; |
41
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
176 } |
170
b9ee44070056
Manage projections and units.
vc11884admin@VC11884.win.bsh.de
parents:
169
diff
changeset
|
177 else if(u.equals("kilometers")) { |
b9ee44070056
Manage projections and units.
vc11884admin@VC11884.win.bsh.de
parents:
169
diff
changeset
|
178 units = MS_UNITS.MS_KILOMETERS; |
41
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
179 } |
170
b9ee44070056
Manage projections and units.
vc11884admin@VC11884.win.bsh.de
parents:
169
diff
changeset
|
180 else if(u.equals("meters")) { |
b9ee44070056
Manage projections and units.
vc11884admin@VC11884.win.bsh.de
parents:
169
diff
changeset
|
181 units = MS_UNITS.MS_METERS; |
41
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
182 } |
170
b9ee44070056
Manage projections and units.
vc11884admin@VC11884.win.bsh.de
parents:
169
diff
changeset
|
183 else if(u.equals("miles")) { |
b9ee44070056
Manage projections and units.
vc11884admin@VC11884.win.bsh.de
parents:
169
diff
changeset
|
184 units = MS_UNITS.MS_MILES; |
b9ee44070056
Manage projections and units.
vc11884admin@VC11884.win.bsh.de
parents:
169
diff
changeset
|
185 } |
b9ee44070056
Manage projections and units.
vc11884admin@VC11884.win.bsh.de
parents:
169
diff
changeset
|
186 else if(u.equals("nauticalmiles")) { |
b9ee44070056
Manage projections and units.
vc11884admin@VC11884.win.bsh.de
parents:
169
diff
changeset
|
187 units = MS_UNITS.MS_NAUTICALMILES; |
b9ee44070056
Manage projections and units.
vc11884admin@VC11884.win.bsh.de
parents:
169
diff
changeset
|
188 } |
b9ee44070056
Manage projections and units.
vc11884admin@VC11884.win.bsh.de
parents:
169
diff
changeset
|
189 else if(u.equals("points")) { |
b9ee44070056
Manage projections and units.
vc11884admin@VC11884.win.bsh.de
parents:
169
diff
changeset
|
190 units = MS_UNITS.MS_PIXELS; |
b9ee44070056
Manage projections and units.
vc11884admin@VC11884.win.bsh.de
parents:
169
diff
changeset
|
191 } |
180
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
192 else if(u.equals("degree")) { |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
193 units = MS_UNITS.MS_DD; |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
194 } |
41
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
195 else { |
170
b9ee44070056
Manage projections and units.
vc11884admin@VC11884.win.bsh.de
parents:
169
diff
changeset
|
196 units = MS_UNITS.MS_METERS; |
41
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
197 } |
170
b9ee44070056
Manage projections and units.
vc11884admin@VC11884.win.bsh.de
parents:
169
diff
changeset
|
198 map.setUnits(units); |
41
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
199 } |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
200 |
43
ef7ca23c4233
Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents:
42
diff
changeset
|
201 /** |
ef7ca23c4233
Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents:
42
diff
changeset
|
202 * Create layer objects and set the attributes. |
ef7ca23c4233
Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents:
42
diff
changeset
|
203 */ |
196
5350621a0294
Verify the SDE databse jointable attribute.
raimund renkert <raimund.renkert@intevation.de>
parents:
190
diff
changeset
|
204 private boolean writeLayer() { |
42
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
205 logger.debug("writeLayer()"); |
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
206 Element mapNode = (Element)XMLUtils.xpath( |
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
207 root, |
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
208 "/mxd/map", |
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
209 XPathConstants.NODE); |
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
210 NodeList list = mapNode.getElementsByTagName("layer"); |
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
211 for(int i = 0; i < list.getLength(); i++) { |
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
212 Element layerElement = (Element)list.item(i); |
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
213 layerObj layer = new layerObj(map); |
190
c640fb351f66
Do not write layer with empty CLASS objects.
raimund renkert <raimund.renkert@intevation.de>
parents:
189
diff
changeset
|
214 NodeList renderer = layerElement.getElementsByTagName("renderer"); |
c640fb351f66
Do not write layer with empty CLASS objects.
raimund renkert <raimund.renkert@intevation.de>
parents:
189
diff
changeset
|
215 if (renderer.getLength() == 0) { |
204
52b918f958d0
Remove incomplete layer from map.
raimund renkert <raimund.renkert@intevation.de>
parents:
203
diff
changeset
|
216 map.removeLayer(layer.getIndex()); |
190
c640fb351f66
Do not write layer with empty CLASS objects.
raimund renkert <raimund.renkert@intevation.de>
parents:
189
diff
changeset
|
217 continue; |
c640fb351f66
Do not write layer with empty CLASS objects.
raimund renkert <raimund.renkert@intevation.de>
parents:
189
diff
changeset
|
218 } |
42
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
219 |
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
220 //The layer name. |
205
07b991b940ab
Concatenate grouplayer name and layer name to have a unique identifier for each
raimund renkert <raimund.renkert@intevation.de>
parents:
204
diff
changeset
|
221 String group = ""; |
148
2bf35f0babd0
Implemented new group layer functionality.
vc11884admin@VC11884.win.bsh.de
parents:
145
diff
changeset
|
222 if(layerElement.hasAttribute("group")) { |
205
07b991b940ab
Concatenate grouplayer name and layer name to have a unique identifier for each
raimund renkert <raimund.renkert@intevation.de>
parents:
204
diff
changeset
|
223 group = layerElement.getAttribute("group"); |
244
276f63c86f1c
Refactored group layer handling and "wms_title" metadata.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
224 String[] splitted = group.split("/"); |
276f63c86f1c
Refactored group layer handling and "wms_title" metadata.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
225 String cleangroup = ""; |
276f63c86f1c
Refactored group layer handling and "wms_title" metadata.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
226 for(int j = 0; j < splitted.length; j++) { |
276f63c86f1c
Refactored group layer handling and "wms_title" metadata.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
227 if(!splitted[j].equals("")) { |
276f63c86f1c
Refactored group layer handling and "wms_title" metadata.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
228 cleangroup += "/" + validateLayerName(splitted[j]); |
276f63c86f1c
Refactored group layer handling and "wms_title" metadata.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
229 } |
276f63c86f1c
Refactored group layer handling and "wms_title" metadata.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
230 } |
276f63c86f1c
Refactored group layer handling and "wms_title" metadata.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
231 group = cleangroup; |
180
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
232 } |
205
07b991b940ab
Concatenate grouplayer name and layer name to have a unique identifier for each
raimund renkert <raimund.renkert@intevation.de>
parents:
204
diff
changeset
|
233 String lname = layerElement.getAttribute("name"); |
244
276f63c86f1c
Refactored group layer handling and "wms_title" metadata.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
234 lname = validateLayerName(lname); |
276f63c86f1c
Refactored group layer handling and "wms_title" metadata.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
235 String ulname = group.replaceAll("/", ".") + "." + lname; |
276f63c86f1c
Refactored group layer handling and "wms_title" metadata.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
236 if(ulname.startsWith(".")) { |
276f63c86f1c
Refactored group layer handling and "wms_title" metadata.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
237 ulname = ulname.substring(1); |
276f63c86f1c
Refactored group layer handling and "wms_title" metadata.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
238 } |
276f63c86f1c
Refactored group layer handling and "wms_title" metadata.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
239 layer.setName(ulname); |
205
07b991b940ab
Concatenate grouplayer name and layer name to have a unique identifier for each
raimund renkert <raimund.renkert@intevation.de>
parents:
204
diff
changeset
|
240 layer.setUnits(units.swigValue()); |
244
276f63c86f1c
Refactored group layer handling and "wms_title" metadata.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
241 if(!group.equals("")) { |
245
2eeeae07aaa2
Set the group attribute to the correct wms metadata.
raimund renkert <raimund.renkert@intevation.de>
parents:
244
diff
changeset
|
242 layer.setMetaData("wms_layer_group", group); |
244
276f63c86f1c
Refactored group layer handling and "wms_title" metadata.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
243 } |
245
2eeeae07aaa2
Set the group attribute to the correct wms metadata.
raimund renkert <raimund.renkert@intevation.de>
parents:
244
diff
changeset
|
244 layer.setMetaData("wms_title", ulname); |
180
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
245 |
42
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
246 //The layer status. |
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
247 String stat = layerElement.getAttribute("status"); |
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
248 if (stat.equals("on")) { |
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
249 layer.setStatus(1); |
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
250 } |
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
251 else { |
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
252 layer.setStatus(0); |
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
253 } |
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
254 |
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
255 //The scale. |
145
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
141
diff
changeset
|
256 double maxScale = 0; |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
141
diff
changeset
|
257 double minScale = 0; |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
141
diff
changeset
|
258 try { |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
141
diff
changeset
|
259 maxScale = |
153
7ed49420ee5a
Changed min scale and max scale in writer.
vc11884admin@VC11884.win.bsh.de
parents:
152
diff
changeset
|
260 Double.parseDouble(layerElement.getAttribute("min_scale")); |
7ed49420ee5a
Changed min scale and max scale in writer.
vc11884admin@VC11884.win.bsh.de
parents:
152
diff
changeset
|
261 minScale = |
145
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
141
diff
changeset
|
262 Double.parseDouble(layerElement.getAttribute("max_scale")); |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
141
diff
changeset
|
263 } |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
141
diff
changeset
|
264 catch(NumberFormatException nfe) { |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
141
diff
changeset
|
265 logger.warn("Error setting scale."); |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
141
diff
changeset
|
266 maxScale = 0; |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
141
diff
changeset
|
267 minScale = 0; |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
141
diff
changeset
|
268 } |
42
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
269 layer.setMaxscaledenom(maxScale); |
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
270 layer.setMinscaledenom(minScale); |
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
271 |
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
272 //The layer type. |
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
273 String type = layerElement.getAttribute("type"); |
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
274 if(type.equals("point")) { |
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
275 layer.setType(MS_LAYER_TYPE.MS_LAYER_POINT); |
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
276 } |
62
e468cf8701ea
Prepared the converter to handle and write line symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
59
diff
changeset
|
277 else if (type.equals("line")) { |
e468cf8701ea
Prepared the converter to handle and write line symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
59
diff
changeset
|
278 layer.setType(MS_LAYER_TYPE.MS_LAYER_LINE); |
e468cf8701ea
Prepared the converter to handle and write line symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
59
diff
changeset
|
279 } |
97
18e4f143896b
Added polygon writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
96
diff
changeset
|
280 else if (type.equals("polygon")) { |
18e4f143896b
Added polygon writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
96
diff
changeset
|
281 layer.setType(MS_LAYER_TYPE.MS_LAYER_POLYGON); |
18e4f143896b
Added polygon writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
96
diff
changeset
|
282 } |
102
3ca2ec55fb3b
Set TILEITEM to an empty string.
Raimund Renkert <rrenkert@intevation.de>
parents:
99
diff
changeset
|
283 layer.setTileitem(""); |
42
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
284 |
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
285 //The layer datasource. |
137
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
286 String con_type = layerElement.getAttribute("connection_type"); |
134
acc9e5430177
Handle SDE connection attributes and expressions.
vc11884admin@VC11884.win.bsh.de
parents:
132
diff
changeset
|
287 if(con_type.equals("local")) { |
181 | 288 // The data source is a local file. (.shp) |
130
5991c1f90f91
Added data source "SDE" to writer.
vc11884admin@VC11884.win.bsh.de
parents:
129
diff
changeset
|
289 String datasource = ""; |
5991c1f90f91
Added data source "SDE" to writer.
vc11884admin@VC11884.win.bsh.de
parents:
129
diff
changeset
|
290 if(layerElement.hasAttribute("workspace")) { |
5991c1f90f91
Added data source "SDE" to writer.
vc11884admin@VC11884.win.bsh.de
parents:
129
diff
changeset
|
291 datasource = layerElement.getAttribute("workspace"); |
5991c1f90f91
Added data source "SDE" to writer.
vc11884admin@VC11884.win.bsh.de
parents:
129
diff
changeset
|
292 datasource += File.separator; |
5991c1f90f91
Added data source "SDE" to writer.
vc11884admin@VC11884.win.bsh.de
parents:
129
diff
changeset
|
293 } |
5991c1f90f91
Added data source "SDE" to writer.
vc11884admin@VC11884.win.bsh.de
parents:
129
diff
changeset
|
294 datasource += layerElement.getAttribute("data_source"); |
180
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
295 datasource = datasource.replaceAll("\\\\", "/"); |
130
5991c1f90f91
Added data source "SDE" to writer.
vc11884admin@VC11884.win.bsh.de
parents:
129
diff
changeset
|
296 layer.setData(datasource); |
137
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
297 } |
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
298 else if(con_type.equals("SDE")) { |
181 | 299 // The data source is a sde database. |
137
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
300 logger.info( |
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
301 "SDE datasource found." + |
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
302 " Please edit password in mapfile."); |
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
303 layer.setConnectionType( |
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
304 MS_CONNECTION_TYPE.MS_PLUGIN.swigValue(), |
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
305 MS_BINDIR + "/ms/plugins/msplugin_sde_93.dll"); |
197
cdbf2f2dca35
Check for database connectio user parameter for SDE connections.
raimund renkert <raimund.renkert@intevation.de>
parents:
196
diff
changeset
|
306 String database_auth = layerElement.getAttribute("database"); |
cdbf2f2dca35
Check for database connectio user parameter for SDE connections.
raimund renkert <raimund.renkert@intevation.de>
parents:
196
diff
changeset
|
307 if (database_auth.equals("") || database_auth == null) { |
cdbf2f2dca35
Check for database connectio user parameter for SDE connections.
raimund renkert <raimund.renkert@intevation.de>
parents:
196
diff
changeset
|
308 logger.warn("Could not set the database connection user." + |
cdbf2f2dca35
Check for database connectio user parameter for SDE connections.
raimund renkert <raimund.renkert@intevation.de>
parents:
196
diff
changeset
|
309 " Setting to \"sde\" as default."); |
cdbf2f2dca35
Check for database connectio user parameter for SDE connections.
raimund renkert <raimund.renkert@intevation.de>
parents:
196
diff
changeset
|
310 database_auth = "sde"; |
cdbf2f2dca35
Check for database connectio user parameter for SDE connections.
raimund renkert <raimund.renkert@intevation.de>
parents:
196
diff
changeset
|
311 } |
238
e672f5134d6e
Remove all non numeric chars from port string.
raimund renkert <raimund.renkert@intevation.de>
parents:
207
diff
changeset
|
312 |
e672f5134d6e
Remove all non numeric chars from port string.
raimund renkert <raimund.renkert@intevation.de>
parents:
207
diff
changeset
|
313 String port = layerElement.getAttribute("instance"); |
e672f5134d6e
Remove all non numeric chars from port string.
raimund renkert <raimund.renkert@intevation.de>
parents:
207
diff
changeset
|
314 StringBuffer strBuff = new StringBuffer(); |
e672f5134d6e
Remove all non numeric chars from port string.
raimund renkert <raimund.renkert@intevation.de>
parents:
207
diff
changeset
|
315 char c; |
e672f5134d6e
Remove all non numeric chars from port string.
raimund renkert <raimund.renkert@intevation.de>
parents:
207
diff
changeset
|
316 |
e672f5134d6e
Remove all non numeric chars from port string.
raimund renkert <raimund.renkert@intevation.de>
parents:
207
diff
changeset
|
317 for (int j = 0; j < port.length() ; j++) { |
e672f5134d6e
Remove all non numeric chars from port string.
raimund renkert <raimund.renkert@intevation.de>
parents:
207
diff
changeset
|
318 c = port.charAt(j); |
e672f5134d6e
Remove all non numeric chars from port string.
raimund renkert <raimund.renkert@intevation.de>
parents:
207
diff
changeset
|
319 |
e672f5134d6e
Remove all non numeric chars from port string.
raimund renkert <raimund.renkert@intevation.de>
parents:
207
diff
changeset
|
320 if(Character.isDigit(c)) { |
e672f5134d6e
Remove all non numeric chars from port string.
raimund renkert <raimund.renkert@intevation.de>
parents:
207
diff
changeset
|
321 strBuff.append(c); |
e672f5134d6e
Remove all non numeric chars from port string.
raimund renkert <raimund.renkert@intevation.de>
parents:
207
diff
changeset
|
322 } |
e672f5134d6e
Remove all non numeric chars from port string.
raimund renkert <raimund.renkert@intevation.de>
parents:
207
diff
changeset
|
323 } |
e672f5134d6e
Remove all non numeric chars from port string.
raimund renkert <raimund.renkert@intevation.de>
parents:
207
diff
changeset
|
324 |
130
5991c1f90f91
Added data source "SDE" to writer.
vc11884admin@VC11884.win.bsh.de
parents:
129
diff
changeset
|
325 layer.setConnection( |
137
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
326 layerElement.getAttribute("server") + "," + |
238
e672f5134d6e
Remove all non numeric chars from port string.
raimund renkert <raimund.renkert@intevation.de>
parents:
207
diff
changeset
|
327 "port:" + strBuff.toString() + "," + |
197
cdbf2f2dca35
Check for database connectio user parameter for SDE connections.
raimund renkert <raimund.renkert@intevation.de>
parents:
196
diff
changeset
|
328 database_auth + "," + |
137
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
329 layerElement.getAttribute("user") + ",<PASSWORD>"); |
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
330 layer.setData( |
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
331 layerElement.getAttribute("data_source") + |
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
332 ",SHAPE," + |
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
333 layerElement.getAttribute("version")); |
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
334 layer.setProcessing("CLOSE_CONNECTION=defer"); |
134
acc9e5430177
Handle SDE connection attributes and expressions.
vc11884admin@VC11884.win.bsh.de
parents:
132
diff
changeset
|
335 layer.setProcessing("ATTRIBUTE_QUALIFIED=TRUE"); |
137
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
336 if(layerElement.hasAttribute("join_table")) { |
196
5350621a0294
Verify the SDE databse jointable attribute.
raimund renkert <raimund.renkert@intevation.de>
parents:
190
diff
changeset
|
337 String join = layerElement.getAttribute("join_table"); |
203
123fd9887a4f
Rollback the jointable checks.
raimund renkert <raimund.renkert@intevation.de>
parents:
200
diff
changeset
|
338 |
134
acc9e5430177
Handle SDE connection attributes and expressions.
vc11884admin@VC11884.win.bsh.de
parents:
132
diff
changeset
|
339 layer.setProcessing( |
137
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
340 "JOINTABLE=" + |
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
341 layerElement.getAttribute("join_table")); |
134
acc9e5430177
Handle SDE connection attributes and expressions.
vc11884admin@VC11884.win.bsh.de
parents:
132
diff
changeset
|
342 layer.setFilter( |
acc9e5430177
Handle SDE connection attributes and expressions.
vc11884admin@VC11884.win.bsh.de
parents:
132
diff
changeset
|
343 "where " + |
acc9e5430177
Handle SDE connection attributes and expressions.
vc11884admin@VC11884.win.bsh.de
parents:
132
diff
changeset
|
344 layerElement.getAttribute("definition_query") + |
acc9e5430177
Handle SDE connection attributes and expressions.
vc11884admin@VC11884.win.bsh.de
parents:
132
diff
changeset
|
345 " AND " + |
acc9e5430177
Handle SDE connection attributes and expressions.
vc11884admin@VC11884.win.bsh.de
parents:
132
diff
changeset
|
346 layerElement.getAttribute("join_table_target") + "." + |
acc9e5430177
Handle SDE connection attributes and expressions.
vc11884admin@VC11884.win.bsh.de
parents:
132
diff
changeset
|
347 layerElement.getAttribute("join_field_target") + "=" + |
acc9e5430177
Handle SDE connection attributes and expressions.
vc11884admin@VC11884.win.bsh.de
parents:
132
diff
changeset
|
348 layerElement.getAttribute("join_table") + "." + |
acc9e5430177
Handle SDE connection attributes and expressions.
vc11884admin@VC11884.win.bsh.de
parents:
132
diff
changeset
|
349 layerElement.getAttribute("join_field")); |
137
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
350 } |
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
351 else { |
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
352 prefix = layerElement.getAttribute("data_source"); |
180
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
353 if(layerElement.hasAttribute("definition_query") && |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
354 !layerElement.getAttribute("definition_query") |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
355 .equals("")) { |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
356 layer.setFilter("where " + |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
357 layerElement.getAttribute("definition_query")); |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
358 } |
137
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
359 } |
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
360 } |
129
0b119169618f
Insert TEMPLATE entry for GFI request.
Raimund Renkert <rrenkert@intevation.de>
parents:
128
diff
changeset
|
361 layer.setTemplate("PleaseInsertAValidTemplateForGFI"); |
179
f3a91cd7440b
Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
175
diff
changeset
|
362 |
181 | 363 // Create labelitem |
180
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
364 NodeList labels = layerElement.getElementsByTagName("label"); |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
365 if(labels.getLength() > 0) { |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
366 Element label = (Element)labels.item(0); |
179
f3a91cd7440b
Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
175
diff
changeset
|
367 String expr = label.getAttribute("expression"); |
180
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
368 expr = expr.replaceAll("\\[", ""); |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
369 expr = expr.replaceAll("\\]", ""); |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
370 if(!prefix.equals("")) { |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
371 expr = prefix + "." + expr; |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
372 } |
199
c56547b228f9
Remove leading and trailing whitespaces from labelitem.
raimund renkert <raimund.renkert@intevation.de>
parents:
197
diff
changeset
|
373 layer.setLabelitem(expr.trim()); |
180
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
374 } |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
375 |
42
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
376 //Write classes. |
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
377 writeClass(layer, layerElement); |
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
378 } |
196
5350621a0294
Verify the SDE databse jointable attribute.
raimund renkert <raimund.renkert@intevation.de>
parents:
190
diff
changeset
|
379 return true; |
41
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
380 } |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
381 |
42
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
382 /** |
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
383 * Adds the classes to the layer. |
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
384 * @param layer Mapscript layer object. |
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
385 * @param layerElement Dom element containing the class attributes. |
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
386 */ |
120
11d63bf00326
Changed exception handling and logging in writer classes.
Raimund Renkert <rrenkert@intevation.de>
parents:
102
diff
changeset
|
387 private void writeClass(layerObj layer, Element layerElement) { |
87
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
62
diff
changeset
|
388 logger.debug("writeClass(layerObj, Element)"); |
42
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
389 //Get all renderer elements (renderer in arcgis equals class in the |
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
390 //mapfile.) |
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
391 NodeList list = layerElement.getElementsByTagName("renderer"); |
41
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
392 |
42
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
393 //Create all found class objects and write the symbols and styles for |
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
394 //each class. |
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
395 for(int i = 0; i < list.getLength(); i++) { |
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
396 Element classElement = (Element)list.item(i); |
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
397 classObj co = new classObj(layer); |
124
0f5819732288
Set label text as class name in mapfile.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
398 String name = classElement.getAttribute("label"); |
189
0965f8af70fa
Replace german umlauts and trim strings.
raimund renkert <raimund.renkert@intevation.de>
parents:
186
diff
changeset
|
399 name = validateString(name); |
99
d6d2a4058ebf
Set the class name to the layer name if it is empty.
Raimund Renkert <rrenkert@intevation.de>
parents:
98
diff
changeset
|
400 if (name.equals("")) { |
d6d2a4058ebf
Set the class name to the layer name if it is empty.
Raimund Renkert <rrenkert@intevation.de>
parents:
98
diff
changeset
|
401 name = layerElement.getAttribute("name"); |
189
0965f8af70fa
Replace german umlauts and trim strings.
raimund renkert <raimund.renkert@intevation.de>
parents:
186
diff
changeset
|
402 name = validateString(name); |
99
d6d2a4058ebf
Set the class name to the layer name if it is empty.
Raimund Renkert <rrenkert@intevation.de>
parents:
98
diff
changeset
|
403 if (list.getLength() > 1) { |
d6d2a4058ebf
Set the class name to the layer name if it is empty.
Raimund Renkert <rrenkert@intevation.de>
parents:
98
diff
changeset
|
404 name += "-" + i; |
d6d2a4058ebf
Set the class name to the layer name if it is empty.
Raimund Renkert <rrenkert@intevation.de>
parents:
98
diff
changeset
|
405 } |
d6d2a4058ebf
Set the class name to the layer name if it is empty.
Raimund Renkert <rrenkert@intevation.de>
parents:
98
diff
changeset
|
406 } |
d6d2a4058ebf
Set the class name to the layer name if it is empty.
Raimund Renkert <rrenkert@intevation.de>
parents:
98
diff
changeset
|
407 co.setName (name); |
179
f3a91cd7440b
Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
175
diff
changeset
|
408 |
181 | 409 //Create label object. |
180
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
410 NodeList labels = layerElement.getElementsByTagName("label"); |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
411 if(labels.getLength() > 0) { |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
412 Element labelElement = (Element)labels.item(0); |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
413 String layerType = layerElement.getAttribute("type"); |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
414 writeLabel(co, labelElement, layerType); |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
415 } |
181 | 416 |
417 //Create definition expression. | |
44
9b5fb5e5914d
Added expressions for mapserver classes.
Raimund Renkert <rrenkert@intevation.de>
parents:
43
diff
changeset
|
418 if(classElement.hasAttribute("field_count")) { |
152
8a87c796bf47
Fixed expression for the first min value.
vc11884admin@VC11884.win.bsh.de
parents:
148
diff
changeset
|
419 co.setExpression(createExpression(classElement, i)); |
44
9b5fb5e5914d
Added expressions for mapserver classes.
Raimund Renkert <rrenkert@intevation.de>
parents:
43
diff
changeset
|
420 } |
181 | 421 |
42
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
422 //Write symbols and styles. |
97
18e4f143896b
Added polygon writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
96
diff
changeset
|
423 NodeList l = classElement.getChildNodes(); |
141
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
137
diff
changeset
|
424 for (int j = l.getLength() - 1; j >= 0; j--) { |
97
18e4f143896b
Added polygon writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
96
diff
changeset
|
425 Element elem = (Element)l.item(j); |
18e4f143896b
Added polygon writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
96
diff
changeset
|
426 |
18e4f143896b
Added polygon writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
96
diff
changeset
|
427 String type = layerElement.getAttribute("type"); |
180
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
428 if(type.equals("point") && |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
429 elem.getTagName().equals("symbol")) { |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
430 MarkerStyleWriter swriter = |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
431 new MarkerStyleWriter (this.map, co); |
97
18e4f143896b
Added polygon writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
96
diff
changeset
|
432 swriter.write (elem); |
87
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
62
diff
changeset
|
433 } |
180
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
434 else if(type.equals("line") && |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
435 elem.getTagName().equals("symbol")) { |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
436 LineStyleWriter swriter = |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
437 new LineStyleWriter (this.map, co); |
97
18e4f143896b
Added polygon writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
96
diff
changeset
|
438 swriter.write (elem); |
18e4f143896b
Added polygon writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
96
diff
changeset
|
439 } |
180
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
440 else if(type.equals("polygon") && |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
441 elem.getTagName().equals("symbol")) { |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
442 FillStyleWriter swriter = |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
443 new FillStyleWriter (this.map, co); |
97
18e4f143896b
Added polygon writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
96
diff
changeset
|
444 swriter.write (elem); |
87
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
62
diff
changeset
|
445 } |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
62
diff
changeset
|
446 } |
42
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
447 } |
41
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
448 } |
126
ff0354265a7d
Write the correct expression for double values.
Raimund Renkert <rrenkert@intevation.de>
parents:
124
diff
changeset
|
449 |
181 | 450 /** |
451 * Create a label object in a class object. | |
452 * | |
453 * @param co Class object. | |
454 * @param labelElement DOM element containing label attributes. | |
455 * @param layertype The layer type. Used to define the label position. | |
456 */ | |
179
f3a91cd7440b
Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
175
diff
changeset
|
457 private void writeLabel( |
180
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
458 classObj co, |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
459 Element labelElement, |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
460 String layerType) { |
179
f3a91cd7440b
Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
175
diff
changeset
|
461 |
181 | 462 //Get the label object. Each class has a predefined labelobject. |
179
f3a91cd7440b
Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
175
diff
changeset
|
463 labelObj label = co.getLabel(); |
181 | 464 |
465 //Get the label text symbol attributes from DOM. | |
180
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
466 Element symbol = (Element)labelElement.getFirstChild(); |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
467 if(symbol != null && symbol.getTagName().equals("symbol")) { |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
468 String type = symbol.getAttribute("type"); |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
469 if(type.equals("text")) { |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
470 label.setType(MS_FONT_TYPE.MS_TRUETYPE); |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
471 } |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
472 label.setSize(Double.parseDouble(symbol.getAttribute("size"))); |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
473 |
179
f3a91cd7440b
Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
175
diff
changeset
|
474 if(symbol.hasAttribute("color")) { |
f3a91cd7440b
Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
175
diff
changeset
|
475 String c = symbol.getAttribute("color"); |
f3a91cd7440b
Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
175
diff
changeset
|
476 Color col = Color.decode(c); |
f3a91cd7440b
Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
175
diff
changeset
|
477 colorObj color = new colorObj( |
f3a91cd7440b
Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
175
diff
changeset
|
478 col.getRed(), |
f3a91cd7440b
Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
175
diff
changeset
|
479 col.getGreen(), |
f3a91cd7440b
Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
175
diff
changeset
|
480 col.getBlue(), |
f3a91cd7440b
Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
175
diff
changeset
|
481 -4); |
f3a91cd7440b
Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
175
diff
changeset
|
482 label.setColor(color); |
180
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
483 } |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
484 if(symbol.hasAttribute("font")) { |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
485 String font = symbol.getAttribute("font"); |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
486 fontSetObj fso = this.map.getFontset(); |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
487 hashTableObj fonts = fso.getFonts(); |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
488 String mapFont = fonts.get(font,""); |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
489 if(mapFont != null && !mapFont.equals("")) { |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
490 label.setFont(font); |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
491 } |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
492 else { |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
493 logger.info( |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
494 "Could not find font " + font + " in font set. " + |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
495 "Using FreeSans for labels."); |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
496 label.setFont("FreeSans"); |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
497 } |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
498 } |
179
f3a91cd7440b
Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
175
diff
changeset
|
499 |
f3a91cd7440b
Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
175
diff
changeset
|
500 if(labelElement.hasAttribute("max_scale")) { |
180
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
501 double min = |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
502 Double.parseDouble(labelElement.getAttribute("max_scale")); |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
503 if(min > 0) { |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
504 label.setMinscaledenom(min); |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
505 } |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
506 } |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
507 if(labelElement.hasAttribute("min_scale")) { |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
508 double max = |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
509 Double.parseDouble(labelElement.getAttribute("min_scale")); |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
510 if(max > 0) { |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
511 label.setMaxscaledenom(max); |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
512 } |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
513 } |
179
f3a91cd7440b
Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
175
diff
changeset
|
514 |
181 | 515 //Set the label position. |
180
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
516 if(layerType.equals("point")) { |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
517 label.setPosition(MS_POSITIONS_ENUM.MS_UC.swigValue()); |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
518 } |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
519 } |
179
f3a91cd7440b
Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
175
diff
changeset
|
520 } |
f3a91cd7440b
Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
175
diff
changeset
|
521 |
181 | 522 /** |
523 * Create definition expression. | |
524 * | |
525 * @param ce DOM elementcontaining the class expression information. | |
526 * @param index Index to determine the correct expression operator. | |
527 */ | |
152
8a87c796bf47
Fixed expression for the first min value.
vc11884admin@VC11884.win.bsh.de
parents:
148
diff
changeset
|
528 private String createExpression(Element ce, int index) { |
137
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
529 String expression = "("; |
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
530 int count = 0; |
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
531 try { |
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
532 count = Integer.parseInt(ce.getAttribute("field_count")); |
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
533 } |
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
534 catch(NumberFormatException nfe) { |
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
535 return ""; |
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
536 } |
181 | 537 |
137
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
538 if(count == 1) { |
181 | 539 //Create single field expression. |
540 try { | |
541 //If no exception is thrown, the expression value is a number. | |
134
acc9e5430177
Handle SDE connection attributes and expressions.
vc11884admin@VC11884.win.bsh.de
parents:
132
diff
changeset
|
542 Double.parseDouble(ce.getAttribute("value")); |
137
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
543 String exp = ce.getAttribute("expression_field_0"); |
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
544 String pre = ""; |
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
545 if (!prefix.equals("") && !exp.startsWith(prefix)) { |
134
acc9e5430177
Handle SDE connection attributes and expressions.
vc11884admin@VC11884.win.bsh.de
parents:
132
diff
changeset
|
546 pre = prefix + "."; |
137
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
547 } |
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
548 expression += "[" + pre; |
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
549 expression += ce.getAttribute("expression_field_0") + "]"; |
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
550 if(ce.hasAttribute("min_value")) { |
180
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
551 if(index == 0) { |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
552 expression += " >= " + ce.getAttribute("min_value"); |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
553 } |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
554 else { |
152
8a87c796bf47
Fixed expression for the first min value.
vc11884admin@VC11884.win.bsh.de
parents:
148
diff
changeset
|
555 expression += " > " + ce.getAttribute("min_value"); |
180
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
556 } |
181 | 557 expression += " AND [" + pre; |
558 expression += ce.getAttribute("expression_field_0"); | |
559 expression += "]"; | |
137
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
560 } |
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
561 expression += " " + ce.getAttribute("expression_operator"); |
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
562 expression += " " + ce.getAttribute("value") + ")"; |
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
563 } |
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
564 catch(NumberFormatException nfe) { |
181 | 565 //The expression value is a strings. |
137
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
566 String exp = ce.getAttribute("expression_field_0"); |
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
567 String pre = ""; |
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
568 if (!prefix.equals("") && !exp.startsWith(prefix)) { |
134
acc9e5430177
Handle SDE connection attributes and expressions.
vc11884admin@VC11884.win.bsh.de
parents:
132
diff
changeset
|
569 pre = prefix + "."; |
137
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
570 } |
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
571 expression += "\"[" + pre; |
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
572 expression += ce.getAttribute("expression_field_0") + "]\""; |
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
573 expression += " " + ce.getAttribute("expression_operator"); |
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
574 expression += " \"" + ce.getAttribute("value") + "\")"; |
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
575 } |
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
576 catch(Exception e) { |
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
577 e.printStackTrace(); |
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
578 } |
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
579 } |
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
580 else { |
181 | 581 //Create a multi field expression. |
134
acc9e5430177
Handle SDE connection attributes and expressions.
vc11884admin@VC11884.win.bsh.de
parents:
132
diff
changeset
|
582 for (int i = 0; i < count; i++) { |
acc9e5430177
Handle SDE connection attributes and expressions.
vc11884admin@VC11884.win.bsh.de
parents:
132
diff
changeset
|
583 try { |
181 | 584 //If no exception is thrown, the expression values are |
585 //numbers. | |
134
acc9e5430177
Handle SDE connection attributes and expressions.
vc11884admin@VC11884.win.bsh.de
parents:
132
diff
changeset
|
586 Double.parseDouble(ce.getAttribute("value_" + i)); |
acc9e5430177
Handle SDE connection attributes and expressions.
vc11884admin@VC11884.win.bsh.de
parents:
132
diff
changeset
|
587 String exp = ce.getAttribute("expression_field_" + i); |
acc9e5430177
Handle SDE connection attributes and expressions.
vc11884admin@VC11884.win.bsh.de
parents:
132
diff
changeset
|
588 String pre = ""; |
acc9e5430177
Handle SDE connection attributes and expressions.
vc11884admin@VC11884.win.bsh.de
parents:
132
diff
changeset
|
589 if (!prefix.equals("") && !exp.startsWith(prefix)) { |
acc9e5430177
Handle SDE connection attributes and expressions.
vc11884admin@VC11884.win.bsh.de
parents:
132
diff
changeset
|
590 pre = prefix + "."; |
acc9e5430177
Handle SDE connection attributes and expressions.
vc11884admin@VC11884.win.bsh.de
parents:
132
diff
changeset
|
591 } |
acc9e5430177
Handle SDE connection attributes and expressions.
vc11884admin@VC11884.win.bsh.de
parents:
132
diff
changeset
|
592 expression += "[" + pre; |
180
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
593 expression += ce.getAttribute("expression_field_" + i); |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
594 expression += "]"; |
134
acc9e5430177
Handle SDE connection attributes and expressions.
vc11884admin@VC11884.win.bsh.de
parents:
132
diff
changeset
|
595 expression += " " + ce.getAttribute("expression_operator"); |
acc9e5430177
Handle SDE connection attributes and expressions.
vc11884admin@VC11884.win.bsh.de
parents:
132
diff
changeset
|
596 expression += " " + ce.getAttribute("value_" + i); |
137
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
597 if (i < count - 1) { |
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
598 expression += " AND "; |
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
599 } |
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
600 else { |
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
601 expression += ")"; |
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
602 } |
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
603 } |
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
604 catch (NumberFormatException nfe) { |
181 | 605 //The expression values are strings. |
137
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
606 String exp = ce.getAttribute("expression_field_" + i); |
134
acc9e5430177
Handle SDE connection attributes and expressions.
vc11884admin@VC11884.win.bsh.de
parents:
132
diff
changeset
|
607 String pre = ""; |
acc9e5430177
Handle SDE connection attributes and expressions.
vc11884admin@VC11884.win.bsh.de
parents:
132
diff
changeset
|
608 if (!prefix.equals("") && !exp.startsWith(prefix)) { |
acc9e5430177
Handle SDE connection attributes and expressions.
vc11884admin@VC11884.win.bsh.de
parents:
132
diff
changeset
|
609 pre = prefix + "."; |
acc9e5430177
Handle SDE connection attributes and expressions.
vc11884admin@VC11884.win.bsh.de
parents:
132
diff
changeset
|
610 } |
acc9e5430177
Handle SDE connection attributes and expressions.
vc11884admin@VC11884.win.bsh.de
parents:
132
diff
changeset
|
611 expression += "\"[" + pre; |
180
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
612 expression += ce.getAttribute("expression_field_" + i); |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
613 expression += "]\""; |
134
acc9e5430177
Handle SDE connection attributes and expressions.
vc11884admin@VC11884.win.bsh.de
parents:
132
diff
changeset
|
614 expression += " " + ce.getAttribute("expression_operator"); |
186
1391f911ee39
Add quotes to an expression if the value is a string.
raimund renkert <raimund.renkert@intevation.de>
parents:
181
diff
changeset
|
615 expression += " \"" + ce.getAttribute("value_" + i); |
137
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
616 if (i < count - 1) { |
186
1391f911ee39
Add quotes to an expression if the value is a string.
raimund renkert <raimund.renkert@intevation.de>
parents:
181
diff
changeset
|
617 expression += "\" AND "; |
137
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
618 } |
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
619 else { |
186
1391f911ee39
Add quotes to an expression if the value is a string.
raimund renkert <raimund.renkert@intevation.de>
parents:
181
diff
changeset
|
620 expression += "\")"; |
137
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
621 } |
126
ff0354265a7d
Write the correct expression for double values.
Raimund Renkert <rrenkert@intevation.de>
parents:
124
diff
changeset
|
622 } |
ff0354265a7d
Write the correct expression for double values.
Raimund Renkert <rrenkert@intevation.de>
parents:
124
diff
changeset
|
623 } |
ff0354265a7d
Write the correct expression for double values.
Raimund Renkert <rrenkert@intevation.de>
parents:
124
diff
changeset
|
624 } |
137
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
625 return expression; |
127
5ba8bf865dc7
Write expressions for string values to the mapfile.
Raimund Renkert <rrenkert@intevation.de>
parents:
126
diff
changeset
|
626 } |
189
0965f8af70fa
Replace german umlauts and trim strings.
raimund renkert <raimund.renkert@intevation.de>
parents:
186
diff
changeset
|
627 |
0965f8af70fa
Replace german umlauts and trim strings.
raimund renkert <raimund.renkert@intevation.de>
parents:
186
diff
changeset
|
628 /** |
0965f8af70fa
Replace german umlauts and trim strings.
raimund renkert <raimund.renkert@intevation.de>
parents:
186
diff
changeset
|
629 * Replaces german umlauts and removes leading and trailing whitespaces. |
0965f8af70fa
Replace german umlauts and trim strings.
raimund renkert <raimund.renkert@intevation.de>
parents:
186
diff
changeset
|
630 * |
0965f8af70fa
Replace german umlauts and trim strings.
raimund renkert <raimund.renkert@intevation.de>
parents:
186
diff
changeset
|
631 * @param s String |
0965f8af70fa
Replace german umlauts and trim strings.
raimund renkert <raimund.renkert@intevation.de>
parents:
186
diff
changeset
|
632 */ |
0965f8af70fa
Replace german umlauts and trim strings.
raimund renkert <raimund.renkert@intevation.de>
parents:
186
diff
changeset
|
633 private String validateString (String s) { |
0965f8af70fa
Replace german umlauts and trim strings.
raimund renkert <raimund.renkert@intevation.de>
parents:
186
diff
changeset
|
634 if (s.equals("")) { |
0965f8af70fa
Replace german umlauts and trim strings.
raimund renkert <raimund.renkert@intevation.de>
parents:
186
diff
changeset
|
635 return ""; |
0965f8af70fa
Replace german umlauts and trim strings.
raimund renkert <raimund.renkert@intevation.de>
parents:
186
diff
changeset
|
636 } |
0965f8af70fa
Replace german umlauts and trim strings.
raimund renkert <raimund.renkert@intevation.de>
parents:
186
diff
changeset
|
637 String tmp = s.trim(); |
243
df4e0946ef02
Added LGPL header.
Raimund Renkert <rrenkert@intevation.de>
parents:
239
diff
changeset
|
638 tmp = tmp.replace ("ö", "oe"); |
df4e0946ef02
Added LGPL header.
Raimund Renkert <rrenkert@intevation.de>
parents:
239
diff
changeset
|
639 tmp = tmp.replace ("ä", "ae"); |
df4e0946ef02
Added LGPL header.
Raimund Renkert <rrenkert@intevation.de>
parents:
239
diff
changeset
|
640 tmp = tmp.replace ("ü", "ue"); |
df4e0946ef02
Added LGPL header.
Raimund Renkert <rrenkert@intevation.de>
parents:
239
diff
changeset
|
641 tmp = tmp.replace ("ß", "ss"); |
239
8aefef8a1626
Remove special characters from layername and classname.
raimund renkert <raimund.renkert@intevation.de>
parents:
238
diff
changeset
|
642 if(!s.equals(tmp)) { |
8aefef8a1626
Remove special characters from layername and classname.
raimund renkert <raimund.renkert@intevation.de>
parents:
238
diff
changeset
|
643 logger.info("Renamed \"" + s + "\" to \"" + tmp + "\"."); |
8aefef8a1626
Remove special characters from layername and classname.
raimund renkert <raimund.renkert@intevation.de>
parents:
238
diff
changeset
|
644 } |
189
0965f8af70fa
Replace german umlauts and trim strings.
raimund renkert <raimund.renkert@intevation.de>
parents:
186
diff
changeset
|
645 return tmp; |
0965f8af70fa
Replace german umlauts and trim strings.
raimund renkert <raimund.renkert@intevation.de>
parents:
186
diff
changeset
|
646 } |
244
276f63c86f1c
Refactored group layer handling and "wms_title" metadata.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
647 |
276f63c86f1c
Refactored group layer handling and "wms_title" metadata.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
648 |
276f63c86f1c
Refactored group layer handling and "wms_title" metadata.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
649 /** |
276f63c86f1c
Refactored group layer handling and "wms_title" metadata.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
650 * Replaces special characters and removes leading and trailing whitespaces. |
276f63c86f1c
Refactored group layer handling and "wms_title" metadata.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
651 * |
276f63c86f1c
Refactored group layer handling and "wms_title" metadata.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
652 * @param s String |
276f63c86f1c
Refactored group layer handling and "wms_title" metadata.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
653 * |
276f63c86f1c
Refactored group layer handling and "wms_title" metadata.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
654 * @return the input string without special chars. |
276f63c86f1c
Refactored group layer handling and "wms_title" metadata.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
655 */ |
276f63c86f1c
Refactored group layer handling and "wms_title" metadata.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
656 private String validateLayerName (String s) { |
276f63c86f1c
Refactored group layer handling and "wms_title" metadata.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
657 if(s.equals("")) { |
276f63c86f1c
Refactored group layer handling and "wms_title" metadata.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
658 return ""; |
276f63c86f1c
Refactored group layer handling and "wms_title" metadata.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
659 } |
276f63c86f1c
Refactored group layer handling and "wms_title" metadata.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
660 |
276f63c86f1c
Refactored group layer handling and "wms_title" metadata.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
661 String tmp = s.trim(); |
276f63c86f1c
Refactored group layer handling and "wms_title" metadata.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
662 tmp = tmp.replace(" ", ""); |
276f63c86f1c
Refactored group layer handling and "wms_title" metadata.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
663 tmp = tmp.replace("/", ""); |
276f63c86f1c
Refactored group layer handling and "wms_title" metadata.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
664 tmp = tmp.replace(",", ""); |
276f63c86f1c
Refactored group layer handling and "wms_title" metadata.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
665 tmp = tmp.replace("#", ""); |
276f63c86f1c
Refactored group layer handling and "wms_title" metadata.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
666 tmp = tmp.replace("+", ""); |
276f63c86f1c
Refactored group layer handling and "wms_title" metadata.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
667 tmp = tmp.replace("~", ""); |
276f63c86f1c
Refactored group layer handling and "wms_title" metadata.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
668 tmp = tmp.replace("(", ""); |
276f63c86f1c
Refactored group layer handling and "wms_title" metadata.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
669 tmp = tmp.replace(")", ""); |
276f63c86f1c
Refactored group layer handling and "wms_title" metadata.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
670 tmp = tmp.replace("{", ""); |
276f63c86f1c
Refactored group layer handling and "wms_title" metadata.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
671 tmp = tmp.replace("}", ""); |
276f63c86f1c
Refactored group layer handling and "wms_title" metadata.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
672 tmp = tmp.replace("[", ""); |
276f63c86f1c
Refactored group layer handling and "wms_title" metadata.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
673 tmp = tmp.replace("]", ""); |
276f63c86f1c
Refactored group layer handling and "wms_title" metadata.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
674 tmp = tmp.replace("<", ""); |
276f63c86f1c
Refactored group layer handling and "wms_title" metadata.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
675 tmp = tmp.replace(">", ""); |
276f63c86f1c
Refactored group layer handling and "wms_title" metadata.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
676 tmp = tmp.replace("*", ""); |
276f63c86f1c
Refactored group layer handling and "wms_title" metadata.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
677 tmp = tmp.replace("\\\\", ""); |
276f63c86f1c
Refactored group layer handling and "wms_title" metadata.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
678 tmp = tmp.replace("^", ""); |
276f63c86f1c
Refactored group layer handling and "wms_title" metadata.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
679 if(!s.equals(tmp)) { |
276f63c86f1c
Refactored group layer handling and "wms_title" metadata.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
680 logger.info("Renamed \"" + s +"\" to \"" + tmp +"\"."); |
276f63c86f1c
Refactored group layer handling and "wms_title" metadata.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
681 } |
276f63c86f1c
Refactored group layer handling and "wms_title" metadata.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
682 return tmp; |
276f63c86f1c
Refactored group layer handling and "wms_title" metadata.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
683 } |
41
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
684 } |