Mercurial > mxd2map
comparison src/java/de/intevation/mxd/writer/MapScriptWriter.java @ 134:acc9e5430177
Handle SDE connection attributes and expressions.
author | vc11884admin@VC11884.win.bsh.de |
---|---|
date | Wed, 22 Jun 2011 12:01:28 +0200 |
parents | 02df1dbc2166 |
children | cd55975ba0c4 |
comparison
equal
deleted
inserted
replaced
133:6b80d2c7536e | 134:acc9e5430177 |
---|---|
39 */ | 39 */ |
40 private Document root; | 40 private Document root; |
41 private mapObj map; | 41 private mapObj map; |
42 private String mapFilename; | 42 private String mapFilename; |
43 private String MS_BINDIR = "c:/ms_6.1-dev/bin"; | 43 private String MS_BINDIR = "c:/ms_6.1-dev/bin"; |
44 private String prefix = ""; | |
44 | 45 |
45 public MapScriptWriter() { | 46 public MapScriptWriter() { |
46 map = new mapObj(""); | 47 map = new mapObj(""); |
47 mapFilename = ""; | 48 mapFilename = ""; |
48 } | 49 } |
182 } | 183 } |
183 layer.setTileitem(""); | 184 layer.setTileitem(""); |
184 | 185 |
185 //The layer datasource. | 186 //The layer datasource. |
186 String con_type = layerElement.getAttribute("connection_type"); | 187 String con_type = layerElement.getAttribute("connection_type"); |
187 if(con_type.equals("local")) { | 188 if(con_type.equals("local")) { |
188 String datasource = ""; | 189 String datasource = ""; |
189 if(layerElement.hasAttribute("workspace")) { | 190 if(layerElement.hasAttribute("workspace")) { |
190 datasource = layerElement.getAttribute("workspace"); | 191 datasource = layerElement.getAttribute("workspace"); |
191 datasource += File.separator; | 192 datasource += File.separator; |
192 } | 193 } |
208 layer.setData( | 209 layer.setData( |
209 layerElement.getAttribute("data_source") + | 210 layerElement.getAttribute("data_source") + |
210 ",SHAPE," + | 211 ",SHAPE," + |
211 layerElement.getAttribute("version")); | 212 layerElement.getAttribute("version")); |
212 layer.setProcessing("CLOSE_CONNECTION=defer"); | 213 layer.setProcessing("CLOSE_CONNECTION=defer"); |
213 layer.setProcessing("ATTRIBUTE_QUALIFIED=TRUE"); | 214 layer.setProcessing("ATTRIBUTE_QUALIFIED=TRUE"); |
214 layer.setProcessing( | 215 if(layerElement.hasAttribute("join_table")) { |
215 "JOINTABLE=" + | 216 layer.setProcessing( |
216 layerElement.getAttribute("join_table")); | 217 "JOINTABLE=" + |
217 layer.setFilter( | 218 layerElement.getAttribute("join_table")); |
218 "where " + | 219 layer.setFilter( |
219 layerElement.getAttribute("definition_query") + | 220 "where " + |
220 " AND " + | 221 layerElement.getAttribute("definition_query") + |
221 layerElement.getAttribute("join_table_target") + "." + | 222 " AND " + |
222 layerElement.getAttribute("join_field_target") + "=" + | 223 layerElement.getAttribute("join_table_target") + "." + |
223 layerElement.getAttribute("join_table") + "." + | 224 layerElement.getAttribute("join_field_target") + "=" + |
224 layerElement.getAttribute("join_field")); | 225 layerElement.getAttribute("join_table") + "." + |
225 | 226 layerElement.getAttribute("join_field")); |
227 } | |
228 else { | |
229 prefix = layerElement.getAttribute("data_source"); | |
230 } | |
226 } | 231 } |
227 layer.setTemplate("PleaseInsertAValidTemplateForGFI"); | 232 layer.setTemplate("PleaseInsertAValidTemplateForGFI"); |
228 //Write classes. | 233 //Write classes. |
229 writeClass(layer, layerElement); | 234 writeClass(layer, layerElement); |
230 } | 235 } |
254 name += "-" + i; | 259 name += "-" + i; |
255 } | 260 } |
256 } | 261 } |
257 co.setName (name); | 262 co.setName (name); |
258 if(classElement.hasAttribute("field_count")) { | 263 if(classElement.hasAttribute("field_count")) { |
259 int count = | 264 co.setExpression(createExpression(classElement)); |
260 Integer.parseInt(classElement.getAttribute("field_count")); | |
261 int type = 0; | |
262 try { | |
263 Double.parseDouble(classElement.getAttribute("value")); | |
264 type = 1; | |
265 } | |
266 catch(Exception e) { | |
267 type = 2; | |
268 } | |
269 if (type == 1) { | |
270 co.setExpression(createDoubleExpression(classElement, count)); | |
271 } | |
272 else if (type == 2) { | |
273 co.setExpression(createStringExpression(classElement, count)); | |
274 } | |
275 | |
276 } | 265 } |
277 //Write symbols and styles. | 266 //Write symbols and styles. |
278 NodeList l = classElement.getChildNodes(); | 267 NodeList l = classElement.getChildNodes(); |
279 for (int j = 0; j < l.getLength(); j++) { | 268 for (int j = 0; j < l.getLength(); j++) { |
280 Element elem = (Element)l.item(j); | 269 Element elem = (Element)l.item(j); |
293 swriter.write (elem); | 282 swriter.write (elem); |
294 } | 283 } |
295 } | 284 } |
296 } | 285 } |
297 } | 286 } |
287 | |
288 | |
289 private String createExpression(Element ce) { | |
290 String expression = "("; | |
291 int count = 0; | |
292 try { | |
293 count = Integer.parseInt(ce.getAttribute("field_count")); | |
294 } | |
295 catch(NumberFormatException nfe) { | |
296 return ""; | |
297 } | |
298 if(count == 1) { | |
299 try { | |
300 Double.parseDouble(ce.getAttribute("value")); | |
301 String exp = ce.getAttribute("expression_field_0"); | |
302 String pre = ""; | |
303 if (!prefix.equals("") && !exp.startsWith(prefix)) { | |
304 pre = prefix + "."; | |
305 } | |
306 expression += "[" + pre; | |
307 expression += ce.getAttribute("expression_field_0") + "]"; | |
308 if(ce.hasAttribute("min_value")) { | |
309 expression += " > " + ce.getAttribute("min_value"); | |
310 expression += " AND ["; | |
311 expression += ce.getAttribute("expression_field_0")+ "]"; | |
312 } | |
313 expression += " " + ce.getAttribute("expression_operator"); | |
314 expression += " " + ce.getAttribute("value") + ")"; | |
315 } | |
316 catch(NumberFormatException nfe) { | |
317 String exp = ce.getAttribute("expression_field_0"); | |
318 String pre = ""; | |
319 if (!prefix.equals("") && !exp.startsWith(prefix)) { | |
320 pre = prefix + "."; | |
321 } | |
322 expression += "\"[" + pre; | |
323 expression += ce.getAttribute("expression_field_0") + "]\""; | |
324 expression += " " + ce.getAttribute("expression_operator"); | |
325 expression += " \"" + ce.getAttribute("value") + "\")"; | |
326 } | |
327 catch(Exception e) { | |
328 e.printStackTrace(); | |
329 } | |
330 } | |
331 else { | |
332 for (int i = 0; i < count; i++) { | |
333 try { | |
334 Double.parseDouble(ce.getAttribute("value_" + i)); | |
335 String exp = ce.getAttribute("expression_field_" + i); | |
336 String pre = ""; | |
337 if (!prefix.equals("") && !exp.startsWith(prefix)) { | |
338 pre = prefix + "."; | |
339 } | |
340 expression += "[" + pre; | |
341 expression += ce.getAttribute("expression_field_" + i) + "]"; | |
342 expression += " " + ce.getAttribute("expression_operator"); | |
343 expression += " " + ce.getAttribute("value_" + i); | |
344 if (i < count - 1) { | |
345 expression += " AND "; | |
346 } | |
347 else { | |
348 expression += ")"; | |
349 } | |
350 } | |
351 catch (NumberFormatException nfe) { | |
352 String exp = ce.getAttribute("expression_field_" + i); | |
353 String pre = ""; | |
354 if (!prefix.equals("") && !exp.startsWith(prefix)) { | |
355 pre = prefix + "."; | |
356 } | |
357 expression += "\"[" + pre; | |
358 expression += ce.getAttribute("expression_field_" + i) + "]\""; | |
359 expression += " " + ce.getAttribute("expression_operator"); | |
360 expression += " " + ce.getAttribute("value_" + i); | |
361 if (i < count - 1) { | |
362 expression += " AND "; | |
363 } | |
364 else { | |
365 expression += ")"; | |
366 } | |
367 } | |
368 } | |
369 } | |
370 return expression; | |
371 } | |
372 | |
373 | |
374 | |
375 | |
376 | |
377 | |
378 | |
379 | |
380 | |
381 | |
382 | |
383 | |
384 | |
385 | |
386 | |
387 | |
388 | |
389 | |
390 | |
391 | |
392 | |
298 | 393 |
299 private String createDoubleExpression (Element classElement, int count) { | 394 private String createDoubleExpression (Element classElement, int count) { |
300 String exp = ""; | 395 String exp = ""; |
301 String op = classElement.getAttribute("expression_operator"); | 396 String op = classElement.getAttribute("expression_operator"); |
302 String op1 = ""; | 397 String op1 = ""; |