Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/utils/ArtifactMapfileGenerator.java @ 4702:13abfb1bcb75
Fix typo in class names and correct file path in floodmap.xml.
author | Christian Lins <christian.lins@intevation.de> |
---|---|
date | Mon, 17 Dec 2012 23:24:27 +0100 |
parents | |
children | 63617e142dfe |
comparison
equal
deleted
inserted
replaced
4701:63d1e91db666 | 4702:13abfb1bcb75 |
---|---|
1 package de.intevation.flys.utils; | |
2 | |
3 import de.intevation.artifacts.CallContext; | |
4 import de.intevation.flys.artifacts.FLYSArtifact; | |
5 import de.intevation.flys.artifacts.model.LayerInfo; | |
6 import de.intevation.flys.artifacts.model.map.WMSDBLayerFacet; | |
7 import de.intevation.flys.artifacts.model.map.WMSLayerFacet; | |
8 import de.intevation.flys.artifacts.model.map.WSPLGENLayerFacet; | |
9 import de.intevation.flys.artifacts.resources.Resources; | |
10 | |
11 import java.io.File; | |
12 import java.io.FileNotFoundException; | |
13 import java.io.IOException; | |
14 import java.util.List; | |
15 | |
16 import org.apache.log4j.Logger; | |
17 import org.apache.velocity.Template; | |
18 import org.geotools.data.shapefile.ShpFiles; | |
19 import org.geotools.data.shapefile.shp.ShapefileHeader; | |
20 import org.geotools.data.shapefile.shp.ShapefileReader; | |
21 | |
22 public class ArtifactMapfileGenerator extends MapfileGenerator { | |
23 | |
24 private static Logger logger = Logger.getLogger(ArtifactMapfileGenerator.class); | |
25 | |
26 @Override | |
27 protected String getVelocityLogfile() { | |
28 return FLYSUtils.getXPathString(FLYSUtils.XPATH_FLOODMAP_VELOCITY_LOGFILE); | |
29 } | |
30 | |
31 @Override | |
32 protected String getMapserverTemplatePath() { | |
33 return FLYSUtils.getXPathString(FLYSUtils.XPATH_FLOODMAP_MAPSERVER_TEMPLATE_PATH); | |
34 } | |
35 | |
36 @Override | |
37 protected String getMapserverUrl() { | |
38 return FLYSUtils.getXPathString(FLYSUtils.XPATH_FLOODMAP_MAPSERVER_URL); | |
39 } | |
40 | |
41 /** | |
42 * Method which starts searching for meta information file and mapfile | |
43 * generation. | |
44 */ | |
45 @Override | |
46 public void generate() throws IOException | |
47 { | |
48 File[] userDirs = getUserDirs(); | |
49 List<String> layers = parseLayers(userDirs); | |
50 logger.info("Found " + layers.size() + " layers for user mapfile."); | |
51 | |
52 writeMapfile(layers); | |
53 } | |
54 | |
55 /** | |
56 * Creates a layer file used for Mapserver's mapfile which represents the | |
57 * floodmap. | |
58 * | |
59 * @param flys The FLYSArtifact that owns <i>wms</i>. | |
60 * @param wms The WMSLayerFacet that contains information for the layer. | |
61 */ | |
62 public void createUeskLayer( | |
63 FLYSArtifact flys, | |
64 WSPLGENLayerFacet wms, | |
65 String style, | |
66 CallContext context | |
67 ) throws FileNotFoundException, IOException | |
68 { | |
69 logger.debug("createUeskLayer"); | |
70 | |
71 LayerInfo layerinfo = new LayerInfo(); | |
72 layerinfo.setName(MS_WSPLGEN_PREFIX + flys.identifier()); | |
73 layerinfo.setType("POLYGON"); | |
74 layerinfo.setDirectory(flys.identifier()); | |
75 layerinfo.setData(WSPLGEN_RESULT_SHAPE); | |
76 layerinfo.setTitle(Resources.getMsg(Resources.getLocale(context.getMeta()), | |
77 "floodmap.uesk", | |
78 "Floodmap")); | |
79 layerinfo.setStyle(style); | |
80 layerinfo.setSrid(wms.getSrid()); | |
81 | |
82 String name = MS_LAYER_PREFIX + wms.getName(); | |
83 | |
84 Template template = getTemplateByName(WSPLGEN_LAYER_TEMPLATE); | |
85 if (template == null) { | |
86 logger.warn("Template '" + WSPLGEN_LAYER_TEMPLATE + "' found."); | |
87 return; | |
88 } | |
89 | |
90 try { | |
91 File dir = new File(getShapefileBaseDir(), flys.identifier()); | |
92 writeLayer(layerinfo, new File(dir, name), template); | |
93 } | |
94 catch (FileNotFoundException fnfe) { | |
95 logger.error(fnfe, fnfe); | |
96 logger.warn("Unable to write layer: " + name); | |
97 } | |
98 } | |
99 | |
100 | |
101 /** | |
102 * Creates a layer file used for Mapserver's mapfile which represents the | |
103 * user defined barriers. | |
104 * | |
105 * @param flys The FLYSArtifact that owns <i>wms</i>. | |
106 * @param wms The WMSLayerFacet that contains information for the layer. | |
107 */ | |
108 public void createBarriersLayer(FLYSArtifact flys, WMSLayerFacet wms) | |
109 throws FileNotFoundException, IOException | |
110 { | |
111 logger.debug("createBarriersLayer"); | |
112 | |
113 //String uuid = flys.identifier(); | |
114 //File dir = new File(getShapefileBaseDir(), uuid); | |
115 | |
116 createBarriersLineLayer(flys, wms); | |
117 createBarriersPolygonLayer(flys, wms); | |
118 } | |
119 | |
120 | |
121 protected void createBarriersLineLayer( | |
122 FLYSArtifact flys, | |
123 WMSLayerFacet wms | |
124 ) | |
125 throws FileNotFoundException, IOException | |
126 { | |
127 String uuid = flys.identifier(); | |
128 String group = MS_BARRIERS_PREFIX + uuid; | |
129 String groupTitle = "I18N_BARRIERS_TITLE"; | |
130 | |
131 File dir = new File(getShapefileBaseDir(), uuid); | |
132 File test = new File(dir, WSPLGEN_LINES_SHAPE); | |
133 | |
134 if (!test.exists() || !test.canRead()) { | |
135 logger.debug("No barrier line layer existing."); | |
136 return; | |
137 } | |
138 | |
139 LayerInfo lineInfo = new LayerInfo(); | |
140 lineInfo.setName(MS_LINE_PREFIX + uuid); | |
141 lineInfo.setType("LINE"); | |
142 lineInfo.setDirectory(uuid); | |
143 lineInfo.setData(WSPLGEN_LINES_SHAPE); | |
144 lineInfo.setTitle("I18N_LINE_SHAPE"); | |
145 lineInfo.setGroup(group); | |
146 lineInfo.setGroupTitle(groupTitle); | |
147 lineInfo.setSrid(wms.getSrid()); | |
148 | |
149 String nameLines = MS_LAYER_PREFIX + wms.getName() + "-lines"; | |
150 | |
151 Template tpl = getTemplateByName(SHP_LAYER_TEMPLATE); | |
152 if (tpl == null) { | |
153 logger.warn("Template '" + SHP_LAYER_TEMPLATE + "' found."); | |
154 return; | |
155 } | |
156 | |
157 try { | |
158 writeLayer(lineInfo, new File(dir, nameLines), tpl); | |
159 } | |
160 catch (FileNotFoundException fnfe) { | |
161 logger.error(fnfe, fnfe); | |
162 logger.warn("Unable to write layer: " + nameLines); | |
163 } | |
164 } | |
165 | |
166 protected void createBarriersPolygonLayer( | |
167 FLYSArtifact flys, | |
168 WMSLayerFacet wms | |
169 ) | |
170 throws FileNotFoundException, IOException | |
171 { | |
172 String uuid = flys.identifier(); | |
173 String group = uuid + MS_BARRIERS_PREFIX; | |
174 String groupTitle = "I18N_BARRIERS_TITLE"; | |
175 | |
176 File dir = new File(getShapefileBaseDir(), uuid); | |
177 File test = new File(dir, WSPLGEN_POLYGONS_SHAPE); | |
178 | |
179 if (!test.exists() || !test.canRead()) { | |
180 logger.debug("No barrier line layer existing."); | |
181 return; | |
182 } | |
183 | |
184 LayerInfo polygonInfo = new LayerInfo(); | |
185 polygonInfo.setName(MS_POLYGONS_PREFIX + uuid); | |
186 polygonInfo.setType("POLYGON"); | |
187 polygonInfo.setDirectory(uuid); | |
188 polygonInfo.setData(WSPLGEN_POLYGONS_SHAPE); | |
189 polygonInfo.setTitle("I18N_POLYGON_SHAPE"); | |
190 polygonInfo.setGroup(group); | |
191 polygonInfo.setGroupTitle(groupTitle); | |
192 polygonInfo.setSrid(wms.getSrid()); | |
193 | |
194 String namePolygons = MS_LAYER_PREFIX + wms.getName() + "-polygons"; | |
195 | |
196 Template tpl = getTemplateByName(SHP_LAYER_TEMPLATE); | |
197 if (tpl == null) { | |
198 logger.warn("Template '" + SHP_LAYER_TEMPLATE + "' found."); | |
199 return; | |
200 } | |
201 | |
202 try { | |
203 writeLayer(polygonInfo, new File(dir, namePolygons), tpl); | |
204 } | |
205 catch (FileNotFoundException fnfe) { | |
206 logger.error(fnfe, fnfe); | |
207 logger.warn("Unable to write layer: " + namePolygons); | |
208 } | |
209 } | |
210 | |
211 | |
212 /** | |
213 * Creates a layer file used for Mapserver's mapfile which represents the | |
214 * shape files uploaded by the user. | |
215 * | |
216 * @param flys The FLYSArtifact that owns <i>wms</i>. | |
217 * @param wms The WMSLayerFacet that contains information for the layer. | |
218 */ | |
219 public void createUserShapeLayer(FLYSArtifact flys, WMSLayerFacet wms) | |
220 throws FileNotFoundException, IOException | |
221 { | |
222 logger.debug("createUserShapeLayer"); | |
223 | |
224 String uuid = flys.identifier(); | |
225 File dir = new File(getShapefileBaseDir(), uuid); | |
226 File test = new File(dir, WSPLGEN_USER_SHAPE); | |
227 | |
228 if (!test.exists() || !test.canRead()) { | |
229 logger.debug("No user layer existing."); | |
230 return; | |
231 } | |
232 | |
233 File userShape = new File(dir, WSPLGEN_USER_SHAPE); | |
234 ShpFiles sf = new ShpFiles(userShape); | |
235 ShapefileReader sfr = new ShapefileReader(sf, true, false, null); | |
236 ShapefileHeader sfh = sfr.getHeader(); | |
237 | |
238 String group = uuid + MS_USERSHAPE_PREFIX; | |
239 String groupTitle = "I18N_USER_SHAPE_TITLE"; | |
240 | |
241 LayerInfo info = new LayerInfo(); | |
242 info.setName(MS_USERSHAPE_PREFIX + uuid); | |
243 if (sfh.getShapeType().isLineType()) { | |
244 info.setType("LINE"); | |
245 } | |
246 else if (sfh.getShapeType().isPolygonType()) { | |
247 info.setType("POLYGON"); | |
248 } | |
249 else { | |
250 return; | |
251 } | |
252 info.setDirectory(uuid); | |
253 info.setData(WSPLGEN_USER_SHAPE); | |
254 info.setTitle("I18N_USER_SHAPE"); | |
255 info.setGroup(group); | |
256 info.setGroupTitle(groupTitle); | |
257 info.setSrid(wms.getSrid()); | |
258 | |
259 String nameUser = MS_LAYER_PREFIX + wms.getName(); | |
260 | |
261 Template tpl = getTemplateByName(SHP_LAYER_TEMPLATE); | |
262 if (tpl == null) { | |
263 logger.warn("Template '" + SHP_LAYER_TEMPLATE + "' found."); | |
264 return; | |
265 } | |
266 | |
267 try { | |
268 writeLayer(info, new File(dir, nameUser), tpl); | |
269 } | |
270 catch (FileNotFoundException fnfe) { | |
271 logger.error(fnfe, fnfe); | |
272 logger.warn("Unable to write layer: " + nameUser); | |
273 } | |
274 | |
275 } | |
276 | |
277 | |
278 /** | |
279 * Creates a layer file used for Mapserver's mapfile which represents | |
280 * geometries from database. | |
281 * | |
282 * @param flys The FLYSArtifact that owns <i>wms</i>. | |
283 * @param wms The WMSLayerFacet that contains information for the layer. | |
284 */ | |
285 public void createDatabaseLayer( | |
286 FLYSArtifact flys, | |
287 WMSDBLayerFacet wms, | |
288 String style | |
289 ) | |
290 throws FileNotFoundException, IOException | |
291 { | |
292 logger.debug("createDatabaseLayer"); | |
293 | |
294 LayerInfo layerinfo = new LayerInfo(); | |
295 layerinfo.setName(wms.getName() + "-" + flys.identifier()); | |
296 layerinfo.setType(wms.getGeometryType()); | |
297 layerinfo.setFilter(wms.getFilter()); | |
298 layerinfo.setData(wms.getData()); | |
299 layerinfo.setTitle(wms.getDescription()); | |
300 layerinfo.setStyle(style); | |
301 if(wms.getExtent() != null) { | |
302 layerinfo.setExtent(GeometryUtils.jtsBoundsToOLBounds(wms.getExtent())); | |
303 } | |
304 layerinfo.setConnection(wms.getConnection()); | |
305 layerinfo.setConnectionType(wms.getConnectionType()); | |
306 layerinfo.setLabelItem(wms.getLabelItem()); | |
307 layerinfo.setSrid(wms.getSrid()); | |
308 | |
309 String name = MS_LAYER_PREFIX + wms.getName(); | |
310 | |
311 Template template = getTemplateByName(DB_LAYER_TEMPLATE); | |
312 if (template == null) { | |
313 logger.warn("Template '" + DB_LAYER_TEMPLATE + "' found."); | |
314 return; | |
315 } | |
316 | |
317 try { | |
318 File dir = new File(getShapefileBaseDir(), flys.identifier()); | |
319 writeLayer(layerinfo, new File(dir, name), template); | |
320 } | |
321 catch (FileNotFoundException fnfe) { | |
322 logger.error(fnfe, fnfe); | |
323 logger.warn("Unable to write layer: " + name); | |
324 } | |
325 } | |
326 | |
327 @Override | |
328 protected String getMapfilePath() { | |
329 return FLYSUtils.getXPathString(FLYSUtils.XPATH_FLOODMAP_MAPFILE_PATH); | |
330 } | |
331 | |
332 @Override | |
333 protected String getMapfileTemplate() { | |
334 return FLYSUtils.getXPathString(FLYSUtils.XPATH_FLOODMAP_MAPFILE_TEMPLATE); | |
335 } | |
336 | |
337 } |