Mercurial > mxd2map
annotate src/java/de/intevation/mxd/reader/PictureMarkerSymbolReader.java @ 115:fb93f20478cc
Improved exception handling for symbol reader.
author | Raimund Renkert <rrenkert@intevation.de> |
---|---|
date | Wed, 15 Jun 2011 16:48:42 +0200 |
parents | 475ee3e4bc8b |
children | a4ab239509f1 |
rev | line source |
---|---|
58
4e0464c620f0
Introduced the picture symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
1 package de.intevation.mxd.reader; |
4e0464c620f0
Introduced the picture symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
2 |
4e0464c620f0
Introduced the picture symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
3 import org.apache.log4j.Logger; |
4e0464c620f0
Introduced the picture symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
4 |
4e0464c620f0
Introduced the picture symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
5 import com.esri.arcgis.display.ISymbol; |
63
5c5ef5768893
Added MultiLayerLineSymbolReader.
Raimund Renkert <rrenkert@intevation.de>
parents:
58
diff
changeset
|
6 import com.esri.arcgis.display.IMarkerSymbol; |
58
4e0464c620f0
Introduced the picture symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
7 import com.esri.arcgis.display.PictureMarkerSymbol; |
4e0464c620f0
Introduced the picture symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
8 import com.esri.arcgis.carto.PictureElement; |
4e0464c620f0
Introduced the picture symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
9 |
4e0464c620f0
Introduced the picture symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
10 import org.w3c.dom.Element; |
115
fb93f20478cc
Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
89
diff
changeset
|
11 import java.io.IOException; |
58
4e0464c620f0
Introduced the picture symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
12 |
4e0464c620f0
Introduced the picture symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
13 /** |
4e0464c620f0
Introduced the picture symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
14 * Reads picture marker symbol information. |
4e0464c620f0
Introduced the picture symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
15 * |
4e0464c620f0
Introduced the picture symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
16 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> |
4e0464c620f0
Introduced the picture symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
17 */ |
80
83932f18dddc
All symbol reader now extend the abstract symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
74
diff
changeset
|
18 public class PictureMarkerSymbolReader |
83932f18dddc
All symbol reader now extend the abstract symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
74
diff
changeset
|
19 extends AbstractSymbolReader { |
58
4e0464c620f0
Introduced the picture symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
20 |
4e0464c620f0
Introduced the picture symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
21 /** |
4e0464c620f0
Introduced the picture symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
22 * The logger. |
4e0464c620f0
Introduced the picture symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
23 */ |
4e0464c620f0
Introduced the picture symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
24 private static final Logger logger = |
4e0464c620f0
Introduced the picture symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
25 Logger.getLogger(PictureMarkerSymbolReader.class); |
4e0464c620f0
Introduced the picture symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
26 |
4e0464c620f0
Introduced the picture symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
27 /** |
4e0464c620f0
Introduced the picture symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
28 * Private member. |
4e0464c620f0
Introduced the picture symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
29 */ |
4e0464c620f0
Introduced the picture symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
30 private PictureMarkerSymbol symbol; |
4e0464c620f0
Introduced the picture symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
31 |
4e0464c620f0
Introduced the picture symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
32 public PictureMarkerSymbolReader(ISymbol symbol) |
4e0464c620f0
Introduced the picture symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
33 throws Exception { |
4e0464c620f0
Introduced the picture symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
34 logger.debug("contructor()"); |
4e0464c620f0
Introduced the picture symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
35 if(symbol instanceof PictureMarkerSymbol) { |
4e0464c620f0
Introduced the picture symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
36 this.symbol = (PictureMarkerSymbol)symbol; |
4e0464c620f0
Introduced the picture symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
37 } |
4e0464c620f0
Introduced the picture symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
38 else { |
4e0464c620f0
Introduced the picture symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
39 throw new Exception("Not a PictureMarkerSymbol!"); |
4e0464c620f0
Introduced the picture symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
40 } |
4e0464c620f0
Introduced the picture symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
41 } |
4e0464c620f0
Introduced the picture symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
42 |
63
5c5ef5768893
Added MultiLayerLineSymbolReader.
Raimund Renkert <rrenkert@intevation.de>
parents:
58
diff
changeset
|
43 public PictureMarkerSymbolReader(IMarkerSymbol symbol) |
5c5ef5768893
Added MultiLayerLineSymbolReader.
Raimund Renkert <rrenkert@intevation.de>
parents:
58
diff
changeset
|
44 throws Exception { |
5c5ef5768893
Added MultiLayerLineSymbolReader.
Raimund Renkert <rrenkert@intevation.de>
parents:
58
diff
changeset
|
45 logger.debug("contructor()"); |
5c5ef5768893
Added MultiLayerLineSymbolReader.
Raimund Renkert <rrenkert@intevation.de>
parents:
58
diff
changeset
|
46 if(symbol instanceof PictureMarkerSymbol) { |
5c5ef5768893
Added MultiLayerLineSymbolReader.
Raimund Renkert <rrenkert@intevation.de>
parents:
58
diff
changeset
|
47 this.symbol = (PictureMarkerSymbol)symbol; |
5c5ef5768893
Added MultiLayerLineSymbolReader.
Raimund Renkert <rrenkert@intevation.de>
parents:
58
diff
changeset
|
48 } |
5c5ef5768893
Added MultiLayerLineSymbolReader.
Raimund Renkert <rrenkert@intevation.de>
parents:
58
diff
changeset
|
49 else { |
5c5ef5768893
Added MultiLayerLineSymbolReader.
Raimund Renkert <rrenkert@intevation.de>
parents:
58
diff
changeset
|
50 throw new Exception("Not a PictureMarkerSymbol!"); |
5c5ef5768893
Added MultiLayerLineSymbolReader.
Raimund Renkert <rrenkert@intevation.de>
parents:
58
diff
changeset
|
51 } |
5c5ef5768893
Added MultiLayerLineSymbolReader.
Raimund Renkert <rrenkert@intevation.de>
parents:
58
diff
changeset
|
52 } |
5c5ef5768893
Added MultiLayerLineSymbolReader.
Raimund Renkert <rrenkert@intevation.de>
parents:
58
diff
changeset
|
53 |
58
4e0464c620f0
Introduced the picture symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
54 /** |
4e0464c620f0
Introduced the picture symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
55 * Reads the symbol attributes. |
4e0464c620f0
Introduced the picture symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
56 * |
4e0464c620f0
Introduced the picture symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
57 * @return The XML node. |
4e0464c620f0
Introduced the picture symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
58 */ |
115
fb93f20478cc
Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
89
diff
changeset
|
59 public Element read() { |
84
2362609ffa66
Added TODOs for picture symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
83
diff
changeset
|
60 //TODO Read the picture from mxd and write it as base64 string to the |
2362609ffa66
Added TODOs for picture symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
83
diff
changeset
|
61 // XML Element. |
58
4e0464c620f0
Introduced the picture symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
62 logger.debug("read()"); |
80
83932f18dddc
All symbol reader now extend the abstract symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
74
diff
changeset
|
63 Element symbolElement = util.addSymbol(parent); |
58
4e0464c620f0
Introduced the picture symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
64 |
115
fb93f20478cc
Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
89
diff
changeset
|
65 try { |
fb93f20478cc
Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
89
diff
changeset
|
66 symbolElement.setAttribute( |
fb93f20478cc
Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
89
diff
changeset
|
67 "angle", |
fb93f20478cc
Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
89
diff
changeset
|
68 String.valueOf(symbol.getAngle())); |
fb93f20478cc
Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
89
diff
changeset
|
69 } |
fb93f20478cc
Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
89
diff
changeset
|
70 catch(IOException ioe) { |
fb93f20478cc
Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
89
diff
changeset
|
71 logger.warn("Could not read angle. Setting angle to 0."); |
fb93f20478cc
Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
89
diff
changeset
|
72 symbolElement.setAttribute("angle", "0"); |
fb93f20478cc
Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
89
diff
changeset
|
73 } |
fb93f20478cc
Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
89
diff
changeset
|
74 |
fb93f20478cc
Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
89
diff
changeset
|
75 try { |
fb93f20478cc
Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
89
diff
changeset
|
76 symbolElement.setAttribute( |
fb93f20478cc
Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
89
diff
changeset
|
77 "size", |
fb93f20478cc
Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
89
diff
changeset
|
78 String.valueOf(symbol.getSize())); |
fb93f20478cc
Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
89
diff
changeset
|
79 } |
fb93f20478cc
Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
89
diff
changeset
|
80 catch (IOException ioe) { |
fb93f20478cc
Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
89
diff
changeset
|
81 logger.warn("Could not read size. Setting size to 1."); |
fb93f20478cc
Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
89
diff
changeset
|
82 symbolElement.setAttribute("size", "0"); |
fb93f20478cc
Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
89
diff
changeset
|
83 } |
fb93f20478cc
Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
89
diff
changeset
|
84 |
fb93f20478cc
Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
89
diff
changeset
|
85 try { |
fb93f20478cc
Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
89
diff
changeset
|
86 symbolElement.setAttribute( |
fb93f20478cc
Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
89
diff
changeset
|
87 "x_offset", |
fb93f20478cc
Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
89
diff
changeset
|
88 String.valueOf(symbol.getXOffset())); |
fb93f20478cc
Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
89
diff
changeset
|
89 } |
fb93f20478cc
Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
89
diff
changeset
|
90 catch(IOException ioe) { |
fb93f20478cc
Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
89
diff
changeset
|
91 logger.warn("Could not read x-offset. Setting x-offset to 0"); |
fb93f20478cc
Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
89
diff
changeset
|
92 symbolElement.setAttribute("x_offset", "0"); |
fb93f20478cc
Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
89
diff
changeset
|
93 } |
fb93f20478cc
Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
89
diff
changeset
|
94 |
fb93f20478cc
Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
89
diff
changeset
|
95 try { |
fb93f20478cc
Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
89
diff
changeset
|
96 symbolElement.setAttribute( |
fb93f20478cc
Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
89
diff
changeset
|
97 "y_offset", |
fb93f20478cc
Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
89
diff
changeset
|
98 String.valueOf(symbol.getYOffset())); |
fb93f20478cc
Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
89
diff
changeset
|
99 } |
fb93f20478cc
Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
89
diff
changeset
|
100 catch(IOException ioe) { |
fb93f20478cc
Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
89
diff
changeset
|
101 logger.warn("Could not read y-offset. Setting y-offset to 0."); |
fb93f20478cc
Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
89
diff
changeset
|
102 symbolElement.setAttribute("y_offset", "0"); |
fb93f20478cc
Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
89
diff
changeset
|
103 } |
fb93f20478cc
Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
89
diff
changeset
|
104 |
fb93f20478cc
Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
89
diff
changeset
|
105 try { |
fb93f20478cc
Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
89
diff
changeset
|
106 symbolElement.setAttribute( |
fb93f20478cc
Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
89
diff
changeset
|
107 "name", |
fb93f20478cc
Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
89
diff
changeset
|
108 symbol.getNameString()); |
fb93f20478cc
Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
89
diff
changeset
|
109 } |
fb93f20478cc
Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
89
diff
changeset
|
110 catch(IOException ioe) { |
fb93f20478cc
Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
89
diff
changeset
|
111 logger.warn("Could not read name. Setting name to \"default\""); |
fb93f20478cc
Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
89
diff
changeset
|
112 symbolElement.setAttribute("name", "default"); |
fb93f20478cc
Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
89
diff
changeset
|
113 } |
fb93f20478cc
Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
89
diff
changeset
|
114 |
fb93f20478cc
Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
89
diff
changeset
|
115 try { |
fb93f20478cc
Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
89
diff
changeset
|
116 PictureElement pElem = new PictureElement(); |
fb93f20478cc
Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
89
diff
changeset
|
117 pElem.importPicture(symbol.getPicture()); |
fb93f20478cc
Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
89
diff
changeset
|
118 } |
fb93f20478cc
Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
89
diff
changeset
|
119 catch(IOException ioe) { |
fb93f20478cc
Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
89
diff
changeset
|
120 logger.warn("Could not read picture. No fallback defined."); |
fb93f20478cc
Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
89
diff
changeset
|
121 } |
58
4e0464c620f0
Introduced the picture symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
122 symbolElement.setAttribute("style", "picture"); |
89
475ee3e4bc8b
Added "type" as XML attribute to symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
84
diff
changeset
|
123 symbolElement.setAttribute("type", "marker"); |
58
4e0464c620f0
Introduced the picture symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
124 return symbolElement; |
4e0464c620f0
Introduced the picture symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
125 } |
4e0464c620f0
Introduced the picture symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
126 } |
4e0464c620f0
Introduced the picture symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
127 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |