Revision 7835

View differences:

trunk/libraries/libRemoteServices/src/org/gvsig/remoteClient/wms/WMSClient.java
80 80
    } 
81 81
    
82 82
    /**
83
     * <p>One of the three interfaces defined by the OGC WMS, it gets legend of a layer</p>
84
     * @return 
85
     */
86
    public File getLegendGraphic(String layerName, ICancellable cancel) throws WMSException, ServerErrorException{        
87
        return handler.getLegendGraphic(layerName, cancel);
88
    } 
89
    
90
    /**
83 91
     * <p> Reads from the WMS Capabilities, the layers available in the service</p>
84 92
     * @return a TreeMap with the available layers in the WMS 
85 93
     */
trunk/libraries/libRemoteServices/src/org/gvsig/remoteClient/wms/WMSProtocolHandler.java
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();
trunk/libraries/libRemoteServices/src/org/gvsig/remoteClient/wms/wms_1_1_1/WMSProtocolHandler1_1_1.java
283 283
					{
284 284
						//serviceInfo.operations.put(WMSProtocolHandler.DESCRIBELAYER_OPERATION)
285 285
						serviceInfo.operations.put(CapabilitiesTags.DESCRIBELAYER, null); 
286
					}					
286
					}		
287
					else if (parser.getName().compareTo(CapabilitiesTags.GETLEGENDGRAPHIC)==0)
288
					{
289
						serviceInfo.operations.put(CapabilitiesTags.GETLEGENDGRAPHIC, null);
290
					}
287 291
					break;
288 292
				case KXmlParser.END_TAG:
289 293
					if (parser.getName().compareTo(CapabilitiesTags.REQUEST) == 0)

Also available in: Unified diff