Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/MapInfoService.java @ 3814:8083f6384023
merged flys-artifacts/pre2.6-2012-01-04
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Fri, 28 Sep 2012 12:14:56 +0200 |
parents | 092e1e5020bc |
children | cbeeaaad1056 |
comparison
equal
deleted
inserted
replaced
1491:2a00f4849738 | 3814:8083f6384023 |
---|---|
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.Envelope; | |
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.model.River; | |
21 | |
22 import de.intevation.flys.model.RiverAxis; | |
23 import de.intevation.flys.utils.GeometryUtils; | |
24 | |
25 /** | |
26 * This service provides information about the supported rivers by this | |
27 * application. | |
28 * | |
29 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> | |
30 */ | |
31 public class MapInfoService extends DefaultService { | |
32 | |
33 /** XPath that points to the river.*/ | |
34 public static final String XPATH_RIVER = "/mapinfo/river/text()"; | |
35 | |
36 public static final String XPATH_RIVER_PROJECTION = | |
37 "/artifact-database/floodmap/river[@name='%RIVER%']/srid/@value"; | |
38 | |
39 public static final String XPATH_RIVER_BACKGROUND = | |
40 "/artifact-database/floodmap/river[@name='%RIVER%']/background-wms"; | |
41 | |
42 public static final String XPATH_RIVER_WMS = | |
43 "/artifact-database/floodmap/river[@name='%RIVER%']/river-wms/@url"; | |
44 | |
45 | |
46 /** The logger used in this service.*/ | |
47 private static Logger logger = Logger.getLogger(MapInfoService.class); | |
48 | |
49 | |
50 /** | |
51 * The default constructor. | |
52 */ | |
53 public MapInfoService() { | |
54 } | |
55 | |
56 | |
57 public Document process( | |
58 Document data, | |
59 GlobalContext globalContext, | |
60 CallMeta callMeta | |
61 ) { | |
62 logger.debug("MapInfoService.process"); | |
63 | |
64 Document result = XMLUtils.newDocument(); | |
65 ElementCreator cr = new ElementCreator(result, null, null); | |
66 | |
67 Element mapinfo = cr.create("mapinfo"); | |
68 result.appendChild(mapinfo); | |
69 | |
70 String river = extractRiver(data); | |
71 if (river == null || river.length() == 0) { | |
72 logger.warn("Cannot generate information: river is empty!"); | |
73 return result; | |
74 } | |
75 | |
76 Element root = cr.create("river"); | |
77 cr.addAttr(root, "name", river); | |
78 mapinfo.appendChild(root); | |
79 | |
80 RiverAxis axis = RiverAxis.getRiverAxis(river); | |
81 if (axis != null) { | |
82 Envelope env = axis.getGeom().getEnvelopeInternal(); | |
83 String bounds = GeometryUtils.jtsBoundsToOLBounds(env); | |
84 | |
85 logger.debug("River '" + river + "' bounds: " + bounds); | |
86 Element bbox = cr.create("bbox"); | |
87 cr.addAttr(bbox, "value", bounds); | |
88 root.appendChild(bbox); | |
89 } | |
90 | |
91 String xpathS = XPATH_RIVER_PROJECTION.replace("%RIVER%", river); | |
92 String sridStr = Config.getStringXPath(xpathS); | |
93 if (sridStr != null && sridStr.length() > 0) { | |
94 Element srid = cr.create("srid"); | |
95 cr.addAttr(srid, "value", sridStr); | |
96 root.appendChild(srid); | |
97 } | |
98 | |
99 String xpathB = XPATH_RIVER_BACKGROUND.replace("%RIVER%", river); | |
100 Element back = (Element) Config.getNodeXPath(xpathB); | |
101 if (back != null) { | |
102 Element background = cr.create("background-wms"); | |
103 cr.addAttr(background, "url", back.getAttribute("url")); | |
104 cr.addAttr(background, "layers", back.getAttribute("layers")); | |
105 root.appendChild(background); | |
106 } | |
107 | |
108 String xpathWMS = XPATH_RIVER_WMS.replace("%RIVER%", river); | |
109 String wmsStr = Config.getStringXPath(xpathWMS); | |
110 if (wmsStr != null && wmsStr.length() > 0) { | |
111 Element wms = cr.create("river-wms"); | |
112 cr.addAttr(wms, "url", wmsStr); | |
113 root.appendChild(wms); | |
114 } | |
115 | |
116 return result; | |
117 } | |
118 | |
119 | |
120 protected String extractRiver(Document data) { | |
121 return XMLUtils.xpathString( | |
122 data, XPATH_RIVER, ArtifactNamespaceContext.INSTANCE); | |
123 } | |
124 } | |
125 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |