svn-gvsig-desktop / branches / v2_0_0_prep / libraries / org.gvsig.arcims / src / org / gvsig / remoteclient / arcims / ArcImsProtocolHandler.java @ 32367
History | View | Annotate | Download (34.9 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.geom.Rectangle2D; |
32 |
import java.io.BufferedReader; |
33 |
import java.io.File; |
34 |
import java.io.FileInputStream; |
35 |
import java.io.FileNotFoundException; |
36 |
import java.io.FileReader; |
37 |
import java.io.IOException; |
38 |
import java.io.InputStreamReader; |
39 |
import java.io.Reader; |
40 |
import java.io.UnsupportedEncodingException; |
41 |
import java.net.ConnectException; |
42 |
import java.net.HttpURLConnection; |
43 |
import java.net.MalformedURLException; |
44 |
import java.net.URL; |
45 |
import java.text.DecimalFormatSymbols; |
46 |
import java.util.ArrayList; |
47 |
import java.util.List; |
48 |
import java.util.Locale; |
49 |
import java.util.TreeMap; |
50 |
import java.util.Vector; |
51 |
|
52 |
import org.gvsig.fmap.geom.Geometry; |
53 |
import org.gvsig.fmap.mapcontext.rendering.legend.ILegend; |
54 |
import org.gvsig.remoteclient.arcims.exceptions.ArcImsException; |
55 |
import org.gvsig.remoteclient.arcims.styling.renderers.ArcImsRendererFactory; |
56 |
import org.gvsig.remoteclient.arcims.styling.renderers.Renderer; |
57 |
import org.gvsig.remoteclient.arcims.utils.ArcImsDownloadUtils; |
58 |
import org.gvsig.remoteclient.arcims.utils.CatalogInfoTags; |
59 |
import org.gvsig.remoteclient.arcims.utils.FieldInformation; |
60 |
import org.gvsig.remoteclient.arcims.utils.GetVariables; |
61 |
import org.gvsig.remoteclient.arcims.utils.ServiceInfoTags; |
62 |
import org.gvsig.remoteclient.arcims.utils.ServiceInformation; |
63 |
import org.gvsig.remoteclient.arcims.utils.ServiceInformationLayer; |
64 |
import org.gvsig.remoteclient.arcims.utils.ServiceInformationLayerFeatures; |
65 |
import org.gvsig.remoteclient.arcims.utils.ServiceInformationLayerImage; |
66 |
import org.gvsig.remoteclient.utils.BoundaryBox; |
67 |
import org.kxml2.io.KXmlParser; |
68 |
import org.slf4j.Logger; |
69 |
import org.slf4j.LoggerFactory; |
70 |
import org.xmlpull.v1.XmlPullParserException; |
71 |
|
72 |
/**
|
73 |
* Abstract class that represents handlers to comunicate via ArcIms protocol
|
74 |
*
|
75 |
* @author jsanz
|
76 |
* @author jcarrasco
|
77 |
* @author vsanjaime version 2.0
|
78 |
*
|
79 |
*/
|
80 |
public abstract class ArcImsProtocolHandler { |
81 |
|
82 |
public static final double INCHES = .02540005; |
83 |
private static Logger logger = LoggerFactory |
84 |
.getLogger(ArcImsProtocolHandler.class.getName()); |
85 |
|
86 |
/**
|
87 |
* Protocol handler name
|
88 |
*/
|
89 |
private String name; |
90 |
|
91 |
/**
|
92 |
* protocol handler version
|
93 |
*/
|
94 |
private String version; |
95 |
|
96 |
/**
|
97 |
* host of the ArcIms to connect
|
98 |
*/
|
99 |
private String host; |
100 |
|
101 |
/**
|
102 |
* port number of the comunication channel of the ArcIms to connect
|
103 |
*/
|
104 |
private String port; |
105 |
private String service; |
106 |
|
107 |
/**
|
108 |
* ArcIms metadata (list of services availables)
|
109 |
*/
|
110 |
private ServiceInformation serviceInfo;
|
111 |
|
112 |
/**
|
113 |
* Layers
|
114 |
*/
|
115 |
public TreeMap layers; |
116 |
public Vector<String> srs; |
117 |
|
118 |
/**
|
119 |
* Constructor
|
120 |
*/
|
121 |
public ArcImsProtocolHandler() {
|
122 |
this.version = "4.0.1"; |
123 |
this.name = "ArcIms4.0.1"; |
124 |
this.serviceInfo = new ServiceInformation(); |
125 |
this.layers = new TreeMap(); |
126 |
} |
127 |
|
128 |
/**
|
129 |
* Parse the xml data retrieved from the ArcIms, it will parse the ArcIms
|
130 |
* Capabilities
|
131 |
*
|
132 |
* @param f
|
133 |
* the XML file to parse to obtain the ServiceInfo
|
134 |
* @throws ArcImsException
|
135 |
*
|
136 |
*/
|
137 |
public ServiceInformation parseServiceInfo(ServiceInformation si, File f) |
138 |
throws ArcImsException {
|
139 |
Reader reader = null; |
140 |
|
141 |
ServiceInformation my_si = si; |
142 |
|
143 |
try {
|
144 |
FileInputStream fis = new FileInputStream(f); |
145 |
InputStreamReader isr = new InputStreamReader(fis, "UTF-8"); |
146 |
BufferedReader br = new BufferedReader(isr); |
147 |
reader = br; |
148 |
} catch (FileNotFoundException e) { |
149 |
logger.error(e.getMessage(), e); |
150 |
} catch (UnsupportedEncodingException e) { |
151 |
logger.error(e.getMessage(), e); |
152 |
} |
153 |
|
154 |
int tag;
|
155 |
KXmlParser kxmlParser = null;
|
156 |
kxmlParser = new KXmlParser();
|
157 |
|
158 |
try {
|
159 |
kxmlParser.setInput(reader); |
160 |
kxmlParser.nextTag(); |
161 |
|
162 |
if (kxmlParser.getEventType() != KXmlParser.END_DOCUMENT) {
|
163 |
kxmlParser.require(KXmlParser.START_TAG, null,
|
164 |
ServiceInfoTags.tARCXML); |
165 |
tag = kxmlParser.nextTag(); |
166 |
|
167 |
while (tag != KXmlParser.END_DOCUMENT) {
|
168 |
switch (tag) {
|
169 |
case KXmlParser.START_TAG:
|
170 |
|
171 |
String name = kxmlParser.getName();
|
172 |
|
173 |
if (name.compareTo(ServiceInfoTags.tENVIRONMENT) == 0) { |
174 |
parseEnvironmentTag(my_si, kxmlParser); |
175 |
} else if (name.compareTo(ServiceInfoTags.tPROPERTIES) == 0) { |
176 |
parsePropertiesTag(my_si, kxmlParser); |
177 |
} else if (name.compareTo(ServiceInfoTags.tLAYERINFO) == 0) { |
178 |
parseLayerInfoTag(my_si, kxmlParser); |
179 |
} else if (name.compareTo(ServiceInfoTags.tERROR) == 0) { |
180 |
logger.error("Error parsing GET_SERVICE_INFO:\r\n"
|
181 |
+ kxmlParser.nextText()); |
182 |
throw new ArcImsException("arcims_catalog_error"); |
183 |
} |
184 |
|
185 |
break;
|
186 |
|
187 |
case KXmlParser.END_TAG:
|
188 |
break;
|
189 |
|
190 |
case KXmlParser.TEXT:
|
191 |
break;
|
192 |
} |
193 |
|
194 |
tag = kxmlParser.next(); |
195 |
} |
196 |
|
197 |
kxmlParser.require(KXmlParser.END_DOCUMENT, null, null); |
198 |
} |
199 |
} catch (XmlPullParserException parser_ex) {
|
200 |
logger.error("Parser error", parser_ex);
|
201 |
throw new ArcImsException("parse_error"); |
202 |
} catch (FileNotFoundException fe) { |
203 |
logger.error("FileNotFound Error", fe);
|
204 |
throw new ArcImsException("arcims_server_error"); |
205 |
} catch (IOException e) { |
206 |
logger.error("IO Error", e);
|
207 |
throw new ArcImsException("arcims_server_error"); |
208 |
} catch (NumberFormatException nfe) { |
209 |
logger.warn("NumberFormat Error");
|
210 |
|
211 |
char dsTemp = my_si.getSeparators().getDs();
|
212 |
|
213 |
if (dsTemp == '.') { |
214 |
logger.warn("NumberFormat Error, changing . by ,");
|
215 |
my_si.getSeparators().setDs(',');
|
216 |
my_si = this.parseServiceInfo(my_si, f);
|
217 |
} else {
|
218 |
if (dsTemp == ',') { |
219 |
logger.warn("NumberFormat Error, changing , by .");
|
220 |
my_si.getSeparators().setDs('.');
|
221 |
my_si = this.parseServiceInfo(my_si, f);
|
222 |
} else {
|
223 |
logger |
224 |
.warn("NumberFormat Error: No Decimal Separator found");
|
225 |
throw new ArcImsException("arcims_decimal_error"); |
226 |
} |
227 |
} |
228 |
|
229 |
} finally {
|
230 |
} |
231 |
|
232 |
return my_si;
|
233 |
} |
234 |
|
235 |
/**
|
236 |
* <p>
|
237 |
* Parses the Environment Information
|
238 |
* </p>
|
239 |
*
|
240 |
* @param my_si
|
241 |
* @param parser
|
242 |
* A KXmlParser object to parse
|
243 |
* @throws IOException
|
244 |
* @throws XmlPullParserException
|
245 |
*/
|
246 |
private void parseEnvironmentTag(ServiceInformation my_si, KXmlParser parser) |
247 |
throws IOException, XmlPullParserException { |
248 |
int currentTag;
|
249 |
boolean end = false; |
250 |
ServiceInformation serviceInfo = my_si; |
251 |
|
252 |
parser |
253 |
.require(KXmlParser.START_TAG, null,
|
254 |
ServiceInfoTags.tENVIRONMENT); |
255 |
currentTag = parser.next(); |
256 |
|
257 |
while (!end) {
|
258 |
switch (currentTag) {
|
259 |
case KXmlParser.START_TAG:
|
260 |
|
261 |
/*
|
262 |
* Parse the LOCALE tag
|
263 |
*/
|
264 |
if (parser.getName().compareTo(ServiceInfoTags.tLOCALE) == 0) { |
265 |
String language = null; |
266 |
language = parser.getAttributeValue("",
|
267 |
ServiceInfoTags.aLANGUAGE); |
268 |
|
269 |
if (language != null) { |
270 |
serviceInfo.getLocale().setLanguage(language); |
271 |
} |
272 |
|
273 |
String country = null; |
274 |
country = parser.getAttributeValue("",
|
275 |
ServiceInfoTags.aCOUNTRY); |
276 |
|
277 |
if (country != null) { |
278 |
serviceInfo.getLocale().setCountry(country); |
279 |
} |
280 |
} |
281 |
/*
|
282 |
* Parse the UIFONT tag
|
283 |
*/
|
284 |
else if (parser.getName().compareTo(ServiceInfoTags.tUIFONT) == 0) { |
285 |
String name = null; |
286 |
name = parser.getAttributeValue("", ServiceInfoTags.aNAME);
|
287 |
|
288 |
if (name != null) { |
289 |
serviceInfo.getUifont().setName(name); |
290 |
} |
291 |
|
292 |
String color = null; |
293 |
color = parser |
294 |
.getAttributeValue("", ServiceInfoTags.aCOLOR);
|
295 |
|
296 |
if (color != null) { |
297 |
serviceInfo.getUifont().setColor(color); |
298 |
} |
299 |
|
300 |
String size = null; |
301 |
size = parser.getAttributeValue("", ServiceInfoTags.aSIZE);
|
302 |
|
303 |
if (name != null) { |
304 |
serviceInfo.getUifont().setSize(size); |
305 |
} |
306 |
|
307 |
String style = null; |
308 |
style = parser |
309 |
.getAttributeValue("", ServiceInfoTags.aSTYLE);
|
310 |
|
311 |
if (style != null) { |
312 |
serviceInfo.getUifont().setStyle(style); |
313 |
} |
314 |
} |
315 |
/*
|
316 |
* Parse the SEPARATORS tag
|
317 |
*/
|
318 |
else if (parser.getName() |
319 |
.compareTo(ServiceInfoTags.tSEPARATORS) == 0) {
|
320 |
String ts = null; |
321 |
ts = parser.getAttributeValue("", ServiceInfoTags.aTS);
|
322 |
|
323 |
if (ts != null) { |
324 |
serviceInfo.getSeparators().setTs(ts); |
325 |
} |
326 |
|
327 |
String cs = null; |
328 |
cs = parser.getAttributeValue("", ServiceInfoTags.aCS);
|
329 |
|
330 |
if (cs != null) { |
331 |
serviceInfo.getSeparators().setCs(cs); |
332 |
} |
333 |
} |
334 |
/*
|
335 |
* Parse the SCREEN tag
|
336 |
*/
|
337 |
else if (parser.getName().compareTo(ServiceInfoTags.tSCREEN) == 0) { |
338 |
String dpi = null; |
339 |
dpi = parser.getAttributeValue("", ServiceInfoTags.aDPI);
|
340 |
|
341 |
if (dpi != null) { |
342 |
serviceInfo.setScreen_dpi(Integer.parseInt(dpi));
|
343 |
serviceInfo.setDpiAssumed(false);
|
344 |
} |
345 |
} |
346 |
/*
|
347 |
* Parse the IMAGELIMIT tag
|
348 |
*/
|
349 |
else if (parser.getName() |
350 |
.compareTo(ServiceInfoTags.tIMAGELIMIT) == 0) {
|
351 |
String pixelcount = null; |
352 |
pixelcount = parser.getAttributeValue("",
|
353 |
ServiceInfoTags.aPIXELCOUNT); |
354 |
|
355 |
if (pixelcount != null) { |
356 |
serviceInfo.setImagelimit_pixelcount(pixelcount); |
357 |
} |
358 |
} |
359 |
|
360 |
break;
|
361 |
|
362 |
case KXmlParser.END_TAG:
|
363 |
|
364 |
if (parser.getName().compareTo(ServiceInfoTags.tENVIRONMENT) == 0) { |
365 |
end = true;
|
366 |
} |
367 |
|
368 |
break;
|
369 |
|
370 |
case KXmlParser.TEXT:
|
371 |
break;
|
372 |
} |
373 |
|
374 |
if (!end) {
|
375 |
currentTag = parser.next(); |
376 |
} |
377 |
} |
378 |
|
379 |
/*
|
380 |
* Sets de decimal separator
|
381 |
*/
|
382 |
if (serviceInfo.getSeparators().getDs() == 'c') { |
383 |
String lang = this.serviceInfo.getLocale().getLanguage(); |
384 |
String coun = this.serviceInfo.getLocale().getCountry(); |
385 |
Locale local = new Locale(lang, coun); |
386 |
DecimalFormatSymbols dfs = new DecimalFormatSymbols(local); |
387 |
serviceInfo.getSeparators().setDs(dfs.getDecimalSeparator()); |
388 |
} |
389 |
|
390 |
parser.require(KXmlParser.END_TAG, null, ServiceInfoTags.tENVIRONMENT);
|
391 |
} |
392 |
|
393 |
/**
|
394 |
* <p>
|
395 |
* Parses the Properties Information
|
396 |
* </p>
|
397 |
*
|
398 |
* @param my_si
|
399 |
* @param parser
|
400 |
* A KXmlParser object to parse
|
401 |
* @throws IOException
|
402 |
* @throws XmlPullParserException
|
403 |
*/
|
404 |
private void parsePropertiesTag(ServiceInformation my_si, KXmlParser parser) |
405 |
throws IOException, XmlPullParserException, NumberFormatException { |
406 |
int currentTag;
|
407 |
boolean end = false; |
408 |
|
409 |
ServiceInformation serviceInfo = my_si; |
410 |
|
411 |
parser.require(KXmlParser.START_TAG, null, ServiceInfoTags.tPROPERTIES);
|
412 |
currentTag = parser.next(); |
413 |
|
414 |
char ds = my_si.getSeparators().getDs();
|
415 |
|
416 |
while (!end) {
|
417 |
switch (currentTag) {
|
418 |
case KXmlParser.START_TAG:
|
419 |
|
420 |
/*
|
421 |
* Parse the ENVELOPE tag
|
422 |
*/
|
423 |
if (parser.getName().compareTo(ServiceInfoTags.tENVELOPE) == 0) { |
424 |
BoundaryBox parseEnvelope = new BoundaryBox();
|
425 |
|
426 |
String value = null; |
427 |
value = parser.getAttributeValue("", ServiceInfoTags.aMINX);
|
428 |
|
429 |
if (value != null) { |
430 |
if (ds != '.') { |
431 |
value = value.replace(ds, '.');
|
432 |
} |
433 |
|
434 |
parseEnvelope.setXmin(Double.parseDouble(value));
|
435 |
} |
436 |
|
437 |
value = null;
|
438 |
value = parser.getAttributeValue("", ServiceInfoTags.aMINY);
|
439 |
|
440 |
if (value != null) { |
441 |
if (ds != '.') { |
442 |
value = value.replace(ds, '.');
|
443 |
} |
444 |
|
445 |
parseEnvelope.setYmin(Double.parseDouble(value));
|
446 |
} |
447 |
|
448 |
value = null;
|
449 |
value = parser.getAttributeValue("", ServiceInfoTags.aMAXY);
|
450 |
|
451 |
if (value != null) { |
452 |
if (ds != '.') { |
453 |
value = value.replace(ds, '.');
|
454 |
} |
455 |
|
456 |
parseEnvelope.setYmax(Double.parseDouble(value));
|
457 |
} |
458 |
|
459 |
value = null;
|
460 |
value = parser.getAttributeValue("", ServiceInfoTags.aMAXX);
|
461 |
|
462 |
if (value != null) { |
463 |
if (ds != '.') { |
464 |
value = value.replace(ds, '.');
|
465 |
} |
466 |
|
467 |
parseEnvelope.setXmax(Double.parseDouble(value));
|
468 |
} |
469 |
|
470 |
/**
|
471 |
* The envelope could be a Initial_Extent or Extent_limit,
|
472 |
*
|
473 |
* @see ServiceInformation#envelope and @see
|
474 |
* ServiceInformation#envelopeEL
|
475 |
*/
|
476 |
if ((parser.getAttributeValue("", ServiceInfoTags.aNAME) != null) |
477 |
&& (parser.getAttributeValue("",
|
478 |
ServiceInfoTags.aNAME).compareTo( |
479 |
ServiceInfoTags.aENVELOPEEL) == 0)) {
|
480 |
serviceInfo.setEnvelopeEL(parseEnvelope); |
481 |
} else {
|
482 |
serviceInfo.setEnvelope(parseEnvelope); |
483 |
} |
484 |
} |
485 |
/*
|
486 |
* Parse the MAPUNITS tag
|
487 |
*/
|
488 |
else if (parser.getName().compareTo(ServiceInfoTags.tMAPUNITS) == 0) { |
489 |
String value = null; |
490 |
value = parser |
491 |
.getAttributeValue("", ServiceInfoTags.aUNITS);
|
492 |
|
493 |
if (value != null) { |
494 |
serviceInfo.setMapunits(value); |
495 |
} |
496 |
} |
497 |
/*
|
498 |
* Parse the FEATURECOORDSYS tag
|
499 |
*/
|
500 |
else if (parser.getName().compareTo( |
501 |
ServiceInfoTags.tFEATURECOORDSYS) == 0) {
|
502 |
String value = null; |
503 |
value = parser.getAttributeValue("", ServiceInfoTags.aID);
|
504 |
|
505 |
if (value != null) { |
506 |
serviceInfo.setFeaturecoordsys(value); |
507 |
serviceInfo.setSrsAssumed(false);
|
508 |
} |
509 |
} |
510 |
|
511 |
break;
|
512 |
|
513 |
case KXmlParser.END_TAG:
|
514 |
|
515 |
if (parser.getName().compareTo(ServiceInfoTags.tPROPERTIES) == 0) { |
516 |
end = true;
|
517 |
} |
518 |
|
519 |
break;
|
520 |
|
521 |
case KXmlParser.TEXT:
|
522 |
break;
|
523 |
} |
524 |
|
525 |
if (!end) {
|
526 |
currentTag = parser.next(); |
527 |
} |
528 |
} |
529 |
|
530 |
parser.require(KXmlParser.END_TAG, null, ServiceInfoTags.tPROPERTIES);
|
531 |
|
532 |
if (serviceInfo.getFeaturecoordsys().compareTo("") == 0) { |
533 |
serviceInfo.setSrsAssumed(true);
|
534 |
} |
535 |
|
536 |
// else
|
537 |
// System.out.println("JS\t"+serviceInfo.featurecoordsys);
|
538 |
} |
539 |
|
540 |
/**
|
541 |
* <p>
|
542 |
* Parses the LayerInfo Information
|
543 |
* </p>
|
544 |
*
|
545 |
* @param my_si
|
546 |
* @param parser
|
547 |
* A KXmlParser object to parse
|
548 |
* @throws IOException
|
549 |
* @throws XmlPullParserException
|
550 |
* @throws ArcImsException
|
551 |
*/
|
552 |
private void parseLayerInfoTag(ServiceInformation my_si, KXmlParser parser) |
553 |
throws IOException, XmlPullParserException, NumberFormatException, |
554 |
ArcImsException { |
555 |
String value = null; |
556 |
String type = null; |
557 |
|
558 |
ServiceInformation serviceInfo = my_si; |
559 |
|
560 |
char ds = serviceInfo.getSeparators().getDs();
|
561 |
|
562 |
// double ratio =
|
563 |
// serviceInfo.screen_dpi/ArcImsProtocolHandler.INCHES;
|
564 |
ServiceInformationLayer sil; |
565 |
|
566 |
type = parser.getAttributeValue("", ServiceInfoTags.aTYPE);
|
567 |
|
568 |
/**
|
569 |
* This way, we can instantiate the proper class
|
570 |
*/
|
571 |
if (type.compareToIgnoreCase(ServiceInfoTags.vLAYERTYPE_F) == 0) { |
572 |
sil = new ServiceInformationLayerFeatures(""); |
573 |
} else {
|
574 |
sil = new ServiceInformationLayerImage();
|
575 |
} |
576 |
|
577 |
/**
|
578 |
* A this time we can continue parsing
|
579 |
*/
|
580 |
value = parser.getAttributeValue("", ServiceInfoTags.aID);
|
581 |
|
582 |
if (value != null) { |
583 |
sil.setId(value); |
584 |
} |
585 |
|
586 |
value = parser.getAttributeValue("", ServiceInfoTags.aVISIBLE);
|
587 |
|
588 |
if (value != null) { |
589 |
sil.setVisible(value); |
590 |
} |
591 |
|
592 |
value = parser.getAttributeValue("", ServiceInfoTags.aMAXSCALE);
|
593 |
|
594 |
if (value != null) { |
595 |
if (ds != '.') { |
596 |
value = value.replace(ds, '.');
|
597 |
} |
598 |
|
599 |
sil.setMaxscale(Double.parseDouble(value));
|
600 |
} |
601 |
|
602 |
value = parser.getAttributeValue("", ServiceInfoTags.aMINSCALE);
|
603 |
|
604 |
if (value != null) { |
605 |
if (ds != '.') { |
606 |
value = value.replace(ds, '.');
|
607 |
} |
608 |
|
609 |
sil.setMinscale(Double.parseDouble(value));
|
610 |
} |
611 |
|
612 |
value = parser.getAttributeValue("", ServiceInfoTags.aNAME);
|
613 |
|
614 |
if (value != null) { |
615 |
sil.setName(value); |
616 |
} |
617 |
|
618 |
/**
|
619 |
* At this time, we can go inside the element to retrieve other child
|
620 |
* elements as ENVELOPE
|
621 |
*/
|
622 |
int currentTag;
|
623 |
boolean end = false; |
624 |
|
625 |
currentTag = parser.next(); |
626 |
|
627 |
while (!end) {
|
628 |
switch (currentTag) {
|
629 |
case KXmlParser.START_TAG:
|
630 |
|
631 |
/**
|
632 |
* Parse the ENVELOPE child element
|
633 |
*/
|
634 |
if (parser.getName().compareTo(ServiceInfoTags.tENVELOPE) == 0) { |
635 |
value = null;
|
636 |
value = parser.getAttributeValue("", ServiceInfoTags.aMINX);
|
637 |
|
638 |
if (value != null) { |
639 |
if (ds != '.') { |
640 |
value = value.replace(ds, '.');
|
641 |
} |
642 |
|
643 |
sil.getEnvelope().setXmin(Double.parseDouble(value));
|
644 |
} |
645 |
|
646 |
value = null;
|
647 |
value = parser.getAttributeValue("", ServiceInfoTags.aMINY);
|
648 |
|
649 |
if (value != null) { |
650 |
if (ds != '.') { |
651 |
value = value.replace(ds, '.');
|
652 |
} |
653 |
|
654 |
sil.getEnvelope().setYmin(Double.parseDouble(value));
|
655 |
} |
656 |
|
657 |
value = null;
|
658 |
value = parser.getAttributeValue("", ServiceInfoTags.aMAXX);
|
659 |
|
660 |
if (value != null) { |
661 |
if (ds != '.') { |
662 |
value = value.replace(ds, '.');
|
663 |
} |
664 |
|
665 |
sil.getEnvelope().setXmax(Double.parseDouble(value));
|
666 |
} |
667 |
|
668 |
value = null;
|
669 |
value = parser.getAttributeValue("", ServiceInfoTags.aMAXY);
|
670 |
|
671 |
if (value != null) { |
672 |
if (ds != '.') { |
673 |
value = value.replace(ds, '.');
|
674 |
} |
675 |
|
676 |
sil.getEnvelope().setYmax(Double.parseDouble(value));
|
677 |
} |
678 |
} |
679 |
|
680 |
/**
|
681 |
* Parse FCLASS and FIELD child element if Layer is of type
|
682 |
* LAYERTYPE_F
|
683 |
*
|
684 |
* @see org.gvsig.remoteClient.arcims.utils.ServiceInfoTags#LAYERTYPE_F
|
685 |
*/
|
686 |
if (type.compareToIgnoreCase(ServiceInfoTags.vLAYERTYPE_F) == 0) { |
687 |
ServiceInformationLayerFeatures silf = (ServiceInformationLayerFeatures) sil; |
688 |
|
689 |
if (parser.getName().compareTo(ServiceInfoTags.tFCLASS) == 0) { |
690 |
// FCLASS element
|
691 |
value = null;
|
692 |
value = parser.getAttributeValue("",
|
693 |
ServiceInfoTags.aTYPE); |
694 |
|
695 |
if (value != null) { |
696 |
silf.setFclasstype(value); |
697 |
} |
698 |
} else if (parser.getName().compareTo( |
699 |
ServiceInfoTags.tFIELD) == 0) {
|
700 |
// FIELD element
|
701 |
FieldInformation fieldInfo = new FieldInformation();
|
702 |
|
703 |
value = null;
|
704 |
value = parser.getAttributeValue("",
|
705 |
ServiceInfoTags.aNAME); |
706 |
|
707 |
if (value != null) { |
708 |
fieldInfo.setName(value); |
709 |
} |
710 |
|
711 |
value = null;
|
712 |
value = parser.getAttributeValue("",
|
713 |
ServiceInfoTags.aTYPE); |
714 |
|
715 |
if (value != null) { |
716 |
fieldInfo.setType(Integer.parseInt(value));
|
717 |
} |
718 |
|
719 |
value = null;
|
720 |
value = parser.getAttributeValue("",
|
721 |
ServiceInfoTags.aPRECISION); |
722 |
|
723 |
if (value != null) { |
724 |
fieldInfo.setPrecision(Integer.parseInt(value));
|
725 |
} |
726 |
|
727 |
value = null;
|
728 |
value = parser.getAttributeValue("",
|
729 |
ServiceInfoTags.aSIZE); |
730 |
|
731 |
if (value != null) { |
732 |
fieldInfo.setSize(Integer.parseInt(value));
|
733 |
} |
734 |
|
735 |
/*
|
736 |
* Now we can add the Field Information into the vector
|
737 |
*/
|
738 |
silf.addFieldInformation(fieldInfo); |
739 |
} |
740 |
/**
|
741 |
* Parse ArcIMS Symbology definition in a separate private
|
742 |
* method
|
743 |
*/
|
744 |
else if (ArcImsRendererFactory.isRenderer(parser.getName())) { |
745 |
// Get FConstant type
|
746 |
String fclasstype = silf.getFclasstype();
|
747 |
int ftype = getFType(fclasstype);
|
748 |
|
749 |
// Get a factory instance
|
750 |
ArcImsRendererFactory airf = new ArcImsRendererFactory(
|
751 |
ftype); |
752 |
|
753 |
// Get the main render
|
754 |
Renderer render = airf.getRenderer(parser);
|
755 |
|
756 |
// Assign it to the layer
|
757 |
silf.setLayerMainRenderer(render); |
758 |
} |
759 |
} |
760 |
|
761 |
break;
|
762 |
|
763 |
case KXmlParser.END_TAG:
|
764 |
|
765 |
if (parser.getName().compareTo(ServiceInfoTags.tLAYERINFO) == 0) { |
766 |
end = true;
|
767 |
} |
768 |
|
769 |
break;
|
770 |
|
771 |
case KXmlParser.TEXT:
|
772 |
break;
|
773 |
} |
774 |
|
775 |
if (!end) {
|
776 |
currentTag = parser.next(); |
777 |
} |
778 |
} |
779 |
|
780 |
/**
|
781 |
* At the end, we can add the layer to the vector of ServicInformation
|
782 |
* layers
|
783 |
*/
|
784 |
serviceInfo.addLayer(sil); |
785 |
} |
786 |
|
787 |
/**
|
788 |
* Converts ArcIMS feature type to a FConstant value
|
789 |
*
|
790 |
* @param fclasstype
|
791 |
* @return
|
792 |
*/
|
793 |
public static int getFType(String fclasstype) { |
794 |
if (fclasstype.equals(ServiceInfoTags.aPOLYGON)) {
|
795 |
return Geometry.TYPES.SURFACE;
|
796 |
} |
797 |
|
798 |
if (fclasstype.equals(ServiceInfoTags.aPOLYLINE)) {
|
799 |
return Geometry.TYPES.MULTICURVE;
|
800 |
} |
801 |
|
802 |
if (fclasstype.equals(ServiceInfoTags.aMULTIPOINT)) {
|
803 |
return Geometry.TYPES.MULTIPOINT;
|
804 |
} |
805 |
|
806 |
return Geometry.TYPES.NULL;
|
807 |
} |
808 |
|
809 |
/**
|
810 |
* Method to parse a request to obtain the Extent of a Service
|
811 |
*
|
812 |
* @param reader
|
813 |
* @param ds
|
814 |
* the Decimal Separator
|
815 |
* @return Rectangle with the boundary box of the Service
|
816 |
* @throws ArcImsException
|
817 |
*/
|
818 |
protected Rectangle2D parseEnvelopeTag(FileReader reader, char ds) |
819 |
throws ArcImsException {
|
820 |
BoundaryBox parseEnvelope = new BoundaryBox();
|
821 |
|
822 |
// char ds = this.serviceInfo.separators.ds;
|
823 |
try {
|
824 |
KXmlParser parser = new KXmlParser();
|
825 |
parser.setInput(reader); |
826 |
|
827 |
int currentTag;
|
828 |
boolean end = false; |
829 |
|
830 |
// parser.require(KXmlParser.START_TAG, null,
|
831 |
// ServiceInfoTags.ARCXML);
|
832 |
currentTag = parser.next(); |
833 |
|
834 |
while (!end) {
|
835 |
switch (currentTag) {
|
836 |
case KXmlParser.START_TAG:
|
837 |
|
838 |
/*
|
839 |
* Parse the ENVELOPE tag
|
840 |
*/
|
841 |
if (parser.getName().compareTo(ServiceInfoTags.tENVELOPE) == 0) { |
842 |
parseEnvelope = parseEnvelope(parser, ds); |
843 |
} else if (parser.getName().compareTo( |
844 |
ServiceInfoTags.tERROR) == 0) {
|
845 |
logger.error("Error requesting Service Extent:\r\n"
|
846 |
+ parser.nextText()); |
847 |
throw new ArcImsException("arcims_extent_error"); |
848 |
} |
849 |
|
850 |
break;
|
851 |
|
852 |
case KXmlParser.END_TAG:
|
853 |
|
854 |
if (parser.getName().compareTo(ServiceInfoTags.tARCXML) == 0) { |
855 |
end = true;
|
856 |
} |
857 |
|
858 |
break;
|
859 |
|
860 |
case KXmlParser.TEXT:
|
861 |
break;
|
862 |
} |
863 |
|
864 |
if (!end) {
|
865 |
currentTag = parser.next(); |
866 |
} |
867 |
} |
868 |
} catch (XmlPullParserException parser_ex) {
|
869 |
parser_ex.printStackTrace(); |
870 |
} catch (ConnectException ce) { |
871 |
logger.error("Timed out error", ce);
|
872 |
throw new ArcImsException("arcims_server_timeout"); |
873 |
} catch (FileNotFoundException fe) { |
874 |
logger.error("FileNotFound Error", fe);
|
875 |
throw new ArcImsException("arcims_server_error"); |
876 |
} catch (IOException e) { |
877 |
logger.error("IO Error", e);
|
878 |
throw new ArcImsException("arcims_server_error"); |
879 |
} |
880 |
|
881 |
/*
|
882 |
* At the end, we convert the BoundaryBox to a Rectangle2D
|
883 |
*/
|
884 |
Rectangle2D rect = new Rectangle2D.Double(); |
885 |
|
886 |
rect.setFrameFromDiagonal(parseEnvelope.getXmin(), parseEnvelope |
887 |
.getYmin(), parseEnvelope.getXmax(), parseEnvelope.getYmax()); |
888 |
|
889 |
return rect;
|
890 |
} |
891 |
|
892 |
/**
|
893 |
* Static method to create a BoundaryBox from a ENVELOPE tag.
|
894 |
*
|
895 |
* @param parser
|
896 |
* @param ds
|
897 |
* @return
|
898 |
*/
|
899 |
protected static BoundaryBox parseEnvelope(KXmlParser parser, char ds) { |
900 |
BoundaryBox parseEnvelope = new BoundaryBox();
|
901 |
|
902 |
String value = null; |
903 |
value = parser.getAttributeValue("", ServiceInfoTags.aMINX);
|
904 |
|
905 |
if (value != null) { |
906 |
if (ds != '.') { |
907 |
value = value.replace(ds, '.');
|
908 |
} |
909 |
|
910 |
parseEnvelope.setXmin(Double.parseDouble(value));
|
911 |
} |
912 |
|
913 |
value = null;
|
914 |
value = parser.getAttributeValue("", ServiceInfoTags.aMINY);
|
915 |
|
916 |
if (value != null) { |
917 |
if (ds != '.') { |
918 |
value = value.replace(ds, '.');
|
919 |
} |
920 |
|
921 |
parseEnvelope.setYmin(Double.parseDouble(value));
|
922 |
} |
923 |
|
924 |
value = null;
|
925 |
value = parser.getAttributeValue("", ServiceInfoTags.aMAXY);
|
926 |
|
927 |
if (value != null) { |
928 |
if (ds != '.') { |
929 |
value = value.replace(ds, '.');
|
930 |
} |
931 |
|
932 |
parseEnvelope.setYmax(Double.parseDouble(value));
|
933 |
} |
934 |
|
935 |
value = null;
|
936 |
value = parser.getAttributeValue("", ServiceInfoTags.aMAXX);
|
937 |
|
938 |
if (value != null) { |
939 |
if (ds != '.') { |
940 |
value = value.replace(ds, '.');
|
941 |
} |
942 |
|
943 |
parseEnvelope.setXmax(Double.parseDouble(value));
|
944 |
} |
945 |
|
946 |
return parseEnvelope;
|
947 |
} |
948 |
|
949 |
/**
|
950 |
* Abstract method to retrieve a valid XML of a Query By Point request
|
951 |
*
|
952 |
* @param status
|
953 |
* @return Vallid XML to build the Element Info GUI
|
954 |
* @throws ArcImsException
|
955 |
*/
|
956 |
|
957 |
// public abstract void getMap(ArcImsStatus status);
|
958 |
public abstract String getElementInfo(ArcImsStatus status, int x, int y, |
959 |
int featureCount) throws ArcImsException; |
960 |
|
961 |
/**
|
962 |
* get Sevice Name
|
963 |
*
|
964 |
* @return
|
965 |
*/
|
966 |
public String getName() { |
967 |
return name;
|
968 |
} |
969 |
|
970 |
/**
|
971 |
* get service version
|
972 |
*
|
973 |
* @return
|
974 |
*/
|
975 |
public String getVersion() { |
976 |
return version;
|
977 |
} |
978 |
|
979 |
/**
|
980 |
* Get service information (services availables)
|
981 |
*
|
982 |
* @return
|
983 |
*/
|
984 |
public ServiceInformation getServiceInformation() {
|
985 |
return this.serviceInfo; |
986 |
} |
987 |
|
988 |
/**
|
989 |
* Get Host
|
990 |
*
|
991 |
* @return
|
992 |
*/
|
993 |
public String getHost() { |
994 |
return host;
|
995 |
} |
996 |
|
997 |
/**
|
998 |
* get Port
|
999 |
*
|
1000 |
* @return
|
1001 |
*/
|
1002 |
public String getPort() { |
1003 |
return port;
|
1004 |
} |
1005 |
|
1006 |
/**
|
1007 |
* Set host
|
1008 |
*
|
1009 |
* @param _host
|
1010 |
*/
|
1011 |
public void setHost(String _host) { |
1012 |
host = _host; |
1013 |
} |
1014 |
|
1015 |
/**
|
1016 |
* Set Port
|
1017 |
*
|
1018 |
* @param _port
|
1019 |
*/
|
1020 |
public void setPort(String _port) { |
1021 |
port = _port; |
1022 |
} |
1023 |
|
1024 |
/**
|
1025 |
* Method to request a GET_SERVICE_INFO to an ArcIMS Server
|
1026 |
*
|
1027 |
* @param status
|
1028 |
* @throws ArcImsException
|
1029 |
*/
|
1030 |
public void getCapabilities(ArcImsStatus status) throws ArcImsException { |
1031 |
try {
|
1032 |
String request = ArcXML.getServiceInfoRequest(getVersion());
|
1033 |
|
1034 |
URL url = new URL(buildCapabilitiesRequest(status)); |
1035 |
logger.info("Requesting ArcIMS Service Information");
|
1036 |
|
1037 |
File f = ArcImsDownloadUtils.doRequestPost(url, request,
|
1038 |
"serviceInfo.xml");
|
1039 |
|
1040 |
this.serviceInfo = parseServiceInfo(this.serviceInfo, f); |
1041 |
} catch (MalformedURLException e) { |
1042 |
logger.error(e.getMessage(), e); |
1043 |
throw new ArcImsException("arcims_server_error"); |
1044 |
} |
1045 |
} |
1046 |
|
1047 |
/**
|
1048 |
* Builds the GetCapabilitiesRequest according to the ArcIms Specifications
|
1049 |
* stored in a @see ArcImsStatus object
|
1050 |
*
|
1051 |
* @param status
|
1052 |
* @return string A convenient request
|
1053 |
*/
|
1054 |
protected String buildCapabilitiesRequest(ArcImsStatus status) { |
1055 |
StringBuffer req = new StringBuffer(); |
1056 |
|
1057 |
String onlineResource;
|
1058 |
String service;
|
1059 |
|
1060 |
if ((status == null) || (status.getOnlineResource() == null)) { |
1061 |
onlineResource = getHost(); |
1062 |
service = getService(); |
1063 |
} else {
|
1064 |
onlineResource = status.getOnlineResource(); |
1065 |
service = status.getServiceName(); |
1066 |
} |
1067 |
|
1068 |
// String symbol = getSymbol(onlineResource);
|
1069 |
req.append(onlineResource); |
1070 |
req.append("?" + GetVariables.SERVICENAME + "="); |
1071 |
|
1072 |
req.append(service); |
1073 |
|
1074 |
return req.toString();
|
1075 |
} |
1076 |
|
1077 |
/**
|
1078 |
* Builds the GetFeatureInfo according to the ArcIms Specifications stored
|
1079 |
* in a @see ArcImsStatus object
|
1080 |
*
|
1081 |
* @param status
|
1082 |
* @param _type
|
1083 |
* of ArcIMS service
|
1084 |
* @return string A convenient request
|
1085 |
*/
|
1086 |
protected String buildGetFeatureInfoRequest(ArcImsStatus status, |
1087 |
String _type) {
|
1088 |
StringBuffer req = new StringBuffer(); |
1089 |
|
1090 |
String onlineResource;
|
1091 |
String service;
|
1092 |
onlineResource = getHost(); |
1093 |
|
1094 |
if ((status == null) || (status.getOnlineResource() == null)) { |
1095 |
onlineResource = getHost(); |
1096 |
service = getService(); |
1097 |
} else {
|
1098 |
onlineResource = status.getOnlineResource(); |
1099 |
service = status.getServiceName(); |
1100 |
} |
1101 |
|
1102 |
// String symbol = getSymbol(onlineResource);
|
1103 |
req.append(onlineResource); |
1104 |
req.append("?" + GetVariables.SERVICENAME + "="); |
1105 |
|
1106 |
req.append(service); |
1107 |
|
1108 |
/**
|
1109 |
* This GET variable is needed when an ImageService is requested
|
1110 |
*/
|
1111 |
if ((this.serviceInfo.getType().equals(ServiceInfoTags.vIMAGESERVICE)) |
1112 |
&& _type.equals(ServiceInfoTags.vLAYERTYPE_F)) { |
1113 |
req.append("&" + GetVariables.CUSTOMSERVICE + "=" |
1114 |
+ GetVariables.QUERY); |
1115 |
} |
1116 |
|
1117 |
return req.toString();
|
1118 |
} |
1119 |
|
1120 |
public void close() { |
1121 |
// your code here
|
1122 |
} |
1123 |
|
1124 |
public String getService() { |
1125 |
return service;
|
1126 |
} |
1127 |
|
1128 |
public void setService(String service) { |
1129 |
this.service = service;
|
1130 |
} |
1131 |
|
1132 |
/**
|
1133 |
* Method that retrieves a catalog from the ArcIMS Server and returns an
|
1134 |
* ArrayList of name, type and status of every service offered by the server
|
1135 |
*
|
1136 |
* @param url
|
1137 |
* @return ArrayList
|
1138 |
* @throws ArcImsException
|
1139 |
*/
|
1140 |
public static List<List<String>> getCatalog(URL url, boolean override) |
1141 |
throws ArcImsException {
|
1142 |
|
1143 |
List<List<String>> services = new ArrayList<List<String>>(); |
1144 |
|
1145 |
try {
|
1146 |
URL urlComplete = new URL(url.toString() + "?" |
1147 |
+ GetVariables.SERVICENAME + "=" + GetVariables.CATALOG);
|
1148 |
|
1149 |
String request = ArcXML.getClientServices();
|
1150 |
|
1151 |
logger.info("Requesting ArcIMS Catalog");
|
1152 |
|
1153 |
File f = ArcImsDownloadUtils.doRequestPost(urlComplete, request,
|
1154 |
"getClientServices.xml", override);
|
1155 |
|
1156 |
services = parseClientServices(f); |
1157 |
} catch (MalformedURLException e) { |
1158 |
logger.error(e.getMessage(), e); |
1159 |
throw new ArcImsException("arcims_server_error"); |
1160 |
} |
1161 |
|
1162 |
return services;
|
1163 |
} |
1164 |
|
1165 |
/**
|
1166 |
* Gets the catalog without setting the override boolean
|
1167 |
*
|
1168 |
* @see #getCatalog(URL, boolean)
|
1169 |
* @param url
|
1170 |
* @return ArrayList with the Catalgo of the Service
|
1171 |
* @throws ArcImsException
|
1172 |
*/
|
1173 |
public static List<List<String>> getCatalog(URL url) throws ArcImsException { |
1174 |
return getCatalog(url, false); |
1175 |
} |
1176 |
|
1177 |
/**
|
1178 |
* Method that parses a ArcXML response for the GETCLIENTSERVICES request
|
1179 |
*
|
1180 |
* @param f
|
1181 |
* @return ArrayList of ArrayLists with name, type and status
|
1182 |
* @throws ArcImsException
|
1183 |
*/
|
1184 |
private static List<List<String>> parseClientServices(File f) |
1185 |
throws ArcImsException {
|
1186 |
List<List<String>> services = new ArrayList<List<String>>(); |
1187 |
List<String> service; |
1188 |
|
1189 |
try {
|
1190 |
KXmlParser parser = new KXmlParser();
|
1191 |
parser.setInput(new FileReader(f)); |
1192 |
|
1193 |
int currentTag;
|
1194 |
boolean end = false; |
1195 |
|
1196 |
// parser.require(KXmlParser.START_TAG, null,
|
1197 |
// ServiceInfoTags.ARCXML);
|
1198 |
currentTag = parser.next(); |
1199 |
|
1200 |
while (!end) {
|
1201 |
switch (currentTag) {
|
1202 |
case KXmlParser.START_TAG:
|
1203 |
|
1204 |
/*
|
1205 |
* Parse the SERVICE tag
|
1206 |
*/
|
1207 |
if (parser.getName().compareTo(CatalogInfoTags.SERVICE) == 0) { |
1208 |
// Initialize metadata
|
1209 |
String servName = new String(); |
1210 |
String servType = new String(); |
1211 |
String servStatus = new String(); |
1212 |
|
1213 |
String value = null; |
1214 |
value = parser.getAttributeValue("",
|
1215 |
CatalogInfoTags.SERVICE_ATT_NAME); |
1216 |
|
1217 |
if (value != null) { |
1218 |
servName = value; |
1219 |
} |
1220 |
|
1221 |
value = null;
|
1222 |
value = parser.getAttributeValue("",
|
1223 |
CatalogInfoTags.SERVICE_ATT_TYPE); |
1224 |
|
1225 |
if (value != null) { |
1226 |
servType = value; |
1227 |
} |
1228 |
|
1229 |
value = null;
|
1230 |
value = parser.getAttributeValue("",
|
1231 |
CatalogInfoTags.SERVICE_ATT_STATUS); |
1232 |
|
1233 |
if (value != null) { |
1234 |
servStatus = value; |
1235 |
} |
1236 |
|
1237 |
// First add an ArrayList with these data
|
1238 |
service = new ArrayList<String>(); |
1239 |
service.add(servName); |
1240 |
service.add(servType); |
1241 |
service.add(servStatus); |
1242 |
|
1243 |
// Now add this object to the services ArrayList
|
1244 |
services.add(service); |
1245 |
service = null;
|
1246 |
} |
1247 |
|
1248 |
break;
|
1249 |
|
1250 |
case KXmlParser.END_TAG:
|
1251 |
|
1252 |
if (parser.getName().compareTo(ServiceInfoTags.tARCXML) == 0) { |
1253 |
end = true;
|
1254 |
} |
1255 |
|
1256 |
break;
|
1257 |
|
1258 |
case KXmlParser.TEXT:
|
1259 |
break;
|
1260 |
} |
1261 |
|
1262 |
if (!end) {
|
1263 |
currentTag = parser.next(); |
1264 |
} |
1265 |
} |
1266 |
} catch (XmlPullParserException parser_ex) {
|
1267 |
parser_ex.printStackTrace(); |
1268 |
} catch (ConnectException ce) { |
1269 |
logger.error("Timed out error", ce);
|
1270 |
throw new ArcImsException("arcims_server_timeout"); |
1271 |
} catch (FileNotFoundException fe) { |
1272 |
logger.error("FileNotFound Error", fe);
|
1273 |
throw new ArcImsException("arcims_server_error"); |
1274 |
} catch (IOException e) { |
1275 |
logger.error("IO Error", e);
|
1276 |
throw new ArcImsException("arcims_server_error"); |
1277 |
} |
1278 |
|
1279 |
return services;
|
1280 |
} |
1281 |
|
1282 |
/**
|
1283 |
* Method that does a Ping to an ArcIMS Server
|
1284 |
*
|
1285 |
* @param url
|
1286 |
* @return true when server exits, false otherwise
|
1287 |
* @throws ArcImsException
|
1288 |
*/
|
1289 |
public static boolean getPing(URL url) throws ArcImsException { |
1290 |
try {
|
1291 |
URL urlWithPing = new URL(url.toString() + "?" |
1292 |
+ GetVariables.COMMAND + "=" + GetVariables.PING);
|
1293 |
HttpURLConnection conn = (HttpURLConnection) urlWithPing |
1294 |
.openConnection(); |
1295 |
conn.setDoOutput(true);
|
1296 |
conn.setRequestMethod("GET");
|
1297 |
|
1298 |
logger.info("Trying connect to: " + conn.getURL().toString());
|
1299 |
conn.connect(); |
1300 |
|
1301 |
Reader isr = new InputStreamReader(conn.getInputStream()); |
1302 |
BufferedReader reader = new BufferedReader(isr); |
1303 |
|
1304 |
String line = reader.readLine();
|
1305 |
|
1306 |
// If the connection was succesful and this line starts with IMS,
|
1307 |
// the server is OK
|
1308 |
if ((conn.getResponseCode() == HttpURLConnection.HTTP_OK) |
1309 |
&& line.startsWith("IMS")) {
|
1310 |
logger.info("Connection succeeded");
|
1311 |
|
1312 |
return true; |
1313 |
} else {
|
1314 |
return false; |
1315 |
} |
1316 |
} catch (MalformedURLException e) { |
1317 |
e.printStackTrace(); |
1318 |
logger.warn("Malformed url", e);
|
1319 |
|
1320 |
return false; |
1321 |
} catch (ConnectException ce) { |
1322 |
logger.error("Timed out error", ce);
|
1323 |
throw new ArcImsException("arcims_server_timeout"); |
1324 |
} catch (NullPointerException npe) { |
1325 |
logger.error("NullPointerException", npe);
|
1326 |
throw new ArcImsException("arcims_server_error"); |
1327 |
} catch (IOException e) { |
1328 |
return false; |
1329 |
} |
1330 |
} |
1331 |
|
1332 |
/**
|
1333 |
* Method that pings with several SERVLETS trying to find a correct one.
|
1334 |
*
|
1335 |
* @param url
|
1336 |
* to start searching
|
1337 |
* @return Correct URL
|
1338 |
* @throws ArcImsException
|
1339 |
*/
|
1340 |
public static URL getUrlWithServlet(URL url) throws ArcImsException { |
1341 |
/*
|
1342 |
* Url with the servlet
|
1343 |
*/
|
1344 |
URL urlTemp;
|
1345 |
URL urlWithServlet = null; |
1346 |
|
1347 |
/*
|
1348 |
* If url ends with a slash, we remove it
|
1349 |
*/
|
1350 |
if (url.toString().endsWith("/")) { |
1351 |
String strUrl = url.toString();
|
1352 |
int size = strUrl.length();
|
1353 |
strUrl = strUrl.substring(0, size - 1); |
1354 |
|
1355 |
try {
|
1356 |
url = new URL(strUrl); |
1357 |
} catch (MalformedURLException e) { |
1358 |
e.printStackTrace(); |
1359 |
logger.error(e.getMessage(), e); |
1360 |
throw new ArcImsException("wrong_url"); |
1361 |
} |
1362 |
} |
1363 |
|
1364 |
int n = GetVariables.SERVLETS.length;
|
1365 |
|
1366 |
// Loop over the SERVLETS to find a valid one.
|
1367 |
logger.info("Start searching correct servlet");
|
1368 |
|
1369 |
for (int i = 0; i < n; i++) { |
1370 |
try {
|
1371 |
urlTemp = new URL(url.toString() + GetVariables.SERVLETS[i]); |
1372 |
} catch (MalformedURLException e) { |
1373 |
// The url is "Malformed" so, we continue with the next block
|
1374 |
continue;
|
1375 |
} |
1376 |
|
1377 |
if (ArcImsProtocolHandler.getPing(urlTemp)) {
|
1378 |
urlWithServlet = urlTemp; |
1379 |
|
1380 |
break;
|
1381 |
} |
1382 |
} |
1383 |
|
1384 |
if (urlWithServlet == null) { |
1385 |
throw new ArcImsException("arcims_no_server"); |
1386 |
} |
1387 |
|
1388 |
logger.info("Complete ArcIMS URL: " + urlWithServlet.toString());
|
1389 |
|
1390 |
return urlWithServlet;
|
1391 |
} |
1392 |
|
1393 |
public static String[] getVersion(URL url) throws ArcImsException { |
1394 |
String[] getV = new String[2]; |
1395 |
Reader isr;
|
1396 |
URL urlCmd;
|
1397 |
HttpURLConnection conn;
|
1398 |
|
1399 |
try {
|
1400 |
// Build the url with the proper command
|
1401 |
urlCmd = new URL(url.toString() + "?" + GetVariables.COMMAND + "=" |
1402 |
+ GetVariables.GETVERSION); |
1403 |
} catch (MalformedURLException e) { |
1404 |
e.printStackTrace(); |
1405 |
logger.error(e.getMessage(), e); |
1406 |
throw new ArcImsException("arcims_no_server"); |
1407 |
} |
1408 |
|
1409 |
try {
|
1410 |
// Stablish the connection
|
1411 |
conn = (HttpURLConnection) urlCmd.openConnection();
|
1412 |
conn.setDoOutput(true);
|
1413 |
conn.setRequestMethod("GET");
|
1414 |
conn.connect(); |
1415 |
|
1416 |
// Get the reader and asign the first two lines of the response
|
1417 |
isr = new InputStreamReader(conn.getInputStream()); |
1418 |
|
1419 |
BufferedReader reader = new BufferedReader(isr); |
1420 |
String strTemp = new String(); |
1421 |
strTemp = reader.readLine(); |
1422 |
getV[0] = strTemp.substring(strTemp.indexOf("=") + 1); |
1423 |
strTemp = reader.readLine(); |
1424 |
getV[1] = strTemp.substring(strTemp.indexOf("=") + 1); |
1425 |
|
1426 |
conn.disconnect(); |
1427 |
} catch (ConnectException ce) { |
1428 |
logger.error("Timed out error", ce);
|
1429 |
throw new ArcImsException("arcims_server_timeout"); |
1430 |
} catch (IOException e) { |
1431 |
logger.error(e.getMessage(), e); |
1432 |
throw new ArcImsException("arcims_no_server"); |
1433 |
} |
1434 |
|
1435 |
return getV;
|
1436 |
} |
1437 |
|
1438 |
/**
|
1439 |
* This method returns a Legend to the client requested by layerId string
|
1440 |
*
|
1441 |
* @param layerId
|
1442 |
* @return Legend with layer simbology
|
1443 |
* @throws ArcImsException
|
1444 |
*/
|
1445 |
public ILegend getLegend(String layerId) throws ArcImsException { |
1446 |
// TODO arreglar la simbologia
|
1447 |
// ArcImsFLegendFactory aiff = new
|
1448 |
// ArcImsFLegendFactory(this.serviceInfo,
|
1449 |
// layerId);
|
1450 |
//
|
1451 |
// return aiff.getMainLegend();
|
1452 |
return null; |
1453 |
} |
1454 |
|
1455 |
} |