comparison src/java/de/intevation/mxd/reader/MarkerFillSymbolReader.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 59e06c405a9a
children a4ab239509f1
comparison
equal deleted inserted replaced
114:93699e8f2d1f 115:fb93f20478cc
12 import com.esri.arcgis.display.esriSimpleFillStyle; 12 import com.esri.arcgis.display.esriSimpleFillStyle;
13 import com.esri.arcgis.display.IRgbColor; 13 import com.esri.arcgis.display.IRgbColor;
14 import com.esri.arcgis.display.RgbColor; 14 import com.esri.arcgis.display.RgbColor;
15 15
16 import org.w3c.dom.Element; 16 import org.w3c.dom.Element;
17 import java.io.IOException;
17 18
18 /** 19 /**
19 * Reads marker line symbol information. 20 * Reads marker line symbol information.
20 * 21 *
21 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> 22 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
60 /** 61 /**
61 * Reads the symbol attributes. 62 * Reads the symbol attributes.
62 * 63 *
63 * @return The XML node. 64 * @return The XML node.
64 */ 65 */
65 public Element read() 66 public Element read() {
66 throws Exception {
67 logger.debug("read()"); 67 logger.debug("read()");
68 68
69 Element symbolElement = util.addSymbol(parent); 69 Element symbolElement = util.addSymbol(parent);
70 70
71 symbolElement.setAttribute("name", symbol.getNameString()); 71 try {
72 symbolElement.setAttribute("name", symbol.getNameString());
73 }
74 catch(IOException ioe) {
75 logger.warn("Could not read name. Setting name to \"default\".");
76 symbolElement.setAttribute("name", "default");
77 }
72 symbolElement.setAttribute("style", "fill"); 78 symbolElement.setAttribute("style", "fill");
73 symbolElement.setAttribute( 79
74 "xoffset", 80 try {
75 String.valueOf(symbol.getXOffset())); 81 symbolElement.setAttribute(
76 symbolElement.setAttribute( 82 "xoffset",
77 "yoffset", 83 String.valueOf(symbol.getXOffset()));
78 String.valueOf(symbol.getYOffset())); 84 }
79 symbolElement.setAttribute( 85 catch(IOException ioe) {
80 "xseparation", 86 logger.warn("Could not read x-offset. Setting x-offset to 0");
81 String.valueOf(symbol.getXSeparation())); 87 symbolElement.setAttribute("xoffset", "0");
82 symbolElement.setAttribute( 88 }
83 "yseparation", 89
84 String.valueOf(symbol.getYSeparation())); 90 try {
85 91 symbolElement.setAttribute(
86 int style = symbol.getStyle(); 92 "yoffset",
93 String.valueOf(symbol.getYOffset()));
94 }
95 catch(IOException ioe) {
96 logger.warn("Could not read y-offset. Setting y-offset to 0.");
97 symbolElement.setAttribute("yoffset", "0");
98 }
99
100 try {
101 symbolElement.setAttribute(
102 "xseparation",
103 String.valueOf(symbol.getXSeparation()));
104 }
105 catch(IOException ioe) {
106 logger.warn(
107 "Could not read x-separation." +
108 " Setting x-separation to 0.");
109 symbolElement.setAttribute("xseparation", "0");
110 }
111
112 try {
113 symbolElement.setAttribute(
114 "yseparation",
115 String.valueOf(symbol.getYSeparation()));
116 }
117 catch(IOException ioe) {
118 logger.warn(
119 "Could not read y-separation." +
120 " Setting y-separation to 0.");
121 symbolElement.setAttribute("yseparation", "0");
122 }
123
124 int style;
125 try {
126 style = symbol.getStyle();
127 }
128 catch(IOException ioe) {
129 logger.warn("Could not read style. Setting style to \"empty\"");
130 style = -1;
131 }
87 switch(style) { 132 switch(style) {
88 case esriSimpleFillStyle.esriSFSCross: 133 case esriSimpleFillStyle.esriSFSCross:
89 symbolElement.setAttribute("fillstyle", "cross"); break; 134 symbolElement.setAttribute("fillstyle", "cross"); break;
90 case esriSimpleFillStyle.esriSFSSolid: 135 case esriSimpleFillStyle.esriSFSSolid:
91 symbolElement.setAttribute("fillstyle", "solid"); break; 136 symbolElement.setAttribute("fillstyle", "solid"); break;
101 symbolElement.setAttribute("fillstyle", "diagonalcross"); 146 symbolElement.setAttribute("fillstyle", "diagonalcross");
102 break; 147 break;
103 default: symbolElement.setAttribute("fillstyle", "empty"); 148 default: symbolElement.setAttribute("fillstyle", "empty");
104 } 149 }
105 150
106 if(symbol.getColor() instanceof IRgbColor) { 151 try {
107 IRgbColor color = (IRgbColor)symbol.getColor(); 152 if(symbol.getColor() instanceof IRgbColor) {
108 Color c = new Color ( 153 IRgbColor color = (IRgbColor)symbol.getColor();
109 color.getRed(), 154 Color c = new Color (
110 color.getGreen(), 155 color.getRed(),
111 color.getBlue()); 156 color.getGreen(),
112 symbolElement.setAttribute("color", String.valueOf(c.getRGB())); 157 color.getBlue());
113 symbolElement.setAttribute("transparency", 158 symbolElement.setAttribute("color", String.valueOf(c.getRGB()));
114 String.valueOf(color.getTransparency())); 159 symbolElement.setAttribute("transparency",
115 } 160 String.valueOf(color.getTransparency()));
116 else { 161 }
117 RgbColor col = new RgbColor(); 162 else {
118 col.setRGB(symbol.getColor().getRGB()); 163 RgbColor col = new RgbColor();
119 Color c = new Color ( 164 col.setRGB(symbol.getColor().getRGB());
120 col.getRed(), 165 Color c = new Color (
121 col.getGreen(), 166 col.getRed(),
122 col.getBlue()); 167 col.getGreen(),
123 symbolElement.setAttribute("color", String.valueOf(c.getRGB())); 168 col.getBlue());
124 symbolElement.setAttribute("transparency", 169 symbolElement.setAttribute("color", String.valueOf(c.getRGB()));
125 String.valueOf(col.getTransparency())); 170 symbolElement.setAttribute("transparency",
126 } 171 String.valueOf(col.getTransparency()));
127 172 }
128 ILineSymbol ls = symbol.getOutline(); 173 }
129 LineSymbolReader lsr = new LineSymbolReader(); 174 catch(IOException ioe) {
130 if(lsr.canRead(ls)) { 175 logger.warn(
131 lsr.setSymbol(ls); 176 "Could not read color." +
132 lsr.setUtil(util); 177 " Setting color to black with no transparency.");
133 lsr.setParent(symbolElement); 178 Color black = new Color (0, 0, 0);
134 lsr.read(); 179 symbolElement.setAttribute("color", String.valueOf(black.getRGB()));
135 } 180 symbolElement.setAttribute("transparency", "-1");
136 else { 181 }
137 logger.debug("The type of " + ls.getClass().toString() + 182
138 " is not implemented!"); 183 try {
139 } 184 ILineSymbol ls = symbol.getOutline();
140 185 LineSymbolReader lsr = new LineSymbolReader();
141 IMarkerSymbol sym = symbol.getMarkerSymbol(); 186 if(lsr.canRead(ls)) {
142 MarkerSymbolReader msr = new MarkerSymbolReader(); 187 lsr.setSymbol(ls);
143 if(msr.canRead(sym)) { 188 lsr.setUtil(util);
144 msr.setSymbol(sym); 189 lsr.setParent(symbolElement);
145 msr.setParent(symbolElement); 190 lsr.read();
146 msr.setUtil(util); 191 }
147 msr.read(); 192 else {
148 } 193 logger.debug("The type of " + ls.getClass().toString() +
149 else { 194 " is not implemented!");
150 logger.debug("The type of " + sym.getClass().toString() + 195 }
151 " is not implemented!"); 196 }
197 catch(Exception e) {
198 logger.warn("Could not read outline. No fallback defined.");
199 }
200
201 try {
202 IMarkerSymbol sym = symbol.getMarkerSymbol();
203 MarkerSymbolReader msr = new MarkerSymbolReader();
204 if(msr.canRead(sym)) {
205 msr.setSymbol(sym);
206 msr.setParent(symbolElement);
207 msr.setUtil(util);
208 msr.read();
209 }
210 else {
211 logger.debug("The type of " + sym.getClass().toString() +
212 " is not implemented!");
213 }
214 }
215 catch(Exception e) {
216 logger.warn("Could not read marker symbol. No fallback defined.");
152 } 217 }
153 return parent; 218 return parent;
154 } 219 }
155 } 220 }
156 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : 221 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)