gvsig-raster / org.gvsig.raster.wmts / trunk / org.gvsig.raster.wmts / org.gvsig.raster.wmts.ogc / org.gvsig.raster.wmts.ogc.impl / src / main / java / org / gvsig / raster / wmts / ogc / impl / base / WMTSClientImpl.java @ 1808
History | View | Annotate | Download (8.53 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Government (CIT)
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 2
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
*/
|
22 |
package org.gvsig.raster.wmts.ogc.impl.base; |
23 |
|
24 |
import java.io.File; |
25 |
import java.io.IOException; |
26 |
import java.net.ConnectException; |
27 |
import java.net.MalformedURLException; |
28 |
import java.net.URL; |
29 |
import java.util.ArrayList; |
30 |
import java.util.List; |
31 |
|
32 |
import org.gvsig.compat.net.ICancellable; |
33 |
import org.gvsig.raster.wmts.ogc.WMTSClient; |
34 |
import org.gvsig.raster.wmts.ogc.WMTSStatus; |
35 |
import org.gvsig.raster.wmts.ogc.exception.DownloadException; |
36 |
import org.gvsig.raster.wmts.ogc.exception.ServerErrorException; |
37 |
import org.gvsig.raster.wmts.ogc.exception.WMTSException; |
38 |
import org.gvsig.raster.wmts.ogc.impl.struct.WMTSLayerImpl; |
39 |
import org.gvsig.raster.wmts.ogc.impl.struct.WMTSServiceProviderImpl; |
40 |
import org.gvsig.raster.wmts.ogc.struct.WMTSLayer; |
41 |
import org.gvsig.raster.wmts.ogc.struct.WMTSServiceIdentification; |
42 |
import org.gvsig.raster.wmts.ogc.struct.WMTSThemes; |
43 |
import org.gvsig.raster.wmts.ogc.struct.WMTSTileMatrixSet; |
44 |
|
45 |
|
46 |
/**
|
47 |
* <p>Represents the class the with the necessary logic to connect to a OGCWMS and interpretate the data </p>
|
48 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
49 |
*/
|
50 |
public class WMTSClientImpl implements WMTSClient { |
51 |
protected String hostName; |
52 |
protected int port; |
53 |
protected String serviceName; |
54 |
private String type; |
55 |
private String subtype; |
56 |
private WMTSProtocolHandler handler = null; |
57 |
private WMTSServerDescription serverDescription = null; |
58 |
protected boolean forceLongitudeFirstAxisOrder = false; |
59 |
|
60 |
/**
|
61 |
* Constructor.
|
62 |
* the parameter host, indicates the WMS host to connect.
|
63 |
* */
|
64 |
public WMTSClientImpl(String host) throws ConnectException, IOException { |
65 |
setHost(host); |
66 |
handler = WMTSProtocolHandlerFactory.negotiate(host); |
67 |
handler.setHost(host); |
68 |
} |
69 |
|
70 |
/**
|
71 |
* Sets longitude first in the axis order
|
72 |
* @param force
|
73 |
*/
|
74 |
public void setForceLongitudeFirstAxisOrder(boolean force) { |
75 |
this.forceLongitudeFirstAxisOrder = force;
|
76 |
if(handler != null) { |
77 |
handler.setForceLongitudeFirstAxisOrder(force); |
78 |
} |
79 |
} |
80 |
|
81 |
public String getVersion() { |
82 |
return handler.getVersion();
|
83 |
} |
84 |
|
85 |
/**
|
86 |
* <p> Reads from the WMS Capabilities, the layers available in the service</p>
|
87 |
* @return a TreeMap with the available layers in the WMS
|
88 |
*/
|
89 |
public ArrayList getLayers() { |
90 |
if(serverDescription != null) |
91 |
return serverDescription.getLayerList();
|
92 |
return null; |
93 |
} |
94 |
|
95 |
/**
|
96 |
* <p>Reads from the WMS Capabilities the number if layers available in the service</p>
|
97 |
* @return, number of layers available
|
98 |
*/
|
99 |
public int getNumberOfLayers() { |
100 |
if(serverDescription != null) |
101 |
return serverDescription.getLayerList().size();
|
102 |
return 0; |
103 |
} |
104 |
|
105 |
public void close() { |
106 |
serverDescription = null;
|
107 |
handler = null;
|
108 |
} |
109 |
|
110 |
/**
|
111 |
* <p>Gets a tile downloading using a specific path and file.</p>
|
112 |
* @throws ServerErrorException
|
113 |
*/
|
114 |
public synchronized File getTile(WMTSStatus status, ICancellable cancel, File file) throws WMTSException, ServerErrorException { |
115 |
return handler.getTile((WMTSStatusImpl)status, cancel, file);
|
116 |
} |
117 |
|
118 |
/**
|
119 |
* <p>One of the three interfaces that OGC WMS defines. Request a map.</p>
|
120 |
* @throws ServerErrorException
|
121 |
*/
|
122 |
public synchronized File getTile(WMTSStatus status, ICancellable cancel) throws WMTSException, ServerErrorException { |
123 |
return handler.getTile((WMTSStatusImpl)status, cancel);
|
124 |
} |
125 |
|
126 |
/**
|
127 |
* Builds the URL to get a tile using a WMTSStatus object
|
128 |
* @throws ServerErrorException
|
129 |
*/
|
130 |
public synchronized URL getTileURL(WMTSStatus status) throws MalformedURLException { |
131 |
return handler.getTileURL((WMTSStatusImpl)status);
|
132 |
} |
133 |
|
134 |
/**
|
135 |
* Downloads a file
|
136 |
* @throws DownloadException
|
137 |
* @throws ServerErrorException
|
138 |
*/
|
139 |
public synchronized File downloadFile(URL url, ICancellable cancel) throws DownloadException { |
140 |
return handler.downloadFile(url, cancel);
|
141 |
} |
142 |
|
143 |
/**
|
144 |
* <p>One of the three interfaces defined by OGC WMS, it gets the service capabilities</p>
|
145 |
* @param override, if true the previous downloaded data will be overridden
|
146 |
*/
|
147 |
public void getCapabilities(WMTSServerDescription serverDescription, boolean override, ICancellable cancel) { |
148 |
handler.getCapabilities(serverDescription, override, cancel); |
149 |
} |
150 |
|
151 |
/**
|
152 |
* <p>It will send a GetFeatureInfo request to the WMTS
|
153 |
* Parsing the response and redirecting the info to the WMTS client</p>
|
154 |
*/
|
155 |
public String getFeatureInfo(WMTSStatus status, int x, int y, ICancellable cancel) { |
156 |
return handler.getFeatureInfo((WMTSStatusImpl)status, x, y, cancel);
|
157 |
} |
158 |
|
159 |
public boolean connect(boolean override, ICancellable cancel) { |
160 |
try {
|
161 |
if (handler == null) { |
162 |
if (getHost().trim().length() > 0) { |
163 |
handler = WMTSProtocolHandlerFactory.negotiate(getHost()); |
164 |
handler.setHost(getHost()); |
165 |
} else {
|
166 |
return false; |
167 |
} |
168 |
} |
169 |
if(serverDescription == null) { |
170 |
serverDescription = new WMTSServerDescription(handler.getVersion());
|
171 |
handler.setServerDescription(serverDescription); |
172 |
handler.setForceLongitudeFirstAxisOrder(forceLongitudeFirstAxisOrder); |
173 |
} |
174 |
getCapabilities(serverDescription, override, cancel); |
175 |
return true; |
176 |
|
177 |
} catch (Exception e) { |
178 |
e.printStackTrace(); |
179 |
return false; |
180 |
} |
181 |
} |
182 |
|
183 |
public boolean connect(ICancellable cancel) { |
184 |
return connect(false, cancel); |
185 |
} |
186 |
|
187 |
/**
|
188 |
* Gets the list of formats supported by a layer
|
189 |
* @param layerTitle
|
190 |
* @return
|
191 |
*/
|
192 |
public ArrayList getFormats(String layerTitle) { |
193 |
if(serverDescription != null) |
194 |
return serverDescription.getLayerByTitle(layerTitle).getFormat();
|
195 |
return null; |
196 |
} |
197 |
|
198 |
public WMTSServiceIdentification getServiceIdentification() {
|
199 |
if(serverDescription != null) |
200 |
return serverDescription.getServiceIdentification();
|
201 |
return null; |
202 |
} |
203 |
|
204 |
public WMTSServiceProviderImpl getServiceProvider() {
|
205 |
if(serverDescription != null) |
206 |
return serverDescription.getServiceProvider();
|
207 |
return null; |
208 |
} |
209 |
|
210 |
/**
|
211 |
* Gets the list of themes
|
212 |
* @return
|
213 |
*/
|
214 |
public WMTSThemes getThemes() {
|
215 |
if(serverDescription != null) |
216 |
return serverDescription.getThemes();
|
217 |
return null; |
218 |
} |
219 |
|
220 |
public List<WMTSTileMatrixSet> getTileMatrixSet() { |
221 |
if(serverDescription != null) |
222 |
return serverDescription.getTileMatrixSet();
|
223 |
return null; |
224 |
} |
225 |
|
226 |
public WMTSLayer getLayer(String layerName) { |
227 |
if(serverDescription != null) { |
228 |
ArrayList list = serverDescription.getLayerList();
|
229 |
for (int i = 0; i < list.size(); i++) { |
230 |
WMTSLayerImpl layer = (WMTSLayerImpl)list.get(i); |
231 |
if(layer.getTitle().compareTo(layerName) == 0) { |
232 |
return layer;
|
233 |
} |
234 |
} |
235 |
} |
236 |
return null; |
237 |
} |
238 |
|
239 |
public String getHost() { |
240 |
return hostName;
|
241 |
} |
242 |
|
243 |
public void setHost(String _hostName) { |
244 |
hostName = _hostName; |
245 |
} |
246 |
|
247 |
public int getPort() { |
248 |
return port;
|
249 |
} |
250 |
|
251 |
public void setPort(int _port) { |
252 |
port = _port; |
253 |
} |
254 |
|
255 |
public String getServiceName() { |
256 |
return serviceName;
|
257 |
} |
258 |
|
259 |
public void setServiceName(String _serviceName) { |
260 |
serviceName = _serviceName; |
261 |
} |
262 |
|
263 |
public String getType() { |
264 |
return type;
|
265 |
} |
266 |
|
267 |
public void setType(String _type) { |
268 |
type = _type; |
269 |
} |
270 |
|
271 |
public String getSubtype() { |
272 |
return subtype;
|
273 |
} |
274 |
|
275 |
public void setSubtype(String _subtype) { |
276 |
subtype = _subtype; |
277 |
} |
278 |
} |