330 |
330 |
}
|
331 |
331 |
}
|
332 |
332 |
|
|
333 |
public File getLegendGraphic(String layerName, ICancellable cancel) throws ServerErrorException, WMSException
|
|
334 |
{
|
|
335 |
URL request = null;
|
|
336 |
try
|
|
337 |
{
|
|
338 |
request = new URL(buildGetLegendGraphicRequest(layerName));
|
|
339 |
System.out.println(request);
|
|
340 |
File f = Utilities.downloadFile(request, "wmsGetLegendGraphic", cancel);
|
|
341 |
if (f== null)
|
|
342 |
return null;
|
|
343 |
if (Utilities.isTextFile(f)) {
|
|
344 |
FileInputStream fis = new FileInputStream(f);
|
|
345 |
FileChannel fc = fis.getChannel();
|
|
346 |
byte[] data = new byte[(int)fc.size()];
|
|
347 |
ByteBuffer bb = ByteBuffer.wrap(data);
|
|
348 |
fc.read(bb);
|
|
349 |
|
|
350 |
WMSException wmsEx = null;
|
|
351 |
|
|
352 |
String exceptionMessage = parseException(data);
|
|
353 |
if (exceptionMessage==null)
|
|
354 |
{
|
|
355 |
String error = new String(data);
|
|
356 |
int pos = error.indexOf("<?xml");
|
|
357 |
if (pos!= -1)
|
|
358 |
{
|
|
359 |
String xml = error.substring(pos,error.length());
|
|
360 |
exceptionMessage = parseException(xml.getBytes());
|
|
361 |
}
|
|
362 |
if (exceptionMessage == null)
|
|
363 |
exceptionMessage = new String(data);
|
|
364 |
|
|
365 |
}
|
|
366 |
wmsEx = new WMSException(exceptionMessage);
|
|
367 |
wmsEx.setWMSMessage(new String(data));
|
|
368 |
Utilities.removeURL(request);
|
|
369 |
throw wmsEx;
|
|
370 |
}
|
|
371 |
return f;
|
|
372 |
}
|
|
373 |
catch(IOException e)
|
|
374 |
{
|
|
375 |
e.printStackTrace();
|
|
376 |
throw new ServerErrorException();
|
|
377 |
}
|
|
378 |
}
|
|
379 |
|
333 |
380 |
public File getMap(WMSStatus status, ICancellable cancel) throws ServerErrorException, WMSException
|
334 |
381 |
{
|
335 |
382 |
URL request = null;
|
... | ... | |
503 |
550 |
/**
|
504 |
551 |
* Builds the GetMapRequest according to the OGC WMS Specifications
|
505 |
552 |
*/
|
|
553 |
private String buildGetLegendGraphicRequest(String layerName)
|
|
554 |
{
|
|
555 |
StringBuffer req = new StringBuffer();
|
|
556 |
String symbol = null;
|
|
557 |
String onlineResource = null;
|
|
558 |
onlineResource = getHost();
|
|
559 |
symbol = getSymbol(onlineResource);
|
|
560 |
|
|
561 |
req.append(onlineResource + symbol + "REQUEST=GetLegendGraphic&SERVICE=WMS&VERSION=").append(getVersion()).append("&");
|
|
562 |
req.append("LAYER=" + layerName)
|
|
563 |
.append("&FORMAT=image/png");
|
|
564 |
return req.toString().replaceAll(" ", "%20");
|
|
565 |
}
|
|
566 |
|
|
567 |
/**
|
|
568 |
* Builds the GetMapRequest according to the OGC WMS Specifications
|
|
569 |
*/
|
506 |
570 |
private String buildMapRequest(WMSStatus status)
|
507 |
571 |
{
|
508 |
572 |
StringBuffer req = new StringBuffer();
|