Mercurial > dive4elements > river
changeset 1781:ef2300b450bf
Modified the process to create mapfiles.
flys-artifacts/trunk@3103 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Fri, 28 Oct 2011 09:26:54 +0000 |
parents | b503d92dd709 |
children | 93fe7debd687 |
files | flys-artifacts/ChangeLog flys-artifacts/doc/conf/mapserver/mapfile.vm flys-artifacts/src/main/java/de/intevation/flys/exports/MapGenerator.java flys-artifacts/src/main/java/de/intevation/flys/utils/MapfileGenerator.java flys-artifacts/src/main/java/de/intevation/flys/wsplgen/JobExecutor.java |
diffstat | 5 files changed, 52 insertions(+), 101 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog Fri Oct 28 09:22:34 2011 +0000 +++ b/flys-artifacts/ChangeLog Fri Oct 28 09:26:54 2011 +0000 @@ -1,3 +1,20 @@ +2011-10-28 Ingo Weinzierl <ingo@intevation.de> + + * doc/conf/mapserver/mapfile.vm: The "layers" injected by VelocityEngine is + now used to include layers. A single string in this list represents the + path to a file which contains a LAYER section for Mapserver' Mapfile. + + * src/main/java/de/intevation/flys/wsplgen/JobExecutor.java: Removed the + update() call of MapfileGenerator. Mapfiles are generated by MapGenerator + only which requires a FLYSArtifactCollection.doOut()! + + * src/main/java/de/intevation/flys/exports/MapGenerator.java: Call update() + of MapfileGenerator to trigger the re-creation of mapfile(s). + + * src/main/java/de/intevation/flys/utils/MapfileGenerator.java: Collect all + LAYER snippets from filesystem and inject the filepath for each snippet + into the Mapfile template. + 2011-10-28 Felix Wolfsteller <felix.wolfsteller@intevation.de> * src/main/java/de/intevation/flys/collections/AttributeWriter.java,
--- a/flys-artifacts/doc/conf/mapserver/mapfile.vm Fri Oct 28 09:22:34 2011 +0000 +++ b/flys-artifacts/doc/conf/mapserver/mapfile.vm Fri Oct 28 09:26:54 2011 +0000 @@ -54,6 +54,6 @@ ## Don't change the following lines. #foreach ($LAYER in $LAYERS) - $LAYER + include "$LAYER" #end END
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/MapGenerator.java Fri Oct 28 09:22:34 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/MapGenerator.java Fri Oct 28 09:26:54 2011 +0000 @@ -145,6 +145,8 @@ { logger.debug("MapGenerator.generate"); + MapfileGenerator.getInstance().update(); + Document response = XMLUtils.newDocument(); ElementCreator c = new ElementCreator( response,
--- a/flys-artifacts/src/main/java/de/intevation/flys/utils/MapfileGenerator.java Fri Oct 28 09:22:34 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/utils/MapfileGenerator.java Fri Oct 28 09:26:54 2011 +0000 @@ -1,6 +1,7 @@ package de.intevation.flys.utils; import java.io.File; +import java.io.FilenameFilter; import java.io.FileNotFoundException; import java.io.FileWriter; import java.io.IOException; @@ -161,7 +162,8 @@ throws FileNotFoundException, IOException { File[] userDirs = getUserDirs(); - List<LayerInfo> layers = parseLayers(userDirs); + + List<String> layers = parseLayers(userDirs); logger.info("Found " + layers.size() + " layers for user mapfile."); @@ -307,22 +309,23 @@ - protected List<LayerInfo> parseLayers(File[] dirs) { - List<LayerInfo> layers = new ArrayList<LayerInfo>(); + protected List<String> parseLayers(File[] dirs) { + List<String> layers = new ArrayList<String>(); for (File dir: dirs) { - LayerInfo layer = parseUeskLayer(dir); - if (layer != null && layer.getData() != null) { - logger.debug(" Add WSPLGEN layer."); - layers.add(layer); - } + File[] layerFiles = dir.listFiles(new FilenameFilter() { + @Override + public boolean accept(File directory, String name) { + return name.startsWith(MS_LAYER_PREFIX); + } + }); - List<LayerInfo> barriers = parseBarriersLayers(dir); - int num = barriers != null ? barriers.size() : 0; - if (num > 0) { - if (barriers.get(0).getData() != null) { - logger.debug(" Add " + num + " BARRIERS layers."); - layers.addAll(barriers); + for (File layer: layerFiles) { + try { + layers.add(layer.getCanonicalPath()); + } + catch (IOException ioe) { + logger.warn(ioe, ioe); } } } @@ -331,22 +334,6 @@ } - protected LayerInfo parseUeskLayer(File dir) { - File uesk = new File(dir, WSPLGEN_RESULT_SHAPE); - - if (!uesk.exists() || !uesk.isFile()) { - return null; - } - - return new LayerInfo( - dir.getName() + MS_WSPLGEN_POSTFIX, - "POLYGON", - dir.getName(), - WSPLGEN_RESULT_SHAPE, - "I18N_WSPLGEN_RESULT"); - } - - /** * Creates a layer file used for Mapserver's mapfile which represents the * floodmap. @@ -448,47 +435,20 @@ } - protected List<LayerInfo> parseBarriersLayers(File dir) { - List<LayerInfo> barriers = new ArrayList<LayerInfo>(2); - - String group = dir.getName() + MS_BARRIERS_POSTFIX; - String groupTitle = "I18N_BARRIERS_TITLE"; - - File lines = new File(dir, WSPLGEN_LINES_SHAPE); - File polygons = new File(dir, WSPLGEN_POLYGONS_SHAPE); - - if (lines.exists() || lines.isFile()) { - barriers.add( - new LayerInfo( - dir.getName() + MS_LINE_POSTFIX, - "LINE", - dir.getName(), - WSPLGEN_LINES_SHAPE, - "I18N_LINE_SHAPE", - group, - groupTitle)); - } - - if (polygons.exists() || polygons.isFile()) { - barriers.add( - new LayerInfo( - dir.getName() + MS_POLYGONS_POSTFIX, - "POLYGON", - dir.getName(), - WSPLGEN_POLYGONS_SHAPE, - "I18N_POLYGON_SHAPE", - group, - groupTitle)); - } - - return barriers; - } - - + /** + * Creates a layer snippet which might be included in the mapfile. + * + * @param layerinfo A LayerInfo object that contains all necessary + * information to build a Mapserver LAYER section. + * @param dir The base dir for the LAYER snippet. + * @param filename The name of the file that is written. + * @param tpl The Velocity template which is used to create the LAYER + * section. + */ protected void writeLayer( LayerInfo layerinfo, File dir, - String name, + String filename, Template tpl ) throws FileNotFoundException @@ -496,10 +456,10 @@ if (logger.isDebugEnabled()) { logger.debug("Write layer for:"); logger.debug(" directory: " + dir.getName()); - logger.debug(" name: " + name); + logger.debug(" name: " + filename); } - File layer = new File(dir, name); + File layer = new File(dir, filename); Writer writer = null; try { @@ -537,7 +497,7 @@ * * @param layers Layer information. */ - protected void writeMapfile(List<LayerInfo> layers) { + protected void writeMapfile(List<String> layers) { String tmpMapName = "mapfile" + new Date().getTime(); File mapfile = new File( @@ -559,7 +519,7 @@ getShapefileBaseDir().getCanonicalPath()); context.put("CONFIGDIR", Config.getConfigDirectory().getCanonicalPath()); - context.put("LAYERS", fillLayerTemplates(layers)); + context.put("LAYERS", layers); Template mapTemplate = getMapfileTemplate(); if (mapTemplate == null) { @@ -598,29 +558,5 @@ } } } - - - protected List<String> fillLayerTemplates(List<LayerInfo> layers) { - List<String> evaluated = new ArrayList<String>(layers.size()); - - for (LayerInfo layer: layers) { - StringWriter writer = new StringWriter(); - - VelocityContext context = new VelocityContext(); - context.put("LAYER", layer); - - Template t = getTemplateByName("layer.vm"); - if (t == null) { - logger.warn("No 'layer.vm' template found."); - return evaluated; - } - - t.merge(context, writer); - - evaluated.add(writer.toString()); - } - - return evaluated; - } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-artifacts/src/main/java/de/intevation/flys/wsplgen/JobExecutor.java Fri Oct 28 09:22:34 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/wsplgen/JobExecutor.java Fri Oct 28 09:26:54 2011 +0000 @@ -9,8 +9,6 @@ import de.intevation.flys.artifacts.model.WSPLGENJob; -import de.intevation.flys.utils.MapfileGenerator; - public class JobExecutor { @@ -91,8 +89,6 @@ FacetCreator fc = job.getFacetCreator(); fc.createWSPLGENFacet(); fc.finish(); - - MapfileGenerator.getInstance().update(); } job.getCallContext().afterBackground(CallContext.STORE);