Mercurial > dive4elements > gnv-client
changeset 730:452fad121560
Implemented code for changing the title of a wms layer (issue198).
gnv-artifacts/trunk@768 c6561f87-3c4e-4783-a992-168aeb5c3f6f
line wrap: on
line diff
--- a/gnv-artifacts/ChangeLog Mon Mar 15 09:23:56 2010 +0000 +++ b/gnv-artifacts/ChangeLog Mon Mar 15 11:13:21 2010 +0000 @@ -1,3 +1,36 @@ +2010-03-15 Ingo Weinzierl <ingo.weinzierl@intevation.de> + + Issue198 + + * src/main/java/de/intevation/gnv/state/profile/horizontalcrosssection/HorizontalCrossSectionMeshOutputState.java: + Read the layer title which might have been adjusted by the user and store + it in the CallContext object to be available in MetaWriter. + + * src/main/java/de/intevation/gnv/utils/MetaWriter.java: Write the layer + title stored in the CallContext object into meta.xml file. + + * src/main/java/de/intevation/gnv/wms/LayerInfo.java: Added a further + attribute named 'title' to adjust the layer name. + + * src/main/java/de/intevation/gnv/utils/MapfileGenerator.java: Read layer + title from meta.xml file. The uuid is used as layer title if no title is + given. + + * doc/conf/products/horizontalcrosssection/conf_mesh.xml: Added a string + input parameter in wms output mode to adjust a wms layer's title. + + * doc/conf/maptemplates/horizontalcrosssection_salinity.vm, + doc/conf/maptemplates/horizontalcrosssection_salinity_isolines.vm, + doc/conf/maptemplates/horizontalcrosssection_flow-velocity.vm, + doc/conf/maptemplates/horizontalcrosssection_flow-velocity_isolines.vm, + doc/conf/maptemplates/horizontalcrosssection_water-levels.vm, + doc/conf/maptemplates/horizontalcrosssection_water-levels_isolines.vm, + doc/conf/maptemplates/horizontalcrosssection_water-temperature.vm, + doc/conf/maptemplates/horizontalcrosssection_water-temperature_isolines.vm: + Read title attribute from LayerInfo object for filling the layer name in + template files. The title can be adjusted by the user himself, but the + shapefiles are stored in the path {shapefile_path}/{uuid}/xxx.shp. + 2010-03-15 Tim Englich <tim.englich@intevation.de> * src/main/java/de/intevation/gnv/state/layer/LayerOutputState.java (fetchData):
--- a/gnv-artifacts/doc/conf/maptemplates/horizontalcrosssection_flow-velocity.vm Mon Mar 15 09:23:56 2010 +0000 +++ b/gnv-artifacts/doc/conf/maptemplates/horizontalcrosssection_flow-velocity.vm Mon Mar 15 11:13:21 2010 +0000 @@ -1,5 +1,6 @@ LAYER - NAME "$info.getName()" + NAME "$info.getTitle()" + GROUP "$info.getTitle()" TYPE $info.getType() DATA "${info.getName()}/${info.getData()}" STATUS $info.getStatus()
--- a/gnv-artifacts/doc/conf/maptemplates/horizontalcrosssection_flow-velocity_isolines.vm Mon Mar 15 09:23:56 2010 +0000 +++ b/gnv-artifacts/doc/conf/maptemplates/horizontalcrosssection_flow-velocity_isolines.vm Mon Mar 15 11:13:21 2010 +0000 @@ -1,6 +1,6 @@ LAYER - NAME "$info.getName()_isolines" - GROUP "$info.getName()" + NAME "$info.getTitle()_isolines" + GROUP "$info.getTitle()" DATA "${info.getName()}/${info.getData()}" TYPE $info.getType() STATUS $info.getStatus()
--- a/gnv-artifacts/doc/conf/maptemplates/horizontalcrosssection_salinity.vm Mon Mar 15 09:23:56 2010 +0000 +++ b/gnv-artifacts/doc/conf/maptemplates/horizontalcrosssection_salinity.vm Mon Mar 15 11:13:21 2010 +0000 @@ -1,5 +1,6 @@ LAYER - NAME "$info.getName()" + NAME "$info.getTitle()" + GROUP "$info.getTitle()" TYPE $info.getType() DATA "${info.getName()}/${info.getData()}" STATUS $info.getStatus()
--- a/gnv-artifacts/doc/conf/maptemplates/horizontalcrosssection_salinity_isolines.vm Mon Mar 15 09:23:56 2010 +0000 +++ b/gnv-artifacts/doc/conf/maptemplates/horizontalcrosssection_salinity_isolines.vm Mon Mar 15 11:13:21 2010 +0000 @@ -1,6 +1,6 @@ LAYER - NAME "$info.getName()_isolines" - GROUP "$info.getName()" + NAME "$info.getTitle()_isolines" + GROUP "$info.getTitle()" DATA "${info.getName()}/${info.getData()}" TYPE $info.getType() STATUS $info.getStatus()
--- a/gnv-artifacts/doc/conf/maptemplates/horizontalcrosssection_water-levels.vm Mon Mar 15 09:23:56 2010 +0000 +++ b/gnv-artifacts/doc/conf/maptemplates/horizontalcrosssection_water-levels.vm Mon Mar 15 11:13:21 2010 +0000 @@ -1,5 +1,6 @@ LAYER - NAME "$info.getName()" + NAME "$info.getTitle()" + GROUP "$info.getTitle()" TYPE $info.getType() DATA "${info.getName()}/${info.getData()}" STATUS $info.getStatus()
--- a/gnv-artifacts/doc/conf/maptemplates/horizontalcrosssection_water-levels_isolines.vm Mon Mar 15 09:23:56 2010 +0000 +++ b/gnv-artifacts/doc/conf/maptemplates/horizontalcrosssection_water-levels_isolines.vm Mon Mar 15 11:13:21 2010 +0000 @@ -1,6 +1,6 @@ LAYER - NAME "$info.getName()_isolines" - GROUP "$info.getName()" + NAME "$info.getTitle()_isolines" + GROUP "$info.getTitle()" DATA "${info.getName()}/${info.getData()}" TYPE $info.getType() STATUS $info.getStatus()
--- a/gnv-artifacts/doc/conf/maptemplates/horizontalcrosssection_water-temperature.vm Mon Mar 15 09:23:56 2010 +0000 +++ b/gnv-artifacts/doc/conf/maptemplates/horizontalcrosssection_water-temperature.vm Mon Mar 15 11:13:21 2010 +0000 @@ -1,5 +1,6 @@ LAYER - NAME "$info.getName()" + NAME "$info.getTitle()" + GROUP "$info.getTitle()" TYPE $info.getType() DATA "${info.getName()}/${info.getData()}" STATUS $info.getStatus()
--- a/gnv-artifacts/doc/conf/maptemplates/horizontalcrosssection_water-temperature_isolines.vm Mon Mar 15 09:23:56 2010 +0000 +++ b/gnv-artifacts/doc/conf/maptemplates/horizontalcrosssection_water-temperature_isolines.vm Mon Mar 15 11:13:21 2010 +0000 @@ -1,6 +1,6 @@ LAYER - NAME "$info.getName()_isolines" - GROUP "$info.getName()" + NAME "$info.getTitle()_isolines" + GROUP "$info.getTitle()" DATA "${info.getName()}/${info.getData()}" TYPE $info.getType() STATUS $info.getStatus()
--- a/gnv-artifacts/doc/conf/products/horizontalcrosssection/conf_mesh.xml Mon Mar 15 09:23:56 2010 +0000 +++ b/gnv-artifacts/doc/conf/products/horizontalcrosssection/conf_mesh.xml Mon Mar 15 11:13:21 2010 +0000 @@ -184,7 +184,11 @@ </value-names> <outputsModes> <outputsMode name="zip" description="Export als ZIP-Archiv" mime-type="application/zip"/> - <outputsMode name="wms" description="WMS-Layer bereitstellen" mime-type="text/url"/> + <outputsMode name="wms" description="WMS-Layer bereitstellen" mime-type="text/url"> + <parameters> + <inputvalue name="title" type="String" value="Layer Title"/> + </parameters> + </outputsMode> </outputsModes> </state>
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/horizontalcrosssection/HorizontalCrossSectionMeshOutputState.java Mon Mar 15 09:23:56 2010 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/horizontalcrosssection/HorizontalCrossSectionMeshOutputState.java Mon Mar 15 11:13:21 2010 +0000 @@ -197,7 +197,7 @@ } else if ("wms".equals(outputMode)) { XMLUtils.toStream( - getWMS(uuid, callContext), + getWMS(uuid, callContext, inputData), outputStream); } else { @@ -233,18 +233,43 @@ } } - protected Document getWMS(String uuid, CallContext callContext) + protected Document getWMS( + String uuid, + CallContext callContext, + Collection<InputData> inputData + ) throws StateException { - // TODO: Do the real WMS publishing here! Document document = XMLUtils.newDocument(); Element pathElement = document.createElement("path"); document.appendChild(pathElement); - String path = getShapeFilePath(); + String path = getShapeFilePath(); if (path != null && new File(path).isDirectory()) { + String title = getLayerTitle(inputData); + if (title == null) { + title = uuid; + } + + callContext.putContextValue( + MetaWriter.CONTEXT_LAYER_TITLE, title); + + String paramType = findParameterType(callContext); + + if (log.isDebugEnabled()) { + log.debug("Layer title: " + title); + log.debug("Layer type: " + paramType); + } + + Document meta = MetaWriter.writeHorizontalcrosssectionMeta( + callContext, uuid, path, paramType); + if (meta != null) { + MapfileGenerator.getInstance().update(); + return meta; + } + pathElement.setTextContent(path); } else { @@ -252,20 +277,19 @@ if (result != null && (path = writeToShapeFile(uuid, result, callContext)) != null) { - InputData inputParam = inputData.get("parameterid"); - Map<Integer, PaletteManager> paletteManagers = - getPalettes(callContext); - String paramType = null; + String paramType = findParameterType(callContext); - if (inputParam == null || paletteManagers == null) { - log.warn("Parameter-id not found."); - paramType = LAYER_MODEL; + InputData inputTitle = this.inputData.get("title"); + String title = getLayerTitle(inputData); + if (title == null) { + title = uuid; } - else { - Integer parameterId = Integer.parseInt(inputParam.getValue()); - PaletteManager paletteManager = paletteManagers.get(parameterId); + callContext.putContextValue( + MetaWriter.CONTEXT_LAYER_TITLE, title); - paramType = LAYER_MODEL + "_" + paletteManager.getName(); + if (log.isDebugEnabled()) { + log.debug("Parameter type: " + paramType); + log.debug("Layer title: " + title); } Document meta = MetaWriter.writeHorizontalcrosssectionMeta( @@ -282,6 +306,35 @@ return document; } + protected String findParameterType(CallContext callContext) { + InputData inputParam = inputData.get("parameterid"); + + Map<Integer, PaletteManager> paletteManagers = getPalettes(callContext); + + if (inputParam == null || paletteManagers == null) { + log.warn("Parameter-id not found."); + return LAYER_MODEL; + } + else { + Integer parameterId = Integer.parseInt(inputParam.getValue()); + PaletteManager paletteManager = paletteManagers.get(parameterId); + + return LAYER_MODEL + "_" + paletteManager.getName(); + } + } + + + protected String getLayerTitle(Collection<InputData> inputData) { + for (InputData data: inputData) { + String name = data.getName(); + if (name != null && name.equals("title")) { + return (String) data.getValue(); + } + } + + return null; + } + protected String writeToShapeFile( String uuid, AttributedPoint2ds result,
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/utils/MapfileGenerator.java Mon Mar 15 09:23:56 2010 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/utils/MapfileGenerator.java Mon Mar 15 11:13:21 2010 +0000 @@ -51,6 +51,7 @@ public static final String XPATH_LAYER = "/art:meta/art:layer"; public static final String XPATH_LAYER_NAME = "art:name"; + public static final String XPATH_LAYER_TITLE = "art:title"; public static final String XPATH_LAYER_TYPE = "art:type"; public static final String XPATH_LAYER_DATA = "art:data"; public static final String XPATH_LAYER_STATUS = "art:status"; @@ -304,6 +305,14 @@ info.setName(name); } + String title = parseLayerAttr(layer, XPATH_LAYER_TITLE); + if (title != null && !title.equals("")) { + info.setTitle(title); + } + else { + info.setTitle(name); + } + String model = parseLayerAttr(layer, XPATH_LAYER_MODEL); if (model != null && !model.equals("")) { info.setModel(model);
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/utils/MetaWriter.java Mon Mar 15 09:23:56 2010 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/utils/MetaWriter.java Mon Mar 15 11:13:21 2010 +0000 @@ -32,6 +32,8 @@ public static final String POLYGON_NAME = "polygons.shp"; public static final String LAYER_DATA_NAME = "data.shp"; + public static final String CONTEXT_LAYER_TITLE = "wms.title"; + private MetaWriter() { } @@ -95,6 +97,11 @@ try { File metaFile = new File(path, META_FILE_NAME); + if (metaFile.exists()) { + logger.info("Delete old meta information file."); + metaFile.delete(); + } + if (!metaFile.createNewFile() || !metaFile.canWrite()) { logger.error("Error while writing meta file: "+metaFile.toString()); return false; @@ -198,8 +205,6 @@ meta.appendChild(layer); } - - public static void writePolygonMeta( @@ -218,18 +223,22 @@ Element layer = creator.create(LayerInfo.LAYER); Element model = creator.create(LayerInfo.LAYER_MODEL); Element name = creator.create(LayerInfo.LAYER_NAME); + Element title = creator.create(LayerInfo.LAYER_TITLE); Element type = creator.create(LayerInfo.LAYER_TYPE); Element status = creator.create(LayerInfo.LAYER_STATUS); Element data = creator.create(LayerInfo.LAYER_DATA); model.setTextContent(paramType); name.setTextContent(uuid); + title.setTextContent( + (String) context.getContextValue(CONTEXT_LAYER_TITLE)); type.setTextContent("POLYGON"); status.setTextContent("OFF"); data.setTextContent(POLYGON_NAME); layer.appendChild(model); layer.appendChild(name); + layer.appendChild(title); layer.appendChild(type); layer.appendChild(status); layer.appendChild(data); @@ -254,18 +263,22 @@ Element layer = creator.create(LayerInfo.LAYER); Element model = creator.create(LayerInfo.LAYER_MODEL); Element name = creator.create(LayerInfo.LAYER_NAME); + Element title = creator.create(LayerInfo.LAYER_TITLE); Element type = creator.create(LayerInfo.LAYER_TYPE); Element status = creator.create(LayerInfo.LAYER_STATUS); Element data = creator.create(LayerInfo.LAYER_DATA); model.setTextContent(paramType+"_isolines"); name.setTextContent(uuid); + title.setTextContent( + (String) context.getContextValue(CONTEXT_LAYER_TITLE)); type.setTextContent("LINE"); status.setTextContent("OFF"); data.setTextContent(ISOLINES_NAME); layer.appendChild(model); layer.appendChild(name); + layer.appendChild(title); layer.appendChild(type); layer.appendChild(status); layer.appendChild(data);
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/wms/LayerInfo.java Mon Mar 15 09:23:56 2010 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/wms/LayerInfo.java Mon Mar 15 11:13:21 2010 +0000 @@ -11,8 +11,10 @@ public static final String LAYER_TYPE = "type"; public static final String LAYER_DATA = "data"; public static final String LAYER_STATUS = "status"; + public static final String LAYER_TITLE = "title"; private String name; + private String title; private String type; private String data; private String status; @@ -39,6 +41,14 @@ return name; } + public void setTitle(String title) { + this.title = title; + } + + public String getTitle() { + return title; + } + public void setModel(String model) { this.model = model; }