001:
002: /*
003: * The Unified Mapping Platform (JUMP) is an extensible, interactive GUI
004: * for visualizing and manipulating spatial features with geometry and attributes.
005: *
006: * Copyright (C) 2003 Vivid Solutions
007: *
008: * This program is free software; you can redistribute it and/or
009: * modify it under the terms of the GNU General Public License
010: * as published by the Free Software Foundation; either version 2
011: * of the License, or (at your option) any later version.
012: *
013: * This program is distributed in the hope that it will be useful,
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
016: * GNU General Public License for more details.
017: *
018: * You should have received a copy of the GNU General Public License
019: * along with this program; if not, write to the Free Software
020: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
021: *
022: * For more information, contact:
023: *
024: * Vivid Solutions
025: * Suite #1A
026: * 2328 Government Street
027: * Victoria BC V8T 5G5
028: * Canada
029: *
030: * (250)385-6040
031: * www.vividsolutions.com
032: */
033:
034: package com.vividsolutions.wms;
035:
036: import java.io.IOException;
037: import java.io.InputStream;
038: import java.net.URL;
039:
040: /**
041: * Represents a remote WMS Service.
042: *
043: * @author Chris Hodgson chodgson@refractions.net
044: */
045: public class WMService {
046:
047: public static final String WMS_1_0_0 = "1.0.0";
048:
049: public static final String WMS_1_1_0 = "1.1.0";
050:
051: public static final String WMS_1_1_1 = "1.1.1";
052:
053: private String serverUrl;
054: private String wmsVersion = WMS_1_0_0;
055: private Capabilities cap;
056:
057: /**
058: * Constructs a WMService object from a server URL.
059: * @param serverUrl the URL of the WMS server
060: */
061: public WMService(String serverUrl, String wmsVersion) {
062: this .serverUrl = serverUrl;
063: this .wmsVersion = wmsVersion;
064: this .cap = null;
065: }
066:
067: /**
068: * Constructs a WMService object from a server URL.
069: * @param serverUrl the URL of the WMS server
070: */
071: public WMService(String serverUrl) {
072: this .serverUrl = serverUrl;
073: this .cap = null;
074: }
075:
076: /**
077: * Connect to the service and get the capabilities.
078: * This must be called before anything else is done with this service.
079: */
080: public void initialize() throws IOException {
081: // [UT]
082: String req = "request=capabilities&WMTVER=1.0";
083: if (WMS_1_1_0.equals(wmsVersion)) {
084: req = "SERVICE=WMS&VERSION=1.1.0&REQUEST=GetCapabilities";
085: } else if (WMS_1_1_1.equals(wmsVersion)) {
086: req = "SERVICE=WMS&VERSION=1.1.1&REQUEST=GetCapabilities";
087: }
088:
089: String requestUrlString = this .serverUrl + req;
090: URL requestUrl = new URL(requestUrlString);
091: InputStream inStream = requestUrl.openStream();
092: Parser p = new Parser();
093: cap = p.parseCapabilities(this , inStream);
094: }
095:
096: /**
097: * Gets the url of the map service.
098: * @return the url of the WMService
099: */
100: public String getServerUrl() {
101: return serverUrl;
102: }
103:
104: /**
105: * Gets the title of the map service.
106: * The service must have previously been initialized, otherwise null is returned.
107: * @return the title of the WMService
108: */
109: public String getTitle() {
110: return cap.getTitle();
111: }
112:
113: /**
114: * Gets the Capabilities for this service.
115: * The service must have previously been initialized, otherwise null is returned.
116: * @return a copy of the MapDescriptor for this service
117: */
118: public Capabilities getCapabilities() {
119: return cap;
120: }
121:
122: /**
123: * Creates a new MapRequest object which can be used to retrieve a Map
124: * from this service.
125: * @return a MapRequest object which can be used to retrieve a map image
126: * from this service
127: */
128: public MapRequest createMapRequest() {
129: // [UT] 04.02.2005 changed
130: MapRequest mr = new MapRequest(this );
131: mr.setVersion(this .wmsVersion);
132: return mr;
133: }
134:
135: public String getVersion() {
136: return wmsVersion;
137: }
138: }
|