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 SetContext 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: int id = Integer.parseInt(params
057: .getChildText(Constants.CONTEXT_ID));
058:
059: // Create a new MapMerger object
060: MapMerger mm = new MapMerger();
061:
062: // Get the element relating the choosen map context
063: Element mapContext = DefaultMapServers.getContext(id);
064:
065: // Add each layer in the map context to the map
066: List<Element> lServers = mapContext.getChildren("server");
067: for (Element elServer : lServers) {
068: String serverType = elServer
069: .getAttributeValue(Constants.MAP_SERVER_TYPE);
070: String serverUrl = elServer
071: .getAttributeValue(Constants.MAP_SERVER_URL);
072:
073: List<Element> elLayers = elServer
074: .getChildren(Constants.MAP_LAYER);
075: for (Element elLayer : elLayers) {
076: try {
077: String serviceName = elLayer
078: .getAttributeValue("name");
079: MapUtil.addService(Integer.parseInt(serverType),
080: serverUrl, serviceName, "", mm);
081: } catch (Exception e) {
082: e.printStackTrace();
083: } // DEBUG: tell the user
084: }
085: }
086:
087: MapUtil.setDefBoundingBox(mm);
088:
089: // Set image size if not set
090: String size = (String) context.getUserSession().getProperty(
091: Constants.SESSION_SIZE);
092: if (size == null)
093: context.getUserSession().setProperty(
094: Constants.SESSION_SIZE,
095: MapUtil.getDefaultImageSize());
096:
097: // Update the user session
098: context.getUserSession().setProperty(Constants.SESSION_MAP, mm);
099:
100: return null;
101: }
102:
103: }
104:
105: //=============================================================================
|