comparison gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/horizontalcrosssection/HorizontalCrossSectionMeshOutputState.java @ 1057:04967dc9c83f

The title of a layer can be changed by the user. Product 'Layer' and 'Horizontalschnitt' now use the same code path to write the meta information file. (issue198) gnv-artifacts/trunk@1134 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Thu, 27 May 2010 16:43:00 +0000
parents c07d9f9a738c
children cc4ec127d666
comparison
equal deleted inserted replaced
1056:0318fda0001e 1057:04967dc9c83f
304 document.appendChild(pathElement); 304 document.appendChild(pathElement);
305 305
306 String path = getShapeFilePath(); 306 String path = getShapeFilePath();
307 307
308 if (path != null && new File(path).isDirectory()) { 308 if (path != null && new File(path).isDirectory()) {
309 String title = getLayerTitle(inputData); 309 Document meta = MetaWriter.initMeta();
310 if (title == null) { 310 MetaWriter.insertAbstractMeta(callContext, meta);
311 title = uuid; 311
312 } 312 String prefix = getLayerPrefix(inputData);
313 313 if (prefix == null) {
314 callContext.putContextValue( 314 prefix = uuid;
315 MetaWriter.CONTEXT_LAYER_TITLE, title); 315 }
316 316
317 String paramType = findParameterType(callContext); 317 // append polygon meta
318 318 String model = findParameterType(callContext);
319 if (log.isDebugEnabled()) { 319 String type = "POLYGON";
320 log.debug("Layer title: " + title); 320 String name = getLayerName(uuid, type);
321 log.debug("Layer type: " + paramType); 321 String title = getLayerTitle(prefix, type);
322 } 322 String data = getLayerData(uuid, POLYGON_NAME);
323 323 String status = "OFF";
324 Document meta = MetaWriter.writeHorizontalcrosssectionMeta( 324 MetaWriter.insertLayer(
325 callContext, uuid, path, paramType); 325 callContext, meta, name, title, data, model, type, status);
326
327 // append isoline meta
328 model += "_isolines";
329 type = "LINE";
330 name = getLayerName(uuid, type);
331 title = getLayerTitle(prefix, type);
332 data = getLayerData(uuid, ISOLINES_NAME);
333 MetaWriter.insertLayer(
334 callContext, meta, name, title, data, model, type, status);
335
326 if (meta != null) { 336 if (meta != null) {
337 MetaWriter.writeMetaFile(path, meta);
327 MapfileGenerator.getInstance().update(); 338 MapfileGenerator.getInstance().update();
328 return meta; 339 return meta;
329 } 340 }
330 341
331 pathElement.setTextContent(path); 342 pathElement.setTextContent(path);
334 AttributedPoint2ds result = getResult(uuid, callContext); 345 AttributedPoint2ds result = getResult(uuid, callContext);
335 ExclusiveExec.UniqueKey key = ExclusiveExec.INSTANCE.acquire(uuid); 346 ExclusiveExec.UniqueKey key = ExclusiveExec.INSTANCE.acquire(uuid);
336 try{ 347 try{
337 if (result != null 348 if (result != null
338 && (path = writeToShapeFile(uuid, result, callContext)) != null) { 349 && (path = writeToShapeFile(uuid, result, callContext)) != null) {
339 350 Document meta = MetaWriter.initMeta();
340 String paramType = findParameterType(callContext); 351 MetaWriter.insertAbstractMeta(callContext, meta);
341 352
342 String title = getLayerTitle(inputData); 353 String prefix = getLayerPrefix(inputData);
343 if (title == null) { 354 if (prefix == null) {
344 title = uuid; 355 prefix = uuid;
345 } 356 }
346 callContext.putContextValue( 357
347 MetaWriter.CONTEXT_LAYER_TITLE, title); 358 // append polygon meta
348 359 String model = findParameterType(callContext);
349 if (log.isDebugEnabled()) { 360 String type = "POLYGON";
350 log.debug("Parameter type: " + paramType); 361 String name = getLayerName(uuid, type);
351 log.debug("Layer title: " + title); 362 String title = getLayerTitle(prefix, type);
352 } 363 String data = getLayerData(uuid, POLYGON_NAME);
353 364 String status = "OFF";
354 Document meta = MetaWriter.writeHorizontalcrosssectionMeta( 365 MetaWriter.insertLayer(
355 callContext, uuid, path, paramType); 366 callContext, meta, name, title, data, model, type, status);
367
368 // append isoline meta
369 model += "_isolines";
370 type = "LINE";
371 name = getLayerName(uuid, type);
372 title = getLayerTitle(prefix, type);
373 data = getLayerData(uuid, ISOLINES_NAME);
374 MetaWriter.insertLayer(
375 callContext, meta, name, title, data, model, type, status);
356 376
357 if (meta != null) { 377 if (meta != null) {
378 MetaWriter.writeMetaFile(path, meta);
358 MapfileGenerator.getInstance().update(); 379 MapfileGenerator.getInstance().update();
359 return meta; 380 return meta;
360 } 381 }
361 382
362 pathElement.setTextContent(path); 383 pathElement.setTextContent(path);
398 * Find the title for a wms layer specified by the user. 419 * Find the title for a wms layer specified by the user.
399 * 420 *
400 * @param inputData A collection with InputData objects. 421 * @param inputData A collection with InputData objects.
401 * @return the title. 422 * @return the title.
402 */ 423 */
403 protected String getLayerTitle(Collection<InputData> inputData) { 424 protected String getLayerPrefix(Collection<InputData> inputData) {
404 for (InputData data: inputData) { 425 for (InputData data: inputData) {
405 String name = data.getName(); 426 String name = data.getName();
406 if (name != null && name.equals("title")) { 427 if (name != null && name.equals("title")) {
407 return (String) data.getValue(); 428 return (String) data.getValue();
408 } 429 }
409 } 430 }
410 431
411 return null; 432 return null;
433 }
434
435
436 /**
437 * Returns the name of the layer.
438 *
439 * @param uuid The uuid the the current session. It is the base part of the
440 * layername.
441 * @param type The type of the layer ('POLYGON' or 'LINE').
442 * @return the name of the layer.
443 */
444 protected String getLayerName(String uuid, String type) {
445 return uuid + "-" + type;
446 }
447
448 /**
449 * Returns the layer title.
450 *
451 * @param prefix A prefix (null not permitted).
452 * @param type The layer type.
453 * @return the title of the layer.
454 */
455 protected String getLayerTitle(String prefix, String type) {
456 return "" + prefix + "-" + type;
457 }
458
459
460 /**
461 * Returns the path to the shapefile that serves the layer data.
462 *
463 * @param shapeDir The shapefile directory.
464 * @param filename The name of the shapefile.
465 * @return the relative path to the shapefile.
466 */
467 protected String getLayerData(String shapeDir, String filename) {
468 File path = new File(shapeDir, filename);
469
470 return path.toString();
412 } 471 }
413 472
414 /** 473 /**
415 * Write the resulting data to shapefiles. 474 * Write the resulting data to shapefiles.
416 * 475 *

http://dive4elements.wald.intevation.org