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.mapServers;
025:
026: import jeeves.exceptions.OperationAbortedEx;
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.DefaultMapServers;
033: import org.wfp.vam.intermap.kernel.map.mapServices.arcims.ArcIMSClient;
034: import org.wfp.vam.intermap.kernel.map.mapServices.arcims.ArcIMSService;
035: import org.wfp.vam.intermap.kernel.map.mapServices.arcims.AxlRequestBuilder;
036: import org.wfp.vam.intermap.kernel.map.mapServices.wms.CapabilitiesStore;
037: import org.wfp.vam.intermap.kernel.map.mapServices.wms.WmsService;
038:
039: //=============================================================================
040:
041: /** main.result service. shows search results
042: */
043:
044: public class GetServices implements Service {
045: public void init(String appPath, ServiceConfig config)
046: throws Exception {
047: }
048:
049: //--------------------------------------------------------------------------
050: //---
051: //--- Service
052: //---
053: //--------------------------------------------------------------------------
054:
055: public Element exec(Element params, ServiceContext context)
056: throws Exception {
057: String id = params.getChildText("mapserver");
058: String user = params.getChildText("user");
059: String pwd = params.getChildText("password");
060: Boolean forceCacheRefresh = "true".equals(params
061: .getChildText("refreshCache"));
062:
063: System.out.println("MAPSERVER ---> " + id);
064:
065: String serverUrl;
066: int serverType;
067: if (!id.startsWith("-")) { // Choosen from the list
068: serverType = DefaultMapServers.getType(id);
069: serverUrl = DefaultMapServers.getUrl(id);
070: } else { // Manually inserted in the text field
071: if (id.equals("-1"))
072: serverType = ArcIMSService.TYPE;
073: else
074: serverType = WmsService.TYPE;
075:
076: serverUrl = params.getChildText(Constants.MAP_SERVER_URL);
077: }
078:
079: System.out.println("URL ---> " + serverUrl);
080: System.out.println("TYPE ---> " + serverType);
081: System.out.println("Force refreshCache ---> "
082: + forceCacheRefresh);
083:
084: Element response = new Element("response").addContent(
085: new Element("url").setText(serverUrl)).addContent(
086: new Element("type").setText(serverType + ""))
087: .addContent(
088: new Element("jscallback").setText(params
089: .getChildText("jscallback")));
090:
091: switch (serverType) {
092: case ArcIMSService.TYPE:
093: // Build the request
094: ArcIMSClient client = new ArcIMSClient(serverUrl,
095: "catalog", AxlRequestBuilder
096: .getRequest("getClientServices.xml"));
097: // Set userId and password
098: if (user != null && pwd != null) {
099: client.setUser(user);
100: client.setPassword(pwd);
101: }
102: try {
103: // Get the service list
104: response.addContent(client.getElement());
105: } catch (Exception e) {
106: throw new OperationAbortedEx("connect"); // TODO
107: // response.setAttribute(new Attribute(Jeeves.ATTR_STATUS, Jeeves.STATUS_ERROR));
108: }
109: break;
110:
111: case WmsService.TYPE:
112: try {
113: // Element capabilities = WmsGetCapClient.getCapabilities(serverUrl, forceCacheRefresh);
114: Element capabilities = CapabilitiesStore
115: .getCapabilities(serverUrl, forceCacheRefresh);
116: response.addContent(capabilities);
117: } catch (Exception e) {
118: throw new OperationAbortedEx("connect"); // TODO
119: // response.setAttribute(new Attribute(Jeeves.ATTR_STATUS, Jeeves.STATUS_ERROR));
120: }
121: break;
122: default:
123: throw new Exception("Illegal map server type");
124: }
125:
126: return response;
127: }
128:
129: }
130:
131: //=============================================================================
|