comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/MapInfoService.java @ 1058:c37084f31c84

Implemented a MapInfo service that returns some basic information to create maps for specific rivers. flys-artifacts/trunk@2528 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Tue, 23 Aug 2011 07:53:41 +0000
parents
children b1b0a0b61845
comparison
equal deleted inserted replaced
1057:d4a5d3941cc0 1058:c37084f31c84
1 package de.intevation.flys.artifacts.services;
2
3 import org.apache.log4j.Logger;
4
5 import org.w3c.dom.Document;
6 import org.w3c.dom.Element;
7
8 import com.vividsolutions.jts.geom.Geometry;
9
10 import de.intevation.artifacts.CallMeta;
11 import de.intevation.artifacts.GlobalContext;
12
13 import de.intevation.artifacts.common.ArtifactNamespaceContext;
14 import de.intevation.artifacts.common.utils.Config;
15 import de.intevation.artifacts.common.utils.XMLUtils;
16 import de.intevation.artifacts.common.utils.XMLUtils.ElementCreator;
17
18 import de.intevation.artifactdatabase.DefaultService;
19
20 import de.intevation.flys.backend.SessionHolder;
21 import de.intevation.flys.model.River;
22
23 import de.intevation.flys.model.RiverAxis;
24 import de.intevation.flys.artifacts.model.RiverFactory;
25 import de.intevation.flys.utils.GeometryUtils;
26
27 import org.hibernate.Session;
28
29 /**
30 * This service provides information about the supported rivers by this
31 * application.
32 *
33 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
34 */
35 public class MapInfoService extends DefaultService {
36
37 /** XPath that points to the river.*/
38 public static final String XPATH_RIVER = "/mapinfo/river/text()";
39
40 public static final String XPATH_RIVER_PROJECTION =
41 "/artifact-database/floodmap/river[@name='%RIVER%']/srid/@value";
42
43 public static final String XPATH_RIVER_BACKGROUND =
44 "/artifact-database/floodmap/river[@name='%RIVER%']/background-wms";
45
46 public static final String XPATH_RIVER_WMS =
47 "/artifact-database/floodmap/river[@name='%RIVER%']/river-wms/@url";
48
49
50 /** The logger used in this service.*/
51 private static Logger logger = Logger.getLogger(MapInfoService.class);
52
53
54 /**
55 * The default constructor.
56 */
57 public MapInfoService() {
58 }
59
60
61 public Document process(
62 Document data,
63 GlobalContext globalContext,
64 CallMeta callMeta
65 ) {
66 logger.debug("MapInfoService.process");
67
68 Document result = XMLUtils.newDocument();
69 ElementCreator cr = new ElementCreator(result, null, null);
70
71 Element mapinfo = cr.create("mapinfo");
72 result.appendChild(mapinfo);
73
74 String river = extractRiver(data);
75 if (river == null || river.length() == 0) {
76 logger.warn("Cannot generate information: river is empty!");
77 return result;
78 }
79
80 Element root = cr.create("river");
81 cr.addAttr(root, "name", river);
82 mapinfo.appendChild(root);
83
84 RiverAxis axis = RiverAxis.getRiverAxis(river);
85 if (axis != null) {
86 Geometry geom = axis.getGeom().getBoundary();
87 String bounds = GeometryUtils.jtsBoundsToOLBounds(geom);
88
89 logger.debug("River '" + river + "' bounds: " + bounds);
90 Element bbox = cr.create("bbox");
91 cr.addAttr(bbox, "value", bounds);
92 root.appendChild(bbox);
93 }
94
95 String xpathS = XPATH_RIVER_PROJECTION.replace("%RIVER%", river);
96 String sridStr = Config.getStringXPath(xpathS);
97 if (sridStr != null && sridStr.length() > 0) {
98 Element srid = cr.create("srid");
99 cr.addAttr(srid, "value", sridStr);
100 root.appendChild(srid);
101 }
102
103 String xpathB = XPATH_RIVER_BACKGROUND.replace("%RIVER%", river);
104 Element back = (Element) Config.getNodeXPath(xpathB);
105 if (back != null) {
106 Element background = cr.create("background-wms");
107 cr.addAttr(background, "url", back.getAttribute("url"));
108 cr.addAttr(background, "layers", back.getAttribute("layers"));
109 root.appendChild(background);
110 }
111
112 String xpathWMS = XPATH_RIVER_WMS.replace("%RIVER%", river);
113 String wmsStr = Config.getStringXPath(xpathWMS);
114 if (wmsStr != null && wmsStr.length() > 0) {
115 Element wms = cr.create("river-wms");
116 cr.addAttr(wms, "url", wmsStr);
117 root.appendChild(wms);
118 }
119
120 return result;
121 }
122
123
124 protected String extractRiver(Document data) {
125 return XMLUtils.xpathString(
126 data, XPATH_RIVER, ArtifactNamespaceContext.INSTANCE);
127 }
128 }
129 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org