comparison artifacts/src/main/java/org/dive4elements/river/artifacts/services/MapInfoService.java @ 9753:7227621f8496 3.2.x

Get rid of duplicate MapServer URL configurations
author Tom Gottfried <tom@intevation.de>
date Tue, 11 Oct 2022 14:02:20 +0200
parents 0a5239a1e46e
children
comparison
equal deleted inserted replaced
9752:a41f9c355204 9753:7227621f8496
16 import org.dive4elements.artifacts.common.ArtifactNamespaceContext; 16 import org.dive4elements.artifacts.common.ArtifactNamespaceContext;
17 import org.dive4elements.artifacts.common.utils.Config; 17 import org.dive4elements.artifacts.common.utils.Config;
18 import org.dive4elements.artifacts.common.utils.XMLUtils; 18 import org.dive4elements.artifacts.common.utils.XMLUtils;
19 import org.dive4elements.artifacts.common.utils.XMLUtils.ElementCreator; 19 import org.dive4elements.artifacts.common.utils.XMLUtils.ElementCreator;
20 import org.dive4elements.river.utils.GeometryUtils; 20 import org.dive4elements.river.utils.GeometryUtils;
21 import org.dive4elements.river.utils.RiverUtils;
21 22
22 import java.util.HashMap; 23 import java.util.HashMap;
23 import java.util.Map; 24 import java.util.Map;
24 25
25 import javax.xml.xpath.XPathConstants; 26 import javax.xml.xpath.XPathConstants;
36 * 37 *
37 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> 38 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
38 */ 39 */
39 public class MapInfoService extends XMLService { 40 public class MapInfoService extends XMLService {
40 41
42 private static final String MAPTYPE_FLOOD = "floodmap";
43 private static final String MAPTYPE_RIVER = "rivermap";
44
41 /** XPath that points to the river.*/ 45 /** XPath that points to the river.*/
42 public static final String XPATH_RIVER = "/mapinfo/river/text()"; 46 public static final String XPATH_RIVER = "/mapinfo/river/text()";
43 47
44 public static final String XPATH_MAPTYPE = "/mapinfo/maptype/text()"; 48 public static final String XPATH_MAPTYPE = "/mapinfo/maptype/text()";
45 49
49 53
50 private static final String XPATH_RIVER_BACKGROUND = 54 private static final String XPATH_RIVER_BACKGROUND =
51 "/artifact-database/*[local-name()=$maptype]/" 55 "/artifact-database/*[local-name()=$maptype]/"
52 + "river[@name=$river]/background-wms"; 56 + "river[@name=$river]/background-wms";
53 57
54 private static final String XPATH_RIVER_WMS =
55 "/artifact-database/*[local-name()=$maptype]/"
56 + "river[@name=$river]/river-wms";
57
58
59 /** The log used in this service.*/
60 private static Logger log = LogManager.getLogger(MapInfoService.class); 58 private static Logger log = LogManager.getLogger(MapInfoService.class);
61 59
62 60
63 /** 61 /**
64 * The default constructor. 62 * The default constructor.
104 return result; 102 return result;
105 } 103 }
106 104
107 String mapType = extractMaptype(data); 105 String mapType = extractMaptype(data);
108 if (mapType == null 106 if (mapType == null
109 || !(mapType.equals("floodmap") || mapType.equals("rivermap"))) { 107 || !(mapType.equals(MAPTYPE_FLOOD) || mapType.equals(MAPTYPE_RIVER))) {
110 mapType = "floodmap"; 108 mapType = MAPTYPE_FLOOD;
111 } 109 }
112 110
113 Element root = cr.create("river"); 111 Element root = cr.create("river");
114 cr.addAttr(root, "name", river); 112 cr.addAttr(root, "name", river);
115 mapinfo.appendChild(root); 113 mapinfo.appendChild(root);
140 138
141 if (log.isDebugEnabled()) { 139 if (log.isDebugEnabled()) {
142 log.debug("processXML: " + XMLUtils.toString(root)); 140 log.debug("processXML: " + XMLUtils.toString(root));
143 } 141 }
144 142
143 Element bgWMS = (Element) getNodeXPath(XPATH_RIVER_BACKGROUND, vars);
145 root.appendChild( 144 root.appendChild(
146 createWMSElement("background-wms", 145 createWMSElement("background-wms",
147 XPATH_RIVER_BACKGROUND, vars, cr)); 146 bgWMS.getAttribute("url"),
147 bgWMS.getAttribute("layers"),
148 cr));
148 149
149 root.appendChild( 150 root.appendChild(
150 createWMSElement("river-wms", 151 createWMSElement("river-wms",
151 XPATH_RIVER_WMS, vars, cr)); 152 mapType == MAPTYPE_FLOOD
153 ? RiverUtils.getUserWMSUrl()
154 : RiverUtils.getRiverWMSUrl(),
155 river,
156 cr));
152 157
153 return result; 158 return result;
154 } 159 }
155 160
156 161
157 protected Element createWMSElement( 162 protected Element createWMSElement(
158 String elementName, 163 String elementName,
159 String xpath, 164 String url,
160 Map<String, String> vars, 165 String layers,
161 ElementCreator cr) 166 ElementCreator cr)
162 { 167 {
163 log.debug("createWMSElement()"); 168 Element el = cr.create(elementName);
164 169
165 Element el = cr.create(elementName); 170 cr.addAttr(el, "url", url);
166 Element wms = (Element)getNodeXPath(xpath, vars); 171 cr.addAttr(el, "layers", layers);
167
168 if (wms != null) {
169 cr.addAttr(el, "url", wms.getAttribute("url"));
170 cr.addAttr(el, "layers", wms.getAttribute("layers"));
171
172 log.debug("createWMSElement: " + XMLUtils.toString(el));
173 }
174 else {
175 log.debug("createWMSElement: wms == null");
176 }
177 172
178 return el; 173 return el;
179 } 174 }
180 175
181 176

http://dive4elements.wald.intevation.org