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