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.map.layers;
025:
026: import org.jdom.*;
027:
028: import jeeves.interfaces.*;
029: import jeeves.server.*;
030: import jeeves.server.context.*;
031:
032: import org.wfp.vam.intermap.kernel.map.*;
033:
034: import org.wfp.vam.intermap.Constants;
035: import java.util.List;
036: import java.util.Iterator;
037: import org.wfp.vam.intermap.services.map.MapUtil;
038: import jeeves.utils.Xml;
039:
040: //=============================================================================
041:
042: /** main.result service. shows search results
043: */
044:
045: public class Add implements Service {
046: public void init(String appPath, ServiceConfig config)
047: throws Exception {
048: }
049:
050: //--------------------------------------------------------------------------
051: //---
052: //--- Service
053: //---
054: //--------------------------------------------------------------------------
055:
056: public Element exec(Element params, ServiceContext context)
057: throws Exception {
058: // get some request parameters
059: String serverUrl = params
060: .getChildText(Constants.MAP_SERVER_URL);
061: //int serverType = Integer.parseInt(params.getChildText(Constants.MAP_SERVER_TYPE));
062: String serviceName = params.getChildText(Constants.MAP_SERVICE);
063:
064: //Element response = new Element("response");
065: //response.addContent(new Element("status").setAttribute("services", "true"));
066:
067: MapMerger mm = MapUtil.getMapMerger(context);
068:
069: // Set a flag to indicate that no services were in the MapMerger
070: boolean mmWasEmpty = false;
071: if (mm.size() == 0)
072: mmWasEmpty = true;
073:
074: MapUtil.addService(2, serverUrl, serviceName, null, mm);
075:
076: // Calculate the starting BoudingBox if flag is set
077: if (mmWasEmpty)
078: MapUtil.setDefBoundingBox(mm);
079:
080: // Update the user session
081: context.getUserSession().setProperty(Constants.SESSION_MAP, mm);
082:
083: // Set image size if not set
084: String size = (String) context.getUserSession().getProperty(
085: Constants.SESSION_SIZE);
086: if (size == null) {
087: // System.out.println("defaultImageSize = " + MapUtil.getDefaultImageSize()); // DEBUG
088: context.getUserSession().setProperty(
089: Constants.SESSION_SIZE,
090: MapUtil.getDefaultImageSize());
091: }
092:
093: // System.out.println("mm" + Xml.getString(mm.toElement()));
094:
095: return null;
096: }
097:
098: }
099:
100: //=============================================================================
|