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 jeeves.interfaces.Service;
027: import jeeves.server.ServiceConfig;
028: import jeeves.server.context.ServiceContext;
029: import org.jdom.Element;
030: import org.wfp.vam.intermap.Constants;
031: import org.wfp.vam.intermap.kernel.map.MapMerger;
032: import org.wfp.vam.intermap.kernel.map.mapServices.MapService;
033: import org.wfp.vam.intermap.kernel.map.mapServices.wms.WmsService;
034: import org.wfp.vam.intermap.kernel.map.mapServices.wms.schema.type.WMSLayer;
035: import org.wfp.vam.intermap.kernel.map.mapServices.wms.schema.type.WMSLegendURL;
036: import org.wfp.vam.intermap.kernel.map.mapServices.wms.schema.type.WMSStyle;
037: import org.wfp.vam.intermap.services.map.MapUtil;
038:
039: /**
040: * Provides some info about styles of a given Layer.
041: * We're exporting a DOM response not related to the WMS one, so that it does not depend on WMS version.
042: *
043: * @author ETj
044: */
045: public class GetStyles 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: int id = Integer.parseInt(params
059: .getChildText(Constants.MAP_SERVICE_ID));
060: MapMerger mm = MapUtil.getMapMerger(context);
061:
062: Element ret = new Element("response");
063: Element eLayer = new Element("layer");
064: ret.addContent(eLayer);
065:
066: MapService ms = mm.getService(id);
067:
068: if (ms instanceof WmsService) {
069: WmsService ws = (WmsService) ms;
070: WMSLayer wlayer = ws.getWmsLayer();
071:
072: eLayer.addContent(new Element("type").setText("WMS"));
073: eLayer.addContent(new Element("id").setText("" + id));
074: eLayer.addContent(new Element("name").setText(wlayer
075: .getName()));
076: eLayer.addContent(new Element("title").setText(wlayer
077: .getTitle()));
078:
079: for (WMSStyle wstyle : wlayer.getStyleIterator()) {
080: Element estyle = new Element("style");
081: ret.addContent(estyle);
082: estyle.addContent(new Element("name").setText(wstyle
083: .getName()));
084: estyle.addContent(new Element("title").setText(wstyle
085: .getTitle()));
086: if (wstyle.getAbstract() != null)
087: estyle.addContent(new Element("abstract")
088: .setText(wstyle.getAbstract()));
089:
090: if (wstyle.getName().equals(ws.getStyleName()))
091: estyle.setAttribute("selected", "true");
092:
093: for (WMSLegendURL wlegend : wstyle
094: .getLegendURLIterator()) {
095: Element elegend = new Element("legend");
096: estyle.addContent(elegend);
097:
098: elegend.setAttribute("format", wlegend.getFormat()
099: .toString());
100: elegend.addContent(new Element("href")
101: .setText(wlegend.getOnlineResource()
102: .getHref()));
103: }
104: }
105: } else {
106: eLayer.addContent(new Element("type").setText("ARCIMS"));
107: eLayer.addContent(new Element("title").setText(ms
108: .getTitle()));
109: }
110:
111: return ret;
112: }
113:
114: }
|