Mercurial > dive4elements > gnv-client
changeset 622:89aca25642d6
Implemented method stubs of MapfileGenerator. Mapfiles are successfully created corresponding meta.xml files.
gnv-artifacts/trunk@693 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Fri, 19 Feb 2010 13:28:34 +0000 |
parents | 567216b56983 |
children | 65f09139e9b3 |
files | gnv-artifacts/ChangeLog gnv-artifacts/doc/conf/conf.xml gnv-artifacts/doc/conf/maptemplates/horizontalcrosssection_salinity.vm gnv-artifacts/doc/conf/maptemplates/horizontalcrosssection_salinity_isolines.vm gnv-artifacts/doc/conf/maptemplates/mapfile.vm gnv-artifacts/doc/conf/maptemplates/salinity_isolines.class.vm gnv-artifacts/doc/conf/maptemplates/salinity_polygons.class.vm gnv-artifacts/pom.xml gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/horizontalcrosssection/HorizontalCrossSectionMeshOutputState.java gnv-artifacts/src/main/java/de/intevation/gnv/utils/MapfileGenerator.java gnv-artifacts/src/main/java/de/intevation/gnv/wms/LayerInfo.java |
diffstat | 11 files changed, 924 insertions(+), 35 deletions(-) [+] |
line wrap: on
line diff
--- a/gnv-artifacts/ChangeLog Wed Feb 17 09:40:15 2010 +0000 +++ b/gnv-artifacts/ChangeLog Fri Feb 19 13:28:34 2010 +0000 @@ -1,3 +1,35 @@ +2010-02-19 Ingo Weinzierl <ingo.weinzierl@intevation.de> + + * src/main/java/de/intevation/gnv/state/profile/horizontalcrosssection/HorizontalCrossSectionMeshOutputState.java: + Write a meta information file after shapefile writing is finished. These + meta information are used to map the type of shapefiles to a specific + template and fill these layer-templates with data. + + * src/main/java/de/intevation/gnv/wms/LayerInfo.java: Class for storing meta + information for mapfile creation. + + * src/main/java/de/intevation/gnv/utils/MapfileGenerator.java: Implemented + method stubs. The MapfileGenerator starts searching for meta information + in filesystem after update() is called. These information are used to to + fill templates for the supported layers and a mapfile will be created out + of this. + + TODO: Configure Velocity. + + * pom.xml: Added Apache Velocity 1.6.1 for templating mapfiles. + + * doc/conf/conf.xml: Adapted a section to configure necessary directories + and filenames for mapfile generation. + + * doc/conf/maptemplates/mapfile.vm: Base template for mapfile. All required + layers will be included into this template. + + * doc/conf/maptemplates/horizontalcrosssection_salinity_isolines.vm, + doc/conf/maptemplates/horizontalcrosssection_salinity.vm, + doc/conf/maptemplates/salinity_isolines.class.vm, + doc/conf/maptemplates/salinity_polygons.class.vm: Template support for + salinity in horizontal crosssection wms. + 2010-02-17 Ingo Weinzierl <ingo.weinzierl@intevation.de> * doc/conf/conf.xml: Added configuration section for writing mapfiles.
--- a/gnv-artifacts/doc/conf/conf.xml Wed Feb 17 09:40:15 2010 +0000 +++ b/gnv-artifacts/doc/conf/conf.xml Fri Feb 19 13:28:34 2010 +0000 @@ -3,41 +3,41 @@ <context-factory>de.intevation.gnv.artifacts.context.GNVArtifactContextFactory</context-factory> <artifact-factories> <artifact-factory name="fis_marnet" description="Factory to create an artifact to be used with the FIS Marnet" - ttl="3600000" artifact="de.intevation.artifactdatabase.ProxyArtifact">de.intevation.gnv.artifacts.GNVProductArtifactFactory</artifact-factory> + ttl="120000" artifact="de.intevation.artifactdatabase.ProxyArtifact">de.intevation.gnv.artifacts.GNVProductArtifactFactory</artifact-factory> <artifact-factory name="fis_imis" description="Factory to create an artifact to be used with the FIS IMIS" - ttl="3600000" artifact="de.intevation.artifactdatabase.ProxyArtifact">de.intevation.gnv.artifacts.GNVProductArtifactFactory</artifact-factory> + ttl="120000" artifact="de.intevation.artifactdatabase.ProxyArtifact">de.intevation.gnv.artifacts.GNVProductArtifactFactory</artifact-factory> <artifact-factory name="fis_staun" description="Factory to create an artifact to be used with the FIS STAUN" - ttl="3600000" artifact="de.intevation.artifactdatabase.ProxyArtifact">de.intevation.gnv.artifacts.GNVProductArtifactFactory</artifact-factory> + ttl="120000" artifact="de.intevation.artifactdatabase.ProxyArtifact">de.intevation.gnv.artifacts.GNVProductArtifactFactory</artifact-factory> <artifact-factory name="fis_modeldata" description="Factory to create an artifact to be used with the FIS Modeldata" - ttl="3600000" artifact="de.intevation.artifactdatabase.ProxyArtifact">de.intevation.gnv.artifacts.GNVProductArtifactFactory</artifact-factory> + ttl="120000" artifact="de.intevation.artifactdatabase.ProxyArtifact">de.intevation.gnv.artifacts.GNVProductArtifactFactory</artifact-factory> <artifact-factory name="fis_eisklimatologie" description="Factory to create an artifact to be used with the FIS Modeldata" - ttl="3600000" artifact="de.intevation.artifactdatabase.ProxyArtifact">de.intevation.gnv.artifacts.GNVProductArtifactFactory</artifact-factory> + ttl="120000" artifact="de.intevation.artifactdatabase.ProxyArtifact">de.intevation.gnv.artifacts.GNVProductArtifactFactory</artifact-factory> <artifact-factory name="fis_icestations" description="Factory to create an artifact to be used with the FIS Modeldata" - ttl="3600000" artifact="de.intevation.artifactdatabase.ProxyArtifact">de.intevation.gnv.artifacts.GNVProductArtifactFactory</artifact-factory> + ttl="120000" artifact="de.intevation.artifactdatabase.ProxyArtifact">de.intevation.gnv.artifacts.GNVProductArtifactFactory</artifact-factory> <artifact-factory name="fis_sst" description="Factory to create an artifact to be used with the FIS Modeldata" - ttl="3600000" artifact="de.intevation.artifactdatabase.ProxyArtifact">de.intevation.gnv.artifacts.GNVProductArtifactFactory</artifact-factory> + ttl="120000" artifact="de.intevation.artifactdatabase.ProxyArtifact">de.intevation.gnv.artifacts.GNVProductArtifactFactory</artifact-factory> <artifact-factory name="fis_delphin" description="Factory to create an artifact to be used with the FIS Modeldata" - ttl="3600000" artifact="de.intevation.artifactdatabase.ProxyArtifact">de.intevation.gnv.artifacts.GNVProductArtifactFactory</artifact-factory> + ttl="120000" artifact="de.intevation.artifactdatabase.ProxyArtifact">de.intevation.gnv.artifacts.GNVProductArtifactFactory</artifact-factory> <artifact-factory name="fis_thermosalinograph" description="Factory to create an artifact to be used with the FIS Modeldata" - ttl="3600000" artifact="de.intevation.artifactdatabase.ProxyArtifact">de.intevation.gnv.artifacts.GNVProductArtifactFactory</artifact-factory> + ttl="120000" artifact="de.intevation.artifactdatabase.ProxyArtifact">de.intevation.gnv.artifacts.GNVProductArtifactFactory</artifact-factory> <artifact-factory name="fis_chemusurvey" description="Factory to create an artifact to be used with the FIS Modeldata" - ttl="3600000" artifact="de.intevation.artifactdatabase.ProxyArtifact">de.intevation.gnv.artifacts.GNVProductArtifactFactory</artifact-factory> + ttl="120000" artifact="de.intevation.artifactdatabase.ProxyArtifact">de.intevation.gnv.artifacts.GNVProductArtifactFactory</artifact-factory> <artifact-factory name="fis_gts" description="Factory to create an artifact to be used with the FIS Modeldata" - ttl="3600000" artifact="de.intevation.artifactdatabase.ProxyArtifact">de.intevation.gnv.artifacts.GNVProductArtifactFactory</artifact-factory> + ttl="120000" artifact="de.intevation.artifactdatabase.ProxyArtifact">de.intevation.gnv.artifacts.GNVProductArtifactFactory</artifact-factory> <artifact-factory name="fis_bsh_ctd" description="Factory to create an artifact to be used with the FIS Modeldata" - ttl="3600000" artifact="de.intevation.artifactdatabase.ProxyArtifact">de.intevation.gnv.artifacts.GNVProductArtifactFactory</artifact-factory> + ttl="120000" artifact="de.intevation.artifactdatabase.ProxyArtifact">de.intevation.gnv.artifacts.GNVProductArtifactFactory</artifact-factory> <artifact-factory name="fis_bsh_xbt" description="Factory to create an artifact to be used with the FIS Modeldata" - ttl="3600000" artifact="de.intevation.artifactdatabase.ProxyArtifact">de.intevation.gnv.artifacts.GNVProductArtifactFactory</artifact-factory> + ttl="120000" artifact="de.intevation.artifactdatabase.ProxyArtifact">de.intevation.gnv.artifacts.GNVProductArtifactFactory</artifact-factory> <artifact-factory name="fis_seacat" description="Factory to create an artifact to be used with the FIS Modeldata" - ttl="3600000" artifact="de.intevation.artifactdatabase.ProxyArtifact">de.intevation.gnv.artifacts.GNVProductArtifactFactory</artifact-factory> + ttl="120000" artifact="de.intevation.artifactdatabase.ProxyArtifact">de.intevation.gnv.artifacts.GNVProductArtifactFactory</artifact-factory> <artifact-factory name="fis_seastate" description="Factory to create an artifact to be used with the FIS Modeldata" - ttl="3600000" artifact="de.intevation.artifactdatabase.ProxyArtifact">de.intevation.gnv.artifacts.GNVProductArtifactFactory</artifact-factory> + ttl="120000" artifact="de.intevation.artifactdatabase.ProxyArtifact">de.intevation.gnv.artifacts.GNVProductArtifactFactory</artifact-factory> <artifact-factory name="fis_currentmeter" description="Factory to create an artifact to be used with the FIS Modeldata" - ttl="3600000" artifact="de.intevation.artifactdatabase.ProxyArtifact">de.intevation.gnv.artifacts.GNVProductArtifactFactory</artifact-factory> + ttl="120000" artifact="de.intevation.artifactdatabase.ProxyArtifact">de.intevation.gnv.artifacts.GNVProductArtifactFactory</artifact-factory> <artifact-factory name="fis_nauthis" description="Factory to create an artifact to be used with the FIS Nauthis" - ttl="3600000" artifact="de.intevation.artifactdatabase.ProxyArtifact">de.intevation.gnv.artifacts.GNVProductArtifactFactory</artifact-factory> + ttl="120000" artifact="de.intevation.artifactdatabase.ProxyArtifact">de.intevation.gnv.artifacts.GNVProductArtifactFactory</artifact-factory> <artifact-factory name="fis_contis" description="Factory to create an artifact to be used with the FIS Conthis" - ttl="3600000" artifact="de.intevation.artifactdatabase.ProxyArtifact">de.intevation.gnv.artifacts.GNVProductArtifactFactory</artifact-factory> + ttl="120000" artifact="de.intevation.artifactdatabase.ProxyArtifact">de.intevation.gnv.artifacts.GNVProductArtifactFactory</artifact-factory> </artifact-factories> <service-factories> <service-factory @@ -500,7 +500,7 @@ </rest-server> <!-- garbage collection of outdated artifacts --> <cleaner> - <sleep-time>900000</sleep-time> + <sleep-time>60000</sleep-time> </cleaner> <database> <user>SA</user> @@ -510,7 +510,17 @@ <sql></sql> --> </database> + <!-- In this section the required Configuration for mapfile generation is + given. --> <map-generator> - <mapfile path="${artifacts.config.dir}/../mapfiles/" /> + <mapfile> + <name>mapfile.map</name> + <path>/opt/artifacts/mapfiles</path> + <shapefiles>/opt/artifacts/shapefiles</shapefiles> + </mapfile> + <templates> + <path>/opt/artifacts/conf/maptemplates</path> + <maptemplate>mapfile.vm</maptemplate> + </templates> </map-generator> </artifact-database>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gnv-artifacts/doc/conf/maptemplates/horizontalcrosssection_salinity.vm Fri Feb 19 13:28:34 2010 +0000 @@ -0,0 +1,7 @@ +LAYER + NAME "$info.getName()" + TYPE $info.getType() + DATA "${info.getName()}/${info.getData()}" + STATUS $info.getStatus() + #include("/opt/artifacts/conf/maptemplates/salinity_polygons.class.vm") +END
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gnv-artifacts/doc/conf/maptemplates/horizontalcrosssection_salinity_isolines.vm Fri Feb 19 13:28:34 2010 +0000 @@ -0,0 +1,9 @@ +LAYER + NAME "$info.getName()_isolines" + GROUP "$info.getName()" + DATA "${info.getName()}/${info.getData()}" + TYPE $info.getType() + STATUS $info.getStatus() + LABELITEM VALUE + #include("/opt/artifacts/conf/maptemplates/salinity_isolines.class.vm") +END
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gnv-artifacts/doc/conf/maptemplates/mapfile.vm Fri Feb 19 13:28:34 2010 +0000 @@ -0,0 +1,17 @@ +MAP + NAME "GNV-Map" + STATUS ON + SIZE 600 400 + EXTENT -1 53 11 58 + UNITS DD + SHAPEPATH "../shapefiles" + FONTSET "fontset.txt" + IMAGECOLOR 255 255 255 + PROJECTION + "init=epsg:4326" + END + + ## Don't change the following lines. + $LAYERS + +END
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gnv-artifacts/doc/conf/maptemplates/salinity_isolines.class.vm Fri Feb 19 13:28:34 2010 +0000 @@ -0,0 +1,20 @@ + CLASS + NAME "DEFAULT" + LABEL + TYPE TRUETYPE + FONT FreeSans + SIZE 10 + MAXSIZE 10 + MINSIZE 7 + COLOR 0 0 0 + MINDISTANCE 250 + ANGLE AUTO + POSITION CC + MINFEATURESIZE AUTO + OUTLINECOLOR 255 255 255 + PARTIALS False + END + STYLE + COLOR "#000000" + END + END
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gnv-artifacts/doc/conf/maptemplates/salinity_polygons.class.vm Fri Feb 19 13:28:34 2010 +0000 @@ -0,0 +1,253 @@ + + + CLASS + NAME "-inf - 2.0" + EXPRESSION ("[CLASS]"="0") + STYLE + COLOR "#02db00" + END + END + + + CLASS + NAME "2.0 - 3.0" + EXPRESSION ("[CLASS]"="1") + STYLE + COLOR "#01e600" + END + END + + + CLASS + NAME "3.0 - 4.0" + EXPRESSION ("[CLASS]"="2") + STYLE + COLOR "#02f200" + END + END + + + CLASS + NAME "4.0 - 5.0" + EXPRESSION ("[CLASS]"="3") + STYLE + COLOR "#00ff00" + END + END + + + CLASS + NAME "5.0 - 6.0" + EXPRESSION ("[CLASS]"="4") + STYLE + COLOR "#23fd22" + END + END + + + CLASS + NAME "6.0 - 7.0" + EXPRESSION ("[CLASS]"="5") + STYLE + COLOR "#47fe46" + END + END + + + CLASS + NAME "7.0 - 8.0" + EXPRESSION ("[CLASS]"="6") + STYLE + COLOR "#5afd59" + END + END + + + CLASS + NAME "8.0 - 9.0" + EXPRESSION ("[CLASS]"="7") + STYLE + COLOR "#6ffe6e" + END + END + + + CLASS + NAME "9.0 - 10.0" + EXPRESSION ("[CLASS]"="8") + STYLE + COLOR "#89fd88" + END + END + + + CLASS + NAME "10.0 - 12.0" + EXPRESSION ("[CLASS]"="9") + STYLE + COLOR "#a5fea4" + END + END + + + CLASS + NAME "12.0 - 14.0" + EXPRESSION ("[CLASS]"="10") + STYLE + COLOR "#b3feb3" + END + END + + + CLASS + NAME "14.0 - 16.0" + EXPRESSION ("[CLASS]"="11") + STYLE + COLOR "#c2fec2" + END + END + + + CLASS + NAME "16.0 - 18.0" + EXPRESSION ("[CLASS]"="12") + STYLE + COLOR "#e0fee0" + END + END + + + CLASS + NAME "18.0 - 20.0" + EXPRESSION ("[CLASS]"="13") + STYLE + COLOR "#ffffff" + END + END + + + CLASS + NAME "20.0 - 24.0" + EXPRESSION ("[CLASS]"="14") + STYLE + COLOR "#fef5ef" + END + END + + + CLASS + NAME "24.0 - 28.0" + EXPRESSION ("[CLASS]"="15") + STYLE + COLOR "#feede0" + END + END + + + CLASS + NAME "28.0 - 30.0" + EXPRESSION ("[CLASS]"="16") + STYLE + COLOR "#fee5d1" + END + END + + + CLASS + NAME "30.0 - 32.0" + EXPRESSION ("[CLASS]"="17") + STYLE + COLOR "#fdd8ba" + END + END + + + CLASS + NAME "32.0 - 34.0" + EXPRESSION ("[CLASS]"="18") + STYLE + COLOR "#fecca4" + END + END + + + CLASS + NAME "34.0 - 34.5" + EXPRESSION ("[CLASS]"="19") + STYLE + COLOR "#fdbe8b" + END + END + + + CLASS + NAME "34.5 - 35.0" + EXPRESSION ("[CLASS]"="20") + STYLE + COLOR "#feb073" + END + END + + + CLASS + NAME "35.0 - 35.2" + EXPRESSION ("[CLASS]"="21") + STYLE + COLOR "#fda35b" + END + END + + + CLASS + NAME "35.2 - 35.4" + EXPRESSION ("[CLASS]"="22") + STYLE + COLOR "#fe9846" + END + END + + + CLASS + NAME "35.4 - 35.6" + EXPRESSION ("[CLASS]"="23") + STYLE + COLOR "#fd8422" + END + END + + + CLASS + NAME "35.6 - 35.8" + EXPRESSION ("[CLASS]"="24") + STYLE + COLOR "#fe7100" + END + END + + + CLASS + NAME "35.8 - 36.0" + EXPRESSION ("[CLASS]"="25") + STYLE + COLOR "#fe6900" + END + END + + + CLASS + NAME "36.0 - 37.0" + EXPRESSION ("[CLASS]"="26") + STYLE + COLOR "#fe6100" + END + END + + + CLASS + NAME "37.0 - inf" + EXPRESSION ("[CLASS]"="27") + STYLE + COLOR "#fe5900" + END + END +
--- a/gnv-artifacts/pom.xml Wed Feb 17 09:40:15 2010 +0000 +++ b/gnv-artifacts/pom.xml Fri Feb 19 13:28:34 2010 +0000 @@ -90,6 +90,11 @@ <version>1.7</version> </dependency> <dependency> + <groupId>org.apache.velocity</groupId> + <artifactId>velocity</artifactId> + <version>1.6.1</version> + </dependency> + <dependency> <groupId>com.lowagie</groupId> <artifactId>itext</artifactId> <version>2.1.7</version>
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/horizontalcrosssection/HorizontalCrossSectionMeshOutputState.java Wed Feb 17 09:40:15 2010 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/horizontalcrosssection/HorizontalCrossSectionMeshOutputState.java Fri Feb 19 13:28:34 2010 +0000 @@ -52,9 +52,13 @@ import de.intevation.gnv.utils.StringUtils; import de.intevation.gnv.utils.WKTUtils; +import de.intevation.gnv.wms.LayerInfo; + import java.awt.Dimension; import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; @@ -74,21 +78,27 @@ /** * @author Tim Englich (tim.englich@intevation.de) * @author Sascha L. Teichmann (sascha.teichmann@intevation.de) + * @author Ingo Weinzierl (ingo.weinzierl@intevation.de) */ -public class HorizontalCrossSectionMeshOutputState +public class HorizontalCrossSectionMeshOutputState extends OutputStateBase { private static Logger log = Logger .getLogger(HorizontalCrossSectionMeshOutputState.class); - + /** * The UID of this Class */ private static final long serialVersionUID = 3233620652465061860L; - + public static final boolean USE_INDEX_BUFFER = Boolean.getBoolean("gnv.horizontal.cross.section.mesh.index.buffer"); + public static final String META_FILE_NAME = "meta.xml"; + public static final String ISOLINES_NAME = "isolines.shp"; + public static final String POLYGON_NAME = "polygons.shp"; + public static final String LAYER_MODEL = "horizontalcrosssection"; + private String ijkQueryID; private Boolean shapeFileLock = new Boolean(true); @@ -250,6 +260,13 @@ AttributedPoint2ds result = getResult(uuid, callContext); if (result != null && (path = writeToShapeFile(uuid, result, callContext)) != null) { + + Document meta = null; + if ((meta = writeMeta(callContext, uuid, path)) != null) { + MapfileGenerator.getInstance().update(); + return meta; + } + pathElement.setTextContent(path); } } @@ -290,8 +307,8 @@ List<Pair<Object, MultiLineString>> isolines = result.getLineStrings(); - File polygonsFile = new File(shapeDir, "polygons.shp"); - File isolinesFile = new File(shapeDir, "isolines.shp"); + File polygonsFile = new File(shapeDir, POLYGON_NAME); + File isolinesFile = new File(shapeDir, ISOLINES_NAME); if (!ShapeFileWriter.writeMultiPolygonsToFile( polygonsFile, @@ -320,8 +337,6 @@ callContext.afterCall(CallContext.STORE); - MapfileGenerator.getInstance().update(); - return shapeFilePath; } finally { @@ -331,6 +346,131 @@ } } + protected Document writeMeta(CallContext context, String uuid, String path){ + InputData inputParam = inputData.get("parameterid"); + Map<Integer, PaletteManager> paletteManagers = getPalettes(context); + String paramType = null; + + if (inputParam == null || paletteManagers == null) { + log.warn("Parameter-id not found."); + paramType = LAYER_MODEL; + } + else { + Integer parameterId = Integer.parseInt(inputParam.getValue()); + PaletteManager paletteManager = paletteManagers.get(parameterId); + + paramType = LAYER_MODEL + "_" + paletteManager.getName(); + } + + + Document meta = XMLUtils.newDocument(); + XMLUtils.ElementCreator creator = new XMLUtils.ElementCreator( + meta, + ArtifactNamespaceContext.NAMESPACE_URI, + ArtifactNamespaceContext.NAMESPACE_PREFIX); + + Element root = creator.create("meta"); + meta.appendChild(root); + + writePolygonMeta(context, meta, root, uuid, path, paramType); + writeIsolineMeta(context, meta, root, uuid, path, paramType); + + try { + File metaFile = new File(path, META_FILE_NAME); + + if (!metaFile.createNewFile() || !metaFile.canWrite()) { + log.error("Error while writing meta file: "+metaFile.toString()); + return null; + } + + OutputStream out = new FileOutputStream(metaFile); + XMLUtils.toStream(meta, out); + + return meta; + } + catch (FileNotFoundException fnfe) { + log.error(fnfe); + } + catch (IOException ioe) { + log.error(ioe, ioe); + } + + return meta; + } + + + protected void writePolygonMeta( + CallContext context, + Document document, + Element meta, + String uuid, + String path, + String paramType + ) { + XMLUtils.ElementCreator creator = new XMLUtils.ElementCreator( + document, + ArtifactNamespaceContext.NAMESPACE_URI, + ArtifactNamespaceContext.NAMESPACE_PREFIX); + + Element layer = creator.create(LayerInfo.LAYER); + Element model = creator.create(LayerInfo.LAYER_MODEL); + Element name = creator.create(LayerInfo.LAYER_NAME); + Element type = creator.create(LayerInfo.LAYER_TYPE); + Element status = creator.create(LayerInfo.LAYER_STATUS); + Element data = creator.create(LayerInfo.LAYER_DATA); + + model.setTextContent(paramType); + name.setTextContent(uuid); + type.setTextContent("POLYGON"); + status.setTextContent("DEFAULT"); + data.setTextContent(POLYGON_NAME); + + layer.appendChild(model); + layer.appendChild(name); + layer.appendChild(type); + layer.appendChild(status); + layer.appendChild(data); + + meta.appendChild(layer); + } + + + protected void writeIsolineMeta( + CallContext context, + Document document, + Element meta, + String uuid, + String path, + String paramType + ) { + XMLUtils.ElementCreator creator = new XMLUtils.ElementCreator( + document, + ArtifactNamespaceContext.NAMESPACE_URI, + ArtifactNamespaceContext.NAMESPACE_PREFIX); + + Element layer = creator.create(LayerInfo.LAYER); + Element model = creator.create(LayerInfo.LAYER_MODEL); + Element name = creator.create(LayerInfo.LAYER_NAME); + Element type = creator.create(LayerInfo.LAYER_TYPE); + Element status = creator.create(LayerInfo.LAYER_STATUS); + Element data = creator.create(LayerInfo.LAYER_DATA); + + model.setTextContent(paramType+"_isolines"); + name.setTextContent(uuid); + type.setTextContent("LINE"); + status.setTextContent("DEFAULT"); + data.setTextContent(ISOLINES_NAME); + + layer.appendChild(model); + layer.appendChild(name); + layer.appendChild(type); + layer.appendChild(status); + layer.appendChild(data); + + meta.appendChild(layer); + } + + protected AttributedPoint2ds getResult(String uuid, CallContext callContext) throws StateException { @@ -486,7 +626,7 @@ return ap2ds; } - + public AttributedPoint2ds process( Envelope boundingBox, Polygon polygon,
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/utils/MapfileGenerator.java Wed Feb 17 09:40:15 2010 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/utils/MapfileGenerator.java Fri Feb 19 13:28:34 2010 +0000 @@ -1,6 +1,36 @@ package de.intevation.gnv.utils; +import de.intevation.artifactdatabase.Config; +import de.intevation.artifactdatabase.XMLUtils; +import de.intevation.artifacts.ArtifactNamespaceContext; +import de.intevation.gnv.artifacts.context.GNVArtifactContext; +import de.intevation.gnv.wms.LayerInfo; + +import java.io.File; +import java.io.FilenameFilter; +import java.io.FileNotFoundException; +import java.io.FileWriter; +import java.io.IOException; +import java.io.StringWriter; +import java.io.Writer; +import java.net.MalformedURLException; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.Properties; + +import javax.xml.xpath.XPathConstants; + import org.apache.log4j.Logger; +import org.apache.log4j.PropertyConfigurator; + +import org.apache.velocity.Template; +import org.apache.velocity.VelocityContext; +import org.apache.velocity.app.VelocityEngine; + +import org.w3c.dom.Document; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; /** @@ -9,9 +39,29 @@ public class MapfileGenerator extends Thread { + public static final String TEMPLATE_PATH = + "/artifact-database/map-generator/templates/path/text()"; + + public static final String TEMPLATE_MAPFILE = + "/artifact-database/map-generator/templates/maptemplate/text()"; public static final String MAPFILE_PATH = - "/artifact-database/map-generator/mapfile/@path"; + "/artifact-database/map-generator/mapfile/path/text()"; + + public static final String MAPFILE_NAME = + "/artifact-database/map-generator/mapfile/name/text()"; + + public static final String SHAPEFILE_BASE_DIR = + "/artifact-database/map-generator/mapfile/shapefiles/text()"; + + public static final String META_FILE_NAME = "meta.xml"; + + public static final String XPATH_LAYER = "/art:meta/art:layer"; + public static final String XPATH_LAYER_NAME = "art:name"; + public static final String XPATH_LAYER_TYPE = "art:type"; + public static final String XPATH_LAYER_DATA = "art:data"; + public static final String XPATH_LAYER_STATUS = "art:status"; + public static final String XPATH_LAYER_MODEL = "art:model"; protected static final long SLEEPTIME = 10 * 1000L; // 10 seconds @@ -19,6 +69,7 @@ private static MapfileGenerator instance; + private VelocityEngine velocityEngine; private boolean lock[]; @@ -29,7 +80,7 @@ public static void main(String[] args) { - // TODO Implement me + // TODO IMPLEMENT ME } @@ -46,6 +97,7 @@ public void update() { synchronized (lock) { + logger.debug("update"); lock[0] = true; lock.notify(); } @@ -53,27 +105,292 @@ public void run() { + logger.debug("Start MapfileGenerator thread..."); try { for (;;) { synchronized (lock) { while (!lock[0]) { lock.wait(SLEEPTIME); } - lock[0] = false; } - - logger.info("Update mapfile for MapServer."); + + logger.debug("Start sync process now..."); generate(); } } catch (InterruptedException ie) { + logger.debug("MapfileGenerator thread got an interrupt."); + } + finally { + logger.debug("THREAD END"); } } - private void generate() { - logger.debug("IMPLEMENT ME"); + protected void generate() { + File basedir = new File(getShapefileBaseDir()); + List layers = new ArrayList(); + searchMetaInformation(basedir, layers); + writeMapfile(layers); + } + + + protected VelocityEngine getVelocityEngine() { + if (velocityEngine == null) { + velocityEngine = new VelocityEngine(); + try { + setupVelocity(velocityEngine); + } + catch (Exception e) { + logger.error(e, e); + return null; + } + } + return velocityEngine; + } + + + protected void setupVelocity(VelocityEngine engine) + throws Exception + { + Properties ps = new Properties(); + + ps.setProperty( + "input.encoding", + "UTF-8"); + + ps.setProperty( + "resource.loader", + "class"); + + ps.setProperty( + "class.resource.loader.class", + "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader"); + + engine.init(ps); + } + + + protected String getTemplateBaseDir() { + return Config.getStringXPath(TEMPLATE_PATH); + } + + + protected Template getTemplateByName(String model) { + String templatePath = getTemplateBaseDir(); + if (model.indexOf(".vm") < 0) { + model = model.concat(".vm"); + } + + File file = new File(templatePath, model); + if (!file.exists() || !file.canRead()) { + logger.warn("Can't find template file: " + file.getAbsolutePath()); + return null; + } + + try { + VelocityEngine engine = getVelocityEngine(); + if (engine == null) { + logger.error("Error while fetching VelocityEngine."); + return null; + } + + return engine.getTemplate(file.getAbsolutePath()); + } + catch (Exception e) { + logger.warn(e, e); + } + + return null; + } + + + protected Template getMapfileTemplate() + throws Exception + { + String mapfileName = Config.getStringXPath(TEMPLATE_MAPFILE); + return getTemplateByName(mapfileName); + } + + + protected String getShapefileBaseDir() { + return Config.getStringXPath(SHAPEFILE_BASE_DIR); + } + + + protected void searchMetaInformation(File file, List store) { + if (file.isDirectory()) { + File[] files = file.listFiles(); + + if (files != null && files.length != 0) { + int size = files.length; + for (File tmp: files) { + searchMetaInformation(tmp, store); + } + } + } + else if (file.getName().equals(META_FILE_NAME)) { + LayerInfo[] info = parseMeta(file); + + int infoSize = info.length; + for (int j = 0; j < infoSize; j++) { + if (info[j] != null) { + store.add(info[j]); + } + } + } + } + + + protected LayerInfo[] parseMeta(File file) { + Document meta = XMLUtils.parseDocument(file); + List layers = new ArrayList(); + + NodeList layerset = (NodeList) XMLUtils.xpath( + meta, + XPATH_LAYER, + XPathConstants.NODESET, + ArtifactNamespaceContext.INSTANCE); + + int size = layerset.getLength(); + for (int i = 0; i < size; i++) { + LayerInfo info = parseLayer(layerset.item(i)); + + if (info != null && !info.isEmpty() && !info.isBroken()) { + layers.add(info); + } + else { + logger.warn("Found broken LayerInfo object."); + } + } + + return (LayerInfo[]) layers.toArray(new LayerInfo[layers.size()]); + } + + + protected LayerInfo parseLayer(Node layer) { + LayerInfo info = new LayerInfo(); + + String name = parseLayerAttr(layer, XPATH_LAYER_NAME); + if (name != null && !name.equals("")) { + info.setName(name); + } + + String model = parseLayerAttr(layer, XPATH_LAYER_MODEL); + if (model != null && !model.equals("")) { + info.setModel(model); + } + + String type = parseLayerAttr(layer, XPATH_LAYER_TYPE); + if (type != null && !type.equals("")) { + info.setType(type); + } + + String data = parseLayerAttr(layer, XPATH_LAYER_DATA); + if (data != null && !data.equals("")) { + info.setData(data); + } + + String status = parseLayerAttr(layer, XPATH_LAYER_STATUS); + if (status != null && !status.equals("")) { + info.setStatus(status); + } + + return info; + } + + + protected String parseLayerAttr(Node node, String xpath) { + return (String) XMLUtils.xpath( + node, + xpath, + XPathConstants.STRING, + ArtifactNamespaceContext.INSTANCE); + } + + + protected void writeMapfile(List layers) { + String pathName = Config.getStringXPath(MAPFILE_PATH); + String mapName = Config.getStringXPath(MAPFILE_NAME); + String tmpMapName = "mapfile" + new Date().getTime(); + + int layersize = layers.size(); + StringBuilder sb = new StringBuilder(); + StringWriter sw = null; + LayerInfo info = null; + + for (int i = 0; i < layersize; i++) { + sw = new StringWriter(); + info = (LayerInfo) layers.get(i); + + Template layerTemplate = getTemplateByName(info.getModel()); + VelocityContext context = new VelocityContext(); + context.put("info", info); + + try { + layerTemplate.merge(context, sw); + sb.append(sw.toString()); + } + catch (IOException ioe) { + logger.warn("Error while filling layer template."); + logger.warn(ioe, ioe); + } + } + + Writer writer = null; + File tmp = null; + File map = null; + + try { + tmp = new File(pathName, tmpMapName); + map = new File(pathName, mapName); + + tmp.createNewFile(); + writer = new FileWriter(tmp); + + VelocityContext context = new VelocityContext(); + context.put("LAYERS", sb.toString()); + + Template mapTemplate = getMapfileTemplate(); + if (mapTemplate == null) { + logger.warn("No mapfile template found."); + return; + } + + mapTemplate.merge(context, writer); + + // we need to create a temporary mapfile first und rename it into + // real mapfile because we don't run into race conditions on this + // way. (iw) + tmp.renameTo(map); + } + catch (FileNotFoundException fnfe) { + logger.error(fnfe, fnfe); + } + catch (IOException ioe) { + logger.error(ioe, ioe); + } + catch (Exception e) { + logger.error(e, e); + } + finally { + try { + // close file writer + if (writer != null) { + writer.close(); + } + + // remove temporary mapfile if an error occured and it still + // exists + if (tmp.exists()) { + tmp.delete(); + } + } + catch (IOException ioe) { + logger.debug(ioe, ioe); + } + } } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8:
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/wms/LayerInfo.java Fri Feb 19 13:28:34 2010 +0000 @@ -0,0 +1,79 @@ +package de.intevation.gnv.wms; + +/** + * @author Ingo Weinzierl (ingo.weinzierl@intevation.de) + */ +public class LayerInfo { + + public static final String LAYER = "layer"; + public static final String LAYER_MODEL = "model"; + public static final String LAYER_NAME = "name"; + public static final String LAYER_TYPE = "type"; + public static final String LAYER_DATA = "data"; + public static final String LAYER_STATUS = "status"; + + private String name; + private String type; + private String data; + private String status; + private String model; + + + public LayerInfo() { + } + + + public void setData(String data) { + this.data = data; + } + + public String getData() { + return data; + } + + public void setName(String name) { + this.name = name; + } + + public String getName() { + return name; + } + + public void setModel(String model) { + this.model = model; + } + + public String getModel() { + return model; + } + + public void setType(String type) { + this.type = type; + } + + public String getType() { + return type; + } + + public void setStatus(String status) { + this.status = status; + } + + public String getStatus() { + return status; + } + + public boolean isEmpty() { + if (name == null && data == null && type == null && status == null) + return true; + + return false; + } + + public boolean isBroken() { + if (name == null || data == null || type == null) + return true; + + return false; + } +}