Mercurial > dive4elements > river
view flys-client/src/main/java/de/intevation/flys/client/server/MapInfoServiceImpl.java @ 1302:17e7d5e437fb
Bumped OpenLayers to version 2.11 and GWT-OpenLayers to version 0.6
flys-client/trunk@2930 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Mon, 10 Oct 2011 15:29:39 +0000 |
parents | 910b03de6857 |
children | ab8eb2f544f2 |
line wrap: on
line source
package de.intevation.flys.client.server; import org.w3c.dom.Document; import org.w3c.dom.Element; import com.google.gwt.user.server.rpc.RemoteServiceServlet; import de.intevation.artifacts.common.utils.XMLUtils; import de.intevation.artifacts.common.utils.XMLUtils.ElementCreator; import de.intevation.artifacts.httpclient.exceptions.ConnectionException; import de.intevation.artifacts.httpclient.http.HttpClient; import de.intevation.artifacts.httpclient.http.HttpClientImpl; import de.intevation.flys.client.shared.exceptions.ServerException; import de.intevation.flys.client.shared.model.BBox; import de.intevation.flys.client.shared.model.MapInfo; import de.intevation.flys.client.client.services.MapInfoService; /** * This service fetches a document that contains meta information for a specific * chart. * * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> */ public class MapInfoServiceImpl extends RemoteServiceServlet implements MapInfoService { public static final String XPATH_RIVER = "/mapinfo/river/@name"; public static final String XPATH_SRID = "/mapinfo/river/srid/@value"; public static final String XPATH_BBOX = "/mapinfo/river/bbox/@value"; public static final String XPATH_RIVER_WMS = "/mapinfo/river/river-wms/@url"; public static final String XPATH_WMS_URL = "/mapinfo/river/background-wms/@url"; public static final String XPATH_WMS_LAYERS = "/mapinfo/river/background-wms/@layers"; public static final String ERROR_NO_MAPINFO_FOUND = "mapinfo_service_no_result"; public MapInfo getMapInfo(String url, String locale, String river) throws ServerException { System.out.println("MapInfoServiceImpl.getMapInfo"); Document request = getRequestDocument(river);; HttpClient client = new HttpClientImpl(url, locale); try { System.out.println("MapInfoServiceImpl.callService"); Document result = client.callService(url, "mapinfo", request); if (result == null) { System.err.println("MapInfo service returned no result."); throw new ServerException(ERROR_NO_MAPINFO_FOUND); } return getMapInfo(result); } catch (ConnectionException ce) { System.err.println(ce.getLocalizedMessage()); } throw new ServerException(ERROR_NO_MAPINFO_FOUND); } public static Document getRequestDocument(String rivername) { System.out.println("MapInfoServiceImpl.getRequestDocument"); Document request = XMLUtils.newDocument(); ElementCreator cr = new ElementCreator(request, null, null); Element root = cr.create("mapinfo"); Element river = cr.create("river"); river.setTextContent(rivername); request.appendChild(root); root.appendChild(river); return request; } public static MapInfo getMapInfo(Document result) { System.out.println("MapInfoServiceImpl.getMapInfo"); String river = XMLUtils.xpathString(result, XPATH_RIVER, null); String sridStr = XMLUtils.xpathString(result, XPATH_SRID, null); String bboxS = XMLUtils.xpathString(result, XPATH_BBOX, null); BBox bbox = BBox.getBBoxFromString(bboxS); String riverWMS = XMLUtils.xpathString(result, XPATH_RIVER_WMS, null); String wmsURL = XMLUtils.xpathString(result, XPATH_WMS_URL, null); String wmsLayers = XMLUtils.xpathString(result, XPATH_WMS_LAYERS, null); int srid = 4326; try { srid = Integer.parseInt(sridStr); } catch (NumberFormatException nfe) { // do nothing } return new MapInfo(river, srid, bbox, riverWMS, wmsURL, wmsLayers); } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :