Mercurial > dive4elements > gnv-client
view gnv/src/main/java/de/intevation/gnv/action/WMSAction.java @ 984:cfc7bd35ee0b
Set the map to the extent which was sent by the rest-server
gnv/trunk@1167 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Tim Englich <tim.englich@intevation.de> |
---|---|
date | Mon, 07 Jun 2010 14:52:45 +0000 |
parents | d1ed5c51c0de |
children | 33198e55371c |
line wrap: on
line source
package de.intevation.gnv.action; import java.text.DateFormat; import java.util.ArrayList; import java.util.Collection; import java.util.Date; import java.util.Iterator; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.log4j.Logger; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; import org.w3c.dom.Document; import org.w3c.dom.Node; import org.w3c.dom.NodeList; import de.intevation.gnv.action.sessionmodel.DiagrammOptions; import de.intevation.gnv.action.sessionmodel.SessionModel; import de.intevation.gnv.action.sessionmodel.SessionModelFactory; import de.intevation.gnv.artifactdatabase.client.ArtifactDatabaseClient; import de.intevation.gnv.artifactdatabase.client.ArtifactDatabaseClientFactory; import de.intevation.gnv.artifactdatabase.objects.ArtifactObject; import de.intevation.gnv.artifactdatabase.objects.DefaultInputParameter; import de.intevation.gnv.artifactdatabase.objects.InputParameter; import de.intevation.gnv.artifactdatabase.objects.OutputMode; import de.intevation.gnv.artifactdatabase.objects.OutputParameter; import de.intevation.gnv.artifactdatabase.objects.map.DefaultLayer; import de.intevation.gnv.artifactdatabase.objects.map.DefaultMapService; import de.intevation.gnv.artifactdatabase.objects.map.Layer; import de.intevation.gnv.artifactdatabase.objects.map.MapService; import de.intevation.gnv.util.XMLUtils; /** * This controller is used to publish the results of the current artifact as * WMS. The wms export mode of the artifact server is triggered which feeds a * MapServer with the given shapefiles (path to the shapefiles is stored in the * artifact). After calling this controller, the shapefiles are ready to be * queried as WMS layers. * * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> */ public class WMSAction extends DescribeUIAction { public static final String XPATH_MAPSERVER_PATH = "/art:meta/art:mapserver/art:server/text()"; public static final String XPATH_MAPSERVER_MAPFILE = "/art:meta/art:mapserver/art:map/text()"; public static final String XPATH_LAYERNODESET = "/art:meta/art:layer"; public static final String XPATH_LAYER_TITLE = "art:title/text()"; public static final String XPATH_LAYER_NAME = "art:name/text()"; public static final String XPATH_TTL = "/art:meta/art:mapserver/art:ttl/text()"; public static final String XPATH_BBOX = "/art:meta/art:mapserver/art:Box/art:coordinates/text()"; /** * the logger, used to log exceptions and additonaly information */ private static Logger logger = Logger.getLogger(WMSAction.class); /** * Constructor */ public WMSAction() { super(); } @Override public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { logger.debug("WMSAction.execute"); try { SessionModel sm = SessionModelFactory.getInstance().getSessionModel( request); OutputMode outputMode = sm.getOutputMode("wms"); Collection<InputParameter> ips = null; if (outputMode != null) { Collection<OutputParameter> inputParameter = outputMode.getOutputParameters(); if (inputParameter != null) { ips = new ArrayList<InputParameter>(inputParameter.size()); Iterator<OutputParameter> it = inputParameter.iterator(); DiagrammOptions diagrammOptions = new DiagrammOptions(); int params = 0; while (it.hasNext()) { String name = it.next().getName(); String[] values = request.getParameterValues(name); String value = request.getParameter(name); InputParameter ip = new DefaultInputParameter(name, encode(values)); ips.add(ip); if (value != null) { ++params; diagrammOptions.setValue(name, encode(value)); } } if (params > 0) { sm.setDiagrammOptions(diagrammOptions); } } } ArtifactObject artifact = sm.getCurrentArtifact(); ArtifactDatabaseClientFactory factory = ArtifactDatabaseClientFactory.getInstance(); ArtifactDatabaseClient adc = factory.getArtifactDatabaseClient( getLocale(request)); ArtifactObject artifactfactory = sm.getSelectedArtifactFactory(); // do wms publishing Document meta = adc.publishWMS(artifactfactory,artifact,ips); // read the Server-information String mapserverPath = XMLUtils.getStringXPath( meta, XPATH_MAPSERVER_PATH); String mapfilePath = XMLUtils.getStringXPath( meta, XPATH_MAPSERVER_MAPFILE); String tmpTTL = XMLUtils.getStringXPath( meta, XPATH_TTL); String bbox = XMLUtils.getStringXPath(meta, XPATH_BBOX); String ttl = null; if (tmpTTL != null) { DateFormat df = DateFormat.getDateTimeInstance( DateFormat.LONG, DateFormat.LONG, request.getLocale()); try { long tmp = Long.parseLong(tmpTTL); ttl = df.format(new Date(tmp)); } catch (NumberFormatException nfe) { logger.error("Error while parsing time to live."); logger.error(nfe,nfe); ttl = ""; } } if (logger.isDebugEnabled()) { logger.debug("Mapserver path: " + mapserverPath); logger.debug("Mapfile path: " + mapfilePath); logger.debug("Layer ttl: " + ttl); } // read the layer information NodeList layerNodes = XMLUtils.getNodeSetXPath(meta, XPATH_LAYERNODESET); Collection<Layer> layers = null; if (layerNodes != null && layerNodes.getLength() > 0){ layers = new ArrayList<Layer>(layerNodes.getLength()); for (int i = 0 ; i < layerNodes.getLength(); i++){ Node tmpLayerNode = layerNodes.item(i); String layerName = XMLUtils.getStringXPath( tmpLayerNode, XPATH_LAYER_NAME); String layerTitle = XMLUtils.getStringXPath( tmpLayerNode, XPATH_LAYER_TITLE); // TODO: write layerTitle to title and not to id Layer currentLayer = new DefaultLayer(layerTitle, layerName, false, null); layers.add(currentLayer); } } // TODO PUT MAPFILEPATH AND TTL to MapServiceObject if (mapserverPath != null && mapfilePath != null) { request.setAttribute("wms_published", Boolean.TRUE); MapService mapService = new DefaultMapService("0815", layers, "UMN", mapserverPath, bbox); sm.setLocalMapService(mapService); return super.execute(mapping, form, request, response); }else{ return super.execute(mapping, form, request, response); } } catch (Exception e) { logger.error(e, e); request.setAttribute( CommunicationKeys.REQUEST_EXCEPTION_MESSAGE_ID, e.getMessage()); return super.getExceptionForward(mapping); } } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :