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;
025:
026: import java.util.*;
027:
028: import org.jdom.*;
029:
030: import jeeves.interfaces.*;
031: import jeeves.server.*;
032: import jeeves.server.context.*;
033:
034: import org.wfp.vam.intermap.kernel.map.*;
035:
036: import org.wfp.vam.intermap.Constants;
037:
038: //=============================================================================
039:
040: /** main.result service. shows search results
041: */
042:
043: public class SetServices implements Service {
044: public void init(String appPath, ServiceConfig config)
045: throws Exception {
046: }
047:
048: //--------------------------------------------------------------------------
049: //---
050: //--- Service
051: //---
052: //--------------------------------------------------------------------------
053:
054: public Element exec(Element params, ServiceContext context)
055: throws Exception {
056: // Get the request parameters
057: int serverType = Integer.parseInt(params
058: .getChildText(Constants.MAP_SERVER_TYPE));
059: String serverUrl = params
060: .getChildText(Constants.MAP_SERVER_URL);
061: List lServices = params.getChildren(Constants.MAP_SERVICE);
062: String vsp = params.getChildText("vendor_spec_par"); // vendor specific parameters
063: String bbox = params.getChildText("BBOX");
064:
065: // System.out.println("vsp: " + vsp); // DEBUG
066:
067: if (lServices.size() > 0) {
068: // Get the MapMerger object from the user session
069: MapMerger mm = MapUtil.getMapMerger(context);
070:
071: // Set a flag to indicate that no services were in the MapMerger
072: boolean flag = false;
073: if (mm.size() == 0)
074: flag = true;
075:
076: // Create the Service objects and attach them to the MapMerge object
077: for (Iterator i = lServices.iterator(); i.hasNext();) {
078: String serviceName = ((Element) i.next()).getText();
079: MapUtil.addService(serverType, serverUrl, serviceName,
080: vsp, mm);
081: }
082:
083: // Set the bounding box as specified in the URL
084: if (bbox != null) {
085: MapUtil.setBBoxFromUrl(bbox, mm);
086: }
087:
088: // Calculate the starting BoudingBox if flag is set
089: else if (flag) {
090: MapUtil.setDefBoundingBox(mm);
091: }
092:
093: // Update the user session
094: context.getUserSession().setProperty(Constants.SESSION_MAP,
095: mm);
096: }
097:
098: // Set image size if not set
099: String size = (String) context.getUserSession().getProperty(
100: Constants.SESSION_SIZE);
101: if (size == null)
102: context.getUserSession().setProperty(
103: Constants.SESSION_SIZE,
104: MapUtil.getDefaultImageSize());
105:
106: return null;
107: }
108:
109: }
110:
111: //=============================================================================
|