comparison gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/horizontalcrosssection/HorizontalCrossSectionMeshOutputState.java @ 646:c8749d83d9b6

Added a configuration section for mapserver relevant stuff. Moved source to write meta files out to an own helper class named MetaWriter. gnv-artifacts/trunk@733 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Thu, 04 Mar 2010 16:23:24 +0000
parents 8d2bd52f05e3
children 8d475151b2c1
comparison
equal deleted inserted replaced
645:0cf162fa4334 646:c8749d83d9b6
45 45
46 import de.intevation.gnv.state.exception.StateException; 46 import de.intevation.gnv.state.exception.StateException;
47 47
48 import de.intevation.gnv.utils.FileUtils; 48 import de.intevation.gnv.utils.FileUtils;
49 import de.intevation.gnv.utils.MapfileGenerator; 49 import de.intevation.gnv.utils.MapfileGenerator;
50 import de.intevation.gnv.utils.MetaWriter;
50 import de.intevation.gnv.utils.Pair; 51 import de.intevation.gnv.utils.Pair;
51 import de.intevation.gnv.utils.ShapeFileWriter; 52 import de.intevation.gnv.utils.ShapeFileWriter;
52 import de.intevation.gnv.utils.StringUtils; 53 import de.intevation.gnv.utils.StringUtils;
53 import de.intevation.gnv.utils.WKTUtils; 54 import de.intevation.gnv.utils.WKTUtils;
54 55
55 import de.intevation.gnv.wms.LayerInfo;
56
57 import java.awt.Dimension; 56 import java.awt.Dimension;
58 57
59 import java.io.File; 58 import java.io.File;
60 import java.io.FileNotFoundException;
61 import java.io.FileOutputStream;
62 import java.io.IOException; 59 import java.io.IOException;
63 import java.io.OutputStream; 60 import java.io.OutputStream;
64 61
65 import java.util.ArrayList; 62 import java.util.ArrayList;
66 import java.util.Collection; 63 import java.util.Collection;
92 private static final long serialVersionUID = 3233620652465061860L; 89 private static final long serialVersionUID = 3233620652465061860L;
93 90
94 public static final boolean USE_INDEX_BUFFER = 91 public static final boolean USE_INDEX_BUFFER =
95 Boolean.getBoolean("gnv.horizontal.cross.section.mesh.index.buffer"); 92 Boolean.getBoolean("gnv.horizontal.cross.section.mesh.index.buffer");
96 93
97 public static final String META_FILE_NAME = "meta.xml";
98 public static final String ISOLINES_NAME = "isolines.shp"; 94 public static final String ISOLINES_NAME = "isolines.shp";
99 public static final String POLYGON_NAME = "polygons.shp"; 95 public static final String POLYGON_NAME = "polygons.shp";
100 public static final String LAYER_MODEL = "horizontalcrosssection"; 96 public static final String LAYER_MODEL = "horizontalcrosssection";
101 97
102 private String ijkQueryID; 98 private String ijkQueryID;
254 else { 250 else {
255 AttributedPoint2ds result = getResult(uuid, callContext); 251 AttributedPoint2ds result = getResult(uuid, callContext);
256 if (result != null 252 if (result != null
257 && (path = writeToShapeFile(uuid, result, callContext)) != null) { 253 && (path = writeToShapeFile(uuid, result, callContext)) != null) {
258 254
259 Document meta = null; 255 InputData inputParam = inputData.get("parameterid");
260 if ((meta = writeMeta(callContext, uuid, path)) != null) { 256 Map<Integer, PaletteManager> paletteManagers =
257 getPalettes(callContext);
258 String paramType = null;
259
260 if (inputParam == null || paletteManagers == null) {
261 log.warn("Parameter-id not found.");
262 paramType = LAYER_MODEL;
263 }
264 else {
265 Integer parameterId = Integer.parseInt(inputParam.getValue());
266 PaletteManager paletteManager = paletteManagers.get(parameterId);
267
268 paramType = LAYER_MODEL + "_" + paletteManager.getName();
269 }
270
271 Document meta = MetaWriter.writeHorizontalcrosssectionMeta(
272 callContext, uuid, path, paramType);
273 if (meta != null) {
261 MapfileGenerator.getInstance().update(); 274 MapfileGenerator.getInstance().update();
262 return meta; 275 return meta;
263 } 276 }
264 277
265 pathElement.setTextContent(path); 278 pathElement.setTextContent(path);
337 finally { 350 finally {
338 if (!success && createdDir) { 351 if (!success && createdDir) {
339 FileUtils.deleteRecursive(shapeDir); 352 FileUtils.deleteRecursive(shapeDir);
340 } 353 }
341 } 354 }
342 } 355 }
343
344 protected Document writeMeta(CallContext context, String uuid, String path){
345 InputData inputParam = inputData.get("parameterid");
346 Map<Integer, PaletteManager> paletteManagers = getPalettes(context);
347 String paramType = null;
348
349 if (inputParam == null || paletteManagers == null) {
350 log.warn("Parameter-id not found.");
351 paramType = LAYER_MODEL;
352 }
353 else {
354 Integer parameterId = Integer.parseInt(inputParam.getValue());
355 PaletteManager paletteManager = paletteManagers.get(parameterId);
356
357 paramType = LAYER_MODEL + "_" + paletteManager.getName();
358 }
359
360
361 Document meta = XMLUtils.newDocument();
362 XMLUtils.ElementCreator creator = new XMLUtils.ElementCreator(
363 meta,
364 ArtifactNamespaceContext.NAMESPACE_URI,
365 ArtifactNamespaceContext.NAMESPACE_PREFIX);
366
367 Element root = creator.create("meta");
368 meta.appendChild(root);
369
370 writePolygonMeta(context, meta, root, uuid, path, paramType);
371 writeIsolineMeta(context, meta, root, uuid, path, paramType);
372
373 try {
374 File metaFile = new File(path, META_FILE_NAME);
375
376 if (!metaFile.createNewFile() || !metaFile.canWrite()) {
377 log.error("Error while writing meta file: "+metaFile.toString());
378 return null;
379 }
380
381 OutputStream out = null;
382 boolean success = false;
383 try {
384 out = new FileOutputStream(metaFile);
385 success = XMLUtils.toStream(meta, out);
386 }
387 finally {
388 if (out != null) {
389 try { out.close(); }
390 catch (IOException ioe) {}
391 }
392 }
393
394 if (!success && metaFile.exists()) {
395 metaFile.delete();
396 }
397
398 return success ? meta : null;
399 }
400 catch (FileNotFoundException fnfe) {
401 log.error(fnfe);
402 }
403 catch (IOException ioe) {
404 log.error(ioe, ioe);
405 }
406
407 return meta;
408 }
409
410
411 protected void writePolygonMeta(
412 CallContext context,
413 Document document,
414 Element meta,
415 String uuid,
416 String path,
417 String paramType
418 ) {
419 XMLUtils.ElementCreator creator = new XMLUtils.ElementCreator(
420 document,
421 ArtifactNamespaceContext.NAMESPACE_URI,
422 ArtifactNamespaceContext.NAMESPACE_PREFIX);
423
424 Element layer = creator.create(LayerInfo.LAYER);
425 Element model = creator.create(LayerInfo.LAYER_MODEL);
426 Element name = creator.create(LayerInfo.LAYER_NAME);
427 Element type = creator.create(LayerInfo.LAYER_TYPE);
428 Element status = creator.create(LayerInfo.LAYER_STATUS);
429 Element data = creator.create(LayerInfo.LAYER_DATA);
430
431 model.setTextContent(paramType);
432 name.setTextContent(uuid);
433 type.setTextContent("POLYGON");
434 status.setTextContent("DEFAULT");
435 data.setTextContent(POLYGON_NAME);
436
437 layer.appendChild(model);
438 layer.appendChild(name);
439 layer.appendChild(type);
440 layer.appendChild(status);
441 layer.appendChild(data);
442
443 meta.appendChild(layer);
444 }
445
446
447 protected void writeIsolineMeta(
448 CallContext context,
449 Document document,
450 Element meta,
451 String uuid,
452 String path,
453 String paramType
454 ) {
455 XMLUtils.ElementCreator creator = new XMLUtils.ElementCreator(
456 document,
457 ArtifactNamespaceContext.NAMESPACE_URI,
458 ArtifactNamespaceContext.NAMESPACE_PREFIX);
459
460 Element layer = creator.create(LayerInfo.LAYER);
461 Element model = creator.create(LayerInfo.LAYER_MODEL);
462 Element name = creator.create(LayerInfo.LAYER_NAME);
463 Element type = creator.create(LayerInfo.LAYER_TYPE);
464 Element status = creator.create(LayerInfo.LAYER_STATUS);
465 Element data = creator.create(LayerInfo.LAYER_DATA);
466
467 model.setTextContent(paramType+"_isolines");
468 name.setTextContent(uuid);
469 type.setTextContent("LINE");
470 status.setTextContent("DEFAULT");
471 data.setTextContent(ISOLINES_NAME);
472
473 layer.appendChild(model);
474 layer.appendChild(name);
475 layer.appendChild(type);
476 layer.appendChild(status);
477 layer.appendChild(data);
478
479 meta.appendChild(layer);
480 }
481 356
482 357
483 protected AttributedPoint2ds getResult(String uuid, CallContext callContext) 358 protected AttributedPoint2ds getResult(String uuid, CallContext callContext)
484 throws StateException 359 throws StateException
485 { 360 {

http://dive4elements.wald.intevation.org