Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/mapserver/MapfileGenerator.java @ 5023:1da61095040c mapgenfix
Renaming methods and fields. Start refactoring with ArtifactMapfileGenerator.generate() which should be the main entry point.
author | Christian Lins <christian.lins@intevation.de> |
---|---|
date | Tue, 19 Feb 2013 14:25:38 +0100 |
parents | a9243df307b1 |
children | cc50e1b9fc60 |
comparison
equal
deleted
inserted
replaced
5022:a9243df307b1 | 5023:1da61095040c |
---|---|
37 public static final String WSPLGEN_LAYER_TEMPLATE = "wsplgen_layer.vm"; | 37 public static final String WSPLGEN_LAYER_TEMPLATE = "wsplgen_layer.vm"; |
38 public static final String SHP_LAYER_TEMPLATE = "shapefile_layer.vm"; | 38 public static final String SHP_LAYER_TEMPLATE = "shapefile_layer.vm"; |
39 public static final String DB_LAYER_TEMPLATE = "db_layer.vm"; | 39 public static final String DB_LAYER_TEMPLATE = "db_layer.vm"; |
40 public static final String RIVERAXIS_LAYER_TEMPLATE = "riveraxis-layer.vm"; | 40 public static final String RIVERAXIS_LAYER_TEMPLATE = "riveraxis-layer.vm"; |
41 | 41 |
42 public static final String MS_WSPLGEN_PREFIX = "wsplgen-"; | 42 public static final String MS_PREFIX_WSPLGEN = "wsplgen-"; |
43 public static final String MS_BARRIERS_PREFIX = "barriers-"; | 43 public static final String MS_PREFIX_BARRIERS = "barriers-"; |
44 public static final String MS_LINE_PREFIX = "lines-"; | 44 // public static final String MS_LINE_PREFIX = "lines-"; |
45 public static final String MS_POLYGONS_PREFIX = "polygons-"; | 45 // public static final String MS_POLYGONS_PREFIX = "polygons-"; |
46 public static final String MS_LAYER_PREFIX = "ms_layer-"; | 46 // public static final String MS_LAYER_PREFIX = "ms_layer-"; |
47 public static final String MS_USERSHAPE_PREFIX = "user-"; | 47 public static final String MS_PREFIX_USER = "user-"; |
48 | 48 |
49 private static Logger logger = Logger.getLogger(MapfileGenerator.class); | 49 private static Logger logger = Logger.getLogger(MapfileGenerator.class); |
50 | 50 |
51 private File shapefileDirectory; | 51 private File shapefileDirectory; |
52 | 52 |
61 * Method to check the existance of a template file. | 61 * Method to check the existance of a template file. |
62 * | 62 * |
63 * @param templateID The name of a template. | 63 * @param templateID The name of a template. |
64 * @return true, of the template exists - otherwise false. | 64 * @return true, of the template exists - otherwise false. |
65 */ | 65 */ |
66 public boolean templateExists(String templateID){ | 66 protected boolean templateExists(String templateID){ |
67 Template template = getTemplateByName(templateID); | 67 Template template = getTemplateByName(templateID); |
68 return template != null; | 68 return template != null; |
69 } | 69 } |
70 | 70 |
71 | 71 |
72 /** | |
73 * Starts the mapfile generation. This is the main entry point for | |
74 * the mapfile generation, all other methods of this class/package | |
75 * *should* be non-public. | |
76 * @throws Exception | |
77 */ | |
72 public abstract void generate() throws Exception; | 78 public abstract void generate() throws Exception; |
73 | 79 |
74 | 80 |
75 /** | 81 /** |
76 * Returns the VelocityEngine used for the template mechanism. | 82 * Returns the VelocityEngine used for the template mechanism. |
226 | 232 |
227 return shapefileDirectory; | 233 return shapefileDirectory; |
228 } | 234 } |
229 | 235 |
230 | 236 |
231 protected File[] getUserDirs() | 237 protected File[] getProjectDirs() |
232 throws FileNotFoundException, IOException | 238 throws FileNotFoundException, IOException |
233 { | 239 { |
234 File baseDir = getShapefileBaseDir(); | 240 File baseDir = getShapefileBaseDir(); |
235 File[] artifactDirs = baseDir.listFiles(); | 241 File[] artifactDirs = baseDir.listFiles(); |
236 | 242 |
237 // TODO ONLY RETURN DIRECTORIES OF THE SPECIFIED USER | |
238 | |
239 return artifactDirs; | 243 return artifactDirs; |
240 } | 244 } |
241 | 245 |
242 | 246 |
243 protected List<String> parseLayers(File[] dirs) { | 247 /** |
244 List<String> layers = new ArrayList<String>(); | 248 * Search in all given directories for shapefiles that can be used |
249 * as barrier, user oder wsplgen layers. | |
250 * @param dirs | |
251 * @return | |
252 */ | |
253 protected List<File> searchForLayerShapes(File[] dirs) { | |
254 List<File> shapes = new ArrayList<File>(); | |
245 | 255 |
246 for (File dir: dirs) { | 256 for (File dir: dirs) { |
247 File[] layerFiles = dir.listFiles(new FilenameFilter() { | 257 File[] layerFiles = dir.listFiles(new FilenameFilter() { |
248 @Override | 258 @Override |
249 public boolean accept(File directory, String name) { | 259 public boolean accept(File directory, String name) { |
250 return name.startsWith(MS_LAYER_PREFIX); | 260 return name.startsWith(MS_PREFIX_BARRIERS) || |
261 name.startsWith(MS_PREFIX_USER) || | |
262 name.startsWith(MS_PREFIX_WSPLGEN); | |
251 } | 263 } |
252 }); | 264 }); |
253 | 265 |
254 for (File layer: layerFiles) { | 266 for (File layer: layerFiles) { |
255 try { | 267 shapes.add(layer); |
256 layers.add(layer.getCanonicalPath()); | 268 } |
257 } | 269 } |
258 catch (IOException ioe) { | 270 |
259 logger.warn(ioe, ioe); | 271 return shapes; |
260 } | |
261 } | |
262 } | |
263 | |
264 return layers; | |
265 } | 272 } |
266 | 273 |
267 | 274 |
268 /** | 275 /** |
269 * Creates a layer snippet which might be included in the mapfile. | 276 * Creates a layer snippet which might be included in the mapfile. |