Mercurial > dive4elements > gnv-client
diff 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 |
line wrap: on
line diff
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/horizontalcrosssection/HorizontalCrossSectionMeshOutputState.java Thu Mar 04 14:06:26 2010 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/horizontalcrosssection/HorizontalCrossSectionMeshOutputState.java Thu Mar 04 16:23:24 2010 +0000 @@ -47,18 +47,15 @@ import de.intevation.gnv.utils.FileUtils; import de.intevation.gnv.utils.MapfileGenerator; +import de.intevation.gnv.utils.MetaWriter; import de.intevation.gnv.utils.Pair; import de.intevation.gnv.utils.ShapeFileWriter; import de.intevation.gnv.utils.StringUtils; import de.intevation.gnv.utils.WKTUtils; -import de.intevation.gnv.wms.LayerInfo; - import java.awt.Dimension; import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; @@ -94,7 +91,6 @@ public static final boolean USE_INDEX_BUFFER = Boolean.getBoolean("gnv.horizontal.cross.section.mesh.index.buffer"); - public static final String META_FILE_NAME = "meta.xml"; public static final String ISOLINES_NAME = "isolines.shp"; public static final String POLYGON_NAME = "polygons.shp"; public static final String LAYER_MODEL = "horizontalcrosssection"; @@ -256,8 +252,25 @@ if (result != null && (path = writeToShapeFile(uuid, result, callContext)) != null) { - Document meta = null; - if ((meta = writeMeta(callContext, uuid, path)) != null) { + InputData inputParam = inputData.get("parameterid"); + Map<Integer, PaletteManager> paletteManagers = + getPalettes(callContext); + String paramType = null; + + if (inputParam == null || paletteManagers == null) { + log.warn("Parameter-id not found."); + paramType = LAYER_MODEL; + } + else { + Integer parameterId = Integer.parseInt(inputParam.getValue()); + PaletteManager paletteManager = paletteManagers.get(parameterId); + + paramType = LAYER_MODEL + "_" + paletteManager.getName(); + } + + Document meta = MetaWriter.writeHorizontalcrosssectionMeta( + callContext, uuid, path, paramType); + if (meta != null) { MapfileGenerator.getInstance().update(); return meta; } @@ -339,145 +352,7 @@ FileUtils.deleteRecursive(shapeDir); } } - } - - protected Document writeMeta(CallContext context, String uuid, String path){ - InputData inputParam = inputData.get("parameterid"); - Map<Integer, PaletteManager> paletteManagers = getPalettes(context); - String paramType = null; - - if (inputParam == null || paletteManagers == null) { - log.warn("Parameter-id not found."); - paramType = LAYER_MODEL; - } - else { - Integer parameterId = Integer.parseInt(inputParam.getValue()); - PaletteManager paletteManager = paletteManagers.get(parameterId); - - paramType = LAYER_MODEL + "_" + paletteManager.getName(); - } - - - Document meta = XMLUtils.newDocument(); - XMLUtils.ElementCreator creator = new XMLUtils.ElementCreator( - meta, - ArtifactNamespaceContext.NAMESPACE_URI, - ArtifactNamespaceContext.NAMESPACE_PREFIX); - - Element root = creator.create("meta"); - meta.appendChild(root); - - writePolygonMeta(context, meta, root, uuid, path, paramType); - writeIsolineMeta(context, meta, root, uuid, path, paramType); - - try { - File metaFile = new File(path, META_FILE_NAME); - - if (!metaFile.createNewFile() || !metaFile.canWrite()) { - log.error("Error while writing meta file: "+metaFile.toString()); - return null; - } - - OutputStream out = null; - boolean success = false; - try { - out = new FileOutputStream(metaFile); - success = XMLUtils.toStream(meta, out); - } - finally { - if (out != null) { - try { out.close(); } - catch (IOException ioe) {} - } - } - - if (!success && metaFile.exists()) { - metaFile.delete(); - } - - return success ? meta : null; - } - catch (FileNotFoundException fnfe) { - log.error(fnfe); - } - catch (IOException ioe) { - log.error(ioe, ioe); - } - - return meta; - } - - - protected void writePolygonMeta( - CallContext context, - Document document, - Element meta, - String uuid, - String path, - String paramType - ) { - XMLUtils.ElementCreator creator = new XMLUtils.ElementCreator( - document, - ArtifactNamespaceContext.NAMESPACE_URI, - ArtifactNamespaceContext.NAMESPACE_PREFIX); - - Element layer = creator.create(LayerInfo.LAYER); - Element model = creator.create(LayerInfo.LAYER_MODEL); - Element name = creator.create(LayerInfo.LAYER_NAME); - 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); - type.setTextContent("POLYGON"); - status.setTextContent("DEFAULT"); - data.setTextContent(POLYGON_NAME); - - layer.appendChild(model); - layer.appendChild(name); - layer.appendChild(type); - layer.appendChild(status); - layer.appendChild(data); - - meta.appendChild(layer); - } - - - protected void writeIsolineMeta( - CallContext context, - Document document, - Element meta, - String uuid, - String path, - String paramType - ) { - XMLUtils.ElementCreator creator = new XMLUtils.ElementCreator( - document, - ArtifactNamespaceContext.NAMESPACE_URI, - ArtifactNamespaceContext.NAMESPACE_PREFIX); - - Element layer = creator.create(LayerInfo.LAYER); - Element model = creator.create(LayerInfo.LAYER_MODEL); - Element name = creator.create(LayerInfo.LAYER_NAME); - 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); - type.setTextContent("LINE"); - status.setTextContent("DEFAULT"); - data.setTextContent(ISOLINES_NAME); - - layer.appendChild(model); - layer.appendChild(name); - layer.appendChild(type); - layer.appendChild(status); - layer.appendChild(data); - - meta.appendChild(layer); - } + } protected AttributedPoint2ds getResult(String uuid, CallContext callContext)