Mercurial > mxd2map
annotate src/java/de/intevation/mxd/reader/SimpleRendererReader.java @ 165:87afe66f7d88
Merged with raimunds changes
author | Stephan Holl <stephan.holl@intevation.de> |
---|---|
date | Thu, 30 Jun 2011 14:59:44 +0200 |
parents | a4ab239509f1 |
children | 0bde090506f9 |
rev | line source |
---|---|
33
c51376f8e24c
Separated converter components into packages.
Raimund Renkert <rrenkert@intevation.de>
parents:
31
diff
changeset
|
1 package de.intevation.mxd.reader; |
25
cbd67b1100d8
Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
2 |
cbd67b1100d8
Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
3 import org.apache.log4j.Logger; |
cbd67b1100d8
Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
4 |
cbd67b1100d8
Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
5 import com.esri.arcgis.carto.IFeatureRenderer; |
cbd67b1100d8
Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
6 import com.esri.arcgis.display.ISymbol; |
cbd67b1100d8
Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
7 import com.esri.arcgis.carto.SimpleRenderer; |
cbd67b1100d8
Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
8 |
31
40c0b4e5f91a
Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
26
diff
changeset
|
9 import org.w3c.dom.Element; |
116
c8a1361ddd38
Improved exceptionhandlin for renderer reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
83
diff
changeset
|
10 import java.io.IOException; |
31
40c0b4e5f91a
Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
26
diff
changeset
|
11 |
33
c51376f8e24c
Separated converter components into packages.
Raimund Renkert <rrenkert@intevation.de>
parents:
31
diff
changeset
|
12 import de.intevation.mxd.utils.MapToXMLUtils; |
c51376f8e24c
Separated converter components into packages.
Raimund Renkert <rrenkert@intevation.de>
parents:
31
diff
changeset
|
13 |
25
cbd67b1100d8
Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
14 /** |
cbd67b1100d8
Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
15 * Reads simple renderer information. |
cbd67b1100d8
Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
16 * |
cbd67b1100d8
Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
17 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> |
cbd67b1100d8
Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
18 */ |
31
40c0b4e5f91a
Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
26
diff
changeset
|
19 public class SimpleRendererReader |
40c0b4e5f91a
Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
26
diff
changeset
|
20 implements IRendererReader { |
25
cbd67b1100d8
Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
21 |
31
40c0b4e5f91a
Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
26
diff
changeset
|
22 /** |
40c0b4e5f91a
Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
26
diff
changeset
|
23 * The logger. |
40c0b4e5f91a
Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
26
diff
changeset
|
24 */ |
40c0b4e5f91a
Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
26
diff
changeset
|
25 private static final Logger logger = |
36
472aa36d0e01
Added a new layer reader and symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
34
diff
changeset
|
26 Logger.getLogger(SimpleRendererReader.class); |
31
40c0b4e5f91a
Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
26
diff
changeset
|
27 |
40c0b4e5f91a
Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
26
diff
changeset
|
28 /** |
40c0b4e5f91a
Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
26
diff
changeset
|
29 * Private member. |
40c0b4e5f91a
Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
26
diff
changeset
|
30 */ |
25
cbd67b1100d8
Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
31 private ISymbol symbol; |
31
40c0b4e5f91a
Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
26
diff
changeset
|
32 private SimpleRenderer renderer; |
40c0b4e5f91a
Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
26
diff
changeset
|
33 private Element layer; |
40c0b4e5f91a
Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
26
diff
changeset
|
34 private MapToXMLUtils util; |
25
cbd67b1100d8
Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
35 |
cbd67b1100d8
Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
36 |
31
40c0b4e5f91a
Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
26
diff
changeset
|
37 public SimpleRendererReader(IFeatureRenderer renderer) |
40c0b4e5f91a
Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
26
diff
changeset
|
38 throws Exception { |
40c0b4e5f91a
Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
26
diff
changeset
|
39 logger.debug("constructor()"); |
40c0b4e5f91a
Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
26
diff
changeset
|
40 if(renderer instanceof SimpleRenderer) { |
40c0b4e5f91a
Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
26
diff
changeset
|
41 this.renderer = (SimpleRenderer)renderer; |
25
cbd67b1100d8
Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
42 } |
31
40c0b4e5f91a
Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
26
diff
changeset
|
43 else{ |
40c0b4e5f91a
Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
26
diff
changeset
|
44 throw new Exception ("Not an instance of SimpleRenderer!"); |
40c0b4e5f91a
Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
26
diff
changeset
|
45 } |
25
cbd67b1100d8
Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
46 } |
cbd67b1100d8
Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
47 |
31
40c0b4e5f91a
Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
26
diff
changeset
|
48 /** |
40c0b4e5f91a
Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
26
diff
changeset
|
49 * Setter for the parent XML element. |
40c0b4e5f91a
Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
26
diff
changeset
|
50 * |
40c0b4e5f91a
Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
26
diff
changeset
|
51 * @param parent The XML parent node. |
40c0b4e5f91a
Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
26
diff
changeset
|
52 */ |
40c0b4e5f91a
Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
26
diff
changeset
|
53 public void setParent(Element parent) { |
40c0b4e5f91a
Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
26
diff
changeset
|
54 this.layer = parent; |
40c0b4e5f91a
Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
26
diff
changeset
|
55 } |
40c0b4e5f91a
Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
26
diff
changeset
|
56 |
40c0b4e5f91a
Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
26
diff
changeset
|
57 /** |
40c0b4e5f91a
Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
26
diff
changeset
|
58 * Setter for the XML document helper. |
40c0b4e5f91a
Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
26
diff
changeset
|
59 * |
40c0b4e5f91a
Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
26
diff
changeset
|
60 * @param util The helper class for storing map information. |
40c0b4e5f91a
Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
26
diff
changeset
|
61 */ |
40c0b4e5f91a
Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
26
diff
changeset
|
62 public void setUtil(MapToXMLUtils util) { |
40c0b4e5f91a
Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
26
diff
changeset
|
63 this.util = util; |
40c0b4e5f91a
Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
26
diff
changeset
|
64 } |
40c0b4e5f91a
Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
26
diff
changeset
|
65 |
40c0b4e5f91a
Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
26
diff
changeset
|
66 /** |
40c0b4e5f91a
Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
26
diff
changeset
|
67 * Reads the renderer attributes. |
40c0b4e5f91a
Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
26
diff
changeset
|
68 * |
40c0b4e5f91a
Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
26
diff
changeset
|
69 * @return The XML node. |
40c0b4e5f91a
Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
26
diff
changeset
|
70 */ |
116
c8a1361ddd38
Improved exceptionhandlin for renderer reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
83
diff
changeset
|
71 public Element read() { |
31
40c0b4e5f91a
Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
26
diff
changeset
|
72 logger.debug("read()"); |
40c0b4e5f91a
Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
26
diff
changeset
|
73 Element rendererElement; |
74
7eba97e8201b
Catch all exceptions in the MXDReader.
Raimund Renkert <rrenkert@intevation.de>
parents:
72
diff
changeset
|
74 rendererElement = util.addRenderer(layer); |
60
37ff67a4991d
Added TODO for line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
46
diff
changeset
|
75 |
116
c8a1361ddd38
Improved exceptionhandlin for renderer reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
83
diff
changeset
|
76 try { |
c8a1361ddd38
Improved exceptionhandlin for renderer reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
83
diff
changeset
|
77 rendererElement.setAttribute("label", renderer.getLabel()); |
31
40c0b4e5f91a
Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
26
diff
changeset
|
78 } |
116
c8a1361ddd38
Improved exceptionhandlin for renderer reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
83
diff
changeset
|
79 catch(IOException ioe) { |
c8a1361ddd38
Improved exceptionhandlin for renderer reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
83
diff
changeset
|
80 logger.warn( |
c8a1361ddd38
Improved exceptionhandlin for renderer reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
83
diff
changeset
|
81 "Could not read label name." + |
c8a1361ddd38
Improved exceptionhandlin for renderer reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
83
diff
changeset
|
82 "Setting label name to \"default-label\""); |
c8a1361ddd38
Improved exceptionhandlin for renderer reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
83
diff
changeset
|
83 rendererElement.setAttribute("label", "default-label"); |
31
40c0b4e5f91a
Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents:
26
diff
changeset
|
84 } |
116
c8a1361ddd38
Improved exceptionhandlin for renderer reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
83
diff
changeset
|
85 |
c8a1361ddd38
Improved exceptionhandlin for renderer reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
83
diff
changeset
|
86 try { |
c8a1361ddd38
Improved exceptionhandlin for renderer reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
83
diff
changeset
|
87 rendererElement.setAttribute( |
c8a1361ddd38
Improved exceptionhandlin for renderer reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
83
diff
changeset
|
88 "description", |
c8a1361ddd38
Improved exceptionhandlin for renderer reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
83
diff
changeset
|
89 renderer.getDescription()); |
74
7eba97e8201b
Catch all exceptions in the MXDReader.
Raimund Renkert <rrenkert@intevation.de>
parents:
72
diff
changeset
|
90 } |
116
c8a1361ddd38
Improved exceptionhandlin for renderer reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
83
diff
changeset
|
91 catch(IOException ioe) { |
135
a4ab239509f1
Updated the default values and reader error handling.
Raimund Renkert <rrenkert@intevation.de>
parents:
116
diff
changeset
|
92 logger.warn("Could not read description."); |
116
c8a1361ddd38
Improved exceptionhandlin for renderer reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
83
diff
changeset
|
93 } |
c8a1361ddd38
Improved exceptionhandlin for renderer reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
83
diff
changeset
|
94 |
c8a1361ddd38
Improved exceptionhandlin for renderer reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
83
diff
changeset
|
95 try { |
c8a1361ddd38
Improved exceptionhandlin for renderer reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
83
diff
changeset
|
96 symbol = renderer.getSymbol(); |
c8a1361ddd38
Improved exceptionhandlin for renderer reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
83
diff
changeset
|
97 |
c8a1361ddd38
Improved exceptionhandlin for renderer reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
83
diff
changeset
|
98 MarkerSymbolReader markerReader = new MarkerSymbolReader(); |
c8a1361ddd38
Improved exceptionhandlin for renderer reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
83
diff
changeset
|
99 LineSymbolReader lineReader = new LineSymbolReader(); |
c8a1361ddd38
Improved exceptionhandlin for renderer reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
83
diff
changeset
|
100 FillSymbolReader fillReader = new FillSymbolReader(); |
c8a1361ddd38
Improved exceptionhandlin for renderer reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
83
diff
changeset
|
101 if(markerReader.canRead(symbol)) { |
c8a1361ddd38
Improved exceptionhandlin for renderer reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
83
diff
changeset
|
102 markerReader.setSymbol(symbol); |
c8a1361ddd38
Improved exceptionhandlin for renderer reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
83
diff
changeset
|
103 markerReader.setUtil(util); |
c8a1361ddd38
Improved exceptionhandlin for renderer reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
83
diff
changeset
|
104 markerReader.setParent(rendererElement); |
c8a1361ddd38
Improved exceptionhandlin for renderer reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
83
diff
changeset
|
105 markerReader.read(); |
c8a1361ddd38
Improved exceptionhandlin for renderer reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
83
diff
changeset
|
106 } |
c8a1361ddd38
Improved exceptionhandlin for renderer reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
83
diff
changeset
|
107 else if(lineReader.canRead(symbol)) { |
c8a1361ddd38
Improved exceptionhandlin for renderer reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
83
diff
changeset
|
108 lineReader.setSymbol(symbol); |
c8a1361ddd38
Improved exceptionhandlin for renderer reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
83
diff
changeset
|
109 lineReader.setUtil(util); |
c8a1361ddd38
Improved exceptionhandlin for renderer reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
83
diff
changeset
|
110 lineReader.setParent(rendererElement); |
c8a1361ddd38
Improved exceptionhandlin for renderer reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
83
diff
changeset
|
111 lineReader.read(); |
c8a1361ddd38
Improved exceptionhandlin for renderer reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
83
diff
changeset
|
112 } |
c8a1361ddd38
Improved exceptionhandlin for renderer reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
83
diff
changeset
|
113 else if(fillReader.canRead(symbol)) { |
c8a1361ddd38
Improved exceptionhandlin for renderer reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
83
diff
changeset
|
114 fillReader.setSymbol(symbol); |
c8a1361ddd38
Improved exceptionhandlin for renderer reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
83
diff
changeset
|
115 fillReader.setUtil(util); |
c8a1361ddd38
Improved exceptionhandlin for renderer reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
83
diff
changeset
|
116 fillReader.setParent(rendererElement); |
c8a1361ddd38
Improved exceptionhandlin for renderer reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
83
diff
changeset
|
117 fillReader.read(); |
c8a1361ddd38
Improved exceptionhandlin for renderer reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
83
diff
changeset
|
118 } |
c8a1361ddd38
Improved exceptionhandlin for renderer reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
83
diff
changeset
|
119 else { |
c8a1361ddd38
Improved exceptionhandlin for renderer reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
83
diff
changeset
|
120 logger.debug( |
c8a1361ddd38
Improved exceptionhandlin for renderer reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
83
diff
changeset
|
121 "No known Symbol type: " + |
c8a1361ddd38
Improved exceptionhandlin for renderer reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
83
diff
changeset
|
122 symbol.getClass().toString()); |
c8a1361ddd38
Improved exceptionhandlin for renderer reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
83
diff
changeset
|
123 } |
c8a1361ddd38
Improved exceptionhandlin for renderer reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
83
diff
changeset
|
124 } |
c8a1361ddd38
Improved exceptionhandlin for renderer reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
83
diff
changeset
|
125 catch(Exception e) { |
c8a1361ddd38
Improved exceptionhandlin for renderer reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
83
diff
changeset
|
126 logger.error("Could not read symbol. Stopped reading renderer."); |
74
7eba97e8201b
Catch all exceptions in the MXDReader.
Raimund Renkert <rrenkert@intevation.de>
parents:
72
diff
changeset
|
127 } |
7eba97e8201b
Catch all exceptions in the MXDReader.
Raimund Renkert <rrenkert@intevation.de>
parents:
72
diff
changeset
|
128 return layer; |
25
cbd67b1100d8
Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
129 } |
cbd67b1100d8
Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
130 } |
cbd67b1100d8
Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
131 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |