Revision 33910
tags/v2_0_0_Build_2020/libraries/libRemoteServices/src/org/gvsig/remoteclient/wcs/WCSClient.java | ||
---|---|---|
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
2 |
* |
|
3 |
* Copyright (C) 2005 IVER T.I. and Generalitat Valenciana. |
|
4 |
* |
|
5 |
* This program is free software; you can redistribute it and/or |
|
6 |
* modify it under the terms of the GNU General Public License |
|
7 |
* as published by the Free Software Foundation; either version 2 |
|
8 |
* of the License, or (at your option) any later version. |
|
9 |
* |
|
10 |
* This program is distributed in the hope that it will be useful, |
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
* GNU General Public License for more details. |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License |
|
16 |
* along with this program; if not, write to the Free Software |
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
18 |
* |
|
19 |
* For more information, contact: |
|
20 |
* |
|
21 |
* Generalitat Valenciana |
|
22 |
* Conselleria d'Infraestructures i Transport |
|
23 |
* Av. Blasco Ib??ez, 50 |
|
24 |
* 46010 VALENCIA |
|
25 |
* SPAIN |
|
26 |
* |
|
27 |
* +34 963862235 |
|
28 |
* gvsig@gva.es |
|
29 |
* www.gvsig.gva.es |
|
30 |
* |
|
31 |
* or |
|
32 |
* |
|
33 |
* IVER T.I. S.A |
|
34 |
* Salamanca 50 |
|
35 |
* 46005 Valencia |
|
36 |
* Spain |
|
37 |
* |
|
38 |
* +34 963163400 |
|
39 |
* dac@iver.es |
|
40 |
*/ |
|
41 |
package org.gvsig.remoteclient.wcs; |
|
42 |
|
|
43 |
import java.awt.geom.Rectangle2D; |
|
44 |
import java.io.File; |
|
45 |
import java.io.IOException; |
|
46 |
import java.net.ConnectException; |
|
47 |
import java.util.ArrayList; |
|
48 |
import java.util.Hashtable; |
|
49 |
import java.util.Iterator; |
|
50 |
|
|
51 |
import org.gvsig.compat.net.ICancellable; |
|
52 |
import org.gvsig.remoteclient.exceptions.ServerErrorException; |
|
53 |
import org.gvsig.remoteclient.exceptions.WCSException; |
|
54 |
import org.gvsig.remoteclient.utils.BoundaryBox; |
|
55 |
|
|
56 |
/** |
|
57 |
* WCSClient managing the low-level comunication to the server. It is used |
|
58 |
* as a bridge between a standard WCS server and other high-level clients. |
|
59 |
* @author jaume dominguez faus - jaume.dominguez@iver.es |
|
60 |
* |
|
61 |
*/ |
|
62 |
public class WCSClient extends org.gvsig.remoteclient.RasterClient{ |
|
63 |
|
|
64 |
private WCSProtocolHandler handler; |
|
65 |
private Hashtable layerPool; |
|
66 |
|
|
67 |
/** |
|
68 |
* Constructor. |
|
69 |
* the parameter host, indicates the WCS host to connect. |
|
70 |
* @throws IOException |
|
71 |
* |
|
72 |
*/ |
|
73 |
public WCSClient(String host) throws ConnectException, IOException { |
|
74 |
setHost(host); |
|
75 |
try { |
|
76 |
handler = WCSProtocolHandlerFactory.negotiate(host); |
|
77 |
handler.setHost(host); |
|
78 |
} catch(ConnectException conE) { |
|
79 |
throw conE; |
|
80 |
} catch(IOException ioE) { |
|
81 |
throw ioE; |
|
82 |
} catch(Exception e) { |
|
83 |
e.printStackTrace(); |
|
84 |
} |
|
85 |
} |
|
86 |
|
|
87 |
/** |
|
88 |
* <p>Checks the connection to de remote WMS and requests its capabilities.</p> |
|
89 |
* @param override |
|
90 |
* |
|
91 |
*/ |
|
92 |
public boolean connect(boolean override, ICancellable cancel) |
|
93 |
{ |
|
94 |
try { |
|
95 |
if (handler == null) { |
|
96 |
if (getHost().trim().length() > 0) { |
|
97 |
handler = WCSProtocolHandlerFactory.negotiate(getHost()); |
|
98 |
handler.setHost(getHost()); |
|
99 |
} else { |
|
100 |
// must to specify host first!!!! |
|
101 |
return false; |
|
102 |
} |
|
103 |
} |
|
104 |
getCapabilities(null, override, cancel); |
|
105 |
|
|
106 |
describeCoverage(null, override, cancel); //TODO falta posar el onlineresource del describe coverage |
|
107 |
return true; |
|
108 |
|
|
109 |
} catch (Exception e) { |
|
110 |
e.printStackTrace(); |
|
111 |
return false; |
|
112 |
} |
|
113 |
} |
|
114 |
|
|
115 |
/** |
|
116 |
* Sends a GetCapabilities request using the properties contained by |
|
117 |
* the status. If status is null, then it uses the default configuration. |
|
118 |
* @param override |
|
119 |
* @param WCSStatus, containing the status properties |
|
120 |
*/ |
|
121 |
private void getCapabilities(WCSStatus status, boolean override, ICancellable cancel) { |
|
122 |
handler.getCapabilities(status, override, cancel); |
|
123 |
} |
|
124 |
|
|
125 |
/** |
|
126 |
* Sends a DescribeCoverage request using the properties contained by |
|
127 |
* the status. |
|
128 |
* @param override, if true the cache is ignored |
|
129 |
* @param WCSStatus, containing the status properties |
|
130 |
*/ |
|
131 |
private void describeCoverage(WCSStatus status, boolean override, ICancellable cancel) { |
|
132 |
handler.describeCoverage(status, override, cancel); |
|
133 |
// check it was response or if we need to perform a specific DescribeCoverage for each coverage |
|
134 |
Hashtable layers = handler.getLayers(); |
|
135 |
Iterator it = layers.keySet().iterator(); |
|
136 |
while (it.hasNext()) { |
|
137 |
Object obj = layers.get(it.next()); |
|
138 |
if (obj instanceof CoverageOfferingBrief) { |
|
139 |
if (status == null) |
|
140 |
status = new WCSStatus(); |
|
141 |
status.setCoveraName( ((CoverageOfferingBrief) obj).getName()); |
|
142 |
handler.describeCoverage(status, override, cancel); |
|
143 |
} |
|
144 |
} |
|
145 |
|
|
146 |
layerPool = handler.getLayers(); |
|
147 |
} |
|
148 |
|
|
149 |
/* (non-Javadoc) |
|
150 |
* @see org.gvsig.remoteClient.RemoteClient#close() |
|
151 |
*/ |
|
152 |
public void close() { |
|
153 |
} |
|
154 |
|
|
155 |
/** |
|
156 |
* Returns the title of the service. The title is a human-readable string format |
|
157 |
* used to label the service connection. |
|
158 |
* @return String |
|
159 |
*/ |
|
160 |
public String getServiceTitle() { |
|
161 |
return handler.serviceInfo.title; |
|
162 |
} |
|
163 |
|
|
164 |
/** |
|
165 |
* Returns the service version (1.0.0, 1.1.0, ...). |
|
166 |
* @return String |
|
167 |
*/ |
|
168 |
public String getVersion() { |
|
169 |
return handler.getVersion(); |
|
170 |
} |
|
171 |
|
|
172 |
/** |
|
173 |
* Returns a brief description of the service, it is a human-readable string. |
|
174 |
* @return String |
|
175 |
*/ |
|
176 |
public String getDescription() { |
|
177 |
return handler.serviceInfo.abstr; |
|
178 |
} |
|
179 |
|
|
180 |
/** |
|
181 |
* |
|
182 |
* @return |
|
183 |
*/ |
|
184 |
public ArrayList getFormats() { |
|
185 |
return handler.getFormats(); |
|
186 |
} |
|
187 |
|
|
188 |
/** |
|
189 |
* Returns a hash table containing the WCSCoverage's produced at parse time using |
|
190 |
* the coverage names as the Hashtable's keys |
|
191 |
* @return Hashtable. |
|
192 |
*/ |
|
193 |
public Hashtable getCoverageList() { |
|
194 |
return layerPool; |
|
195 |
} |
|
196 |
|
|
197 |
/** |
|
198 |
* Given a coverage name, it returns the coverage's title. |
|
199 |
* @param coverageName |
|
200 |
* @return String |
|
201 |
*/ |
|
202 |
public String getLabel(String coverageName) { |
|
203 |
return ((WCSCoverage) layerPool.get(coverageName)).getTitle(); |
|
204 |
} |
|
205 |
|
|
206 |
/** |
|
207 |
* Given a coverage name and the CRS name, it returns the extent defined by the |
|
208 |
* server in the DescribeCoverage document. |
|
209 |
* |
|
210 |
* @param coverageName |
|
211 |
* @param crs |
|
212 |
* @return Rectangle2D |
|
213 |
*/ |
|
214 |
public Rectangle2D getExtent(String coverageName, String crs) { |
|
215 |
BoundaryBox bbox = (BoundaryBox) ((WCSCoverage) layerPool.get(coverageName)).getBbox(crs);; |
|
216 |
if (bbox == null) return null; |
|
217 |
double xmin = bbox.getXmin(); |
|
218 |
double xmax = bbox.getXmax(); |
|
219 |
double ymin = bbox.getYmin(); |
|
220 |
double ymax = bbox.getYmax(); |
|
221 |
return new Rectangle2D.Double(xmin, ymin, xmax-xmin, ymax-ymin); |
|
222 |
} |
|
223 |
|
|
224 |
/** |
|
225 |
* Sends the GetCoverage request according to the settings passed in the status |
|
226 |
* argument. |
|
227 |
* @param status |
|
228 |
* @return File |
|
229 |
* @throws ServerErrorException |
|
230 |
* @throws WCSException |
|
231 |
*/ |
|
232 |
public File getCoverage(WCSStatus status, ICancellable cancel) throws ServerErrorException, WCSException { |
|
233 |
return handler.getCoverage(status, cancel); |
|
234 |
} |
|
235 |
} |
|
236 |
|
|
0 | 237 |
tags/v2_0_0_Build_2020/libraries/libRemoteServices/src/org/gvsig/remoteclient/wcs/WCSProtocolHandler.java | ||
---|---|---|
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
2 |
* |
|
3 |
* Copyright (C) 2005 IVER T.I. and Generalitat Valenciana. |
|
4 |
* |
|
5 |
* This program is free software; you can redistribute it and/or |
|
6 |
* modify it under the terms of the GNU General Public License |
|
7 |
* as published by the Free Software Foundation; either version 2 |
|
8 |
* of the License, or (at your option) any later version. |
|
9 |
* |
|
10 |
* This program is distributed in the hope that it will be useful, |
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
* GNU General Public License for more details. |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License |
|
16 |
* along with this program; if not, write to the Free Software |
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
18 |
* |
|
19 |
* For more information, contact: |
|
20 |
* |
|
21 |
* Generalitat Valenciana |
|
22 |
* Conselleria d'Infraestructures i Transport |
|
23 |
* Av. Blasco Ib??ez, 50 |
|
24 |
* 46010 VALENCIA |
|
25 |
* SPAIN |
|
26 |
* |
|
27 |
* +34 963862235 |
|
28 |
* gvsig@gva.es |
|
29 |
* www.gvsig.gva.es |
|
30 |
* |
|
31 |
* or |
|
32 |
* |
|
33 |
* IVER T.I. S.A |
|
34 |
* Salamanca 50 |
|
35 |
* 46005 Valencia |
|
36 |
* Spain |
|
37 |
* |
|
38 |
* +34 963163400 |
|
39 |
* dac@iver.es |
|
40 |
*/ |
|
41 |
package org.gvsig.remoteclient.wcs; |
|
42 |
|
|
43 |
import java.io.ByteArrayInputStream; |
|
44 |
import java.io.File; |
|
45 |
import java.io.IOException; |
|
46 |
import java.net.MalformedURLException; |
|
47 |
import java.net.URL; |
|
48 |
import java.util.ArrayList; |
|
49 |
import java.util.Hashtable; |
|
50 |
import java.util.StringTokenizer; |
|
51 |
|
|
52 |
import org.kxml2.io.KXmlParser; |
|
53 |
import org.xmlpull.v1.XmlPullParserException; |
|
54 |
|
|
55 |
import org.gvsig.compat.CompatLocator; |
|
56 |
import org.gvsig.compat.lang.StringUtils; |
|
57 |
import org.gvsig.compat.net.ICancellable; |
|
58 |
import org.gvsig.remoteclient.exceptions.ServerErrorException; |
|
59 |
import org.gvsig.remoteclient.exceptions.WCSException; |
|
60 |
import org.gvsig.remoteclient.ogc.OGCProtocolHandler; |
|
61 |
import org.gvsig.remoteclient.ogc.OGCServiceInformation; |
|
62 |
import org.gvsig.remoteclient.utils.ExceptionTags; |
|
63 |
import org.gvsig.remoteclient.utils.Utilities; |
|
64 |
import org.gvsig.remoteclient.wcs.request.WCSDescribeCoverageRequest; |
|
65 |
import org.gvsig.remoteclient.wcs.request.WCSGetCoverageRequest; |
|
66 |
/** |
|
67 |
* |
|
68 |
* @author jaume |
|
69 |
* |
|
70 |
*/ |
|
71 |
public abstract class WCSProtocolHandler extends OGCProtocolHandler { |
|
72 |
/** |
|
73 |
* Encoding used to parse different xml documents. |
|
74 |
*/ |
|
75 |
protected String encoding = "UTF-8"; |
|
76 |
protected Hashtable layerPool = new Hashtable(); |
|
77 |
|
|
78 |
/** |
|
79 |
* WCS metadata |
|
80 |
*/ |
|
81 |
protected WCSServiceInformation serviceInfo = new WCSServiceInformation(); |
|
82 |
|
|
83 |
private static final StringUtils stringUtils = CompatLocator.getStringUtils(); |
|
84 |
|
|
85 |
/* |
|
86 |
* (non-Javadoc) |
|
87 |
* @see org.gvsig.remoteClient.OGCProtocolHandler#setHost(java.lang.String) |
|
88 |
*/ |
|
89 |
public void setHost(String host) { |
|
90 |
try { |
|
91 |
// Validates the URL if doesn't produces an exception |
|
92 |
new URL(host); |
|
93 |
|
|
94 |
int index = host.indexOf("?"); |
|
95 |
|
|
96 |
if (index == -1) |
|
97 |
super.setHost(host); |
|
98 |
else |
|
99 |
super.setHost(host.substring(0, index)); |
|
100 |
} |
|
101 |
catch (MalformedURLException m) { |
|
102 |
// Bad URL -> hold it |
|
103 |
super.setHost(host); |
|
104 |
} |
|
105 |
} |
|
106 |
|
|
107 |
/** |
|
108 |
* <p> |
|
109 |
* Builds a GetCapabilities request that is sent to the WCS |
|
110 |
* the response will be parse to extract the data needed by the |
|
111 |
* WCS client. |
|
112 |
* </p> |
|
113 |
* @param override, if true the cache is ignored |
|
114 |
*/ |
|
115 |
public void getCapabilities(WCSStatus status, boolean override, ICancellable cancel) { |
|
116 |
URL request = null; |
|
117 |
try { |
|
118 |
request = new URL(buildCapabilitiesRequest(status)); |
|
119 |
} |
|
120 |
catch(Exception e) { |
|
121 |
e.printStackTrace(); |
|
122 |
} |
|
123 |
try { |
|
124 |
if (override) |
|
125 |
downloader.removeURL(request); |
|
126 |
File f = downloader.downloadFile(request,"wcs_capabilities.xml", cancel); |
|
127 |
if (f!=null) |
|
128 |
parseCapabilities(f); |
|
129 |
} catch(Exception e) { |
|
130 |
e.printStackTrace(); |
|
131 |
} |
|
132 |
} |
|
133 |
|
|
134 |
/** |
|
135 |
* Builds a complete URL-string that can be used to send a GetCapabilities request. |
|
136 |
* @return String |
|
137 |
*/ |
|
138 |
private String buildCapabilitiesRequest(WCSStatus status) { |
|
139 |
StringBuffer req = new StringBuffer(); |
|
140 |
String symbol = null; |
|
141 |
|
|
142 |
String onlineResource; |
|
143 |
if (status == null || status.getOnlineResource() == null) |
|
144 |
onlineResource = getHost(); |
|
145 |
else |
|
146 |
onlineResource = status.getOnlineResource(); |
|
147 |
symbol = getSymbol(onlineResource); |
|
148 |
|
|
149 |
req.append(onlineResource).append(symbol).append("REQUEST=GetCapabilities&SERVICE=WCS&"); |
|
150 |
req.append("VERSION=").append(getVersion()).append("&EXCEPTIONS=XML"); |
|
151 |
return req.toString(); |
|
152 |
} |
|
153 |
|
|
154 |
|
|
155 |
|
|
156 |
/** |
|
157 |
* parses the data retrieved by the DescribeCoverage XML document |
|
158 |
*/ |
|
159 |
public abstract boolean parseDescribeCoverage(File f); |
|
160 |
|
|
161 |
/** |
|
162 |
* Send a DescribeCoverage request using the settings passed in the status argument. |
|
163 |
* If status is null, then default settings are used. |
|
164 |
* @param override |
|
165 |
* @return String |
|
166 |
*/ |
|
167 |
public void describeCoverage(WCSStatus status, boolean override, ICancellable cancel) { |
|
168 |
try { |
|
169 |
WCSDescribeCoverageRequest request = createDescribeCoverageRequest(status); |
|
170 |
File f = request.sendRequest(); |
|
171 |
if (f!=null) |
|
172 |
parseDescribeCoverage(f); |
|
173 |
} catch(Exception e) { |
|
174 |
e.printStackTrace(); |
|
175 |
} |
|
176 |
} |
|
177 |
|
|
178 |
/** |
|
179 |
* Send a GetCoverage request using the settings passed in the status. |
|
180 |
* @return String |
|
181 |
*/ |
|
182 |
public File getCoverage(WCSStatus status, ICancellable cancel) throws ServerErrorException, WCSException { |
|
183 |
try |
|
184 |
{ |
|
185 |
//TODO: |
|
186 |
//pass this buildXXXRequest to the WCSProtocolHandlerXXX: The request can depend on the WCS version. |
|
187 |
WCSGetCoverageRequest request = createGetCoverageRequest(status); |
|
188 |
File f = request.sendRequest(); |
|
189 |
|
|
190 |
if (f!=null && Utilities.isTextFile(f)) { |
|
191 |
byte[] data = fileToBytes(f); |
|
192 |
|
|
193 |
WCSException wcsEx = null; |
|
194 |
|
|
195 |
String exceptionMessage = parseException(data); |
|
196 |
if (exceptionMessage==null) |
|
197 |
{ |
|
198 |
String error = new String(data); |
|
199 |
int pos = error.indexOf("<?xml"); |
|
200 |
if (pos!= -1) |
|
201 |
{ |
|
202 |
String xml = error.substring(pos,error.length()); |
|
203 |
exceptionMessage = parseException(xml.getBytes()); |
|
204 |
} |
|
205 |
if (exceptionMessage == null) |
|
206 |
exceptionMessage = new String(data); |
|
207 |
|
|
208 |
} |
|
209 |
wcsEx = new WCSException(exceptionMessage); |
|
210 |
wcsEx.setWCSMessage(new String(data)); |
|
211 |
|
|
212 |
// Since it is an error file, It must be deleted from the cache |
|
213 |
downloader.removeURL(request); |
|
214 |
throw wcsEx; |
|
215 |
} |
|
216 |
return f; |
|
217 |
} |
|
218 |
catch(IOException e) |
|
219 |
{ |
|
220 |
e.printStackTrace(); |
|
221 |
throw new ServerErrorException(); |
|
222 |
} |
|
223 |
} |
|
224 |
|
|
225 |
|
|
226 |
/** |
|
227 |
* Parses the WCS Exception document. |
|
228 |
* @param bytes, byte[] |
|
229 |
* @return |
|
230 |
*/ |
|
231 |
private String parseException(byte[] data) { |
|
232 |
// TODO: a?? est? fusilat del WMS, comprovar que funciona. |
|
233 |
ArrayList errors = new ArrayList(); |
|
234 |
KXmlParser kxmlParser = new KXmlParser(); |
|
235 |
try |
|
236 |
{ |
|
237 |
kxmlParser.setInput(new ByteArrayInputStream(data), encoding); |
|
238 |
kxmlParser.nextTag(); |
|
239 |
int tag; |
|
240 |
if ( kxmlParser.getEventType() != KXmlParser.END_DOCUMENT ) |
|
241 |
{ |
|
242 |
kxmlParser.require(KXmlParser.START_TAG, null, ExceptionTags.EXCEPTION_ROOT); |
|
243 |
tag = kxmlParser.nextTag(); |
|
244 |
while(tag != KXmlParser.END_DOCUMENT) |
|
245 |
{ |
|
246 |
switch(tag) |
|
247 |
{ |
|
248 |
case KXmlParser.START_TAG: |
|
249 |
if (kxmlParser.getName().compareTo(ExceptionTags.SERVICE_EXCEPTION)==0){ |
|
250 |
String errorCode = kxmlParser.getAttributeValue("", ExceptionTags.CODE); |
|
251 |
errorCode = (errorCode != null) ? "["+errorCode+"] " : ""; |
|
252 |
String errorMessage = kxmlParser.nextText(); |
|
253 |
errors.add(errorCode+errorMessage); |
|
254 |
} |
|
255 |
break; |
|
256 |
case KXmlParser.END_TAG: |
|
257 |
break; |
|
258 |
|
|
259 |
} |
|
260 |
tag = kxmlParser.nextTag(); |
|
261 |
} |
|
262 |
//kxmlParser.require(KXmlParser.END_DOCUMENT, null, null); |
|
263 |
} |
|
264 |
} |
|
265 |
catch(XmlPullParserException parser_ex){ |
|
266 |
parser_ex.printStackTrace(); |
|
267 |
} |
|
268 |
catch (IOException ioe) { |
|
269 |
ioe.printStackTrace(); |
|
270 |
} |
|
271 |
String message = errors.size()>0? "" : null; |
|
272 |
for (int i = 0; i < errors.size(); i++) { |
|
273 |
message += (String) errors.get(i)+"\n"; |
|
274 |
} |
|
275 |
return message; |
|
276 |
} |
|
277 |
|
|
278 |
/** |
|
279 |
* Builds the GetCapabilitiesRequest according to the OGC WCS Specifications |
|
280 |
* without a VERSION, to get the highest version than a WCS supports. |
|
281 |
*/ |
|
282 |
public static String buildCapabilitiesSuitableVersionRequest(String _host, String _version) { |
|
283 |
int index = _host.indexOf('?'); |
|
284 |
|
|
285 |
if (index > -1) { |
|
286 |
String host = _host.substring(0, index + 1); |
|
287 |
String query = _host.substring(index + 1, _host.length()); |
|
288 |
|
|
289 |
StringTokenizer tokens = new StringTokenizer(query, "&"); |
|
290 |
String newQuery = "", token; |
|
291 |
|
|
292 |
// If there is a field or a value with spaces, (and then it's on different tokens) -> unify them |
|
293 |
while (tokens.hasMoreTokens()) { |
|
294 |
token = tokens.nextToken().trim(); |
|
295 |
|
|
296 |
if (token.toUpperCase().compareTo("REQUEST=GETCAPABILITIES") == 0) |
|
297 |
continue; |
|
298 |
|
|
299 |
if (token.toUpperCase().compareTo("SERVICE=WCS") == 0) |
|
300 |
continue; |
|
301 |
|
|
302 |
if ((_version != null) && (_version.length() > 0)) { |
|
303 |
if (token.toUpperCase().compareTo("VERSION=" + _version) == 0) |
|
304 |
continue; |
|
305 |
} |
|
306 |
|
|
307 |
if (token.toUpperCase().compareTo("EXCEPTIONS=XML") == 0) |
|
308 |
continue; |
|
309 |
|
|
310 |
newQuery += token + "&"; |
|
311 |
} |
|
312 |
|
|
313 |
_host = host + newQuery; |
|
314 |
} |
|
315 |
else { |
|
316 |
_host += "?"; |
|
317 |
} |
|
318 |
|
|
319 |
if ((_version != null) && (_version.compareTo("") != 0)) |
|
320 |
_host += "REQUEST=GetCapabilities&SERVICE=WCS&VERSION=" + _version + "&EXCEPTIONS=XML"; |
|
321 |
else |
|
322 |
_host += "REQUEST=GetCapabilities&SERVICE=WCS&EXCEPTIONS=XML"; |
|
323 |
|
|
324 |
return stringUtils.replaceAll(_host, " ", "%20"); |
|
325 |
} |
|
326 |
|
|
327 |
public ArrayList getFormats() { |
|
328 |
return new ArrayList(serviceInfo.formats); |
|
329 |
} |
|
330 |
|
|
331 |
public Hashtable getLayers() { |
|
332 |
return layerPool; |
|
333 |
} |
|
334 |
|
|
335 |
public abstract WCSDescribeCoverageRequest createDescribeCoverageRequest(WCSStatus status); |
|
336 |
|
|
337 |
public abstract WCSGetCoverageRequest createGetCoverageRequest(WCSStatus status); |
|
338 |
|
|
339 |
/* (non-Javadoc) |
|
340 |
* @see org.gvsig.remoteclient.ogc.OGCProtocolHandler#getServiceInformation() |
|
341 |
*/ |
|
342 |
public OGCServiceInformation getServiceInformation() { |
|
343 |
return serviceInfo; |
|
344 |
} |
|
345 |
|
|
346 |
} |
|
0 | 347 |
tags/v2_0_0_Build_2020/libraries/libRemoteServices/src/org/gvsig/remoteclient/wcs/WCSOperation.java | ||
---|---|---|
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 |
|
|
23 |
/* |
|
24 |
* AUTHORS (In addition to CIT): |
|
25 |
* 2009 Iver T.I. {{Task}} |
|
26 |
*/ |
|
27 |
|
|
28 |
package org.gvsig.remoteclient.wcs; |
|
29 |
|
|
30 |
import java.util.Hashtable; |
|
31 |
|
|
32 |
import org.gvsig.remoteclient.ogc.OGCClientOperation; |
|
33 |
import org.gvsig.remoteclient.utils.CapabilitiesTags; |
|
34 |
|
|
35 |
/** |
|
36 |
* @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a> |
|
37 |
*/ |
|
38 |
public class WCSOperation extends OGCClientOperation{ |
|
39 |
protected static Hashtable operations = new Hashtable(); |
|
40 |
|
|
41 |
static{ |
|
42 |
operations.put(CapabilitiesTags.GETCAPABILITIES, new WCSOperation(CapabilitiesTags.GETCAPABILITIES)); |
|
43 |
operations.put(CapabilitiesTags.DESCRIBECOVERAGE, new WCSOperation(CapabilitiesTags.DESCRIBECOVERAGE)); |
|
44 |
operations.put(CapabilitiesTags.GETCOVERAGE, new WCSOperation(CapabilitiesTags.GETCOVERAGE)); |
|
45 |
} |
|
46 |
|
|
47 |
public WCSOperation(String operationName) { |
|
48 |
super(operationName); |
|
49 |
} |
|
50 |
|
|
51 |
public WCSOperation(String operationName, String onlineResource) { |
|
52 |
super(operationName, onlineResource); |
|
53 |
} |
|
54 |
|
|
55 |
/* |
|
56 |
* (non-Javadoc) |
|
57 |
* @see org.gvsig.remoteClient.OGCClientOperation#getOperations() |
|
58 |
*/ |
|
59 |
public Hashtable getOperations() { |
|
60 |
return operations; |
|
61 |
} |
|
62 |
} |
|
63 |
|
|
0 | 64 |
tags/v2_0_0_Build_2020/libraries/libRemoteServices/src/org/gvsig/remoteclient/wcs/WCSStatus.java | ||
---|---|---|
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
2 |
* |
|
3 |
* Copyright (C) 2005 IVER T.I. and Generalitat Valenciana. |
|
4 |
* |
|
5 |
* This program is free software; you can redistribute it and/or |
|
6 |
* modify it under the terms of the GNU General Public License |
|
7 |
* as published by the Free Software Foundation; either version 2 |
|
8 |
* of the License, or (at your option) any later version. |
|
9 |
* |
|
10 |
* This program is distributed in the hope that it will be useful, |
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
* GNU General Public License for more details. |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License |
|
16 |
* along with this program; if not, write to the Free Software |
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
18 |
* |
|
19 |
* For more information, contact: |
|
20 |
* |
|
21 |
* Generalitat Valenciana |
|
22 |
* Conselleria d'Infraestructures i Transport |
|
23 |
* Av. Blasco Ib??ez, 50 |
|
24 |
* 46010 VALENCIA |
|
25 |
* SPAIN |
|
26 |
* |
|
27 |
* +34 963862235 |
|
28 |
* gvsig@gva.es |
|
29 |
* www.gvsig.gva.es |
|
30 |
* |
|
31 |
* or |
|
32 |
* |
|
33 |
* IVER T.I. S.A |
|
34 |
* Salamanca 50 |
|
35 |
* 46005 Valencia |
|
36 |
* Spain |
|
37 |
* |
|
38 |
* +34 963163400 |
|
39 |
* dac@iver.es |
|
40 |
*/ |
|
41 |
/* |
|
42 |
* $Id$ |
|
43 |
* $Log$ |
|
44 |
* Revision 1.9 2006-12-05 16:27:15 fdiaz |
|
45 |
* *** empty log message *** |
|
46 |
* |
|
47 |
* Revision 1.8 2006/05/12 07:45:49 jaume |
|
48 |
* some warnings removed |
|
49 |
* |
|
50 |
* Revision 1.7 2006/04/25 06:47:50 jaume |
|
51 |
* clean up unnecessary imports |
|
52 |
* |
|
53 |
* Revision 1.6 2006/04/19 11:04:51 jaume |
|
54 |
* *** empty log message *** |
|
55 |
* |
|
56 |
* Revision 1.5 2006/03/27 15:20:15 jaume |
|
57 |
* *** empty log message *** |
|
58 |
* |
|
59 |
* Revision 1.3 2006/03/21 11:30:26 jaume |
|
60 |
* some wcs client operation stuff |
|
61 |
* |
|
62 |
* Revision 1.2 2006/03/15 08:54:42 jaume |
|
63 |
* *** empty log message *** |
|
64 |
* |
|
65 |
* Revision 1.1.2.1 2006/03/08 09:08:31 jaume |
|
66 |
* *** empty log message *** |
|
67 |
* |
|
68 |
* Revision 1.1 2006/03/06 15:18:32 jaume |
|
69 |
* *** empty log message *** |
|
70 |
* |
|
71 |
*/ |
|
72 |
package org.gvsig.remoteclient.wcs; |
|
73 |
|
|
74 |
import java.awt.geom.Rectangle2D; |
|
75 |
|
|
76 |
import org.gvsig.remoteclient.RemoteClientStatus; |
|
77 |
/** |
|
78 |
* Describes the status of a WCSclient, so it adds to the Remote client status |
|
79 |
* a list of layers, a list of layer styles, the extent of the map. |
|
80 |
* Provides the functionality to modify these lists. |
|
81 |
* |
|
82 |
* @author jaume dom?nguez faus - jaume.dominguez@iver.es |
|
83 |
*/ |
|
84 |
public class WCSStatus extends RemoteClientStatus { |
|
85 |
//private String resolution = null; TODO do I need it? |
|
86 |
private Rectangle2D bBox = null; |
|
87 |
private String coverageName = null; |
|
88 |
private String onlineResource = null; |
|
89 |
private String depth = null; |
|
90 |
private String times = null; |
|
91 |
private String parameters = null; |
|
92 |
private String message = null; |
|
93 |
|
|
94 |
/** |
|
95 |
* Sets the Bounding Box that is going to be requested to the server. |
|
96 |
* @param bBox, Rectangle2D containing the edges of the bounding box |
|
97 |
*/ |
|
98 |
public void setExtent(Rectangle2D bBox) { |
|
99 |
this.bBox = bBox; |
|
100 |
} |
|
101 |
|
|
102 |
/** |
|
103 |
* Sets the name of the coverage requested to the server. |
|
104 |
* @param coverageName, String containing the name of the requesting coverage |
|
105 |
*/ |
|
106 |
public void setCoveraName(String coverageName) { |
|
107 |
this.coverageName = coverageName; |
|
108 |
} |
|
109 |
|
|
110 |
/** |
|
111 |
* Sets the parameter string. The parameter string is the part of the request |
|
112 |
* containing the value for the axis as described in the DescribeCoverage |
|
113 |
* document. |
|
114 |
* @param parameters |
|
115 |
*/ |
|
116 |
public void setParameters(String parameters) { |
|
117 |
this.parameters = parameters; |
|
118 |
} |
|
119 |
|
|
120 |
/** |
|
121 |
* Will set the address of the host that serves the following request |
|
122 |
* @param onlineResources |
|
123 |
*/ |
|
124 |
public void setOnlineResource(String onlineResources) { |
|
125 |
this.onlineResource = onlineResources; |
|
126 |
} |
|
127 |
|
|
128 |
/** |
|
129 |
* Sets the depth. The depth is the third dimension for the size. |
|
130 |
* @param depth, String |
|
131 |
*/ |
|
132 |
public void setDepth(String depth) { |
|
133 |
this.depth = depth; |
|
134 |
} |
|
135 |
|
|
136 |
/** |
|
137 |
* Returns the address host that will serve the request |
|
138 |
* @return String |
|
139 |
*/ |
|
140 |
public String getOnlineResource() { |
|
141 |
return onlineResource; |
|
142 |
} |
|
143 |
|
|
144 |
/** |
|
145 |
* Return the name of the coverage requested to the server. |
|
146 |
* @return String containing the name of the requesting coverage |
|
147 |
*/ |
|
148 |
public String getCoverageName() { |
|
149 |
return this.coverageName; |
|
150 |
} |
|
151 |
|
|
152 |
/** |
|
153 |
* Returns the Bounding Box that is going to be requested to the server. |
|
154 |
* @return Rectangle2D containing the edges of the bounding box |
|
155 |
*/ |
|
156 |
public Rectangle2D getExtent() { |
|
157 |
return this.bBox; |
|
158 |
} |
|
159 |
|
|
160 |
/** |
|
161 |
* Returns the depth of the next request. |
|
162 |
* @return String |
|
163 |
*/ |
|
164 |
public String getDepth() { |
|
165 |
return depth; |
|
166 |
} |
|
167 |
|
|
168 |
/** |
|
169 |
* Returns the value for the time parameter that will be used in the next request |
|
170 |
* @return String |
|
171 |
*/ |
|
172 |
public String getTime() { |
|
173 |
return times; |
|
174 |
} |
|
175 |
|
|
176 |
/** |
|
177 |
* Returns the parameter string. |
|
178 |
* The parameter string is the part of the request containing the value for the |
|
179 |
* axis as described in the DescribeCoverage. |
|
180 |
* @return String |
|
181 |
*/ |
|
182 |
public String getParameters() { |
|
183 |
return parameters; |
|
184 |
} |
|
185 |
|
|
186 |
/** |
|
187 |
* Sets the value(s) for the time that will be used in the next request. |
|
188 |
* @param times |
|
189 |
*/ |
|
190 |
public void setTime(String times) { |
|
191 |
this.times = times; |
|
192 |
} |
|
193 |
|
|
194 |
/** |
|
195 |
* Returns the message string |
|
196 |
* @return String |
|
197 |
*/ |
|
198 |
public String getMessage() { |
|
199 |
return message; |
|
200 |
} |
|
201 |
|
|
202 |
/** |
|
203 |
* Sets the message string |
|
204 |
* @param message |
|
205 |
*/ |
|
206 |
public void setMessage(String message) { |
|
207 |
this.message = message; |
|
208 |
} |
|
209 |
|
|
210 |
} |
|
0 | 211 |
tags/v2_0_0_Build_2020/libraries/libRemoteServices/src/org/gvsig/remoteclient/wcs/CoverageOfferingBrief.java | ||
---|---|---|
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
2 |
* |
|
3 |
* Copyright (C) 2005 IVER T.I. and Generalitat Valenciana. |
|
4 |
* |
|
5 |
* This program is free software; you can redistribute it and/or |
|
6 |
* modify it under the terms of the GNU General Public License |
|
7 |
* as published by the Free Software Foundation; either version 2 |
|
8 |
* of the License, or (at your option) any later version. |
|
9 |
* |
|
10 |
* This program is distributed in the hope that it will be useful, |
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
* GNU General Public License for more details. |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License |
|
16 |
* along with this program; if not, write to the Free Software |
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
18 |
* |
|
19 |
* For more information, contact: |
|
20 |
* |
|
21 |
* Generalitat Valenciana |
|
22 |
* Conselleria d'Infraestructures i Transport |
|
23 |
* Av. Blasco Ib??ez, 50 |
|
24 |
* 46010 VALENCIA |
|
25 |
* SPAIN |
|
26 |
* |
|
27 |
* +34 963862235 |
|
28 |
* gvsig@gva.es |
|
29 |
* www.gvsig.gva.es |
|
30 |
* |
|
31 |
* or |
|
32 |
* |
|
33 |
* IVER T.I. S.A |
|
34 |
* Salamanca 50 |
|
35 |
* 46005 Valencia |
|
36 |
* Spain |
|
37 |
* |
|
38 |
* +34 963163400 |
|
39 |
* dac@iver.es |
|
40 |
*/ |
|
41 |
|
|
42 |
/* CVS MESSAGES: |
|
43 |
* |
|
44 |
* $Id$ |
|
45 |
* $Log$ |
|
46 |
* Revision 1.1 2006-09-04 16:12:17 jaume |
|
47 |
* *** empty log message *** |
|
48 |
* |
|
49 |
* |
|
50 |
*/ |
|
51 |
package org.gvsig.remoteclient.wcs; |
|
52 |
|
|
53 |
import java.io.IOException; |
|
54 |
|
|
55 |
import org.kxml2.io.KXmlParser; |
|
56 |
import org.xmlpull.v1.XmlPullParserException; |
|
57 |
|
|
58 |
import org.gvsig.compat.CompatLocator; |
|
59 |
import org.gvsig.compat.lang.StringUtils; |
|
60 |
import org.gvsig.remoteclient.utils.BoundaryBox; |
|
61 |
import org.gvsig.remoteclient.utils.CapabilitiesTags; |
|
62 |
import org.gvsig.remoteclient.utils.DescribeCoverageTags; |
|
63 |
|
|
64 |
public class CoverageOfferingBrief { |
|
65 |
private String name; |
|
66 |
private String label; |
|
67 |
private BoundaryBox lonLatBbox; |
|
68 |
private static final StringUtils stringUtils = CompatLocator.getStringUtils(); |
|
69 |
|
|
70 |
public String getLabel() { |
|
71 |
return label; |
|
72 |
} |
|
73 |
public void setLabel(String label) { |
|
74 |
this.label = label; |
|
75 |
} |
|
76 |
public BoundaryBox getLonLatBbox() { |
|
77 |
return lonLatBbox; |
|
78 |
} |
|
79 |
public void setLonLatBbox(BoundaryBox lonLatBbox) { |
|
80 |
this.lonLatBbox = lonLatBbox; |
|
81 |
} |
|
82 |
public String getName() { |
|
83 |
return name; |
|
84 |
} |
|
85 |
|
|
86 |
public void setName(String name) { |
|
87 |
this.name = name; |
|
88 |
} |
|
89 |
|
|
90 |
public void parse(KXmlParser parser) throws XmlPullParserException, IOException { |
|
91 |
int currentTag; |
|
92 |
boolean end = false; |
|
93 |
|
|
94 |
parser.require(KXmlParser.START_TAG, null, "wcs:"+CapabilitiesTags.WCS_COVERAGEOFFERINGBRIEF); |
|
95 |
currentTag = parser.next(); |
|
96 |
|
|
97 |
while (!end) |
|
98 |
{ |
|
99 |
switch(currentTag) |
|
100 |
{ |
|
101 |
case KXmlParser.START_TAG: |
|
102 |
|
|
103 |
if (parser.getName().toLowerCase().compareTo(CapabilitiesTags.NAME.toLowerCase())==0) { |
|
104 |
this.name = parser.nextText(); |
|
105 |
} else if (parser.getName().compareTo(CapabilitiesTags.WCS_LABEL)==0) { |
|
106 |
this.label = parser.nextText(); |
|
107 |
} else if (parser.getName().compareTo(DescribeCoverageTags.LONLAT_ENVELOPE)==0) { |
|
108 |
parser.nextTag(); |
|
109 |
this.lonLatBbox = new BoundaryBox(); |
|
110 |
this.lonLatBbox.setSrs(DescribeCoverageTags.WGS84); |
|
111 |
parser.require(KXmlParser.START_TAG, null, DescribeCoverageTags.GML_POS); |
|
112 |
String[][] coord = new String[2][2]; |
|
113 |
coord[0] = stringUtils.split(parser.nextText(), WCSCoverage.SEPARATOR); |
|
114 |
parser.nextTag(); |
|
115 |
parser.require(KXmlParser.START_TAG, null, DescribeCoverageTags.GML_POS); |
|
116 |
coord[1] = stringUtils.split(parser.nextText(), WCSCoverage.SEPARATOR); |
|
117 |
this.lonLatBbox.setXmin(Double.parseDouble(coord[0][0])); |
|
118 |
this.lonLatBbox.setYmin(Double.parseDouble(coord[0][1])); |
|
119 |
this.lonLatBbox.setXmax(Double.parseDouble(coord[1][0])); |
|
120 |
this.lonLatBbox.setYmax(Double.parseDouble(coord[1][1])); |
|
121 |
} |
|
122 |
|
|
123 |
case KXmlParser.END_TAG: |
|
124 |
if (parser.getName().compareTo("wcs:"+CapabilitiesTags.WCS_COVERAGEOFFERINGBRIEF) == 0) |
|
125 |
end = true; |
|
126 |
break; |
|
127 |
case KXmlParser.TEXT: |
|
128 |
break; |
|
129 |
} |
|
130 |
currentTag = parser.next(); |
|
131 |
} |
|
132 |
|
|
133 |
} |
|
134 |
} |
|
0 | 135 |
tags/v2_0_0_Build_2020/libraries/libRemoteServices/src/org/gvsig/remoteclient/wcs/WCSServiceInformation.java | ||
---|---|---|
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 |
|
|
23 |
/* |
|
24 |
* AUTHORS (In addition to CIT): |
|
25 |
* 2009 {Iver T.I.} {Task} |
|
26 |
*/ |
|
27 |
|
|
28 |
package org.gvsig.remoteclient.wcs; |
|
29 |
|
|
30 |
import java.util.HashMap; |
|
31 |
import java.util.Vector; |
|
32 |
|
|
33 |
import org.gvsig.remoteclient.ogc.OGCClientOperation; |
|
34 |
import org.gvsig.remoteclient.ogc.OGCServiceInformation; |
|
35 |
|
|
36 |
/** |
|
37 |
* @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a> |
|
38 |
*/ |
|
39 |
public class WCSServiceInformation extends OGCServiceInformation { |
|
40 |
public String online_resource = null; |
|
41 |
public String version; |
|
42 |
public String name; |
|
43 |
public String scope; |
|
44 |
public String title; |
|
45 |
public String abstr; |
|
46 |
public String keywords; |
|
47 |
public String fees; |
|
48 |
public String operationsInfo; |
|
49 |
public String personname; |
|
50 |
public String organization; |
|
51 |
public String function; |
|
52 |
public String addresstype; |
|
53 |
public String address; |
|
54 |
public String place; |
|
55 |
public String province; |
|
56 |
public String postcode; |
|
57 |
public String country; |
|
58 |
public String phone; |
|
59 |
public String fax; |
|
60 |
public String email; |
|
61 |
public Vector formats; |
|
62 |
public HashMap operations; // operations that WCS supports |
|
63 |
|
|
64 |
public WCSServiceInformation() |
|
65 |
{ |
|
66 |
version = new String(); |
|
67 |
name = new String(); |
|
68 |
scope = new String(); |
|
69 |
title = new String(); |
|
70 |
abstr = new String(); |
|
71 |
keywords = new String(); |
|
72 |
fees = new String(); |
|
73 |
operationsInfo = new String(); |
|
74 |
personname = new String(); |
|
75 |
organization = new String(); |
|
76 |
function = new String(); |
|
77 |
addresstype = new String(); |
|
78 |
address = new String(); |
|
79 |
place = new String(); |
|
80 |
province = new String(); |
|
81 |
postcode = new String(); |
|
82 |
country = new String(); |
|
83 |
phone = new String(); |
|
84 |
fax = new String(); |
|
85 |
email = new String(); |
|
86 |
operations = new HashMap(); |
|
87 |
} |
|
88 |
|
|
89 |
public OGCClientOperation createOperation(String name) { |
|
90 |
return new WCSOperation(name); |
|
91 |
} |
|
92 |
|
|
93 |
public OGCClientOperation createOperation(String name, String onlineResource) { |
|
94 |
return new WCSOperation(name, onlineResource); |
|
95 |
} |
|
96 |
|
|
97 |
|
|
98 |
} |
|
99 |
|
|
0 | 100 |
tags/v2_0_0_Build_2020/libraries/libRemoteServices/src/org/gvsig/remoteclient/wcs/WCSProtocolHandlerFactory.java | ||
---|---|---|
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
2 |
* |
|
3 |
* Copyright (C) 2005 IVER T.I. and Generalitat Valenciana. |
|
4 |
* |
|
5 |
* This program is free software; you can redistribute it and/or |
|
6 |
* modify it under the terms of the GNU General Public License |
|
7 |
* as published by the Free Software Foundation; either version 2 |
|
8 |
* of the License, or (at your option) any later version. |
|
9 |
* |
|
10 |
* This program is distributed in the hope that it will be useful, |
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
* GNU General Public License for more details. |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License |
|
16 |
* along with this program; if not, write to the Free Software |
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
18 |
* |
|
19 |
* For more information, contact: |
|
20 |
* |
|
21 |
* Generalitat Valenciana |
|
22 |
* Conselleria d'Infraestructures i Transport |
|
23 |
* Av. Blasco Ib??ez, 50 |
|
24 |
* 46010 VALENCIA |
|
25 |
* SPAIN |
|
26 |
* |
|
27 |
* +34 963862235 |
|
28 |
* gvsig@gva.es |
|
29 |
* www.gvsig.gva.es |
|
30 |
* |
|
31 |
* or |
|
32 |
* |
|
33 |
* IVER T.I. S.A |
|
34 |
* Salamanca 50 |
|
35 |
* 46005 Valencia |
|
36 |
* Spain |
|
37 |
* |
|
38 |
* +34 963163400 |
|
39 |
* dac@iver.es |
|
40 |
*/ |
|
41 |
/* |
|
42 |
* $Id$ |
|
43 |
* $Log$ |
|
44 |
* Revision 1.4 2006-07-18 11:41:05 jaume |
|
45 |
* no hay nada nuevo pero el team synchronize est? pesado |
|
46 |
* |
|
47 |
* Revision 1.3 2006/04/25 06:47:50 jaume |
|
48 |
* clean up unnecessary imports |
|
49 |
* |
|
50 |
* Revision 1.2 2006/03/15 08:54:42 jaume |
|
51 |
* *** empty log message *** |
|
52 |
* |
|
53 |
* Revision 1.1.2.1 2006/03/08 09:08:31 jaume |
|
54 |
* *** empty log message *** |
|
55 |
* |
|
56 |
* Revision 1.1 2006/03/06 15:18:32 jaume |
|
57 |
* *** empty log message *** |
|
58 |
* |
|
59 |
*/ |
|
60 |
package org.gvsig.remoteclient.wcs; |
|
61 |
|
|
62 |
import java.io.DataInputStream; |
|
63 |
import java.io.IOException; |
|
64 |
import java.io.StringReader; |
|
65 |
import java.net.ConnectException; |
|
66 |
import java.net.URL; |
|
67 |
import java.util.ArrayList; |
|
68 |
import java.util.Iterator; |
|
69 |
|
|
70 |
import org.kxml2.io.KXmlParser; |
|
71 |
import org.xmlpull.v1.XmlPullParserException; |
|
72 |
|
|
73 |
import org.gvsig.remoteclient.utils.CapabilitiesTags; |
|
74 |
|
|
75 |
/** |
|
76 |
* |
|
77 |
* @author jaume dominguez faus |
|
78 |
* |
|
79 |
*/ |
|
80 |
public class WCSProtocolHandlerFactory { |
|
81 |
|
|
82 |
public org.gvsig.remoteclient.wcs.WCSProtocolHandler wCSProtocolHandler; |
|
83 |
|
|
84 |
private static ArrayList supportedVersions = new ArrayList(); |
|
85 |
|
|
86 |
static { |
|
87 |
supportedVersions.add("1.0.0"); |
|
88 |
} |
|
89 |
|
|
90 |
/** |
|
91 |
* M?todo que dada una respuesta de getCapabilities y un iterador sobre una |
|
92 |
* coleccion de WCSClient's ordenada descendentemente devuelve el cliente |
|
93 |
* cuya version es igual o inmediatamente inferior |
|
94 |
* |
|
95 |
* @param caps Capabilities con la respuesta del servidor |
|
96 |
* @param clients Iterador de conjunto ordenado descendientemente |
|
97 |
* |
|
98 |
* @return cliente cuya version es igual o inmediatamente inferior |
|
99 |
* @throws IllegalAccessException |
|
100 |
* @throws InstantiationException |
|
101 |
* |
|
102 |
*/ |
|
103 |
private static String getDriverVersion(String version, Iterator clients) throws InstantiationException, IllegalAccessException { |
|
104 |
while (clients.hasNext()) { |
|
105 |
String clientVersion = (String)clients.next(); |
|
106 |
int ret = version.compareTo(clientVersion); |
|
107 |
|
|
108 |
if (ret >= 0) { |
|
109 |
return clientVersion; |
|
110 |
} |
|
111 |
} |
|
112 |
return null; |
|
113 |
} |
|
114 |
|
|
115 |
/** |
|
116 |
* Establece la versi?n con la que se comunicar? con el servidor y devuelve |
|
117 |
* el objeto Capabilities obtenido con dicha versi?n |
|
118 |
* |
|
119 |
* @param host maquina con la que se negocia |
|
120 |
* |
|
121 |
* @return instancia de un cliente capaz de negociar con el host que se |
|
122 |
* pasa como par?metro |
|
123 |
*/ |
|
124 |
public static WCSProtocolHandler negotiate(String host) throws ConnectException, IOException { |
|
125 |
|
|
126 |
if (supportedVersions.size() == 0) |
|
127 |
{ |
|
128 |
return null; |
|
129 |
} |
|
130 |
|
|
131 |
try |
|
132 |
{ |
|
133 |
String highestVersionSupportedByServer = getSuitableWCSVersion(host,""); |
|
134 |
if (supportedVersions.contains(highestVersionSupportedByServer)) |
|
135 |
{ |
|
136 |
// we support the highest version supported by the server |
|
137 |
// this is the best case |
|
138 |
return createVersionDriver(highestVersionSupportedByServer); |
|
139 |
} |
|
140 |
else |
|
141 |
{ |
|
142 |
// in case we dont support the highest version from the server |
|
143 |
// we start the negotiation process in which we have to get the higest version |
|
144 |
// the WCS supports and we are able to read. |
|
145 |
Iterator iVersion = supportedVersions.iterator(); |
|
146 |
String wcsVersion; |
|
147 |
String gvSIGVersion; |
|
148 |
|
|
149 |
while (iVersion.hasNext()) { |
|
150 |
gvSIGVersion = (String)iVersion.next(); |
|
151 |
wcsVersion = getSuitableWCSVersion(host,gvSIGVersion); |
|
152 |
//TODO: |
|
153 |
//compare with the version returned by the WMS!!!!! |
|
154 |
// send GetCapabilities and read the version to compare. |
|
155 |
int res = wcsVersion.compareTo(gvSIGVersion); |
|
156 |
|
|
157 |
if (res == 0) { //Si es la misma que nuestra version |
|
158 |
return createVersionDriver(gvSIGVersion); |
|
159 |
} else if (res > 0) { //Si es mayor que nuestra version |
|
160 |
throw new Exception("Server Version too high: " + wcsVersion); |
|
161 |
} else { //Si es menor que nuestra version |
|
162 |
//Obtenemos la primera version menor o igual que tengamos |
|
163 |
String lowerVersion = WCSProtocolHandlerFactory.getDriverVersion(wcsVersion, iVersion); |
|
164 |
|
|
165 |
if (lowerVersion == null) { //Si no hay ninguna |
|
166 |
throw new Exception("Lowest server version is " + wcsVersion); |
|
167 |
} else { |
|
168 |
if (lowerVersion.equals(wcsVersion)) { |
|
169 |
return createVersionDriver(lowerVersion); |
|
170 |
} else { //Si hay una version menor que la que retorno el servidor |
|
171 |
//iV = lower; |
|
172 |
} |
|
173 |
} |
|
174 |
} |
|
175 |
} |
|
176 |
}//case we had to start the negotiation process. |
|
177 |
return null; // if it did not find any suitable version. |
|
178 |
} |
|
179 |
catch(ConnectException conEx) |
|
180 |
{ |
|
181 |
throw conEx; |
|
182 |
} |
|
183 |
catch(IOException ioEx) |
|
184 |
{ |
|
185 |
throw ioEx; |
|
186 |
} |
|
187 |
catch(Exception e) |
|
188 |
{ |
|
189 |
// e.printStackTrace(); |
|
190 |
return null; |
|
191 |
} |
|
192 |
} |
|
193 |
|
|
194 |
/** |
|
195 |
* Sends a GetCapabilities to the WCS server to get the version |
|
196 |
* if the version parameter is null, the WCS will return the highest version supported |
|
197 |
* if not it will return the lower highest version than the one requested. |
|
198 |
* @param host |
|
199 |
* @param version |
|
200 |
* @return suitable version supported by the server |
|
201 |
*/ |
|
202 |
private static String getSuitableWCSVersion(String host, String _version) throws ConnectException, IOException { |
|
203 |
String request = WCSProtocolHandler.buildCapabilitiesSuitableVersionRequest(host, _version); |
|
204 |
String version = new String(); |
|
205 |
StringReader reader = null; |
|
206 |
//InputStreamReader reader; |
|
207 |
//InputStream is = null; |
|
208 |
DataInputStream dis = null; |
|
209 |
try { |
|
210 |
URL url = new URL(request); |
|
211 |
byte[] buffer = new byte[1024];//new byte[1024*256]; |
|
212 |
// is = url.openStream(); |
|
213 |
// reader = new InputStreamReader(is); |
|
214 |
//int numberOfBytes = is.read(buffer); |
|
215 |
//String readed = new String(buffer); |
|
216 |
dis = new DataInputStream(url.openStream()); |
|
217 |
dis.readFully(buffer); |
|
218 |
|
|
219 |
reader = new StringReader(new String(buffer)); |
|
220 |
KXmlParser kxmlParser = null; |
|
221 |
kxmlParser = new KXmlParser(); |
|
222 |
kxmlParser.setInput(reader); |
|
223 |
kxmlParser.nextTag(); |
|
224 |
if ( kxmlParser.getEventType() != KXmlParser.END_DOCUMENT ) { |
|
225 |
if ((kxmlParser.getName().compareTo(CapabilitiesTags.WCS_CAPABILITIES_ROOT1_0_0)==0)) { |
|
226 |
version = kxmlParser.getAttributeValue("", CapabilitiesTags.VERSION); |
|
227 |
} |
|
228 |
} |
|
229 |
// do not forget to close the Stream. |
|
230 |
reader.close(); |
|
231 |
dis.close(); |
|
232 |
return version; |
|
233 |
} catch(ConnectException conEx) { |
|
234 |
throw new ConnectException(conEx.getMessage()); |
|
235 |
} catch(IOException ioEx) { |
|
236 |
throw new IOException(ioEx.getMessage()); |
|
237 |
} catch(XmlPullParserException xmlEx) { |
|
238 |
xmlEx.printStackTrace(); |
|
239 |
return ""; |
|
240 |
} finally { |
|
241 |
if (reader != null) { |
|
242 |
try { |
|
243 |
reader.close(); |
|
244 |
} catch(Exception ex) { |
|
245 |
ex.printStackTrace(); |
|
246 |
} |
|
247 |
} if (dis != null) { |
|
248 |
try { |
|
249 |
dis.close(); |
|
250 |
} catch(Exception ex){ |
|
251 |
ex.printStackTrace(); |
|
252 |
} |
|
253 |
} |
|
254 |
} |
|
255 |
} |
|
256 |
|
|
257 |
/** |
|
258 |
* It creates an instance of a WCSDriver class. |
|
259 |
* |
|
260 |
* @param String, with the version of the driver to be created |
|
261 |
* @return WCSDriver. |
|
262 |
*/ |
|
263 |
private static WCSProtocolHandler createVersionDriver(String version) { |
|
264 |
try { |
|
265 |
Class driver; |
|
266 |
version = version.replace('.', '_'); |
|
267 |
driver = Class.forName("org.gvsig.remoteclient.wcs.wcs_"+version+".WCSProtocolHandler" + version); |
|
268 |
return (WCSProtocolHandler)driver.newInstance(); |
|
269 |
} catch (Exception e) { |
|
270 |
e.printStackTrace(); |
|
271 |
//throw new Exception("WCSDriverFactory. Unknown driver version " + e); |
|
272 |
return null; |
|
273 |
} |
|
274 |
} |
|
275 |
|
|
276 |
|
|
277 |
} |
|
0 | 278 |
tags/v2_0_0_Build_2020/libraries/libRemoteServices/src/org/gvsig/remoteclient/wcs/WCSCoverage.java | ||
---|---|---|
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
2 |
* |
|
3 |
* Copyright (C) 2005 IVER T.I. and Generalitat Valenciana. |
|
4 |
* |
|
5 |
* This program is free software; you can redistribute it and/or |
|
6 |
* modify it under the terms of the GNU General Public License |
|
7 |
* as published by the Free Software Foundation; either version 2 |
|
8 |
* of the License, or (at your option) any later version. |
|
9 |
* |
|
10 |
* This program is distributed in the hope that it will be useful, |
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
* GNU General Public License for more details. |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License |
|
16 |
* along with this program; if not, write to the Free Software |
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
18 |
* |
|
19 |
* For more information, contact: |
|
20 |
* |
|
21 |
* Generalitat Valenciana |
|
22 |
* Conselleria d'Infraestructures i Transport |
|
23 |
* Av. Blasco Ib??ez, 50 |
|
24 |
* 46010 VALENCIA |
|
25 |
* SPAIN |
|
26 |
* |
|
27 |
* +34 963862235 |
|
28 |
* gvsig@gva.es |
|
29 |
* www.gvsig.gva.es |
|
30 |
* |
|
31 |
* or |
|
32 |
* |
|
33 |
* IVER T.I. S.A |
|
34 |
* Salamanca 50 |
Also available in: Unified diff