christian@4654: package de.intevation.flys.utils; christian@4654: christian@4654: import de.intevation.flys.artifacts.model.LayerInfo; christian@4654: import de.intevation.flys.artifacts.model.RiverFactory; christian@4654: import de.intevation.flys.model.River; christian@4654: christian@4656: import java.io.File; christian@4656: import java.io.FileNotFoundException; christian@4702: import java.util.ArrayList; christian@4654: import java.util.List; christian@4654: christian@4656: import org.apache.log4j.Logger; christian@4656: import org.apache.velocity.Template; christian@4656: christian@4654: public class RiverMapfileGenerator extends MapfileGenerator { christian@4654: christian@4703: public static final String XPATH_RIVERMAP_RIVER_PROJECTION = christian@4703: "/artifact-database/rivermap/river[@name=$name]/srid/@value"; christian@4703: christian@4703: public static final String XPATH_RIVERMAP_SHAPEFILE_DIR = christian@4703: "/artifact-database/rivermap/shapefile-path/@value"; christian@4703: christian@4703: public static final String XPATH_RIVERMAP_VELOCITY_LOGFILE = christian@4703: "/artifact-database/rivermap/velocity/logfile/@path"; christian@4703: christian@4703: public static final String XPATH_RIVERMAP_MAPSERVER_URL = christian@4703: "/artifact-database/rivermap/mapserver/server/@path"; christian@4703: christian@4703: public static final String XPATH_RIVERMAP_MAPFILE_PATH = christian@4703: "/artifact-database/rivermap/mapserver/mapfile/@path"; christian@4703: christian@4703: public static final String XPATH_RIVERMAP_MAPFILE_TEMPLATE = christian@4703: "/artifact-database/rivermap/mapserver/map-template/@path"; christian@4703: christian@4703: public static final String XPATH_RIVERMAP_MAPSERVER_TEMPLATE_PATH = christian@4703: "/artifact-database/rivermap/mapserver/templates/@path"; christian@4703: christian@4656: private static Logger logger = Logger.getLogger(RiverMapfileGenerator.class); christian@4656: christian@4654: /** christian@4654: * Generate river axis mapfile. christian@4654: */ christian@4654: @Override christian@4656: public void generate() { christian@4702: logger.debug("generate()"); christian@4702: christian@4702: List rivers = RiverFactory.getRivers(); christian@4703: List riverFiles = new ArrayList(); christian@4654: christian@4654: for (River river : rivers) { christian@4703: createRiverAxisLayer( christian@4654: river.getName(), christian@4654: river.getId(), christian@4654: "41677", christian@4703: "100,100,100,100"); christian@4703: riverFiles.add("river-" + river.getName() + ".map"); christian@4654: } christian@4703: writeMapfile(riverFiles); christian@4654: } christian@4654: christian@4654: protected void createRiverAxisLayer(String riverName, int riverID, String srid, String extend) { christian@4654: LayerInfo layerInfo = new LayerInfo(); christian@4654: layerInfo.setName(riverName); christian@4654: layerInfo.setSrid(srid); christian@4654: layerInfo.setExtent(extend); christian@4703: layerInfo.setConnectionType(FLYSUtils.isUsingOracle() ? "oraclespatial" : "postgis"); christian@4656: christian@4703: File layerFile = new File("river-" + riverName + ".map"); christian@4656: Template template = getTemplateByName(DB_LAYER_TEMPLATE); christian@4656: if (template == null) { christian@4703: logger.warn("Template '" + DB_LAYER_TEMPLATE + "' not found."); christian@4656: return; christian@4656: } christian@4656: christian@4656: try { christian@4656: writeLayer(layerInfo, layerFile, template); christian@4656: } christian@4656: catch (FileNotFoundException e) { christian@4656: logger.warn(e.getLocalizedMessage(), e); christian@4656: } christian@4654: } christian@4654: christian@4656: @Override christian@4656: protected String getVelocityLogfile() { christian@4703: return FLYSUtils.getXPathString(XPATH_RIVERMAP_VELOCITY_LOGFILE); christian@4656: } christian@4656: christian@4656: @Override christian@4656: protected String getMapserverTemplatePath() { christian@4703: return FLYSUtils.getXPathString(XPATH_RIVERMAP_MAPSERVER_TEMPLATE_PATH); christian@4656: } christian@4656: christian@4656: @Override christian@4656: protected String getMapserverUrl() { christian@4703: return FLYSUtils.getXPathString(XPATH_RIVERMAP_MAPSERVER_URL); christian@4656: } christian@4656: christian@4656: @Override christian@4656: protected String getMapfilePath() { christian@4703: return FLYSUtils.getXPathString(XPATH_RIVERMAP_MAPFILE_PATH); christian@4656: } christian@4656: christian@4656: @Override christian@4656: protected String getMapfileTemplate() { christian@4703: return FLYSUtils.getXPathString(XPATH_RIVERMAP_MAPFILE_TEMPLATE); christian@4656: } christian@4654: }