001: /*
002: * GeoTools - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2004-2006, Geotools Project Managment Committee (PMC)
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or (at your option) any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: */
016: package org.geotools.data.wms.gce;
017:
018: import java.net.MalformedURLException;
019: import java.net.URL;
020: import java.util.HashMap;
021: import java.util.Map;
022:
023: import org.geotools.data.ows.WMSCapabilities;
024: import org.geotools.parameter.DefaultParameterDescriptorGroup;
025: import org.geotools.parameter.ParameterGroup;
026: import org.opengis.coverage.grid.Format;
027: import org.opengis.parameter.GeneralParameterDescriptor;
028: import org.opengis.parameter.ParameterValueGroup;
029:
030: /**
031: * GridCoverageExchangeFormat describing Capabilities of a Web Map Server.
032: *
033: * <p>
034: * Unlike several file system Formats this represents the abilities of a
035: * dynamic Server. In addition file formats are often called by client code
036: * with the specification of a single URL for processing. WMSFormat will need
037: * a series of Layers.
038: * </p>
039: *
040: * @author Richard Gould, Refractions Researach
041: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/plugin/wms/src/main/java/org/geotools/data/wms/gce/WMSFormat.java $
042: */
043: public class WMSFormat implements Format {
044: /** Parsed Capabilities Document */
045: private WMSCapabilities capabilities;
046:
047: /**
048: * WMSFormat creation.
049: *
050: * @param capabilities Parsed Capabilties document from a Web Map Server
051: */
052: public WMSFormat(WMSCapabilities capabilities) {
053: this .capabilities = capabilities;
054: }
055:
056: /**
057: * Determines if the input can be processed or not.
058: *
059: * <p>
060: * Currently it accepts WebMapServers, WMT_MS_Capabilities, and URLs and
061: * Strings that point to the WMS's getCapabilities address.
062: * </p>
063: *
064: * <p>
065: * Feedback: this seams a bit crazy?
066: * </p>
067: *
068: * @param input DOCUMENT ME!
069: *
070: * @return DOCUMENT ME!
071: */
072: public boolean accepts(Object input) {
073: if (input instanceof String) {
074: try {
075: URL url = new URL((String) input);
076:
077: return true;
078: } catch (MalformedURLException e) {
079: return false;
080: }
081: }
082:
083: if (input instanceof URL) {
084: return true;
085: }
086:
087: if (input instanceof WMSCapabilities) {
088: return true;
089: }
090:
091: return false;
092: }
093:
094: /**
095: * Retrive parameter metadata describing parameters required by this Web
096: * Map Server.
097: *
098: * <p>
099: * This information should be specific enough to allow the creation of a
100: * user interface.
101: * </p>
102: *
103: * @return DOCUMENT ME!
104: */
105: public ParameterValueGroup getReadParameters() {
106: GeneralParameterDescriptor[] params = new GeneralParameterDescriptor[16];
107:
108: WMSParameterMaker maker = new WMSParameterMaker(capabilities);
109: params[0] = maker.createVersionReadParam();
110: params[1] = maker.createRequestReadParam();
111: params[2] = maker.createFormatReadParam();
112: params[3] = maker.createHeightReadParam();
113: params[4] = maker.createWidthReadParam();
114: params[5] = maker.createSRSReadParam();
115: params[6] = maker.createLayersReadParam();
116: params[7] = maker.createBBoxMinXReadParam();
117: params[8] = maker.createBBoxMinYReadParam();
118: params[9] = maker.createBBoxMaxXReadParam();
119: params[10] = maker.createBBoxMaxYReadParam();
120: params[11] = maker.createTransparentReadParam();
121: params[12] = maker.createBGColorReadParam();
122: params[13] = maker.createExceptionsReadParam();
123: params[14] = maker.createElevationReadParam();
124: params[15] = maker.createTimeReadParam();
125:
126: Map properties = new HashMap();
127: properties.put("name", capabilities.getService().getName());
128: properties.put("remarks", capabilities.getService()
129: .get_abstract());
130: return new ParameterGroup(new DefaultParameterDescriptorGroup(
131: properties, params));
132: }
133:
134: /* (non-Javadoc)
135: * @see org.opengis.coverage.grid.Format#getName()
136: */
137: public String getName() {
138: return "Web Map Server";
139: }
140:
141: /* (non-Javadoc)
142: * @see org.opengis.coverage.grid.Format#getDescription()
143: */
144: public String getDescription() {
145: return "Web Map Server";
146: }
147:
148: /* (non-Javadoc)
149: * @see org.opengis.coverage.grid.Format#getVendor()
150: */
151: public String getVendor() {
152: return "Open GIS Consortium";
153: }
154:
155: /* (non-Javadoc)
156: * @see org.opengis.coverage.grid.Format#getDocURL()
157: */
158: public String getDocURL() {
159: return "http://www.opengis.org";
160: }
161:
162: /* (non-Javadoc)
163: * @see org.opengis.coverage.grid.Format#getVersion()
164: */
165: public String getVersion() {
166: return capabilities.getVersion();
167: }
168:
169: /* (non-Javadoc)
170: * @see org.opengis.coverage.grid.Format#getWriteParameters()
171: */
172: public ParameterValueGroup getWriteParameters() {
173: return null;
174: }
175: }
|