Mercurial > dive4elements > river
changeset 828:910b03de6857
Added a service to get some basic spatial information used for map creation.
flys-client/trunk@2529 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Tue, 23 Aug 2011 09:43:12 +0000 |
parents | bd56dc762e7f |
children | f14cefeed243 |
files | flys-client/ChangeLog flys-client/src/main/java/de/intevation/flys/client/client/services/MapInfoService.java flys-client/src/main/java/de/intevation/flys/client/client/services/MapInfoServiceAsync.java flys-client/src/main/java/de/intevation/flys/client/server/MapInfoServiceImpl.java flys-client/src/main/java/de/intevation/flys/client/shared/model/BBox.java flys-client/src/main/java/de/intevation/flys/client/shared/model/MapInfo.java flys-client/src/main/webapp/WEB-INF/web.xml |
diffstat | 7 files changed, 335 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-client/ChangeLog Mon Aug 22 14:38:35 2011 +0000 +++ b/flys-client/ChangeLog Tue Aug 23 09:43:12 2011 +0000 @@ -1,3 +1,21 @@ +2011-08-23 Ingo Weinzierl <ingo@intevation.de> + + * src/main/java/de/intevation/flys/client/shared/model/MapInfo.java: New. + Instances of this class are used to store basic information which are + necessary to create maps. + + * src/main/java/de/intevation/flys/client/shared/model/BBox.java: New. An + internal representation of a bounding box which consists of four + coordinates. + + * src/main/java/de/intevation/flys/client/client/services/MapInfoServiceAsync.java, + src/main/java/de/intevation/flys/client/client/services/MapInfoService.java, + src/main/java/de/intevation/flys/client/server/MapInfoServiceImpl.java: + The interface definitions and the implementation of a service that + queries basic map information from artifact server. + + * src/main/webapp/WEB-INF/web.xml: Registered the new MapInfo service. + 2011-08-22 Sascha L. Teichmann <sascha.teichmann@intevation.de> * src/main/java/de/intevation/flys/client/server/MetaDataServiceImpl.java,
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/services/MapInfoService.java Tue Aug 23 09:43:12 2011 +0000 @@ -0,0 +1,19 @@ +package de.intevation.flys.client.client.services; + +import com.google.gwt.user.client.rpc.RemoteService; +import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; + +import de.intevation.flys.client.shared.exceptions.ServerException; +import de.intevation.flys.client.shared.model.MapInfo; + + +/** + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +@RemoteServiceRelativePath("map-info") +public interface MapInfoService extends RemoteService { + + MapInfo getMapInfo(String url, String locale, String river) + throws ServerException; +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/services/MapInfoServiceAsync.java Tue Aug 23 09:43:12 2011 +0000 @@ -0,0 +1,19 @@ +package de.intevation.flys.client.client.services; + +import com.google.gwt.user.client.rpc.AsyncCallback; + +import de.intevation.flys.client.shared.model.MapInfo; + + +/** + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public interface MapInfoServiceAsync { + + public void getMapInfo( + String url, + String locale, + String river, + AsyncCallback<MapInfo> callback); +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/server/MapInfoServiceImpl.java Tue Aug 23 09:43:12 2011 +0000 @@ -0,0 +1,124 @@ +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 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/shared/model/BBox.java Tue Aug 23 09:43:12 2011 +0000 @@ -0,0 +1,74 @@ +package de.intevation.flys.client.shared.model; + +import java.io.Serializable; + + +public class BBox implements Serializable { + + public double lowerX; + public double upperX; + public double lowerY; + public double upperY; + + + public BBox() { + } + + + public BBox(double lowerX, double lowerY, double upperX, double upperY) { + this.lowerX = lowerX; + this.lowerY = lowerY; + this.upperX = upperX; + this.upperY = upperY; + } + + + public double getLowerX() { + return lowerX; + } + + + public double getLowerY() { + return lowerY; + } + + + public double getUpperX() { + return upperX; + } + + + public double getUpperY() { + return upperY; + } + + + public String toString() { + return + "(" + lowerX + "," + lowerY + ")" + + "(" + upperX + "," + upperY + ")"; + } + + + public static BBox getBBoxFromString(String bbox) { + String[] coords = bbox != null ? bbox.split(" ") : null; + + if (coords == null || coords.length < 4) { + return null; + } + + try { + return new BBox( + Double.parseDouble(coords[0]), + Double.parseDouble(coords[1]), + Double.parseDouble(coords[2]), + Double.parseDouble(coords[3])); + } + catch (NumberFormatException nfe) { + // do nothing here + } + + return null; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/shared/model/MapInfo.java Tue Aug 23 09:43:12 2011 +0000 @@ -0,0 +1,71 @@ +package de.intevation.flys.client.shared.model; + +import java.io.Serializable; + + +public class MapInfo implements Serializable { + + protected String river; + protected int srid; + protected BBox bbox; + protected String wmsUrl; + protected String backgroundWmsUrl; + protected String backgroundWmsLayers; + + + public MapInfo() { + } + + + public MapInfo( + String river, + int srid, + BBox bbox, + String wmsUrl, + String backgroundWmsUrl, + String backgroundWmsLayers) + { + this.river = river; + this.srid = srid; + this.bbox = bbox; + this.wmsUrl = wmsUrl; + this.backgroundWmsUrl = backgroundWmsUrl; + this.backgroundWmsLayers = backgroundWmsLayers; + } + + + public String getRiver() { + return river; + } + + + public int getSrid() { + return srid; + } + + + public String getProjection() { + return "EPSG:" + srid; + } + + + public BBox getBBox() { + return bbox; + } + + + public String getWmsUrl() { + return wmsUrl; + } + + + public String getBackgroundWmsUrl() { + return backgroundWmsUrl; + } + + + public String getBackgroundWmsLayers() { + return backgroundWmsLayers; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/webapp/WEB-INF/web.xml Mon Aug 22 14:38:35 2011 +0000 +++ b/flys-client/src/main/webapp/WEB-INF/web.xml Tue Aug 23 09:43:12 2011 +0000 @@ -237,6 +237,16 @@ <url-pattern>/flys/delete-collection</url-pattern> </servlet-mapping> + <servlet> + <servlet-name>MapInfoService</servlet-name> + <servlet-class>de.intevation.flys.client.server.MapInfoServiceImpl</servlet-class> + </servlet> + + <servlet-mapping> + <servlet-name>MapInfoService</servlet-name> + <url-pattern>/flys/map-info</url-pattern> + </servlet-mapping> + <!-- Default page to serve --> <welcome-file-list> <welcome-file>FLYS.html</welcome-file>