annotate artifacts/src/main/java/org/dive4elements/river/utils/MapfileGenerator.java @ 8202:e4606eae8ea5

sed src/**/*.java 's/logger/log/g'
author Sascha L. Teichmann <teichmann@intevation.de>
date Fri, 05 Sep 2014 12:58:17 +0200
parents 81ae2a4873f2
children e9d912c97fa8
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 *
5994
af13ceeba52a Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5865
diff changeset
4 * This file is Free Software under the GNU AGPL (>=v3)
5863
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
5994
af13ceeba52a Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5865
diff changeset
6 * documentation coming with Dive4Elements River for details.
5863
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
8202
e4606eae8ea5 sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7655
diff changeset
56 private static Logger log = Logger.getLogger(MapfileGenerator.class);
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
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) {
8202
e4606eae8ea5 sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7655
diff changeset
94 log.error(e, e);
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
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
8202
e4606eae8ea5 sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7655
diff changeset
149 log.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
8202
e4606eae8ea5 sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7655
diff changeset
153 log.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) {
8202
e4606eae8ea5 sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7655
diff changeset
174 log.error("Error while fetching VelocityEngine.");
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
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) {
8202
e4606eae8ea5 sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7655
diff changeset
181 log.warn(e, e);
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
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
7655
81ae2a4873f2 Do not NPE if there is a folder without mapfiles in the shapefile path
Andre Heinecke <aheinecke@intevation.de>
parents: 5994
diff changeset
262 if (layerFiles == null) {
81ae2a4873f2 Do not NPE if there is a folder without mapfiles in the shapefile path
Andre Heinecke <aheinecke@intevation.de>
parents: 5994
diff changeset
263 continue;
81ae2a4873f2 Do not NPE if there is a folder without mapfiles in the shapefile path
Andre Heinecke <aheinecke@intevation.de>
parents: 5994
diff changeset
264 }
81ae2a4873f2 Do not NPE if there is a folder without mapfiles in the shapefile path
Andre Heinecke <aheinecke@intevation.de>
parents: 5994
diff changeset
265
1781
ef2300b450bf Modified the process to create mapfiles.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1775
diff changeset
266 for (File layer: layerFiles) {
ef2300b450bf Modified the process to create mapfiles.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1775
diff changeset
267 try {
ef2300b450bf Modified the process to create mapfiles.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1775
diff changeset
268 layers.add(layer.getCanonicalPath());
ef2300b450bf Modified the process to create mapfiles.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1775
diff changeset
269 }
ef2300b450bf Modified the process to create mapfiles.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1775
diff changeset
270 catch (IOException ioe) {
8202
e4606eae8ea5 sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7655
diff changeset
271 log.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
272 }
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
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
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
276 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
277 }
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
278
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
279
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
280
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
281
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
282 /**
1781
ef2300b450bf Modified the process to create mapfiles.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1775
diff changeset
283 * 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
284 *
ef2300b450bf Modified the process to create mapfiles.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1775
diff changeset
285 * @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
286 * information to build a Mapserver LAYER section.
ef2300b450bf Modified the process to create mapfiles.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1775
diff changeset
287 * @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
288 * @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
289 * @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
290 * section.
ef2300b450bf Modified the process to create mapfiles.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1775
diff changeset
291 */
5309
b55975761708 Changed visiblitiy of some methods. TODO: A lot of refactoring.
Raimund Renkert <rrenkert@intevation.de>
parents: 4703
diff changeset
292 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
293 LayerInfo layerInfo,
442fbb290fa8 Introduce river mapfile generation (WARNING: Changes in config xml files required!).
Christian Lins <christian.lins@intevation.de>
parents: 4654
diff changeset
294 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
295 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
296 )
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
297 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
298 {
8202
e4606eae8ea5 sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7655
diff changeset
299 if (log.isDebugEnabled()) {
e4606eae8ea5 sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7655
diff changeset
300 log.debug("Write layer for:");
e4606eae8ea5 sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7655
diff changeset
301 log.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
302 }
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
303
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 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
305
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
306 try {
4656
442fbb290fa8 Introduce river mapfile generation (WARNING: Changes in config xml files required!).
Christian Lins <christian.lins@intevation.de>
parents: 4654
diff changeset
307 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
308
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
309 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
310 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
311
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 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
313 }
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 catch (FileNotFoundException fnfe) {
8202
e4606eae8ea5 sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7655
diff changeset
315 log.error(fnfe, fnfe);
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
316 }
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 catch (IOException ioe) {
8202
e4606eae8ea5 sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7655
diff changeset
318 log.error(ioe, ioe);
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
319 }
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 catch (Exception e) {
8202
e4606eae8ea5 sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7655
diff changeset
321 log.error(e, e);
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
322 }
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 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
324 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
325 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
326 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
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 catch (IOException ioe) {
8202
e4606eae8ea5 sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7655
diff changeset
330 log.debug(ioe, ioe);
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
331 }
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
332 }
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
333 }
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
334
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
335
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
336 /**
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
337 * 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
338 *
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 * @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
340 */
5309
b55975761708 Changed visiblitiy of some methods. TODO: A lot of refactoring.
Raimund Renkert <rrenkert@intevation.de>
parents: 4703
diff changeset
341 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
342 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
343
4656
442fbb290fa8 Introduce river mapfile generation (WARNING: Changes in config xml files required!).
Christian Lins <christian.lins@intevation.de>
parents: 4654
diff changeset
344 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
345
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 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
347 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
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 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
350 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
351 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
352
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 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
354
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
355 VelocityContext context = getVelocityContext();
1781
ef2300b450bf Modified the process to create mapfiles.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1775
diff changeset
356 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
357
4656
442fbb290fa8 Introduce river mapfile generation (WARNING: Changes in config xml files required!).
Christian Lins <christian.lins@intevation.de>
parents: 4654
diff changeset
358 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
359 if (mapTemplate == null) {
8202
e4606eae8ea5 sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7655
diff changeset
360 log.warn("No mapfile template found.");
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
361 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
362 }
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
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 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
365
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 // 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
367 // 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
368 // 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
369 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
370 }
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 catch (FileNotFoundException fnfe) {
8202
e4606eae8ea5 sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7655
diff changeset
372 log.error(fnfe, fnfe);
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
373 }
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 catch (IOException ioe) {
8202
e4606eae8ea5 sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7655
diff changeset
375 log.error(ioe, ioe);
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
376 }
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 catch (Exception e) {
8202
e4606eae8ea5 sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7655
diff changeset
378 log.error(e, e);
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
379 }
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 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
381 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
382 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
383 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
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 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
387 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
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 catch (IOException ioe) {
8202
e4606eae8ea5 sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7655
diff changeset
391 log.debug(ioe, ioe);
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
392 }
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
393 }
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
394 }
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
395 }
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
396 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org