Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.remoteclient / src / main / java / org / gvsig / remoteclient / wms / WMSProtocolHandler.java @ 40559

History | View | Annotate | Download (24.6 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
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 3
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
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.remoteclient.wms;
25

    
26
import java.io.ByteArrayInputStream;
27
import java.io.File;
28
import java.io.FileInputStream;
29
import java.io.FileReader;
30
import java.io.IOException;
31
import java.io.InputStream;
32
import java.net.URL;
33
import java.net.URLConnection;
34
import java.nio.ByteBuffer;
35
import java.nio.channels.FileChannel;
36
import java.util.ArrayList;
37
import java.util.Iterator;
38
import java.util.StringTokenizer;
39
import java.util.TreeMap;
40

    
41
import org.gvsig.compat.net.ICancellable;
42
import org.gvsig.remoteclient.exceptions.ServerErrorException;
43
import org.gvsig.remoteclient.exceptions.WMSException;
44
import org.gvsig.remoteclient.ogc.OGCProtocolHandler;
45
import org.gvsig.remoteclient.ogc.OGCServiceInformation;
46
import org.gvsig.remoteclient.utils.CapabilitiesTags;
47
import org.gvsig.remoteclient.utils.ExceptionTags;
48
import org.gvsig.remoteclient.utils.Utilities;
49
import org.gvsig.remoteclient.wms.request.WMSGetCapabilitiesRequest;
50
import org.gvsig.remoteclient.wms.request.WMSGetFeatureInfoRequest;
51
import org.gvsig.remoteclient.wms.request.WMSGetLegendGraphicRequest;
52
import org.gvsig.remoteclient.wms.request.WMSGetMapRequest;
53
import org.kxml2.io.KXmlParser;
54
import org.xmlpull.v1.XmlPullParserException;
55

    
56
/**
57
 * <p> Abstract class that represents handlers to comunicate via WMS protocol.
58
 * </p>
59
 *
60
 */
61
public abstract class WMSProtocolHandler extends OGCProtocolHandler {
62
        /**
63
         * Encoding used to parse different xml documents.
64
         */
65
        protected String encoding = "UTF-8";
66
    /**
67
     * WMS metadata
68
     */
69
    protected WMSServiceInformation serviceInfo;
70
    public TreeMap layers;
71
    public WMSLayer rootLayer;
72

    
73
    /**
74
     * returns the alfanumeric information of the layers at the specified point.
75
     * the diference between the other getfeatureInfo method is that this will
76
     * be implemented by each specific version because the XML from the server will be
77
     * parsed and presented by a well known structure.
78
     */
79

    
80
    public String getName() {
81
            return name;
82
    }
83

    
84
    /*
85
     * (non-Javadoc)
86
     * @see org.gvsig.remoteClient.ogc.OGCProtocolHandler#getServiceInformation()
87
     */
88
    public OGCServiceInformation getServiceInformation() {
89
        return serviceInfo;
90
    }
91

    
92
    /**
93
         * <p>Builds a GetCapabilities request that is sent to the WMS
94
         * the response will be parse to extract the data needed by the
95
         * WMS client</p>
96
         * @param override, if true the previous downloaded data will be overridden
97
         */
98
    public void getCapabilities(WMSStatus status, boolean override, ICancellable cancel) {
99
            URL request = null;
100
                try {
101
                        request = new URL(buildCapabilitiesRequest(status));
102
                } catch(Exception e) {
103
                        e.printStackTrace();
104
                }
105
                try {
106
                        if (override)
107
                                Utilities.removeURL(request);
108
                        File f = Utilities.downloadFile(request,"wms_capabilities.xml", cancel);
109
                        //WMSGetCapabilitiesRequest request = createGetCapabilitiesRequest(status);
110
                        //File f = request.sendRequest();        
111
                        if (f == null)
112
                                return;
113
                        clear();
114
                        parseCapabilities(f);
115
            } catch(Exception e) {
116
                        e.printStackTrace();
117
                }
118
    }
119

    
120
    private void clear() {
121
                layers.clear();
122
                serviceInfo.clear();
123
        }
124

    
125
        /**
126
     * <p>It will send a GetFeatureInfo request to the WMS
127
     * Parsing the response and redirecting the info to the WMS client</p>
128
     * TODO: return a stored file instead a String.
129
     */
130
    public String getFeatureInfo(WMSStatus status, int x, int y, int featureCount, ICancellable cancel)
131
    {
132
            StringBuffer output = new StringBuffer();
133
            String outputFormat = new String();
134
            String ServiceException = "ServiceExceptionReport";
135
            StringBuffer sb = new StringBuffer();
136
            sb.append("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>");
137
                try
138
                {
139
                        WMSGetFeatureInfoRequest request = createGetFeatureInfoRequest(status, x, y);
140
                        URL url = request.getURL();
141
                    outputFormat = url.openConnection().getContentType();
142
                    File f = request.sendRequest(cancel);
143
                        if (f == null){
144
                                return "";
145
                        }
146

    
147
                        FileReader fReader = new FileReader(f);
148
                        char[] buffer = new char[1024*256];
149
                        for (int i = fReader.read(buffer); i>0; i = fReader.read(buffer))
150
                    {
151
                            String str = new String(buffer,0,i);
152
                            output.append(str);
153
                    }
154
                    if ( (outputFormat == null) || (outputFormat.indexOf("xml") != -1)
155
                                    ||output.toString().toLowerCase().startsWith("<?xml")
156
                                    ||(outputFormat.indexOf("gml") != -1))
157
                    {
158
                            int tag;
159
                            KXmlParser kxmlParser = null;
160
                            kxmlParser = new KXmlParser();
161
                            //kxmlParser.setInput(new StringReader(output.toString()));
162
                            kxmlParser.setInput(new FileReader(f));
163

    
164
                            tag = kxmlParser.nextTag();
165
                            if (kxmlParser.getName().compareTo(ServiceException)==0)
166
                                {
167
                                    sb.append("<INFO>").append(parseException( output.toString().getBytes())).append("</INFO>");
168
                                    return sb.toString();
169
                                }
170
                                else if (kxmlParser.getName().compareToIgnoreCase("ERROR")==0)
171
                                {
172
                                        return output.toString();
173
                                }
174
                                else
175
                                {
176
                                        return output.toString();
177
                                }
178
                    }
179
                    else
180
                    {                  
181
                            //Para que funcione con el GetFeatureInfo Viewer generico hay que devolver:
182
                             return output.toString();
183
                    }
184
                }
185
            catch(XmlPullParserException parserEx)
186
            {
187
                    if (output.toString().toLowerCase().indexOf("xml") != -1)
188
                    {
189
                            return output.toString().trim();
190
                    }
191
                    else
192
                    {
193
                               sb.append("<INFO>").append("Info format not supported").append("</INFO>");
194
                        return sb.toString();
195
                    }
196
            }
197
            catch(Exception e)
198
            {
199
                    e.printStackTrace();
200
                    sb.append("<INFO>").append("Info format not supported").append("</INFO>");
201
                    return sb.toString();
202

    
203
            }
204
    }
205
    /**
206
     * <p>Builds a GetMap request that is sent to the WMS
207
     * the response (image) will be redirect to the
208
     * WMS client</p>
209
     */
210
    public byte[] _getMap(WMSStatus status) throws ServerErrorException, WMSException
211
    {
212
            try
213
                {
214
                        //TODO:
215
                        //pass this buildXXXRequest to the WMSProtocolHandlerXXX: The request can depend on the WMS version.
216
                        WMSGetMapRequest request = createGetMapRequest(status);
217
                        URL url = request.getURL();
218
                        
219
                        URLConnection conn = url.openConnection();
220
                        System.out.println(request.toString());
221
            String type = conn.getContentType();
222

    
223

    
224
                    byte[] imageBytes = null;
225
                    byte[] buffer = new byte[1024*256];
226
            InputStream is = conn.getInputStream();
227
                    int readed = 0;
228

    
229
                    for (int i = is.read(buffer); i>0; i = is.read(buffer)){
230
                // Creates a new buffer to contain the previous readed bytes and the next bunch of bytes
231
                            byte[] buffered = new byte[readed+i];
232
                            for (int j = 0; j < buffered.length; j++) {
233
                                    if (j<readed){
234
                        // puts the previously downloaded bytes into the image buffer
235
                                            buffered[j] = imageBytes[j];
236
                                    }
237
                                    else {
238
                        // appends the recently downloaded bytes to the image buffer.
239
                                            buffered[j] = buffer[j-readed];
240
                                    }
241
                                }
242
                            imageBytes = (byte[]) buffered.clone();
243
                            readed += i;
244
                    }
245

    
246
                    if ((type !=null && !type.subSequence(0,5).equals("image"))
247
                            ||(Utilities.isTextData(imageBytes)))
248
                    {
249
                       WMSException wmsEx = null;
250

    
251
                    String exceptionMessage = parseException(imageBytes);
252
                if (exceptionMessage==null)
253
                {
254
                         String error = new String(imageBytes);
255
                        int pos = error.indexOf("<?xml");
256
                        if (pos!= -1)
257
                        {
258
                                String xml = error.substring(pos,error.length());
259
                                exceptionMessage = parseException(xml.getBytes());
260
                        if (exceptionMessage == null)
261
                                exceptionMessage = new String(imageBytes);
262
                        }
263
                }
264
                     wmsEx = new WMSException(exceptionMessage);
265
                    wmsEx.setWMSMessage(new String(imageBytes));
266
                throw wmsEx;
267
            }
268
                        return imageBytes;
269
                }
270
                catch(IOException e)
271
                {
272
                        e.printStackTrace();
273
            throw new ServerErrorException();
274
                }
275
    }
276

    
277
    public File getLegendGraphic_old(WMSStatus status, String layerName, ICancellable cancel) throws ServerErrorException, WMSException
278
    {
279
            try
280
                {
281
                        WMSGetLegendGraphicRequest request = createGetLegendGraphicRequest(status, layerName);
282
                        File f = request.sendRequest(cancel);
283
                    if (f== null)
284
                            return null;
285
            if (Utilities.isTextFile(f)) {
286
                            
287
                byte[] data = fileToBytes(f);
288

    
289
                            WMSException wmsEx = null;
290

    
291
                    String exceptionMessage = parseException(data);
292
                if (exceptionMessage==null)
293
                {
294
                         String error = new String(data);
295
                        int pos = error.indexOf("<?xml");
296
                        if (pos!= -1)
297
                        {
298
                                String xml = error.substring(pos,error.length());
299
                                exceptionMessage = parseException(xml.getBytes());
300
                        }
301
                    if (exceptionMessage == null)
302
                            exceptionMessage = new String(data);
303

    
304
                }
305
                     wmsEx = new WMSException(exceptionMessage);
306
                    wmsEx.setWMSMessage(new String(data));
307
                    downloader.removeURL(request);
308
                throw wmsEx;
309
            }
310
                        return f;
311
                }
312
                catch(IOException e)
313
                {
314
                        e.printStackTrace();
315
            throw new ServerErrorException();
316
                }
317
    }
318
    
319
    public File getLegendGraphic(WMSStatus status, String layerName, ICancellable cancel) 
320
            throws ServerErrorException, WMSException {
321
            URL request = null;
322
                try {
323
                        request = new URL(buildGetLegendGraphicRequest(status, layerName));
324
                        System.out.println(request);
325
            File f = Utilities.downloadFile(request, "wmsGetLegendGraphic", cancel);
326
                    if (f== null)
327
                            return null;
328
            if (Utilities.isTextFile(f)) {
329
                            FileInputStream fis = new FileInputStream(f);
330
                            FileChannel fc = fis.getChannel();
331
                            byte[] data = new byte[(int)fc.size()];
332
                            ByteBuffer bb = ByteBuffer.wrap(data);
333
                            fc.read(bb);
334

    
335
                            WMSException wmsEx = null;
336

    
337
                    String exceptionMessage = parseException(data);
338
                if (exceptionMessage == null) {
339
                         String error = new String(data);
340
                        int pos = error.indexOf("<?xml");
341
                        if (pos!= -1) {
342
                                String xml = error.substring(pos,error.length());
343
                                exceptionMessage = parseException(xml.getBytes());
344
                        }
345
                    if (exceptionMessage == null)
346
                            exceptionMessage = new String(data);
347

    
348
                }
349
                     wmsEx = new WMSException(exceptionMessage);
350
                    wmsEx.setWMSMessage(new String(data));
351
                    Utilities.removeURL(request);
352
                throw wmsEx;
353
            }
354
                        return f;
355
                } catch(IOException e) {
356
                        e.printStackTrace();
357
            throw new ServerErrorException();
358
                }
359
    }
360
    
361
    /**
362
     * @return string that represents the url for getting the wms legend
363
     * If the layer has the object layer-->style-->legendurl that url will be returned 
364
     * otherwise builds the getLegendGraphic according to the OGC WMS Specifications
365
     * 
366
     */
367
    private String buildGetLegendGraphicRequest(WMSStatus status, String layerName) {
368
            //TODO: deal with more than one layer            
369
            WMSLayer lyr = (WMSLayer) this.layers.get(layerName);
370
            WMSStyle sty =null;
371
            if (lyr != null){
372
                    Iterator it = lyr.getStyles().iterator();
373
                    while (it.hasNext()){
374
                            sty = (WMSStyle) it.next();
375
                            if (sty.getName().equals(status.getStyles().get(0).toString())){                                    
376
                                    return sty.getLegendURLOnlineResourceHRef();
377
                            }
378
                    }
379
            }
380
            //TODO: pass by parameter the legend output format?
381
                StringBuffer req = new StringBuffer();
382
                String symbol = null;
383
                String onlineResource = null;
384

    
385
                if (status.getOnlineResource() == null)
386
                        onlineResource = getHost();
387
                else
388
                        onlineResource = status.getOnlineResource();
389
                symbol = getSymbol(onlineResource);
390

    
391
                req.append(onlineResource + symbol + "REQUEST=GetLegendGraphic&SERVICE=WMS&VERSION=").append(getVersion());
392
        req.append("&LAYER=" + layerName).append("&TRANSPARENT=TRUE").append("&FORMAT=image/png");
393
        String aux = req.toString().replaceAll(" ", "%20");
394
        System.out.println("GetLegendGraphic url:" + aux);
395
                return aux;
396
    }
397
    
398
    public URL getMapURL(WMSStatus status, ICancellable cancel) throws ServerErrorException, WMSException {
399
            try {
400
                        WMSGetMapRequest request = createGetMapRequest(status);
401
                        return request.getURL();
402
                } catch(IOException e) {
403
                        e.printStackTrace();
404
            throw new ServerErrorException();
405
                }
406
    }
407
    
408
    /**
409
     * Returns the exception message if the file is a XML instead of a image.
410
     * @param file3
411
     * @return
412
     * @throws IOException 
413
     */
414
    public String getExceptionMessage(File f) throws IOException {
415
            if (f == null)
416
                    return null;
417
            
418
        if (Utilities.isTextFile(f)) {
419
            byte[] data = fileToBytes(f);
420

    
421
                String exceptionMessage = parseException(data);
422
            if (exceptionMessage == null) {
423
                     String error = new String(data);
424
                    int pos = error.indexOf("<?xml");
425
                    if (pos!= -1) {
426
                            String xml = error.substring(pos,error.length());
427
                            exceptionMessage = parseException(xml.getBytes());
428
                    }
429
                if (exceptionMessage == null)
430
                        exceptionMessage = new String(data);
431
            }
432
                 return exceptionMessage;
433
        }
434
        return null;
435
    }
436

    
437
    public File getMap(WMSStatus status, ICancellable cancel) throws ServerErrorException, WMSException {
438
            try {
439
                        WMSGetMapRequest request = createGetMapRequest(status);
440
                        File f = request.sendRequest(cancel);
441
                        
442
                        if (f== null)
443
                            return null;
444
            if (Utilities.isTextFile(f)) {
445
                byte[] data = fileToBytes(f);
446

    
447
                            WMSException wmsEx = null;
448

    
449
                    String exceptionMessage = parseException(data);
450
                if (exceptionMessage==null) {
451
                         String error = new String(data);
452
                        int pos = error.indexOf("<?xml");
453
                        if (pos!= -1) {
454
                                String xml = error.substring(pos,error.length());
455
                                exceptionMessage = parseException(xml.getBytes());
456
//                        if (exceptionMessage == null)
457
//                                exceptionMessage = new String(data);
458
                        }
459
                    if (exceptionMessage == null)
460
                            exceptionMessage = new String(data);
461

    
462
                }
463
                     wmsEx = new WMSException(exceptionMessage);
464
                    wmsEx.setWMSMessage(new String(data));
465

    
466
                    // Since it is an error file, It must be deleted from the cache
467
                    downloader.removeURL(request);
468
                throw wmsEx;
469
            }
470
                        return f;
471
                } catch(IOException e) {
472
            throw new ServerErrorException(e.getMessage(), e);
473
                }
474
    }
475

    
476

    
477
    /* (non-Javadoc)
478
     * @see org.gvsig.remoteClient.wms.WMSProtocolHandler#parseException(byte[])
479
     */
480
    protected String parseException(byte[] data) {
481
        ArrayList errors = new ArrayList();
482
        KXmlParser kxmlParser = new KXmlParser();
483
        try
484
        {
485
            kxmlParser.setInput(new ByteArrayInputStream(data), encoding);
486
            kxmlParser.nextTag();
487
            int tag;
488
            if ( kxmlParser.getEventType() != KXmlParser.END_DOCUMENT )
489
            {
490
                kxmlParser.require(KXmlParser.START_TAG, null, ExceptionTags.EXCEPTION_ROOT);
491
                tag = kxmlParser.nextTag();
492
                 while(tag != KXmlParser.END_DOCUMENT)
493
                 {
494
                     switch(tag)
495
                     {
496
                        case KXmlParser.START_TAG:
497
                            if (kxmlParser.getName().compareTo(ExceptionTags.SERVICE_EXCEPTION)==0){
498
                                String errorCode = kxmlParser.getAttributeValue("", ExceptionTags.CODE);
499
                                errorCode = (errorCode != null) ? "["+errorCode+"] " : "";
500
                                String errorMessage = kxmlParser.nextText();
501
                                errors.add(errorCode+errorMessage);
502
                            }
503
                            break;
504
                        case KXmlParser.END_TAG:
505
                            break;
506

    
507
                     }
508
                     tag = kxmlParser.nextTag();
509
                 }
510
                 //kxmlParser.require(KXmlParser.END_DOCUMENT, null, null);
511
            }
512
        }
513
        catch(XmlPullParserException parser_ex){
514
            parser_ex.printStackTrace();
515
        }
516
        catch (IOException ioe) {
517
            ioe.printStackTrace();
518
        }
519
        String message = errors.size()>0? "" : null;
520
        for (int i = 0; i < errors.size(); i++) {
521
            message += (String) errors.get(i)+"\n";
522
        }
523
        return message;
524
    }
525
    /**
526
     * Builds the GetCapabilitiesRequest according to the OGC WMS Specifications
527
     * without a VERSION, to get the highest version than a WMS supports.
528
     */
529
    public static String buildCapabilitiesSuitableVersionRequest(String _host, String _version)
530
    {
531
                int index = _host.indexOf('?');
532
                
533
                if (index > -1) {
534
                        String host = _host.substring(0, index + 1);
535
                        String query = _host.substring(index + 1, _host.length());
536
                        
537
                        StringTokenizer tokens = new StringTokenizer(query, "&");
538
                        String newQuery = "", token;
539

    
540
                        // If there is a field or a value with spaces, (and then it's on different tokens) -> unify them
541
                        while (tokens.hasMoreTokens()) {
542
                                token = tokens.nextToken().trim();
543

    
544
                                if (token.toUpperCase().compareTo("REQUEST=GETCAPABILITIES") == 0)
545
                                        continue;
546

    
547
                                if (token.toUpperCase().compareTo("SERVICE=WMS") == 0)
548
                                        continue;
549

    
550
                                if ((_version != null) && (_version.length() > 0)) {
551
                                    if (token.toUpperCase().compareTo("VERSION=" + _version) == 0)
552
                                            continue;
553
                                }
554

    
555
                                if (token.toUpperCase().compareTo("EXCEPTIONS=XML") == 0)
556
                                        continue;
557

    
558
                                newQuery += token + "&";
559
                        }
560

    
561
                _host = host + newQuery;
562
                }
563
                else {
564
                        _host += "?";
565
                }
566

    
567
            if ((_version != null) && (_version.compareTo("") != 0))
568
                    _host += "REQUEST=GetCapabilities&SERVICE=WMS&VERSION=" + _version;
569
            else
570
                    _host += "REQUEST=GetCapabilities&SERVICE=WMS";
571

    
572
            return _host;
573
    }
574

    
575
    /**
576
     * Builds the GetCapabilitiesRequest according to the OGC WMS Specifications
577
     * @param WMSStatus
578
     */
579
    private String buildCapabilitiesRequest(WMSStatus status)
580
    {
581
                StringBuffer req = new StringBuffer();
582
                String symbol = null;
583

    
584
                String onlineResource;
585
                if (status == null || status.getOnlineResource() == null)
586
                        onlineResource = getHost();
587
                else
588
                        onlineResource = status.getOnlineResource();
589
                symbol = getSymbol(onlineResource);
590

    
591
                req.append(onlineResource).append(symbol).append("REQUEST=GetCapabilities&SERVICE=WMS&");
592
                req.append("VERSION=").append(getVersion());
593
                return req.toString();
594
    }  
595
   
596
     public void close() {
597
        // your code here
598
    } 
599
     
600
     /**
601
          * @param status
602
          * The WMS status
603
          * @param protocolHandler
604
          * The handler to parse the requests
605
          * @return an object to send the GetMap requests
606
          */
607
         protected abstract WMSGetMapRequest createGetMapRequest(WMSStatus status);
608
         
609
         protected abstract WMSGetFeatureInfoRequest createGetFeatureInfoRequest(WMSStatus status, int x, int y);
610
         
611
         protected abstract WMSGetLegendGraphicRequest createGetLegendGraphicRequest(WMSStatus status, String layerName);
612

    
613
         protected abstract WMSGetCapabilitiesRequest createGetCapabilitiesRequest(WMSStatus status);
614
         
615
         /**
616
     * <p>Parses the Request tag </p>
617
     */ 
618
    protected void parseRequestTag(KXmlParser parser) throws IOException, XmlPullParserException
619
    {        
620
            int currentTag;
621
            boolean end = false;
622
            
623
            parser.require(KXmlParser.START_TAG, null, CapabilitiesTags.REQUEST);
624
            currentTag = parser.next();
625
            
626
            while (!end) 
627
            {
628
                         switch(currentTag)
629
                         {
630
                                case KXmlParser.START_TAG:
631
                                        if (parser.getName().compareTo(CapabilitiesTags.GETCAPABILITIES)==0)
632
                                        {
633
                                                parserDcpType(parser, CapabilitiesTags.GETCAPABILITIES);
634
                                        }        
635
                                        else if (parser.getName().compareTo(CapabilitiesTags.GETMAP)==0)
636
                                        {        
637
                                                parseGetMapTag(parser);                                                
638
                                        }
639
                                        else if (parser.getName().compareTo(CapabilitiesTags.GETFEATUREINFO)==0)
640
                                        {
641
                                                parseGetFeatureInfoTag(parser);
642
                                        }                
643
                                        else if (parser.getName().compareTo(CapabilitiesTags.DESCRIBELAYER)==0)
644
                                        {
645
                                                parserDcpType(parser, CapabilitiesTags.DESCRIBELAYER);
646
                                        }        
647
                                        else if (parser.getName().compareTo(CapabilitiesTags.GETLEGENDGRAPHIC)==0)
648
                                        {
649
                                                parseGetLegendGraphicTag(parser);
650
                                        }                                        
651
                                        break;
652
                                case KXmlParser.END_TAG:
653
                                        if (parser.getName().compareTo(CapabilitiesTags.REQUEST) == 0)
654
                                                end = true;
655
                                        break;
656
                                case KXmlParser.TEXT:                                        
657
                                break;
658
                         }
659
                         if(!end)
660
                                 currentTag = parser.next();
661
            }
662
            // TODO: does not get such a tag when arrives here!!!!!!
663
            //parser.require(KXmlParser.END_TAG, null, CapabilitiesTags.REQUEST);            
664
    }   
665
          /**
666
     * <p>Parses the GetMap tag </p>
667
     */ 
668
    protected void parseGetMapTag(KXmlParser parser) throws IOException, XmlPullParserException
669
    {        
670
            int currentTag;
671
            boolean end = false;
672
            
673
            parser.require(KXmlParser.START_TAG, null, CapabilitiesTags.GETMAP);
674
            currentTag = parser.next();
675
            
676
            while (!end) 
677
            {
678
                         switch(currentTag)
679
                         {
680
                                case KXmlParser.START_TAG:
681
                                        if (parser.getName().compareTo(CapabilitiesTags.FORMAT)==0)
682
                                        {
683
                                                serviceInfo.formats.add(parser.nextText());
684
                                        }        
685
                                        else if (parser.getName().compareTo(CapabilitiesTags.DCPTYPE)==0)
686
                                        {                
687
                                                parserDcpType(parser, CapabilitiesTags.GETMAP);                                                
688
                                        }                        
689
                                        break;
690
                                case KXmlParser.END_TAG:
691
                                        if (parser.getName().compareTo(CapabilitiesTags.GETMAP) == 0)
692
                                                end = true;
693
                                        break;
694
                                case KXmlParser.TEXT:                                        
695
                                break;
696
                         }
697
                         if(!end)
698
                                 currentTag = parser.next();
699
            }        
700
    }    
701
    
702
    /**
703
     * <p>Parses the GetFeatureInfo tag </p>
704
     */ 
705
    protected void parseGetFeatureInfoTag(KXmlParser parser) throws IOException, XmlPullParserException
706
    {        
707
            int currentTag;
708
            boolean end = false;
709
            
710
            parser.require(KXmlParser.START_TAG, null, CapabilitiesTags.GETFEATUREINFO);
711
            currentTag = parser.next();
712
            
713
            while (!end) 
714
            {
715
                         switch(currentTag)
716
                         {
717
                                case KXmlParser.START_TAG:
718
                                        if (parser.getName().compareTo(CapabilitiesTags.FORMAT)==0)
719
                                        {
720
                                                serviceInfo.infoformats.add(parser.nextText());
721
                                        }        
722
                                        else if (parser.getName().compareTo(CapabilitiesTags.DCPTYPE)==0)
723
                                        {                        
724
                                                parserDcpType(parser, CapabilitiesTags.GETFEATUREINFO);                
725
                                        }                        
726
                                        break;
727
                                case KXmlParser.END_TAG:
728
                                        if (parser.getName().compareTo(CapabilitiesTags.GETFEATUREINFO) == 0)
729
                                                end = true;
730
                                        break;
731
                                case KXmlParser.TEXT:                                        
732
                                break;
733
                         }
734
                         if(!end)
735
                                 currentTag = parser.next();
736
            }        
737
    }     
738
 
739
    /**
740
     * <p>Parses the GetLegendGraphic tag </p>
741
     */ 
742
    protected void parseGetLegendGraphicTag(KXmlParser parser) throws IOException, XmlPullParserException
743
    {        
744
            int currentTag;
745
            boolean end = false;
746
            
747
            parser.require(KXmlParser.START_TAG, null, CapabilitiesTags.GETLEGENDGRAPHIC);
748
            currentTag = parser.next();
749
            
750
            while (!end) 
751
            {
752
                         switch(currentTag)
753
                         {
754
                                case KXmlParser.START_TAG:
755
                                        if (parser.getName().compareTo(CapabilitiesTags.FORMAT)==0)
756
                                        {
757
                                                //TODO:
758
                                                // add the supported formats by the GetLegendGraphic request
759
                                                //serviceInfo.formats.add(parser.nextText());
760
                                        }        
761
                                        else if (parser.getName().compareTo(CapabilitiesTags.DCPTYPE)==0)
762
                                        {                        
763
                                                parserDcpType(parser, CapabilitiesTags.GETLEGENDGRAPHIC);                
764
                                        }                        
765
                                        break;
766
                                case KXmlParser.END_TAG:
767
                                        if (parser.getName().compareTo(CapabilitiesTags.GETLEGENDGRAPHIC) == 0)
768
                                                end = true;
769
                                        break;
770
                                case KXmlParser.TEXT:                                        
771
                                break;
772
                         }
773
                         if(!end)
774
                                 currentTag = parser.next();
775
            }        
776
    }
777
 }