Mercurial > dive4elements > gnv-client
changeset 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 | 0cf162fa4334 |
children | bb0aa1f81280 |
files | gnv-artifacts/ChangeLog gnv-artifacts/doc/conf/conf.xml gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/context/GNVArtifactContext.java gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/context/GNVArtifactContextFactory.java gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/horizontalcrosssection/HorizontalCrossSectionMeshOutputState.java |
diffstat | 5 files changed, 83 insertions(+), 146 deletions(-) [+] |
line wrap: on
line diff
--- a/gnv-artifacts/ChangeLog Thu Mar 04 14:06:26 2010 +0000 +++ b/gnv-artifacts/ChangeLog Thu Mar 04 16:23:24 2010 +0000 @@ -1,3 +1,27 @@ +2010-03-04 Ingo Weinzierl <ingo.weinzierl@intevation.de> + + * doc/conf/conf.xml: Added a section to configure MapServer relevant stuff. + + * src/main/java/de/intevation/gnv/artifacts/context/GNVArtifactContextFactory.java: + Store mapserver path in CallContext object to have access everywhere we + have a CallContext object (avoids reading config.xml all the time we want + to write mapfile). + + * src/main/java/de/intevation/gnv/artifacts/context/GNVArtifactContext.java: + Added key to store MapServer information into CallContext and fetch it + from it. + + * src/main/java/de/intevation/gnv/state/profile/horizontalcrosssection/HorizontalCrossSectionMeshOutputState.java: + Removed code to write meta information files (sourced out to MetaWriter). + This has been done with the intend to write meta information of CONTIS and + NAUTHIS using that class as well. + + * src/main/java/de/intevation/gnv/utils/MetaWriter.java: Helper class to + write meta information files used for mapfile generation. Write general + information about our wms service (MapServer) into meta information file. + This is used to give the user information about the place where he can + find the wms service and his generated wms layer. + 2010-03-04 Ingo Weinzierl <ingo.weinzierl@intevation.de> * doc/conf/maptemplates/flow-velocity_polygons.class.vm,
--- a/gnv-artifacts/doc/conf/conf.xml Thu Mar 04 14:06:26 2010 +0000 +++ b/gnv-artifacts/doc/conf/conf.xml Thu Mar 04 16:23:24 2010 +0000 @@ -490,6 +490,11 @@ </map-generator> </gnv> + <mapserver> + <server path="http://denmark.atlas/cgi-bin/mapserv-gp" /> + <map path="/opt/artifacts/mapfiles/mapfile.map" /> + </mapserver> + <velocity> <logfile path="/var/log/artifacts/velocity.log" /> </velocity>
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/context/GNVArtifactContext.java Thu Mar 04 14:06:26 2010 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/context/GNVArtifactContext.java Thu Mar 04 16:23:24 2010 +0000 @@ -83,6 +83,12 @@ public static final String VERTICAL_CROSS_SECTION_GROUND_FILL_KEY = "gnv.vertical.cross.section.ground.fill"; + public static final String MAPSERVER_SERVER_PATH_KEY = + "mapserver.server.path"; + + public static final String MAPSERVER_MAP_PATH_KEY = + "mapserver.map.path"; + public static final Paint DEFAULT_VERTICAL_CROSS_SECTION_GROUND_FILL = new Color(0x7c8683);
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/context/GNVArtifactContextFactory.java Thu Mar 04 14:06:26 2010 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/context/GNVArtifactContextFactory.java Thu Mar 04 16:23:24 2010 +0000 @@ -96,6 +96,12 @@ public final static String VERTICAL_CROSS_SECTION_GROUND_FILL_COLOR = "/artifact-database/gnv/vertical-cross-section/ground/@fill-color"; + public final static String XPATH_MAPSERVER_PATH = + "/artifact-database/mapserver/server/@path"; + + public final static String XPATH_MAP_PATH = + "/artifact-database/mapserver/map/@path"; + /** * Constructor */ @@ -145,6 +151,8 @@ configureVerticalCrossSection(config, returnValue); + configureMapserver(config, returnValue); + } catch (FileNotFoundException e) { log.error(e, e); } catch (IOException e) { @@ -605,6 +613,25 @@ context.put(GNVArtifactContext.PALETTES_KEY, palettes); } + + protected void configureMapserver( + Document config, + GNVArtifactContext context + ) { + log.info("read configuration of mapserver."); + + String serverPath = (String) Config.getStringXPath( + config, XPATH_MAPSERVER_PATH); + + String mapPath = (String) Config.getStringXPath( + config, XPATH_MAP_PATH); + + if (serverPath != null && mapPath != null) { + context.put(GNVArtifactContext.MAPSERVER_SERVER_PATH_KEY,serverPath); + context.put(GNVArtifactContext.MAPSERVER_MAP_PATH_KEY, mapPath); + } + } + /** * @param filePath * @return
--- 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)