root / branches / v10 / libraries / libArcIMS / src / org / gvsig / remoteClient / arcims / ArcImsProtImageHandler.java @ 20977
History | View | Annotate | Download (23.7 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2006 Prodevelop 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 |
* Prodevelop Integraci?n de Tecnolog?as SL
|
34 |
* Conde Salvatierra de ?lava , 34-10
|
35 |
* 46004 Valencia
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 963 510 612
|
39 |
* +34 963 510 968
|
40 |
* gis@prodevelop.es
|
41 |
* http://www.prodevelop.es
|
42 |
*/
|
43 |
|
44 |
package org.gvsig.remoteClient.arcims; |
45 |
|
46 |
import org.apache.log4j.Logger; |
47 |
|
48 |
import org.cresques.cts.IProjection; |
49 |
|
50 |
import org.gvsig.remoteClient.arcims.exceptions.ArcImsException; |
51 |
import org.gvsig.remoteClient.arcims.utils.ArcImsDownloadUtils; |
52 |
import org.gvsig.remoteClient.arcims.utils.GetImageTags; |
53 |
import org.gvsig.remoteClient.arcims.utils.ServiceInfoTags; |
54 |
import org.gvsig.remoteClient.arcims.utils.ServiceInformation; |
55 |
import org.gvsig.remoteClient.arcims.utils.ServiceInformationLayer; |
56 |
import org.gvsig.remoteClient.exceptions.ServerErrorException; |
57 |
import org.gvsig.remoteClient.utils.BoundaryBox; |
58 |
|
59 |
import org.kxml2.io.KXmlParser; |
60 |
|
61 |
import org.xmlpull.v1.XmlPullParserException; |
62 |
|
63 |
import java.awt.Rectangle; |
64 |
import java.awt.geom.Area; |
65 |
import java.awt.geom.Rectangle2D; |
66 |
|
67 |
import java.io.BufferedReader; |
68 |
import java.io.File; |
69 |
import java.io.FileNotFoundException; |
70 |
import java.io.FileReader; |
71 |
import java.io.IOException; |
72 |
import java.io.Reader; |
73 |
|
74 |
import java.net.ConnectException; |
75 |
import java.net.MalformedURLException; |
76 |
import java.net.URL; |
77 |
|
78 |
import java.util.Vector; |
79 |
|
80 |
|
81 |
/**
|
82 |
* <p>
|
83 |
* Describes the handler to communicate to a ArcIMS ImageServer
|
84 |
* </p>
|
85 |
*/
|
86 |
public class ArcImsProtImageHandler extends ArcImsProtocolHandler { |
87 |
private static Logger logger = Logger.getLogger(ArcImsProtImageHandler.class.getName()); |
88 |
|
89 |
/**
|
90 |
* Method to obtain the correct extent of the Service in a specific SRS
|
91 |
* @param srsFlyr The SRS of the View
|
92 |
* @param status
|
93 |
* @return Rectangle2D The boundary box of the Service
|
94 |
* @throws ArcImsException
|
95 |
*/
|
96 |
public Rectangle2D getServiceExtent(IProjection srsFlyr, ArcImsStatus status) |
97 |
throws ArcImsException {
|
98 |
Rectangle2D rect = new Rectangle(); |
99 |
|
100 |
try {
|
101 |
URL url = new URL(this.buildCapabilitiesRequest(status)); |
102 |
|
103 |
/**
|
104 |
* The seriveInfo
|
105 |
*/
|
106 |
ServiceInformation si = status.getServiceInfo(); |
107 |
|
108 |
/**
|
109 |
* Gets de Decimal Separator and SRS from the status.ServiceInfo
|
110 |
*/
|
111 |
char ds = si.getSeparators().getDs();
|
112 |
String srsSI = si.getFeaturecoordsys();
|
113 |
|
114 |
/**
|
115 |
* The EPSG code that image requested will have,
|
116 |
* the ArcIMS server will reproject data into this
|
117 |
* code, see <a href="http://www.epsg.org">EPSG</a>
|
118 |
*/
|
119 |
String srsView = srsFlyr.getAbrev();
|
120 |
|
121 |
/**
|
122 |
* We suppose that status.getSrs() allways will give a
|
123 |
* string started by this string
|
124 |
*/
|
125 |
String ini_srs = ServiceInfoTags.vINI_SRS;
|
126 |
|
127 |
/**
|
128 |
* Assign the srs from the status
|
129 |
* @see org.gvsig.remoteClient.RemoteClientStatus#getSrs()
|
130 |
*/
|
131 |
if (srsView.startsWith(ini_srs)) {
|
132 |
srsView = srsView.substring(ini_srs.length()).trim(); |
133 |
} |
134 |
|
135 |
/**
|
136 |
* If both SRS are the same or status we pass empty strings
|
137 |
*/
|
138 |
if (srsView.equalsIgnoreCase(srsSI)) {
|
139 |
srsView = "";
|
140 |
srsSI = "";
|
141 |
} |
142 |
|
143 |
/**
|
144 |
* Build the custom request for this extent
|
145 |
*/
|
146 |
String request = ArcXMLImage.getCustomExtentRequest(srsSI,
|
147 |
//ServiceInfo SRS
|
148 |
null, //envelope |
149 |
srsView, //SRS of the view
|
150 |
ds, //Decimal separator
|
151 |
null, //Image size |
152 |
"", si.getLayer(0).getId() //A valid Layer Id |
153 |
); |
154 |
|
155 |
if (status.verbose) {
|
156 |
logger.debug(request); |
157 |
} |
158 |
|
159 |
logger.info("Requesting Service Extent XML");
|
160 |
|
161 |
File response = ArcImsDownloadUtils.doRequestPost(url, request,
|
162 |
"getServiceExtent.xml");
|
163 |
rect = parseEnvelopeTag(new FileReader(response), ds); |
164 |
} catch (MalformedURLException e) { |
165 |
logger.error(e.getMessage(), e); |
166 |
throw new ArcImsException("arcims_server_error"); |
167 |
} catch (FileNotFoundException e) { |
168 |
logger.error(e.getMessage(), e); |
169 |
throw new ArcImsException("arcims_server_error"); |
170 |
} |
171 |
|
172 |
return rect;
|
173 |
} |
174 |
|
175 |
/**
|
176 |
* <p>It will send a GetFeatureInfo request to the ArcIms
|
177 |
* Parsing the response and redirecting the info to the ArcIms client</p>
|
178 |
* @throws ArcImsException
|
179 |
*/
|
180 |
public String getElementInfo(ArcImsStatus status, int x, int y, |
181 |
int featureCount) throws ArcImsException { |
182 |
double iViewX;
|
183 |
double iViewY;
|
184 |
double iServiceX;
|
185 |
double iServiceY;
|
186 |
double xReal;
|
187 |
double yReal;
|
188 |
|
189 |
// double dist;
|
190 |
int ratio;
|
191 |
double currentScale;
|
192 |
|
193 |
/**
|
194 |
* ServiceInformation of the current Service
|
195 |
*/
|
196 |
ServiceInformation si = status.getServiceInfo(); |
197 |
char ds = si.getSeparators().getDs();
|
198 |
|
199 |
/**
|
200 |
* Determine the SRS to do all the requests, if the ServiceInformation
|
201 |
* doesn't provide a valid SRS, then we use the status srs
|
202 |
*/
|
203 |
String srs = status.getSrs().substring(ServiceInfoTags.vINI_SRS.length())
|
204 |
.trim(); |
205 |
|
206 |
/**
|
207 |
* The geographic extent of the current window
|
208 |
*/
|
209 |
Rectangle2D geoServiceExtent = new Rectangle(); |
210 |
Rectangle2D geoViewExtent = status.getExtent();
|
211 |
|
212 |
/**
|
213 |
* If the SRS's are different we need a reprojection, using a properly
|
214 |
* formed ArcIms GETIMAGE request
|
215 |
*/
|
216 |
if (!si.getFeaturecoordsys().equalsIgnoreCase(srs)) {
|
217 |
try {
|
218 |
logger.info("Requesting the Extent of the Image");
|
219 |
|
220 |
URL url = new URL(this.buildCapabilitiesRequest(status)); |
221 |
String request = ArcXMLImage.getCustomExtentRequest(srs,
|
222 |
status.getExtent(), si.getFeaturecoordsys(), ds, null,
|
223 |
"", si.getLayer(0).getId()); |
224 |
|
225 |
if (status.verbose) {
|
226 |
logger.debug(request); |
227 |
} |
228 |
|
229 |
File response = ArcImsDownloadUtils.doRequestPost(url, request,
|
230 |
"getInfoImageExtent.xml");
|
231 |
geoServiceExtent = parseEnvelopeTag(new FileReader(response), ds); |
232 |
} catch (MalformedURLException e) { |
233 |
logger.error(e.getMessage(), e); |
234 |
throw new ArcImsException("arcims_server_error"); |
235 |
} catch (FileNotFoundException e) { |
236 |
logger.error(e.getMessage(), e); |
237 |
throw new ArcImsException("arcims_server_error"); |
238 |
} |
239 |
} else {
|
240 |
geoServiceExtent = status.getExtent(); |
241 |
} |
242 |
|
243 |
/**
|
244 |
* URL for the requests of info
|
245 |
*/
|
246 |
URL requestF;
|
247 |
URL requestI;
|
248 |
URL request;
|
249 |
|
250 |
/**
|
251 |
* StringBuffer to store the POST info to pass to the server
|
252 |
*/
|
253 |
StringBuffer sb = new StringBuffer(); |
254 |
|
255 |
/**
|
256 |
* Vector of Layers IDs to request
|
257 |
*/
|
258 |
Vector idLayers = status.getLayerIds();
|
259 |
|
260 |
/**
|
261 |
* String with the ArcXML request (GET_FEATURES)
|
262 |
*/
|
263 |
String sArcXML = new String(); |
264 |
|
265 |
/**
|
266 |
* First at all, we build the request for this service
|
267 |
*/
|
268 |
try {
|
269 |
requestF = new URL(buildGetFeatureInfoRequest(status, |
270 |
ServiceInfoTags.vLAYERTYPE_F)); |
271 |
requestI = new URL(buildGetFeatureInfoRequest(status, |
272 |
ServiceInfoTags.vLAYERTYPE_I)); |
273 |
} catch (Exception e) { |
274 |
e.printStackTrace(); |
275 |
|
276 |
return ""; |
277 |
} |
278 |
|
279 |
sb.append("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>");
|
280 |
sb.append("<FeatureInfoResponse>");
|
281 |
|
282 |
/**
|
283 |
* We need to obtain the real (geographic) x,y not the pixels of the
|
284 |
* image, a BoundaryBox of the area we will query, the envelope and
|
285 |
* scale of the current view
|
286 |
*
|
287 |
*/
|
288 |
ratio = 3;
|
289 |
iViewX = geoViewExtent.getWidth() / status.getWidth(); |
290 |
iViewY = geoViewExtent.getHeight() / status.getHeight(); |
291 |
iServiceX = geoServiceExtent.getWidth() / status.getWidth(); |
292 |
iServiceY = geoServiceExtent.getHeight() / status.getHeight(); |
293 |
xReal = geoViewExtent.getMinX() + (x * iViewX); |
294 |
yReal = geoViewExtent.getMaxY() - (y * iViewY); |
295 |
|
296 |
if (serviceInfo.getScreen_dpi() == -1) { |
297 |
serviceInfo.setScreen_dpi(96);
|
298 |
} |
299 |
|
300 |
// currentScale = serviceInfo.screen_dpi/INCHES*((iX+iY)/2);
|
301 |
currentScale = 1.0 * ((iServiceX + iServiceY) / 2.0); |
302 |
|
303 |
/**
|
304 |
* Now we are ready to run over the layers to request the info for every
|
305 |
* one
|
306 |
*/
|
307 |
Vector ids = status.getLayerIds();
|
308 |
int n = ids.size();
|
309 |
String fields;
|
310 |
|
311 |
ServiceInformationLayer sil; |
312 |
ServiceInformationLayer silTemp; |
313 |
|
314 |
/*
|
315 |
* If ServiceInfo is Assumed we don't pass a valid SRS to
|
316 |
* avoid projection problems.
|
317 |
*/
|
318 |
if (si.isSrsAssumed()) {
|
319 |
srs = "";
|
320 |
} |
321 |
|
322 |
logger.info("Searching candidate layers");
|
323 |
|
324 |
for (int i = 0; i < n; i++) { |
325 |
/**
|
326 |
* Before we do any request to the server, we will ensure that the
|
327 |
* layer is viewed in the current envelope and scale
|
328 |
*/
|
329 |
|
330 |
/**
|
331 |
* Retrieve the proper ServiceInformationLayer
|
332 |
*/
|
333 |
sil = silTemp = (ServiceInformationLayer) si.getLayers().get(0);
|
334 |
|
335 |
for (int j = 0; j < si.getLayers().size(); j++) { |
336 |
silTemp = (ServiceInformationLayer) si.getLayers().get(j); |
337 |
|
338 |
if (silTemp.getId().equals(ids.get(i))) {
|
339 |
sil = silTemp; |
340 |
|
341 |
break;
|
342 |
} |
343 |
} |
344 |
|
345 |
/**
|
346 |
* Querying about the scale
|
347 |
*/
|
348 |
boolean inScale = false; |
349 |
|
350 |
if (sil.getMinscale() == -1) { |
351 |
if (sil.getMaxscale() == -1) { |
352 |
inScale = true;
|
353 |
} else {
|
354 |
inScale = (currentScale < sil.getMaxscale()); |
355 |
} |
356 |
} else {
|
357 |
if (sil.getMaxscale() == -1) { |
358 |
inScale = (currentScale > sil.getMinscale()); |
359 |
} else {
|
360 |
inScale = (currentScale > sil.getMinscale()) && |
361 |
(currentScale < sil.getMaxscale()); |
362 |
} |
363 |
} |
364 |
|
365 |
if (inScale) {
|
366 |
/**
|
367 |
* Querying about the envelope, we have to ask if geoExtent has
|
368 |
* the Envelope of the layer inside it.
|
369 |
*/
|
370 |
boolean inEnvelope = false; |
371 |
BoundaryBox mEnv = sil.getEnvelope(); |
372 |
|
373 |
Area mVentana = new Area((java.awt.Shape) geoServiceExtent); |
374 |
Rectangle2D rectCapa = new Rectangle2D.Double(mEnv.getXmin(), |
375 |
mEnv.getYmin(), mEnv.getXmax() - mEnv.getXmin(), |
376 |
mEnv.getYmax() - mEnv.getYmin()); |
377 |
|
378 |
inEnvelope = mVentana.intersects(rectCapa); |
379 |
|
380 |
/**
|
381 |
* If two conditions are true, we do the request
|
382 |
*/
|
383 |
|
384 |
if (inEnvelope) {
|
385 |
fields = "";
|
386 |
|
387 |
/**
|
388 |
* Get the Info request for a featureclass or raster layer
|
389 |
*/
|
390 |
double[] coords = { xReal, yReal }; |
391 |
double[] dists = { ratio * iServiceX, ratio * iServiceY }; |
392 |
sArcXML = ArcXMLImage.getInfoRequest(sil.getType(), |
393 |
idLayers.get(i).toString(), coords, dists, srs, |
394 |
si.getSeparators().getDs()); |
395 |
|
396 |
if (status.verbose) {
|
397 |
logger.debug("sArcXML = " + sArcXML);
|
398 |
} |
399 |
|
400 |
/**
|
401 |
* File with a layer info response
|
402 |
*/
|
403 |
if (sil.getType().equals(ServiceInfoTags.vLAYERTYPE_F)) {
|
404 |
request = requestF; |
405 |
} else {
|
406 |
request = requestI; |
407 |
} |
408 |
|
409 |
logger.info("Requesting layer \"" + sil.getName() +
|
410 |
"\" information");
|
411 |
|
412 |
File response = ArcImsDownloadUtils.doRequestPost(request,
|
413 |
sArcXML, "getElementInfo.xml");
|
414 |
|
415 |
/**
|
416 |
* Now we can parse the file to get the FIELDS element
|
417 |
*/
|
418 |
fields = parseFieldsInfoResponse(response); |
419 |
|
420 |
if (!fields.equals("")) { |
421 |
sb.append(ArcXML.getLayerHeaderInfoResponse( |
422 |
ids.get(i).toString(), status.getServiceInfo())); |
423 |
|
424 |
/**
|
425 |
* FIELDS element
|
426 |
*/
|
427 |
sb.append(fields.replaceAll("#", "_")); |
428 |
|
429 |
// sb.append("\t\t"+"<FIELDS #IY_PRE=\"1000\"
|
430 |
// #SHAPE#=\"[Geometry]\" #ID#=\"11\" />\r\n");
|
431 |
sb.append(ArcXML.getLayerFooterInfoResponse()); |
432 |
} |
433 |
|
434 |
} // Fin del if de ventana
|
435 |
else {
|
436 |
logger.info("Layer \"" + sil.getName() +
|
437 |
"\" is not shown at this envelope");
|
438 |
} |
439 |
} |
440 |
// Fin del if de escala
|
441 |
else {
|
442 |
logger.info("Layer \"" + sil.getName() +
|
443 |
"\" is not shown at this scale");
|
444 |
} |
445 |
} |
446 |
|
447 |
// Fin del for
|
448 |
sb.append("</FeatureInfoResponse>");
|
449 |
return sb.toString();
|
450 |
} |
451 |
|
452 |
/**
|
453 |
* Parse the xml data retrieved from the ArcIms, it will parse the ArcIms
|
454 |
* Features
|
455 |
* @see #getElementInfo(ArcImsStatus, int, int, int)
|
456 |
* @param f
|
457 |
* The XML file to parse to obtain the FIELDS element
|
458 |
* @return XML with FIELDS or BAND tags as a response to a getElementInfo
|
459 |
*/
|
460 |
private String parseFieldsInfoResponse(File f) { |
461 |
BufferedReader fi;
|
462 |
String buf;
|
463 |
StringBuffer fields = new StringBuffer(); |
464 |
String token = null; |
465 |
int l = 0; |
466 |
|
467 |
try {
|
468 |
fi = new BufferedReader(new FileReader(f)); |
469 |
|
470 |
while ((buf = fi.readLine()) != null) { |
471 |
l++; |
472 |
if ((buf.length() > 2) && |
473 |
(buf.substring(0, 1).compareTo("<") == 0)) { |
474 |
token = buf.substring(1); //,l.indexOf(GT)); |
475 |
|
476 |
if (token.startsWith("FIELDS")) { |
477 |
fields.append(buf + "");
|
478 |
} |
479 |
|
480 |
if (token.startsWith("BAND ")) { |
481 |
fields.append(buf + "");
|
482 |
} |
483 |
} |
484 |
} |
485 |
|
486 |
fi.close(); |
487 |
logger.debug("Parsed finidhed: " + l + " lines."); |
488 |
} catch (FileNotFoundException e) { |
489 |
e.printStackTrace(); |
490 |
} catch (IOException ie) { |
491 |
logger.error("ERROR. (" + l + "lines reeded)"); |
492 |
ie.printStackTrace(); |
493 |
} |
494 |
|
495 |
return fields.toString();
|
496 |
} |
497 |
|
498 |
/**
|
499 |
* <p>Builds a GetMap request that is sent to the ArcIms
|
500 |
* the response (image) will be redirect to the
|
501 |
* ArcIms client</p>
|
502 |
* @param status An @see ArcImsStatus object
|
503 |
* @return File The image requested (a map)
|
504 |
* @throws ArcImsException
|
505 |
* @throws ServerErrorException
|
506 |
*/
|
507 |
public File getMap(ArcImsStatus status) |
508 |
throws ArcImsException, ServerErrorException {
|
509 |
File img = null; |
510 |
String currentImageUrl = ""; |
511 |
|
512 |
try {
|
513 |
URL url = new URL(buildCapabilitiesRequest(status)); |
514 |
|
515 |
String request = ArcXMLImage.getMapRequest(status);
|
516 |
|
517 |
if (status.verbose) {
|
518 |
logger.debug(request); |
519 |
} |
520 |
|
521 |
logger.info("Requesting ArcIMS GetImage XML");
|
522 |
|
523 |
File response = ArcImsDownloadUtils.doRequestPost(url, request,
|
524 |
"getImage.xml");
|
525 |
|
526 |
try {
|
527 |
currentImageUrl = parseGetImageRequest(new FileReader(response)); |
528 |
|
529 |
//Control if not /output/blahblah has been passed
|
530 |
if (!currentImageUrl.startsWith("http://")) { |
531 |
String servlet = status.getServer();
|
532 |
int ind1 = servlet.indexOf("//"); |
533 |
int ind = servlet.indexOf("/", ind1 + 2); |
534 |
currentImageUrl = servlet.substring(0, ind) +
|
535 |
currentImageUrl; |
536 |
} |
537 |
} catch (FileNotFoundException e) { |
538 |
logger.error(e.getMessage(), e); |
539 |
throw new ArcImsException("Fichero remoto no encontrado"); |
540 |
} |
541 |
|
542 |
URL virtualURL = ArcImsDownloadUtils.getVirtualUrlFromStatus(status);
|
543 |
logger.info("Downloading ArcIMS image");
|
544 |
|
545 |
String[] urlSplitted = currentImageUrl.split("\\."); |
546 |
String extension = urlSplitted[urlSplitted.length - 1]; |
547 |
img = ArcImsDownloadUtils.downloadFile(new URL(currentImageUrl), |
548 |
virtualURL, "getImage." + extension);
|
549 |
|
550 |
// img =com.iver.andami.Utilities.downloadFile(new URL(currentImageUrl),"getImage");
|
551 |
if (img.length() == 0) { |
552 |
return null; |
553 |
} |
554 |
|
555 |
// response.delete();
|
556 |
} catch (MalformedURLException e) { |
557 |
logger.error(e.getMessage(), e); |
558 |
throw new ArcImsException("arcims_server_timeout"); |
559 |
} catch (ConnectException ce) { |
560 |
logger.error("Timed out error", ce);
|
561 |
throw new ArcImsException("arcims_server_timeout"); |
562 |
} catch (FileNotFoundException fe) { |
563 |
logger.error("FileNotFound Error", fe);
|
564 |
throw new ArcImsException("arcims_server_error"); |
565 |
} catch (IOException e) { |
566 |
logger.error("IO Error", e);
|
567 |
throw new ArcImsException("arcims_server_error"); |
568 |
} |
569 |
|
570 |
return img;
|
571 |
} |
572 |
|
573 |
/**
|
574 |
* Method that parses a GET_IMAGE request, sets the
|
575 |
* url to download the rendered image.
|
576 |
* @param fr
|
577 |
* @return @see org.gvsig.remoteClient.arcims.ArcImsProtImageHandler#getMap(ArcImsStatus)
|
578 |
* @throws ArcImsException
|
579 |
* @throws ServerErrorException
|
580 |
*/
|
581 |
private String parseGetImageRequest(Reader fr) |
582 |
throws ArcImsException, ServerErrorException {
|
583 |
String imageUrl = ""; |
584 |
int tag;
|
585 |
KXmlParser kxmlParser = new KXmlParser();
|
586 |
String value = null; |
587 |
|
588 |
try {
|
589 |
kxmlParser.setInput(fr); |
590 |
kxmlParser.nextTag(); |
591 |
|
592 |
if (kxmlParser.getEventType() != KXmlParser.END_DOCUMENT) {
|
593 |
kxmlParser.require(KXmlParser.START_TAG, null,
|
594 |
ServiceInfoTags.tARCXML); |
595 |
tag = kxmlParser.nextTag(); |
596 |
|
597 |
while (tag != KXmlParser.END_DOCUMENT) {
|
598 |
switch (tag) {
|
599 |
case KXmlParser.START_TAG:
|
600 |
|
601 |
if (kxmlParser.getName().compareTo(GetImageTags.OUTPUT) == 0) { |
602 |
value = kxmlParser.getAttributeValue("",
|
603 |
GetImageTags.URL); |
604 |
|
605 |
if (value != null) { |
606 |
imageUrl = value; |
607 |
} |
608 |
} else if (kxmlParser.getName() |
609 |
.compareTo(ServiceInfoTags.tERROR) == 0) {
|
610 |
throw new ServerErrorException( |
611 |
"Error parsing GET_IMAGE:\r\n" +
|
612 |
kxmlParser.nextText()); |
613 |
} |
614 |
|
615 |
break;
|
616 |
|
617 |
case KXmlParser.END_TAG:
|
618 |
break;
|
619 |
|
620 |
case KXmlParser.TEXT:
|
621 |
break;
|
622 |
} |
623 |
|
624 |
tag = kxmlParser.next(); |
625 |
} |
626 |
|
627 |
kxmlParser.require(KXmlParser.END_DOCUMENT, null, null); |
628 |
} |
629 |
} catch (XmlPullParserException parser_ex) {
|
630 |
logger.error(parser_ex.getMessage(), parser_ex); |
631 |
throw new ArcImsException("arcims_server_error"); |
632 |
} catch (IOException ioe) { |
633 |
logger.error(ioe.getMessage(), ioe); |
634 |
throw new ArcImsException("arcims_server_error"); |
635 |
} |
636 |
|
637 |
return imageUrl;
|
638 |
} |
639 |
|
640 |
/**
|
641 |
* Simple method to test if an ArcIMS server responses with an image
|
642 |
* of an specified format
|
643 |
* @param status
|
644 |
* @return
|
645 |
* @throws ArcImsException
|
646 |
*/
|
647 |
public boolean testFormat(ArcImsStatus status, String format) |
648 |
throws ArcImsException {
|
649 |
boolean resp = true; |
650 |
URL url;
|
651 |
|
652 |
try {
|
653 |
ServiceInformation si = status.getServiceInfo(); |
654 |
url = new URL(this.buildCapabilitiesRequest(status)); |
655 |
|
656 |
/**
|
657 |
* Build the custom request for this extent
|
658 |
*/
|
659 |
String request = ArcXMLImage.getCustomExtentRequest("", // ServiceInfo |
660 |
// SRS
|
661 |
null, // envelope |
662 |
"", // SRS of the view |
663 |
si.getSeparators().getDs(), // Decimal separator
|
664 |
null, // Image size |
665 |
format, si.getLayer(0).getId() // A valid Layer Id |
666 |
); |
667 |
|
668 |
if (status.verbose) {
|
669 |
logger.debug(request); |
670 |
} |
671 |
|
672 |
logger.info("Querying for a specific format");
|
673 |
|
674 |
// BufferedReader lector = ArcImsDownloadUtils.getRemoteReader(url,request);
|
675 |
File f = ArcImsDownloadUtils.doRequestPost(url, request,
|
676 |
"testFormat.xml");
|
677 |
BufferedReader lector = new BufferedReader(new FileReader(f)); |
678 |
|
679 |
/**
|
680 |
* Loop over the reader until it ends or an ERROR is found
|
681 |
*/
|
682 |
String lin = lector.readLine();
|
683 |
|
684 |
//The regular expression to match
|
685 |
String regex = ".*<" + ServiceInfoTags.tERROR + ".*</" + |
686 |
ServiceInfoTags.tERROR + ">.*";
|
687 |
|
688 |
do {
|
689 |
if (lin.matches(regex)) {
|
690 |
return false; |
691 |
} |
692 |
|
693 |
lin = lector.readLine(); |
694 |
} while (lin != null); |
695 |
} catch (MalformedURLException e) { |
696 |
logger.error(e.getMessage(), e); |
697 |
throw new ArcImsException("arcims_server_eror"); |
698 |
} catch (IOException e) { |
699 |
logger.error(e.getMessage(), e); |
700 |
throw new ArcImsException("arcims_server_eror"); |
701 |
} |
702 |
|
703 |
return resp;
|
704 |
} |
705 |
} |