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.List;
027: import jeeves.interfaces.Service;
028: import jeeves.server.ServiceConfig;
029: import jeeves.server.context.ServiceContext;
030: import org.jdom.Element;
031: import org.wfp.vam.intermap.Constants;
032: import org.wfp.vam.intermap.kernel.map.MapMerger;
033: import org.wfp.vam.intermap.kernel.map.mapServices.wms.schema.impl.Utils;
034:
035: //=============================================================================
036:
037: /** main.result service. shows search results
038: *
039: * FIXME: this class and map.layers.Add seem to do the same thing. Please clean up.
040: */
041:
042: public class AddServices implements Service {
043: public void init(String appPath, ServiceConfig config)
044: throws Exception {
045: }
046:
047: //--------------------------------------------------------------------------
048: //---
049: //--- Service
050: //---
051: //--------------------------------------------------------------------------
052:
053: public Element exec(Element params, ServiceContext context)
054: throws Exception {
055: // get some request parameters
056: String serverUrl = params
057: .getChildText(Constants.MAP_SERVER_URL);
058: int serverType = Integer.parseInt(params
059: .getChildText(Constants.MAP_SERVER_TYPE));
060: List<Element> lServices = (List<Element>) params
061: .getChildren(Constants.MAP_SERVICE);
062:
063: if (lServices.size() == 0)
064: throw new IllegalArgumentException("Missing services.");
065:
066: // Get the other request parameters
067: String vsp = params.getChildText("vendor_spec_par"); // vendor specific parameters
068: String bbox = params.getChildText("BBOX");
069:
070: String sreplace = params.getChildText("clear");
071: boolean breplace = Utils.getBooleanAttrib(sreplace, false);
072:
073: MapMerger mm = breplace ? new MapMerger() : MapUtil
074: .getMapMerger(context);
075:
076: Element added = new Element("added");
077:
078: // Set a flag to indicate that no services were in the MapMerger
079: boolean mmWasEmpty = mm.size() == 0;
080:
081: // Create the Service objects and attach them to the MapMerge object
082: for (Element eService : lServices) {
083: String serviceName = eService.getText();
084: int servid = MapUtil.addService(serverType, serverUrl,
085: serviceName, vsp, mm);
086: if (servid != -1) {
087: //System.err.println("ADDING SERVICE " + serviceName + " @ " + servid);
088: added.addContent(new Element("newLayer").setAttribute(
089: "name", serviceName).setAttribute("id",
090: "" + servid));
091: }
092: }
093:
094: // Set the bounding box as specified in the URL
095: if (bbox != null) {
096: MapUtil.setBBoxFromUrl(bbox, mm);
097: }
098: // Calculate the starting BoundingBox if flag is set
099: else if (mmWasEmpty) {
100: MapUtil.setDefBoundingBox(mm);
101: }
102:
103: // Update the user session
104: context.getUserSession().setProperty(Constants.SESSION_MAP, mm);
105:
106: // DEBUGME: side server image dimensioning is obsolete. Please make sure the client does not rely on this stuff.
107: // // Set image size if not set
108: // String size = (String)context.getUserSession().getProperty(Constants.SESSION_SIZE);
109: // if (size == null) {
110: //// System.out.println("defaultImageSize = " + MapUtil.getDefaultImageSize()); // DEBUG
111: // context.getUserSession().setProperty(Constants.SESSION_SIZE, MapUtil.getDefaultImageSize());
112: // }
113:
114: //System.err.println(" --ADDED --> " + Xml.getString(added));
115: return mm.toElementSimple().addContent(added);
116: }
117:
118: }
119:
120: //=============================================================================
|