Mercurial > dive4elements > gnv-client
diff gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/horizontalcrosssection/HorizontalCrossSectionMeshOutputState.java @ 730:452fad121560
Implemented code for changing the title of a wms layer (issue198).
gnv-artifacts/trunk@768 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Mon, 15 Mar 2010 11:13:21 +0000 |
parents | 8d475151b2c1 |
children | 93489a0c1328 |
line wrap: on
line diff
--- 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,