annotate artifacts/src/main/java/org/dive4elements/river/utils/MapfileGenerator.java @ 5865:73da40528cf2

River artifacts: Renamed FLYSUtils to RiverUtils.
author Sascha L. Teichmann <teichmann@intevation.de>
date Sun, 28 Apr 2013 15:09:31 +0200
parents 4897a58c8746
children af13ceeba52a
rev   line source
5863
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
1 /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
2 * Software engineering by Intevation GmbH
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
3 *
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
4 * This file is Free Software under the GNU AGPL (>=v3)
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
6 * documentation coming with Dive4Elements River for details.
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
7 */
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
8
5831
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5309
diff changeset
9 package org.dive4elements.river.utils;
1129
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
10
5831
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5309
diff changeset
11 import org.dive4elements.artifacts.common.utils.Config;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5309
diff changeset
12 import org.dive4elements.river.artifacts.model.LayerInfo;
3303
96daa8a4c48f Fix and workaround NullPointerExceptions
Christian Lins <christian.lins@intevation.de>
parents: 3302
diff changeset
13
1129
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
14 import java.io.File;
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
15 import java.io.FileNotFoundException;
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
16 import java.io.FileWriter;
3302
453d2d0c4258 Organized and added missing imports.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2669
diff changeset
17 import java.io.FilenameFilter;
1129
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
18 import java.io.IOException;
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
19 import java.io.Writer;
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
20 import java.util.ArrayList;
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
21 import java.util.Date;
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
22 import java.util.List;
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
23
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
24 import org.apache.log4j.Logger;
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
25 import org.apache.velocity.Template;
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
26 import org.apache.velocity.VelocityContext;
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
27 import org.apache.velocity.app.VelocityEngine;
4656
442fbb290fa8 Introduce river mapfile generation (WARNING: Changes in config xml files required!).
Christian Lins <christian.lins@intevation.de>
parents: 4654
diff changeset
28 import org.apache.velocity.runtime.RuntimeConstants;
1129
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
29
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
30 /**
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
31 * This class iterates over a bunch of directories, searches for meta
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
32 * information coresponding to shapefiles and creates a mapfile which is used by
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
33 * a <i>MapServer</i>.
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
34 *
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
35 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
36 */
4654
861c47e0a8a0 Refactor Mapserver mapfile generation.
Christian Lins <christian.lins@intevation.de>
parents: 4648
diff changeset
37 public abstract class MapfileGenerator
1129
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
38 {
1134
bcf70a452646 Read barrier layers from filesystem while mapfile creation and build a facet for this layer in the artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1129
diff changeset
39 public static final String WSPLGEN_RESULT_SHAPE = "wsplgen.shp";
bcf70a452646 Read barrier layers from filesystem while mapfile creation and build a facet for this layer in the artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1129
diff changeset
40 public static final String WSPLGEN_LINES_SHAPE = "barrier_lines.shp";
bcf70a452646 Read barrier layers from filesystem while mapfile creation and build a facet for this layer in the artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1129
diff changeset
41 public static final String WSPLGEN_POLYGONS_SHAPE = "barrier_polygons.shp";
2639
a78dafdd8590 Issue 657.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2638
diff changeset
42 public static final String WSPLGEN_USER_SHAPE = "user-rgd.shp";
1134
bcf70a452646 Read barrier layers from filesystem while mapfile creation and build a facet for this layer in the artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1129
diff changeset
43
2637
baaf7d125c43 Issue 560.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2616
diff changeset
44 public static final String WSPLGEN_LAYER_TEMPLATE = "wsplgen_layer.vm";
1775
0156105222c9 Improved the MapfileGenerator. It offers methods to create barrier and wsplgen layer files for mapserver.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1710
diff changeset
45 public static final String SHP_LAYER_TEMPLATE = "shapefile_layer.vm";
1792
49ad801076e4 Enabled the MapGenerator to create WMS layers with database datastore - riveraxis is the first layer that is no longer fetched from static WMS service but from user specific one.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1781
diff changeset
46 public static final String DB_LAYER_TEMPLATE = "db_layer.vm";
4648
c04db3178d09 Work on river axis mapfile generator.
Christian Lins <christian.lins@intevation.de>
parents: 4633
diff changeset
47 public static final String RIVERAXIS_LAYER_TEMPLATE = "riveraxis-layer.vm";
1775
0156105222c9 Improved the MapfileGenerator. It offers methods to create barrier and wsplgen layer files for mapserver.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1710
diff changeset
48
2639
a78dafdd8590 Issue 657.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2638
diff changeset
49 public static final String MS_WSPLGEN_PREFIX = "wsplgen-";
a78dafdd8590 Issue 657.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2638
diff changeset
50 public static final String MS_BARRIERS_PREFIX = "barriers-";
a78dafdd8590 Issue 657.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2638
diff changeset
51 public static final String MS_LINE_PREFIX = "lines-";
a78dafdd8590 Issue 657.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2638
diff changeset
52 public static final String MS_POLYGONS_PREFIX = "polygons-";
a78dafdd8590 Issue 657.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2638
diff changeset
53 public static final String MS_LAYER_PREFIX = "ms_layer-";
a78dafdd8590 Issue 657.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 2638
diff changeset
54 public static final String MS_USERSHAPE_PREFIX = "user-";
1129
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
55
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
56 private static Logger logger = Logger.getLogger(MapfileGenerator.class);
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
57
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
58 private File shapefileDirectory;
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
59
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
60 private VelocityEngine velocityEngine;
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
61
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
62
4654
861c47e0a8a0 Refactor Mapserver mapfile generation.
Christian Lins <christian.lins@intevation.de>
parents: 4648
diff changeset
63 protected MapfileGenerator() {
1129
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
64 }
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
65
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
66
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
67 /**
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
68 * Method to check the existance of a template file.
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
69 *
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
70 * @param templateID The name of a template.
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
71 * @return true, of the template exists - otherwise false.
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
72 */
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
73 public boolean templateExists(String templateID){
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
74 Template template = getTemplateByName(templateID);
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
75 return template != null;
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
76 }
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
77
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
78
4656
442fbb290fa8 Introduce river mapfile generation (WARNING: Changes in config xml files required!).
Christian Lins <christian.lins@intevation.de>
parents: 4654
diff changeset
79 public abstract void generate() throws Exception;
4648
c04db3178d09 Work on river axis mapfile generator.
Christian Lins <christian.lins@intevation.de>
parents: 4633
diff changeset
80
c04db3178d09 Work on river axis mapfile generator.
Christian Lins <christian.lins@intevation.de>
parents: 4633
diff changeset
81
c04db3178d09 Work on river axis mapfile generator.
Christian Lins <christian.lins@intevation.de>
parents: 4633
diff changeset
82 /**
1129
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
83 * Returns the VelocityEngine used for the template mechanism.
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
84 *
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
85 * @return the velocity engine.
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
86 */
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
87 protected VelocityEngine getVelocityEngine() {
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
88 if (velocityEngine == null) {
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
89 velocityEngine = new VelocityEngine();
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
90 try {
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
91 setupVelocity(velocityEngine);
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
92 }
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
93 catch (Exception e) {
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
94 logger.error(e, e);
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
95 return null;
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
96 }
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
97 }
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
98 return velocityEngine;
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
99 }
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
100
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
101
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
102 /**
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
103 * Initialize velocity.
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
104 *
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
105 * @param engine Velocity engine.
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
106 * @throws Exception if an error occured while initializing velocity.
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
107 */
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
108 protected void setupVelocity(VelocityEngine engine)
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
109 throws Exception
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
110 {
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
111 engine.setProperty(
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
112 "input.encoding",
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
113 "UTF-8");
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
114
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
115 engine.setProperty(
4656
442fbb290fa8 Introduce river mapfile generation (WARNING: Changes in config xml files required!).
Christian Lins <christian.lins@intevation.de>
parents: 4654
diff changeset
116 RuntimeConstants.RUNTIME_LOG,
442fbb290fa8 Introduce river mapfile generation (WARNING: Changes in config xml files required!).
Christian Lins <christian.lins@intevation.de>
parents: 4654
diff changeset
117 getVelocityLogfile());
1129
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
118
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
119 engine.setProperty(
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
120 "resource.loader",
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
121 "file");
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
122
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
123 engine.setProperty(
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
124 "file.resource.loader.path",
4656
442fbb290fa8 Introduce river mapfile generation (WARNING: Changes in config xml files required!).
Christian Lins <christian.lins@intevation.de>
parents: 4654
diff changeset
125 getMapserverTemplatePath());
1129
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
126
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
127 engine.init();
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
128 }
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
129
4656
442fbb290fa8 Introduce river mapfile generation (WARNING: Changes in config xml files required!).
Christian Lins <christian.lins@intevation.de>
parents: 4654
diff changeset
130 protected abstract String getVelocityLogfile();
442fbb290fa8 Introduce river mapfile generation (WARNING: Changes in config xml files required!).
Christian Lins <christian.lins@intevation.de>
parents: 4654
diff changeset
131
442fbb290fa8 Introduce river mapfile generation (WARNING: Changes in config xml files required!).
Christian Lins <christian.lins@intevation.de>
parents: 4654
diff changeset
132 protected abstract String getMapserverTemplatePath();
442fbb290fa8 Introduce river mapfile generation (WARNING: Changes in config xml files required!).
Christian Lins <christian.lins@intevation.de>
parents: 4654
diff changeset
133
5309
b55975761708 Changed visiblitiy of some methods. TODO: A lot of refactoring.
Raimund Renkert <rrenkert@intevation.de>
parents: 4703
diff changeset
134 public abstract String getMapserverUrl();
1129
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
135
1792
49ad801076e4 Enabled the MapGenerator to create WMS layers with database datastore - riveraxis is the first layer that is no longer fetched from static WMS service but from user specific one.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1781
diff changeset
136 protected VelocityContext getVelocityContext() {
49ad801076e4 Enabled the MapGenerator to create WMS layers with database datastore - riveraxis is the first layer that is no longer fetched from static WMS service but from user specific one.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1781
diff changeset
137 VelocityContext context = new VelocityContext();
49ad801076e4 Enabled the MapGenerator to create WMS layers with database datastore - riveraxis is the first layer that is no longer fetched from static WMS service but from user specific one.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1781
diff changeset
138
49ad801076e4 Enabled the MapGenerator to create WMS layers with database datastore - riveraxis is the first layer that is no longer fetched from static WMS service but from user specific one.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1781
diff changeset
139 try {
49ad801076e4 Enabled the MapGenerator to create WMS layers with database datastore - riveraxis is the first layer that is no longer fetched from static WMS service but from user specific one.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1781
diff changeset
140 context.put("MAPSERVERURL",
4656
442fbb290fa8 Introduce river mapfile generation (WARNING: Changes in config xml files required!).
Christian Lins <christian.lins@intevation.de>
parents: 4654
diff changeset
141 getMapserverUrl());
1792
49ad801076e4 Enabled the MapGenerator to create WMS layers with database datastore - riveraxis is the first layer that is no longer fetched from static WMS service but from user specific one.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1781
diff changeset
142 context.put("SHAPEFILEPATH",
49ad801076e4 Enabled the MapGenerator to create WMS layers with database datastore - riveraxis is the first layer that is no longer fetched from static WMS service but from user specific one.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1781
diff changeset
143 getShapefileBaseDir().getCanonicalPath());
49ad801076e4 Enabled the MapGenerator to create WMS layers with database datastore - riveraxis is the first layer that is no longer fetched from static WMS service but from user specific one.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1781
diff changeset
144 context.put("CONFIGDIR",
49ad801076e4 Enabled the MapGenerator to create WMS layers with database datastore - riveraxis is the first layer that is no longer fetched from static WMS service but from user specific one.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1781
diff changeset
145 Config.getConfigDirectory().getCanonicalPath());
49ad801076e4 Enabled the MapGenerator to create WMS layers with database datastore - riveraxis is the first layer that is no longer fetched from static WMS service but from user specific one.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1781
diff changeset
146 }
49ad801076e4 Enabled the MapGenerator to create WMS layers with database datastore - riveraxis is the first layer that is no longer fetched from static WMS service but from user specific one.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1781
diff changeset
147 catch (FileNotFoundException fnfe) {
49ad801076e4 Enabled the MapGenerator to create WMS layers with database datastore - riveraxis is the first layer that is no longer fetched from static WMS service but from user specific one.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1781
diff changeset
148 // this is bad
4633
fc52ee878412 Preparations for autogenerated riveraxis WMSs.
Christian Lins <christian.lins@intevation.de>
parents: 4047
diff changeset
149 logger.warn(fnfe, fnfe);
1792
49ad801076e4 Enabled the MapGenerator to create WMS layers with database datastore - riveraxis is the first layer that is no longer fetched from static WMS service but from user specific one.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1781
diff changeset
150 }
49ad801076e4 Enabled the MapGenerator to create WMS layers with database datastore - riveraxis is the first layer that is no longer fetched from static WMS service but from user specific one.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1781
diff changeset
151 catch (IOException ioe) {
49ad801076e4 Enabled the MapGenerator to create WMS layers with database datastore - riveraxis is the first layer that is no longer fetched from static WMS service but from user specific one.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1781
diff changeset
152 // this is also bad
4633
fc52ee878412 Preparations for autogenerated riveraxis WMSs.
Christian Lins <christian.lins@intevation.de>
parents: 4047
diff changeset
153 logger.warn(ioe, ioe);
1792
49ad801076e4 Enabled the MapGenerator to create WMS layers with database datastore - riveraxis is the first layer that is no longer fetched from static WMS service but from user specific one.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1781
diff changeset
154 }
49ad801076e4 Enabled the MapGenerator to create WMS layers with database datastore - riveraxis is the first layer that is no longer fetched from static WMS service but from user specific one.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1781
diff changeset
155
49ad801076e4 Enabled the MapGenerator to create WMS layers with database datastore - riveraxis is the first layer that is no longer fetched from static WMS service but from user specific one.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1781
diff changeset
156 return context;
49ad801076e4 Enabled the MapGenerator to create WMS layers with database datastore - riveraxis is the first layer that is no longer fetched from static WMS service but from user specific one.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1781
diff changeset
157 }
49ad801076e4 Enabled the MapGenerator to create WMS layers with database datastore - riveraxis is the first layer that is no longer fetched from static WMS service but from user specific one.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1781
diff changeset
158
49ad801076e4 Enabled the MapGenerator to create WMS layers with database datastore - riveraxis is the first layer that is no longer fetched from static WMS service but from user specific one.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1781
diff changeset
159
1129
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
160 /**
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
161 * Returns a template specified by <i>model</i>.
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
162 *
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
163 * @param model The name of the template.
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
164 * @return a template.
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
165 */
5309
b55975761708 Changed visiblitiy of some methods. TODO: A lot of refactoring.
Raimund Renkert <rrenkert@intevation.de>
parents: 4703
diff changeset
166 public Template getTemplateByName(String model) {
1129
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
167 if (model.indexOf(".vm") < 0) {
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
168 model = model.concat(".vm");
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
169 }
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
170
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
171 try {
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
172 VelocityEngine engine = getVelocityEngine();
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
173 if (engine == null) {
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
174 logger.error("Error while fetching VelocityEngine.");
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
175 return null;
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
176 }
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
177
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
178 return engine.getTemplate(model);
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
179 }
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
180 catch (Exception e) {
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
181 logger.warn(e, e);
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
182 }
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
183
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
184 return null;
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
185 }
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
186
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
187
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
188 /**
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
189 * Returns the mapfile template.
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
190 *
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
191 * @return the mapfile template.
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
192 * @throws Exception if an error occured while reading the configuration.
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
193 */
4656
442fbb290fa8 Introduce river mapfile generation (WARNING: Changes in config xml files required!).
Christian Lins <christian.lins@intevation.de>
parents: 4654
diff changeset
194 protected Template getMapfileTemplateObj()
1129
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
195 throws Exception
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
196 {
4703
38ec171544de Work on rivers.map Generator.
Christian Lins <christian.lins@intevation.de>
parents: 4656
diff changeset
197 String mapfileName = getMapfileTemplate();
1129
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
198 return getTemplateByName(mapfileName);
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
199 }
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
200
4656
442fbb290fa8 Introduce river mapfile generation (WARNING: Changes in config xml files required!).
Christian Lins <christian.lins@intevation.de>
parents: 4654
diff changeset
201 protected abstract String getMapfilePath();
442fbb290fa8 Introduce river mapfile generation (WARNING: Changes in config xml files required!).
Christian Lins <christian.lins@intevation.de>
parents: 4654
diff changeset
202
442fbb290fa8 Introduce river mapfile generation (WARNING: Changes in config xml files required!).
Christian Lins <christian.lins@intevation.de>
parents: 4654
diff changeset
203 protected abstract String getMapfileTemplate();
442fbb290fa8 Introduce river mapfile generation (WARNING: Changes in config xml files required!).
Christian Lins <christian.lins@intevation.de>
parents: 4654
diff changeset
204
1129
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
205
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
206 /**
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
207 * Returns the base directory storing the shapefiles.
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
208 *
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
209 * @return the shapefile base directory.
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
210 *
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
211 * @throws FileNotFoundException if no shapefile path is found or
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
212 * configured.
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
213 */
1792
49ad801076e4 Enabled the MapGenerator to create WMS layers with database datastore - riveraxis is the first layer that is no longer fetched from static WMS service but from user specific one.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1781
diff changeset
214 public File getShapefileBaseDir()
3306
1b41dc00b1f7 Create shapefile directory instead of shapefile 'file'
Christian Lins <christian.lins@intevation.de>
parents: 3303
diff changeset
215 throws FileNotFoundException, IOException
1129
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
216 {
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
217 if (shapefileDirectory == null) {
5865
73da40528cf2 River artifacts: Renamed FLYSUtils to RiverUtils.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
218 String path = RiverUtils.getXPathString(
73da40528cf2 River artifacts: Renamed FLYSUtils to RiverUtils.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
219 RiverUtils.XPATH_FLOODMAP_SHAPEFILE_DIR);
1129
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
220
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
221 if (path != null) {
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
222 shapefileDirectory = new File(path);
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
223 }
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
224
1775
0156105222c9 Improved the MapfileGenerator. It offers methods to create barrier and wsplgen layer files for mapserver.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1710
diff changeset
225 if (shapefileDirectory == null) {
1129
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
226 throw new FileNotFoundException("No shapefile directory given");
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
227 }
1775
0156105222c9 Improved the MapfileGenerator. It offers methods to create barrier and wsplgen layer files for mapserver.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1710
diff changeset
228
0156105222c9 Improved the MapfileGenerator. It offers methods to create barrier and wsplgen layer files for mapserver.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1710
diff changeset
229 if (!shapefileDirectory.exists()) {
3306
1b41dc00b1f7 Create shapefile directory instead of shapefile 'file'
Christian Lins <christian.lins@intevation.de>
parents: 3303
diff changeset
230 shapefileDirectory.mkdirs();
1775
0156105222c9 Improved the MapfileGenerator. It offers methods to create barrier and wsplgen layer files for mapserver.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1710
diff changeset
231 }
1129
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
232 }
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
233
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
234 return shapefileDirectory;
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
235 }
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
236
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
237
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
238 protected File[] getUserDirs()
3306
1b41dc00b1f7 Create shapefile directory instead of shapefile 'file'
Christian Lins <christian.lins@intevation.de>
parents: 3303
diff changeset
239 throws FileNotFoundException, IOException
1129
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
240 {
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
241 File baseDir = getShapefileBaseDir();
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
242 File[] artifactDirs = baseDir.listFiles();
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
243
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
244 // TODO ONLY RETURN DIRECTORIES OF THE SPECIFIED USER
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
245
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
246 return artifactDirs;
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
247 }
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
248
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
249
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
250
1781
ef2300b450bf Modified the process to create mapfiles.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1775
diff changeset
251 protected List<String> parseLayers(File[] dirs) {
ef2300b450bf Modified the process to create mapfiles.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1775
diff changeset
252 List<String> layers = new ArrayList<String>();
1129
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
253
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
254 for (File dir: dirs) {
1781
ef2300b450bf Modified the process to create mapfiles.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1775
diff changeset
255 File[] layerFiles = dir.listFiles(new FilenameFilter() {
ef2300b450bf Modified the process to create mapfiles.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1775
diff changeset
256 @Override
ef2300b450bf Modified the process to create mapfiles.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1775
diff changeset
257 public boolean accept(File directory, String name) {
ef2300b450bf Modified the process to create mapfiles.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1775
diff changeset
258 return name.startsWith(MS_LAYER_PREFIX);
ef2300b450bf Modified the process to create mapfiles.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1775
diff changeset
259 }
ef2300b450bf Modified the process to create mapfiles.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1775
diff changeset
260 });
1129
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
261
1781
ef2300b450bf Modified the process to create mapfiles.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1775
diff changeset
262 for (File layer: layerFiles) {
ef2300b450bf Modified the process to create mapfiles.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1775
diff changeset
263 try {
ef2300b450bf Modified the process to create mapfiles.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1775
diff changeset
264 layers.add(layer.getCanonicalPath());
ef2300b450bf Modified the process to create mapfiles.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1775
diff changeset
265 }
ef2300b450bf Modified the process to create mapfiles.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1775
diff changeset
266 catch (IOException ioe) {
ef2300b450bf Modified the process to create mapfiles.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1775
diff changeset
267 logger.warn(ioe, ioe);
1134
bcf70a452646 Read barrier layers from filesystem while mapfile creation and build a facet for this layer in the artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1129
diff changeset
268 }
1129
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
269 }
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
270 }
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
271
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
272 return layers;
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
273 }
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
274
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
275
1792
49ad801076e4 Enabled the MapGenerator to create WMS layers with database datastore - riveraxis is the first layer that is no longer fetched from static WMS service but from user specific one.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1781
diff changeset
276
49ad801076e4 Enabled the MapGenerator to create WMS layers with database datastore - riveraxis is the first layer that is no longer fetched from static WMS service but from user specific one.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1781
diff changeset
277
49ad801076e4 Enabled the MapGenerator to create WMS layers with database datastore - riveraxis is the first layer that is no longer fetched from static WMS service but from user specific one.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1781
diff changeset
278 /**
1781
ef2300b450bf Modified the process to create mapfiles.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1775
diff changeset
279 * Creates a layer snippet which might be included in the mapfile.
ef2300b450bf Modified the process to create mapfiles.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1775
diff changeset
280 *
ef2300b450bf Modified the process to create mapfiles.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1775
diff changeset
281 * @param layerinfo A LayerInfo object that contains all necessary
ef2300b450bf Modified the process to create mapfiles.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1775
diff changeset
282 * information to build a Mapserver LAYER section.
ef2300b450bf Modified the process to create mapfiles.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1775
diff changeset
283 * @param dir The base dir for the LAYER snippet.
ef2300b450bf Modified the process to create mapfiles.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1775
diff changeset
284 * @param filename The name of the file that is written.
ef2300b450bf Modified the process to create mapfiles.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1775
diff changeset
285 * @param tpl The Velocity template which is used to create the LAYER
ef2300b450bf Modified the process to create mapfiles.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1775
diff changeset
286 * section.
ef2300b450bf Modified the process to create mapfiles.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1775
diff changeset
287 */
5309
b55975761708 Changed visiblitiy of some methods. TODO: A lot of refactoring.
Raimund Renkert <rrenkert@intevation.de>
parents: 4703
diff changeset
288 public void writeLayer(
4656
442fbb290fa8 Introduce river mapfile generation (WARNING: Changes in config xml files required!).
Christian Lins <christian.lins@intevation.de>
parents: 4654
diff changeset
289 LayerInfo layerInfo,
442fbb290fa8 Introduce river mapfile generation (WARNING: Changes in config xml files required!).
Christian Lins <christian.lins@intevation.de>
parents: 4654
diff changeset
290 File layerFile,
1775
0156105222c9 Improved the MapfileGenerator. It offers methods to create barrier and wsplgen layer files for mapserver.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1710
diff changeset
291 Template tpl
0156105222c9 Improved the MapfileGenerator. It offers methods to create barrier and wsplgen layer files for mapserver.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1710
diff changeset
292 )
0156105222c9 Improved the MapfileGenerator. It offers methods to create barrier and wsplgen layer files for mapserver.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1710
diff changeset
293 throws FileNotFoundException
0156105222c9 Improved the MapfileGenerator. It offers methods to create barrier and wsplgen layer files for mapserver.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1710
diff changeset
294 {
0156105222c9 Improved the MapfileGenerator. It offers methods to create barrier and wsplgen layer files for mapserver.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1710
diff changeset
295 if (logger.isDebugEnabled()) {
0156105222c9 Improved the MapfileGenerator. It offers methods to create barrier and wsplgen layer files for mapserver.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1710
diff changeset
296 logger.debug("Write layer for:");
4656
442fbb290fa8 Introduce river mapfile generation (WARNING: Changes in config xml files required!).
Christian Lins <christian.lins@intevation.de>
parents: 4654
diff changeset
297 logger.debug(" directory/file: " + layerFile.getName());
1775
0156105222c9 Improved the MapfileGenerator. It offers methods to create barrier and wsplgen layer files for mapserver.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1710
diff changeset
298 }
0156105222c9 Improved the MapfileGenerator. It offers methods to create barrier and wsplgen layer files for mapserver.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1710
diff changeset
299
0156105222c9 Improved the MapfileGenerator. It offers methods to create barrier and wsplgen layer files for mapserver.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1710
diff changeset
300 Writer writer = null;
0156105222c9 Improved the MapfileGenerator. It offers methods to create barrier and wsplgen layer files for mapserver.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1710
diff changeset
301
0156105222c9 Improved the MapfileGenerator. It offers methods to create barrier and wsplgen layer files for mapserver.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1710
diff changeset
302 try {
4656
442fbb290fa8 Introduce river mapfile generation (WARNING: Changes in config xml files required!).
Christian Lins <christian.lins@intevation.de>
parents: 4654
diff changeset
303 writer = new FileWriter(layerFile);
1775
0156105222c9 Improved the MapfileGenerator. It offers methods to create barrier and wsplgen layer files for mapserver.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1710
diff changeset
304
1792
49ad801076e4 Enabled the MapGenerator to create WMS layers with database datastore - riveraxis is the first layer that is no longer fetched from static WMS service but from user specific one.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1781
diff changeset
305 VelocityContext context = getVelocityContext();
4656
442fbb290fa8 Introduce river mapfile generation (WARNING: Changes in config xml files required!).
Christian Lins <christian.lins@intevation.de>
parents: 4654
diff changeset
306 context.put("LAYER", layerInfo);
1775
0156105222c9 Improved the MapfileGenerator. It offers methods to create barrier and wsplgen layer files for mapserver.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1710
diff changeset
307
0156105222c9 Improved the MapfileGenerator. It offers methods to create barrier and wsplgen layer files for mapserver.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1710
diff changeset
308 tpl.merge(context, writer);
0156105222c9 Improved the MapfileGenerator. It offers methods to create barrier and wsplgen layer files for mapserver.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1710
diff changeset
309 }
0156105222c9 Improved the MapfileGenerator. It offers methods to create barrier and wsplgen layer files for mapserver.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1710
diff changeset
310 catch (FileNotFoundException fnfe) {
0156105222c9 Improved the MapfileGenerator. It offers methods to create barrier and wsplgen layer files for mapserver.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1710
diff changeset
311 logger.error(fnfe, fnfe);
0156105222c9 Improved the MapfileGenerator. It offers methods to create barrier and wsplgen layer files for mapserver.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1710
diff changeset
312 }
0156105222c9 Improved the MapfileGenerator. It offers methods to create barrier and wsplgen layer files for mapserver.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1710
diff changeset
313 catch (IOException ioe) {
0156105222c9 Improved the MapfileGenerator. It offers methods to create barrier and wsplgen layer files for mapserver.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1710
diff changeset
314 logger.error(ioe, ioe);
0156105222c9 Improved the MapfileGenerator. It offers methods to create barrier and wsplgen layer files for mapserver.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1710
diff changeset
315 }
0156105222c9 Improved the MapfileGenerator. It offers methods to create barrier and wsplgen layer files for mapserver.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1710
diff changeset
316 catch (Exception e) {
0156105222c9 Improved the MapfileGenerator. It offers methods to create barrier and wsplgen layer files for mapserver.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1710
diff changeset
317 logger.error(e, e);
0156105222c9 Improved the MapfileGenerator. It offers methods to create barrier and wsplgen layer files for mapserver.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1710
diff changeset
318 }
0156105222c9 Improved the MapfileGenerator. It offers methods to create barrier and wsplgen layer files for mapserver.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1710
diff changeset
319 finally {
0156105222c9 Improved the MapfileGenerator. It offers methods to create barrier and wsplgen layer files for mapserver.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1710
diff changeset
320 try {
0156105222c9 Improved the MapfileGenerator. It offers methods to create barrier and wsplgen layer files for mapserver.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1710
diff changeset
321 if (writer != null) {
0156105222c9 Improved the MapfileGenerator. It offers methods to create barrier and wsplgen layer files for mapserver.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1710
diff changeset
322 writer.close();
0156105222c9 Improved the MapfileGenerator. It offers methods to create barrier and wsplgen layer files for mapserver.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1710
diff changeset
323 }
0156105222c9 Improved the MapfileGenerator. It offers methods to create barrier and wsplgen layer files for mapserver.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1710
diff changeset
324 }
0156105222c9 Improved the MapfileGenerator. It offers methods to create barrier and wsplgen layer files for mapserver.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1710
diff changeset
325 catch (IOException ioe) {
0156105222c9 Improved the MapfileGenerator. It offers methods to create barrier and wsplgen layer files for mapserver.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1710
diff changeset
326 logger.debug(ioe, ioe);
0156105222c9 Improved the MapfileGenerator. It offers methods to create barrier and wsplgen layer files for mapserver.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1710
diff changeset
327 }
0156105222c9 Improved the MapfileGenerator. It offers methods to create barrier and wsplgen layer files for mapserver.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1710
diff changeset
328 }
0156105222c9 Improved the MapfileGenerator. It offers methods to create barrier and wsplgen layer files for mapserver.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1710
diff changeset
329 }
0156105222c9 Improved the MapfileGenerator. It offers methods to create barrier and wsplgen layer files for mapserver.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1710
diff changeset
330
0156105222c9 Improved the MapfileGenerator. It offers methods to create barrier and wsplgen layer files for mapserver.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1710
diff changeset
331
1129
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
332 /**
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
333 * Creates a mapfile with the layer information stored in <i>layers</i>.
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
334 *
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
335 * @param layers Layer information.
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
336 */
5309
b55975761708 Changed visiblitiy of some methods. TODO: A lot of refactoring.
Raimund Renkert <rrenkert@intevation.de>
parents: 4703
diff changeset
337 public void writeMapfile(List<String> layers) {
1129
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
338 String tmpMapName = "mapfile" + new Date().getTime();
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
339
4656
442fbb290fa8 Introduce river mapfile generation (WARNING: Changes in config xml files required!).
Christian Lins <christian.lins@intevation.de>
parents: 4654
diff changeset
340 File mapfile = new File(getMapfilePath());
1129
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
341
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
342 File tmp = null;
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
343 Writer writer = null;
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
344
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
345 try {
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
346 tmp = new File(mapfile.getParent(), tmpMapName);
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
347 tmp.createNewFile();
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
348
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
349 writer = new FileWriter(tmp);
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
350
1792
49ad801076e4 Enabled the MapGenerator to create WMS layers with database datastore - riveraxis is the first layer that is no longer fetched from static WMS service but from user specific one.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1781
diff changeset
351 VelocityContext context = getVelocityContext();
1781
ef2300b450bf Modified the process to create mapfiles.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1775
diff changeset
352 context.put("LAYERS", layers);
1129
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
353
4656
442fbb290fa8 Introduce river mapfile generation (WARNING: Changes in config xml files required!).
Christian Lins <christian.lins@intevation.de>
parents: 4654
diff changeset
354 Template mapTemplate = getMapfileTemplateObj();
1129
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
355 if (mapTemplate == null) {
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
356 logger.warn("No mapfile template found.");
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
357 return;
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
358 }
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
359
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
360 mapTemplate.merge(context, writer);
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
361
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
362 // we need to create a temporary mapfile first und rename it into
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
363 // real mapfile because we don't run into race conditions on this
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
364 // way. (iw)
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
365 tmp.renameTo(mapfile);
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
366 }
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
367 catch (FileNotFoundException fnfe) {
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
368 logger.error(fnfe, fnfe);
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
369 }
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
370 catch (IOException ioe) {
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
371 logger.error(ioe, ioe);
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
372 }
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
373 catch (Exception e) {
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
374 logger.error(e, e);
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
375 }
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
376 finally {
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
377 try {
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
378 if (writer != null) {
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
379 writer.close();
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
380 }
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
381
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
382 if (tmp.exists()) {
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
383 tmp.delete();
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
384 }
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
385 }
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
386 catch (IOException ioe) {
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
387 logger.debug(ioe, ioe);
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
388 }
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
389 }
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
390 }
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
391 }
da3c3e286c88 Introduced a MapfileGenerator that creates Mapserver specific mapfiles based on WSPLGEN results read from filesystem.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
392 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org