Mercurial > dive4elements > gnv-client
comparison gnv-artifacts/src/main/java/de/intevation/gnv/state/layer/LayerOutputState.java @ 828:28028979c813
Integrated the possibility to change the Title of an Layer in Product Layer.
gnv-artifacts/trunk@922 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Tim Englich <tim.englich@intevation.de> |
---|---|
date | Tue, 13 Apr 2010 14:22:52 +0000 |
parents | ac1b9f00603f |
children | 2423cefe7d39 |
comparison
equal
deleted
inserted
replaced
827:fe0263926870 | 828:28028979c813 |
---|---|
26 import de.intevation.gnv.geobackend.base.query.exception.QueryException; | 26 import de.intevation.gnv.geobackend.base.query.exception.QueryException; |
27 import de.intevation.gnv.state.InputData; | 27 import de.intevation.gnv.state.InputData; |
28 import de.intevation.gnv.state.OutputStateBase; | 28 import de.intevation.gnv.state.OutputStateBase; |
29 import de.intevation.gnv.state.exception.StateException; | 29 import de.intevation.gnv.state.exception.StateException; |
30 import de.intevation.gnv.utils.ArtifactXMLUtilities; | 30 import de.intevation.gnv.utils.ArtifactXMLUtilities; |
31 import de.intevation.gnv.utils.ExclusiveExec; | |
31 import de.intevation.gnv.utils.FileUtils; | 32 import de.intevation.gnv.utils.FileUtils; |
32 import de.intevation.gnv.utils.MapfileGenerator; | 33 import de.intevation.gnv.utils.MapfileGenerator; |
33 import de.intevation.gnv.utils.MetaWriter; | 34 import de.intevation.gnv.utils.MetaWriter; |
34 import de.intevation.gnv.utils.ShapeFileWriter; | 35 import de.intevation.gnv.utils.ShapeFileWriter; |
35 | 36 |
125 format, XPATH_OUTPUT_MODE, ArtifactNamespaceContext.INSTANCE); | 126 format, XPATH_OUTPUT_MODE, ArtifactNamespaceContext.INSTANCE); |
126 if (outputMode.equalsIgnoreCase("wms")) { | 127 if (outputMode.equalsIgnoreCase("wms")) { |
127 Collection<Result> data = this.fetchData(); | 128 Collection<Result> data = this.fetchData(); |
128 if (data != null && !data.isEmpty()){ | 129 if (data != null && !data.isEmpty()){ |
129 XMLUtils.toStream(this.getWMS(uuid, callContext, | 130 XMLUtils.toStream(this.getWMS(uuid, callContext, |
130 data, geometryType), | 131 data, geometryType, |
132 inputData), | |
131 outputStream); | 133 outputStream); |
132 }else{ | 134 }else{ |
133 this.writeExceptionReport2Stream(outputStream); | 135 this.writeExceptionReport2Stream(outputStream); |
134 } | 136 } |
135 }else if (outputMode.equalsIgnoreCase("zip")){ | 137 }else if (outputMode.equalsIgnoreCase("zip")){ |
397 boolean success = false; | 399 boolean success = false; |
398 boolean createdDir = false; | 400 boolean createdDir = false; |
399 | 401 |
400 try { | 402 try { |
401 synchronized (shapeFileLock) { | 403 synchronized (shapeFileLock) { |
402 int count = 0; | 404 if (shapeDir.exists()) { |
403 while (shapeDir.exists()) { | 405 FileUtils.deleteContent(shapeDir); |
404 shapeDir = new File(baseDir, uuid + "-" + count); | 406 } |
405 ++count; | 407 else if (!shapeDir.mkdirs()) { |
406 } | |
407 | |
408 if (!shapeDir.mkdirs()) { | |
409 log.error("cannot create directory '" | 408 log.error("cannot create directory '" |
410 + shapeDir.getAbsolutePath() + "'"); | 409 + shapeDir.getAbsolutePath() + "'"); |
411 return null; | 410 return null; |
412 } | 411 } |
413 createdDir = true; | 412 createdDir = true; |
554 * | 553 * |
555 * @param uuid The UUID of the current artifact. | 554 * @param uuid The UUID of the current artifact. |
556 * @param callContext The CallContext object. | 555 * @param callContext The CallContext object. |
557 * @param data A collection with some input data. | 556 * @param data A collection with some input data. |
558 * @param geometryType The geometry type. | 557 * @param geometryType The geometry type. |
558 * @param inputData the Parameters which are send by the out-Call. | |
559 * @return a document with some meta information (shapefile path, geometry | 559 * @return a document with some meta information (shapefile path, geometry |
560 * type, time to live of the current artifact, etc). | 560 * type, time to live of the current artifact, etc). |
561 * @throws StateException if an error occured while shapefile writing. | 561 * @throws StateException if an error occured while shapefile writing. |
562 */ | 562 */ |
563 protected Document getWMS(String uuid, | 563 protected Document getWMS(String uuid, |
564 CallContext callContext, | 564 CallContext callContext, |
565 Collection<Result> data, | 565 Collection<Result> data, |
566 String geometryType) | 566 String geometryType, |
567 Collection<InputData> inputData) | |
567 throws StateException | 568 throws StateException |
568 { | 569 { |
569 Document document = XMLUtils.newDocument(); | 570 Document document = XMLUtils.newDocument(); |
570 | 571 |
571 Element pathElement = document.createElement("path"); | 572 Element pathElement = document.createElement("path"); |
572 document.appendChild(pathElement); | 573 document.appendChild(pathElement); |
573 | 574 |
574 String path = getShapeFilePath(); | 575 String path = getShapeFilePath(); |
575 | 576 |
576 if (path != null && new File(path).isDirectory()) { | 577 if (path != null && new File(path).isDirectory()) { |
578 String title = getLayerTitle(inputData); | |
579 if (title == null) { | |
580 title = uuid; | |
581 } | |
582 | |
583 callContext.putContextValue( | |
584 MetaWriter.CONTEXT_LAYER_TITLE, title); | |
585 | |
586 String paramType = findParameterTitle(geometryType); | |
587 | |
588 if (log.isDebugEnabled()) { | |
589 log.debug("Layer title: " + title); | |
590 log.debug("Layer type: " + paramType); | |
591 } | |
592 | |
593 Document meta = MetaWriter.writeHorizontalcrosssectionMeta( | |
594 callContext, uuid, path, paramType); | |
595 if (meta != null) { | |
596 MapfileGenerator.getInstance().update(); | |
597 return meta; | |
598 } | |
599 | |
577 pathElement.setTextContent(path); | 600 pathElement.setTextContent(path); |
578 } | 601 } |
579 else { | 602 else { |
580 | 603 ExclusiveExec.UniqueKey key = ExclusiveExec.INSTANCE.acquire(uuid); |
581 if (data != null && | 604 try{ |
582 (path = writeToShapeFile(uuid, data, callContext,geometryType)) != null) { | 605 if (data != null && |
583 | 606 (path = writeToShapeFile(uuid, data, callContext,geometryType)) != null) { |
584 String paramType = LAYER_MODEL+"_"+templateID; | 607 String paramType = findParameterTitle(geometryType); |
585 | 608 String title = getLayerTitle(inputData); |
586 if (!MapfileGenerator.getInstance().templateExists(paramType)){ | 609 if (title == null) { |
587 // If the template doesn't exist the Defaulttemplates will be used. | 610 title = uuid; |
588 paramType = LAYER_MODEL+"_"+ | 611 } |
589 this.determineDefaultTemplateName(geometryType); | 612 Document meta = MetaWriter.writeLayerMeta(callContext, uuid, |
590 } | 613 path, paramType, |
591 Document meta = MetaWriter.writeLayerMeta(callContext, uuid, | 614 this.determineGeometryType(geometryType)); |
592 path, paramType, | 615 if (meta != null) { |
593 this.determineGeometryType(geometryType)); | 616 MapfileGenerator.getInstance().update(); |
594 if (meta != null) { | 617 return meta; |
595 MapfileGenerator.getInstance().update(); | 618 } |
596 return meta; | 619 pathElement.setTextContent(path); |
597 } | 620 } |
598 | 621 }finally{ |
599 pathElement.setTextContent(path); | 622 ExclusiveExec.INSTANCE.release(key); |
600 } | 623 } |
601 } | 624 } |
602 | 625 |
603 return document; | 626 return document; |
627 } | |
628 | |
629 /** | |
630 * Returns the parameterType for the Layer. | |
631 * @param geometryType | |
632 * @return | |
633 */ | |
634 private String findParameterTitle(String geometryType) { | |
635 String paramType = LAYER_MODEL+"_"+templateID; | |
636 | |
637 if (!MapfileGenerator.getInstance().templateExists(paramType)){ | |
638 // If the template doesn't exist the Defaulttemplates will be used. | |
639 paramType = LAYER_MODEL+"_"+ | |
640 this.determineDefaultTemplateName(geometryType); | |
641 } | |
642 return paramType; | |
643 } | |
644 | |
645 /** | |
646 * Find the title for a wms layer specified by the user. | |
647 * | |
648 * @param inputData A collection with InputData objects. | |
649 * @return the title. | |
650 */ | |
651 protected String getLayerTitle(Collection<InputData> inputData) { | |
652 for (InputData data: inputData) { | |
653 String name = data.getName(); | |
654 if (name != null && name.equals("title")) { | |
655 return (String) data.getValue(); | |
656 } | |
657 } | |
658 return null; | |
604 } | 659 } |
605 | 660 |
606 | 661 |
607 /** | 662 /** |
608 * Turns the geometry type into a form used for the templating mechanism | 663 * Turns the geometry type into a form used for the templating mechanism |