001: //=============================================================================
002: //=== Copyright (C) 2001-2007 Food and Agriculture Organization of the
003: //=== United Nations (FAO-UN), United Nations World Food Programme (WFP)
004: //=== and United Nations Environment Programme (UNEP)
005: //===
006: //=== This program is free software; you can redistribute it and/or modify
007: //=== it under the terms of the GNU General Public License as published by
008: //=== the Free Software Foundation; either version 2 of the License, or (at
009: //=== your option) any later version.
010: //===
011: //=== This program is distributed in the hope that it will be useful, but
012: //=== WITHOUT ANY WARRANTY; without even the implied warranty of
013: //=== MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: //=== General Public License for more details.
015: //===
016: //=== You should have received a copy of the GNU General Public License
017: //=== along with this program; if not, write to the Free Software
018: //=== Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
019: //===
020: //=== Contact: Jeroen Ticheler - FAO - Viale delle Terme di Caracalla 2,
021: //=== Rome - Italy. email: geonetwork@osgeo.org
022: //==============================================================================
023:
024: package org.wfp.vam.intermap.services.wmc;
025:
026: import java.net.URLDecoder;
027: import jeeves.interfaces.Service;
028: import jeeves.server.ServiceConfig;
029: import jeeves.server.context.ServiceContext;
030: import jeeves.utils.Xml;
031: import org.jdom.Element;
032: import org.wfp.vam.intermap.Constants;
033: import org.wfp.vam.intermap.kernel.map.MapMerger;
034: import org.wfp.vam.intermap.kernel.map.mapServices.wmc.GeoRSSCodec;
035: import org.wfp.vam.intermap.kernel.map.mapServices.wmc.schema.impl.WMCFactory;
036: import org.wfp.vam.intermap.kernel.map.mapServices.wmc.schema.type.WMCExtension;
037: import org.wfp.vam.intermap.kernel.map.mapServices.wmc.schema.type.WMCViewContext;
038: import org.wfp.vam.intermap.kernel.map.mapServices.wmc.schema.type.WMCWindow;
039: import org.wfp.vam.intermap.kernel.map.mapServices.wms.schema.impl.Utils;
040: import org.wfp.vam.intermap.kernel.marker.MarkerSet;
041: import org.wfp.vam.intermap.services.map.MapUtil;
042:
043: /**
044: * Set the WMC from an URL-encoded parameter.
045: *
046: * @author ETj
047: */
048: public class SetWmcContext implements Service {
049: public void init(String appPath, ServiceConfig config)
050: throws Exception {
051: }
052:
053: //--------------------------------------------------------------------------
054: //---
055: //--- Service
056: //---
057: //--------------------------------------------------------------------------
058:
059: public Element exec(Element params, ServiceContext context)
060: throws Exception {
061: String wmc = params.getChildText("wmc");
062: String dec = URLDecoder.decode(wmc, "UTF-8");
063:
064: // System.out.println("DECODED\n" + dec);
065:
066: Element mapContext = Xml.loadString(dec, false);
067:
068: // XMLOutputter xo = new XMLOutputter(Format.getPrettyFormat());
069: // System.out.println(" ============= request wmc is:\n\n" +xo.outputString(mapContext));
070:
071: // Create a new MapMerger object
072: String sreplace = params.getChildText("clearLayers"); // TODO: let's set the same param in all services supporting it. "clear" is simpler.
073: boolean breplace = Utils.getBooleanAttrib(sreplace, true);
074:
075: MapMerger mm = breplace ? new MapMerger() : MapUtil
076: .getMapMerger(context);
077:
078: WMCViewContext vc = WMCFactory.parseViewContext(mapContext);
079: WMCWindow win = vc.getGeneral().getWindow();
080:
081: String url = MapUtil.setContext(mm, vc);
082:
083: // Update the user session
084: context.getUserSession().setProperty(Constants.SESSION_MAP, mm);
085:
086: // load markerset, if any, from context
087: WMCExtension ext = vc.getGeneral().getExtension();
088: if (ext != null) {
089: Element georss = ext.getChild("georss");
090: if (georss != null) {
091: Element feed = (Element) georss.getChildren().get(0);
092: MarkerSet ms = GeoRSSCodec.parseGeoRSS(feed);
093: context.getUserSession().setProperty(
094: Constants.SESSION_MARKERSET, ms);
095: }
096: }
097:
098: // Prepare response
099: Element response = new Element("response").addContent(
100: new Element("imgUrl").setText(url)).addContent(
101: new Element("scale").setText(mm.getDistScale()))
102: .addContent(mm.getBoundingBox().toElement())
103: .addContent(
104: new Element("width").setText(""
105: + win.getWidth())).addContent(
106: new Element("height").setText(""
107: + win.getHeight()));
108:
109: MarkerSet ms = (MarkerSet) context.getUserSession()
110: .getProperty(Constants.SESSION_MARKERSET);
111: if (ms != null)
112: response.addContent(ms.select(mm.getBoundingBox())
113: .toElement());
114:
115: return response;
116: }
117: }
118:
119: //=============================================================================
|