gvsig-raster / org.gvsig.raster.wmts / trunk / org.gvsig.raster.wmts / org.gvsig.raster.wmts.io / src / main / java / org / gvsig / raster / wmts / io / WMTSConnector.java @ 393
History | View | Annotate | Download (5.2 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.io; |
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.TreeMap; |
31 |
|
32 |
import org.gvsig.compat.net.ICancellable; |
33 |
import org.gvsig.raster.impl.datastruct.WMSLayerNode; |
34 |
import org.gvsig.remoteclient.exceptions.ServerErrorException; |
35 |
import org.gvsig.remoteclient.wmts.WMTSClient; |
36 |
import org.gvsig.remoteclient.wmts.WMTSStatus; |
37 |
import org.gvsig.remoteclient.wmts.exception.DownloadException; |
38 |
import org.gvsig.remoteclient.wmts.exception.WMTSException; |
39 |
import org.gvsig.remoteclient.wmts.struct.WMTSLayer; |
40 |
import org.gvsig.remoteclient.wmts.struct.WMTSServiceIdentification; |
41 |
import org.gvsig.remoteclient.wmts.struct.WMTSServiceProvider; |
42 |
import org.gvsig.remoteclient.wmts.struct.WMTSThemes; |
43 |
import org.gvsig.remoteclient.wmts.struct.WMTSTileMatrixSet; |
44 |
|
45 |
/**
|
46 |
* This class offers an interface of services for a WMTS
|
47 |
*
|
48 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
49 |
*/
|
50 |
public class WMTSConnector { |
51 |
private WMTSClient client = null; |
52 |
private TreeMap<String, WMSLayerNode> layers = new TreeMap<String, WMSLayerNode>(); |
53 |
|
54 |
public WMTSConnector(URL url) throws ConnectException, IOException { |
55 |
client = new WMTSClient(url.toString());
|
56 |
} |
57 |
|
58 |
/**
|
59 |
* Establishes the connection.
|
60 |
* @param override, if true the previous downloaded data will be overridden
|
61 |
* @return <b>true</b> if the connection was successful, or <b>false</b> if it was no possible
|
62 |
* to establish the connection for any reason such as version negotiation.
|
63 |
*/
|
64 |
public boolean connect(boolean override, ICancellable cancel) { |
65 |
if (override) {
|
66 |
layers.clear(); |
67 |
} |
68 |
return client.connect(override, cancel);
|
69 |
} |
70 |
|
71 |
public boolean connect(ICancellable cancel) { |
72 |
return client.connect(false, cancel); |
73 |
} |
74 |
|
75 |
/**
|
76 |
* Gets the list of themes
|
77 |
* @return
|
78 |
*/
|
79 |
public WMTSThemes getThemes() {
|
80 |
return client.getThemes();
|
81 |
} |
82 |
|
83 |
/**
|
84 |
* Gets a layer
|
85 |
* @param layerName
|
86 |
* @return
|
87 |
*/
|
88 |
public WMTSLayer getLayer(String layerName) { |
89 |
return client.getLayer(layerName);
|
90 |
} |
91 |
|
92 |
/**
|
93 |
* Gets the set of tiles definition
|
94 |
* @return
|
95 |
*/
|
96 |
@SuppressWarnings("unchecked") |
97 |
public ArrayList<WMTSTileMatrixSet> getTileMatrixSet() { |
98 |
return client.getTileMatrixSet();
|
99 |
} |
100 |
|
101 |
/*
|
102 |
* (non-Javadoc)
|
103 |
* @see org.gvsig.fmap.dal.coverage.explorer.WMTSServerExplorer#getServiceIdentification()
|
104 |
*/
|
105 |
public WMTSServiceIdentification getServiceIdentification() {
|
106 |
return client.getServiceIdentification();
|
107 |
} |
108 |
|
109 |
public WMTSServiceProvider getServiceProvider() {
|
110 |
return client.getServiceProvider();
|
111 |
} |
112 |
|
113 |
/**
|
114 |
* Gets the host
|
115 |
* @return
|
116 |
*/
|
117 |
public String getHost(){ |
118 |
return client.getHost();
|
119 |
} |
120 |
|
121 |
/**
|
122 |
* <p>Gets a tile downloading using a specific path and file.</p>
|
123 |
* @throws ServerErrorException
|
124 |
*/
|
125 |
public synchronized File getTile(WMTSStatus status, ICancellable cancel, File file) throws WMTSException, ServerErrorException { |
126 |
return client.getTile(status, cancel, file);
|
127 |
} |
128 |
|
129 |
/**
|
130 |
* <p>One of the three interfaces that OGC WMTS defines. Request a map.</p>
|
131 |
* @throws ServerErrorException
|
132 |
*/
|
133 |
public synchronized File getTile(WMTSStatus status, ICancellable cancel) throws WMTSException, ServerErrorException { |
134 |
return client.getTile(status, cancel);
|
135 |
} |
136 |
|
137 |
/**
|
138 |
* Builds the URL to get a tile using a WMTSStatus object
|
139 |
* @throws ServerErrorException
|
140 |
*/
|
141 |
public synchronized URL getTileURL(WMTSStatus status) throws MalformedURLException { |
142 |
return client.getTileURL(status);
|
143 |
} |
144 |
|
145 |
/**
|
146 |
* Downloads a file
|
147 |
* @throws DownloadException
|
148 |
* @throws ServerErrorException
|
149 |
*/
|
150 |
public synchronized File downloadFile(URL url, ICancellable cancel) throws DownloadException { |
151 |
return client.downloadFile(url, cancel);
|
152 |
} |
153 |
|
154 |
/**
|
155 |
* <p>It will send a GetFeatureInfo request to the WMTS
|
156 |
* Parsing the response and redirecting the info to the WMTS client</p>
|
157 |
*/
|
158 |
public String getFeatureInfo(WMTSStatus status, int x, int y, ICancellable cancel) throws WMTSException, ServerErrorException { |
159 |
return client.getFeatureInfo(status, x, y, cancel);
|
160 |
} |
161 |
} |