Statistics
| Revision:

svn-gvsig-desktop / tags / v2_0_0_Build_2020 / libraries / libRemoteServices / src / org / gvsig / remoteclient / wms / WMSProtocolHandler.java @ 33910

History | View | Annotate | Download (19.4 KB)

1 29658 jpiera
package org.gvsig.remoteclient.wms;
2 3323 ldiaz
3 3798 ldiaz
import java.io.ByteArrayInputStream;
4 3323 ldiaz
import java.io.File;
5 8559 ldiaz
import java.io.FileReader;
6 3377 ldiaz
import java.io.IOException;
7 3323 ldiaz
import java.io.InputStream;
8
import java.net.URL;
9 3776 jaume
import java.net.URLConnection;
10 3798 ldiaz
import java.util.ArrayList;
11 17849 jmvivo
import java.util.StringTokenizer;
12 3323 ldiaz
import java.util.TreeMap;
13 3776 jaume
14 33738 jpiera
import org.kxml2.io.KXmlParser;
15
import org.xmlpull.v1.XmlPullParserException;
16
17
import org.gvsig.compat.net.ICancellable;
18 29658 jpiera
import org.gvsig.remoteclient.exceptions.ServerErrorException;
19
import org.gvsig.remoteclient.exceptions.WMSException;
20
import org.gvsig.remoteclient.ogc.OGCProtocolHandler;
21
import org.gvsig.remoteclient.ogc.OGCServiceInformation;
22
import org.gvsig.remoteclient.utils.CapabilitiesTags;
23
import org.gvsig.remoteclient.utils.ExceptionTags;
24
import org.gvsig.remoteclient.utils.Utilities;
25 30324 jpiera
import org.gvsig.remoteclient.wms.request.WMSGetCapabilitiesRequest;
26 29658 jpiera
import org.gvsig.remoteclient.wms.request.WMSGetFeatureInfoRequest;
27
import org.gvsig.remoteclient.wms.request.WMSGetLegendGraphicRequest;
28
import org.gvsig.remoteclient.wms.request.WMSGetMapRequest;
29 3323 ldiaz
30
/**
31
 * <p> Abstract class that represents handlers to comunicate via WMS protocol.
32
 * </p>
33 11381 jaume
 *
34 3323 ldiaz
 */
35 27881 jpiera
public abstract class WMSProtocolHandler extends OGCProtocolHandler{
36 3483 jaume
        /**
37 4500 jaume
         * Encoding used to parse different xml documents.
38
         */
39
        protected String encoding = "UTF-8";
40 3483 jaume
    /**
41
     * WMS metadata
42
     */
43 27881 jpiera
    protected WMSServiceInformation serviceInfo;
44 3323 ldiaz
    public TreeMap layers;
45 3483 jaume
    public WMSLayer rootLayer;
46 11381 jaume
47 3323 ldiaz
    /**
48 5239 ldiaz
     * returns the alfanumeric information of the layers at the specified point.
49
     * the diference between the other getfeatureInfo method is that this will
50
     * be implemented by each specific version because the XML from the server will be
51
     * parsed and presented by a well known structure.
52 11381 jaume
     */
53 3323 ldiaz
54 11381 jaume
    public String getName() {
55 3323 ldiaz
            return name;
56 11381 jaume
    }
57 3323 ldiaz
58 27881 jpiera
    /*
59
     * (non-Javadoc)
60
     * @see org.gvsig.remoteClient.ogc.OGCProtocolHandler#getServiceInformation()
61
     */
62
    public OGCServiceInformation getServiceInformation() {
63 3323 ldiaz
        return serviceInfo;
64 11381 jaume
    }
65 17849 jmvivo
66 3323 ldiaz
    /**
67 3853 ldiaz
         * <p>Builds a GetCapabilities request that is sent to the WMS
68 5239 ldiaz
         * the response will be parse to extract the data needed by the
69 3853 ldiaz
         * WMS client</p>
70 4355 jaume
         * @param override, if true the previous downloaded data will be overridden
71 3853 ldiaz
         */
72 5409 jaume
    public void getCapabilities(WMSStatus status, boolean override, ICancellable cancel)
73 11381 jaume
    {
74 30324 jpiera
            try
75 3853 ldiaz
                {
76 30324 jpiera
                    if (status == null){
77
78
                    }
79
                        WMSGetCapabilitiesRequest request = createGetCapabilitiesRequest(status);
80
                        File f = request.sendRequest();
81
82 5409 jaume
                        if (f == null)
83
                                return;
84 5343 jaume
                        clear();
85 27881 jpiera
                        parseCapabilities(f);
86 3853 ldiaz
            } catch(Exception e)
87
                {
88
                        //TODO
89
                        e.printStackTrace();
90
                }
91
    }
92
93 5343 jaume
    private void clear() {
94
                layers.clear();
95
                serviceInfo.clear();
96
        }
97
98
        /**
99 3853 ldiaz
     * <p>It will send a GetFeatureInfo request to the WMS
100
     * Parsing the response and redirecting the info to the WMS client</p>
101 8559 ldiaz
     * TODO: return a stored file instead a String.
102 3853 ldiaz
     */
103 8559 ldiaz
    public String getFeatureInfo(WMSStatus status, int x, int y, int featureCount, ICancellable cancel)
104 3853 ldiaz
    {
105
            StringBuffer output = new StringBuffer();
106
            String outputFormat = new String();
107 11381 jaume
            String ServiceException = "ServiceExceptionReport";
108 3853 ldiaz
            StringBuffer sb = new StringBuffer();
109
            sb.append("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>");
110
                try
111
                {
112 27881 jpiera
                        WMSGetFeatureInfoRequest request = createGetFeatureInfoRequest(status, x, y);
113
                        URL url = request.getURL();
114
                    outputFormat = url.openConnection().getContentType();
115
                    File f = request.sendRequest();
116
                        if (f == null){
117 8559 ldiaz
                                return "";
118 27881 jpiera
                        }
119 11381 jaume
120 8559 ldiaz
                        FileReader fReader = new FileReader(f);
121
                        char[] buffer = new char[1024*256];
122
                        for (int i = fReader.read(buffer); i>0; i = fReader.read(buffer))
123
                    {
124
                            String str = new String(buffer,0,i);
125 11381 jaume
                            output.append(str);
126 8559 ldiaz
                    }
127 3853 ldiaz
                    if ( (outputFormat == null) || (outputFormat.indexOf("xml") != -1)
128
                                    ||output.toString().toLowerCase().startsWith("<?xml")
129
                                    ||(outputFormat.indexOf("gml") != -1))
130
                    {
131
                            int tag;
132
                            KXmlParser kxmlParser = null;
133 11381 jaume
                            kxmlParser = new KXmlParser();
134
                            //kxmlParser.setInput(new StringReader(output.toString()));
135 8559 ldiaz
                            kxmlParser.setInput(new FileReader(f));
136 11381 jaume
137
                            tag = kxmlParser.nextTag();
138 4222 jaume
                            if (kxmlParser.getName().compareTo(ServiceException)==0)
139
                                {
140
                                    sb.append("<INFO>").append(parseException( output.toString().getBytes())).append("</INFO>");
141 11381 jaume
                                    return sb.toString();
142 4222 jaume
                                }
143
                                else if (kxmlParser.getName().compareToIgnoreCase("ERROR")==0)
144
                                {
145
                                        return output.toString();
146
                                }
147 11381 jaume
                                else
148 4222 jaume
                                {
149 11381 jaume
                                        return output.toString();
150 4222 jaume
                                }
151 3853 ldiaz
                    }
152
                    else
153 27881 jpiera
                    {
154 5428 ldiaz
                            //Para que funcione con el GetFeatureInfo Viewer generico hay que devolver:
155 5838 ldiaz
                             return output.toString();
156 3853 ldiaz
                    }
157
                }
158
            catch(XmlPullParserException parserEx)
159
            {
160
                    if (output.toString().toLowerCase().indexOf("xml") != -1)
161
                    {
162
                            return output.toString().trim();
163
                    }
164
                    else
165
                    {
166 5536 jaume
                               sb.append("<INFO>").append("Info format not supported").append("</INFO>");
167 3853 ldiaz
                        return sb.toString();
168
                    }
169
            }
170
            catch(Exception e)
171
            {
172
                    e.printStackTrace();
173 5536 jaume
                    sb.append("<INFO>").append("Info format not supported").append("</INFO>");
174 3853 ldiaz
                    return sb.toString();
175
176
            }
177
    }
178
    /**
179 3323 ldiaz
     * <p>Builds a GetMap request that is sent to the WMS
180
     * the response (image) will be redirect to the
181
     * WMS client</p>
182 11381 jaume
     */
183 4222 jaume
    public byte[] _getMap(WMSStatus status) throws ServerErrorException, WMSException
184 11381 jaume
    {
185 27881 jpiera
            try
186 3351 ldiaz
                {
187
                        //TODO:
188
                        //pass this buildXXXRequest to the WMSProtocolHandlerXXX: The request can depend on the WMS version.
189 27881 jpiera
                        WMSGetMapRequest request = createGetMapRequest(status);
190
                        URL url = request.getURL();
191
192
                        URLConnection conn = url.openConnection();
193 3776 jaume
                        System.out.println(request.toString());
194
            String type = conn.getContentType();
195 11381 jaume
196
197 3516 jaume
                    byte[] imageBytes = null;
198 3377 ldiaz
                    byte[] buffer = new byte[1024*256];
199 3776 jaume
            InputStream is = conn.getInputStream();
200 3377 ldiaz
                    int readed = 0;
201 11381 jaume
202 3377 ldiaz
                    for (int i = is.read(buffer); i>0; i = is.read(buffer)){
203 3483 jaume
                // Creates a new buffer to contain the previous readed bytes and the next bunch of bytes
204 3377 ldiaz
                            byte[] buffered = new byte[readed+i];
205
                            for (int j = 0; j < buffered.length; j++) {
206
                                    if (j<readed){
207 3483 jaume
                        // puts the previously downloaded bytes into the image buffer
208 3377 ldiaz
                                            buffered[j] = imageBytes[j];
209
                                    }
210
                                    else {
211 3483 jaume
                        // appends the recently downloaded bytes to the image buffer.
212 3377 ldiaz
                                            buffered[j] = buffer[j-readed];
213
                                    }
214
                                }
215
                            imageBytes = (byte[]) buffered.clone();
216 11381 jaume
                            readed += i;
217 3377 ldiaz
                    }
218 11381 jaume
219
                    if ((type !=null && !type.subSequence(0,5).equals("image"))
220 3824 ldiaz
                            ||(Utilities.isTextData(imageBytes)))
221 11381 jaume
                    {
222 3853 ldiaz
                       WMSException wmsEx = null;
223 11381 jaume
224 3776 jaume
                    String exceptionMessage = parseException(imageBytes);
225 3853 ldiaz
                if (exceptionMessage==null)
226 3824 ldiaz
                {
227 3853 ldiaz
                         String error = new String(imageBytes);
228 3824 ldiaz
                        int pos = error.indexOf("<?xml");
229
                        if (pos!= -1)
230
                        {
231
                                String xml = error.substring(pos,error.length());
232
                                exceptionMessage = parseException(xml.getBytes());
233 3853 ldiaz
                        if (exceptionMessage == null)
234
                                exceptionMessage = new String(imageBytes);
235 3824 ldiaz
                        }
236
                }
237 4222 jaume
                     wmsEx = new WMSException(exceptionMessage);
238 3853 ldiaz
                    wmsEx.setWMSMessage(new String(imageBytes));
239
                throw wmsEx;
240 3776 jaume
            }
241 11381 jaume
                        return imageBytes;
242 3351 ldiaz
                }
243 3516 jaume
                catch(IOException e)
244 3351 ldiaz
                {
245 3405 jaume
                        e.printStackTrace();
246 3516 jaume
            throw new ServerErrorException();
247 3351 ldiaz
                }
248 11381 jaume
    }
249
250 7945 ldiaz
    public File getLegendGraphic(WMSStatus status, String layerName, ICancellable cancel) throws ServerErrorException, WMSException
251 7835 ldiaz
    {
252 27881 jpiera
            try
253 7835 ldiaz
                {
254 27881 jpiera
                        WMSGetLegendGraphicRequest request = createGetLegendGraphicRequest(status, layerName);
255
                        File f = request.sendRequest();
256 7835 ldiaz
                    if (f== null)
257
                            return null;
258
            if (Utilities.isTextFile(f)) {
259 33738 jpiera
260
                byte[] data = fileToBytes(f);
261 11381 jaume
262 7835 ldiaz
                            WMSException wmsEx = null;
263 11381 jaume
264 7835 ldiaz
                    String exceptionMessage = parseException(data);
265
                if (exceptionMessage==null)
266
                {
267
                         String error = new String(data);
268
                        int pos = error.indexOf("<?xml");
269
                        if (pos!= -1)
270
                        {
271
                                String xml = error.substring(pos,error.length());
272
                                exceptionMessage = parseException(xml.getBytes());
273 11381 jaume
                        }
274 7835 ldiaz
                    if (exceptionMessage == null)
275
                            exceptionMessage = new String(data);
276 11381 jaume
277 7835 ldiaz
                }
278
                     wmsEx = new WMSException(exceptionMessage);
279
                    wmsEx.setWMSMessage(new String(data));
280 33738 jpiera
                    downloader.removeURL(request);
281 7835 ldiaz
                throw wmsEx;
282
            }
283 11381 jaume
                        return f;
284 7835 ldiaz
                }
285
                catch(IOException e)
286
                {
287
                        e.printStackTrace();
288
            throw new ServerErrorException();
289
                }
290 11381 jaume
    }
291
292 5409 jaume
    public File getMap(WMSStatus status, ICancellable cancel) throws ServerErrorException, WMSException
293 11381 jaume
    {
294 27881 jpiera
            try
295 4222 jaume
                {
296 27881 jpiera
                        WMSGetMapRequest request = createGetMapRequest(status);
297
                        File f = request.sendRequest();
298
299
                        if (f== null)
300 5720 ldiaz
                            return null;
301 4222 jaume
            if (Utilities.isTextFile(f)) {
302 33738 jpiera
                byte[] data = fileToBytes(f);
303 11381 jaume
304 4222 jaume
                            WMSException wmsEx = null;
305 11381 jaume
306 4222 jaume
                    String exceptionMessage = parseException(data);
307
                if (exceptionMessage==null)
308
                {
309
                         String error = new String(data);
310
                        int pos = error.indexOf("<?xml");
311
                        if (pos!= -1)
312
                        {
313
                                String xml = error.substring(pos,error.length());
314
                                exceptionMessage = parseException(xml.getBytes());
315
//                        if (exceptionMessage == null)
316
//                                exceptionMessage = new String(data);
317 11381 jaume
                        }
318 4222 jaume
                    if (exceptionMessage == null)
319
                            exceptionMessage = new String(data);
320 11381 jaume
321 4222 jaume
                }
322
                     wmsEx = new WMSException(exceptionMessage);
323
                    wmsEx.setWMSMessage(new String(data));
324 11381 jaume
325 4222 jaume
                    // Since it is an error file, It must be deleted from the cache
326 33738 jpiera
                    downloader.removeURL(request);
327 4222 jaume
                throw wmsEx;
328
            }
329 11381 jaume
                        return f;
330 4222 jaume
                }
331
                catch(IOException e)
332
                {
333
                        e.printStackTrace();
334
            throw new ServerErrorException();
335
                }
336 11381 jaume
    }
337
338
339 3798 ldiaz
    /* (non-Javadoc)
340
     * @see org.gvsig.remoteClient.wms.WMSProtocolHandler#parseException(byte[])
341 3516 jaume
     */
342 3798 ldiaz
    protected String parseException(byte[] data) {
343
        ArrayList errors = new ArrayList();
344
        KXmlParser kxmlParser = new KXmlParser();
345
        try
346
        {
347 11381 jaume
            kxmlParser.setInput(new ByteArrayInputStream(data), encoding);
348 3798 ldiaz
            kxmlParser.nextTag();
349
            int tag;
350 11381 jaume
            if ( kxmlParser.getEventType() != KXmlParser.END_DOCUMENT )
351
            {
352
                kxmlParser.require(KXmlParser.START_TAG, null, ExceptionTags.EXCEPTION_ROOT);
353 3798 ldiaz
                tag = kxmlParser.nextTag();
354
                 while(tag != KXmlParser.END_DOCUMENT)
355
                 {
356
                     switch(tag)
357
                     {
358
                        case KXmlParser.START_TAG:
359
                            if (kxmlParser.getName().compareTo(ExceptionTags.SERVICE_EXCEPTION)==0){
360
                                String errorCode = kxmlParser.getAttributeValue("", ExceptionTags.CODE);
361
                                errorCode = (errorCode != null) ? "["+errorCode+"] " : "";
362
                                String errorMessage = kxmlParser.nextText();
363
                                errors.add(errorCode+errorMessage);
364
                            }
365
                            break;
366 11381 jaume
                        case KXmlParser.END_TAG:
367 3798 ldiaz
                            break;
368 11381 jaume
369 3798 ldiaz
                     }
370
                     tag = kxmlParser.nextTag();
371
                 }
372
                 //kxmlParser.require(KXmlParser.END_DOCUMENT, null, null);
373
            }
374
        }
375 11381 jaume
        catch(XmlPullParserException parser_ex){
376 3798 ldiaz
            parser_ex.printStackTrace();
377
        }
378 11381 jaume
        catch (IOException ioe) {
379
            ioe.printStackTrace();
380 3798 ldiaz
        }
381
        String message = errors.size()>0? "" : null;
382
        for (int i = 0; i < errors.size(); i++) {
383
            message += (String) errors.get(i)+"\n";
384
        }
385
        return message;
386
    }
387 3345 ldiaz
    /**
388
     * Builds the GetCapabilitiesRequest according to the OGC WMS Specifications
389 3687 ldiaz
     * without a VERSION, to get the highest version than a WMS supports.
390 3345 ldiaz
     */
391 3687 ldiaz
    public static String buildCapabilitiesSuitableVersionRequest(String _host, String _version)
392
    {
393 17849 jmvivo
                int index = _host.indexOf('?');
394
395
                if (index > -1) {
396
                        String host = _host.substring(0, index + 1);
397
                        String query = _host.substring(index + 1, _host.length());
398
399
                        StringTokenizer tokens = new StringTokenizer(query, "&");
400
                        String newQuery = "", token;
401
402
                        // If there is a field or a value with spaces, (and then it's on different tokens) -> unify them
403
                        while (tokens.hasMoreTokens()) {
404
                                token = tokens.nextToken().trim();
405
406
                                if (token.toUpperCase().compareTo("REQUEST=GETCAPABILITIES") == 0)
407
                                        continue;
408
409
                                if (token.toUpperCase().compareTo("SERVICE=WMS") == 0)
410
                                        continue;
411
412
                                if ((_version != null) && (_version.length() > 0)) {
413
                                    if (token.toUpperCase().compareTo("VERSION=" + _version) == 0)
414
                                            continue;
415
                                }
416
417
                                if (token.toUpperCase().compareTo("EXCEPTIONS=XML") == 0)
418
                                        continue;
419
420
                                newQuery += token + "&";
421
                        }
422
423
                _host = host + newQuery;
424
                }
425
                else {
426
                        _host += "?";
427
                }
428
429
            if ((_version != null) && (_version.compareTo("") != 0))
430 30324 jpiera
                    _host += "REQUEST=GetCapabilities&SERVICE=WMS&VERSION=" + _version;
431 17849 jmvivo
            else
432 30324 jpiera
                    _host += "REQUEST=GetCapabilities&SERVICE=WMS";
433 17849 jmvivo
434
            return _host;
435 3687 ldiaz
    }
436 11381 jaume
437 3687 ldiaz
    /**
438
     * Builds the GetCapabilitiesRequest according to the OGC WMS Specifications
439 4222 jaume
     * @param WMSStatus
440 3687 ldiaz
     */
441 5239 ldiaz
    private String buildCapabilitiesRequest(WMSStatus status)
442 3345 ldiaz
    {
443 4222 jaume
                StringBuffer req = new StringBuffer();
444
                String symbol = null;
445 11381 jaume
446 4222 jaume
                String onlineResource;
447
                if (status == null || status.getOnlineResource() == null)
448
                        onlineResource = getHost();
449 11381 jaume
                else
450 4222 jaume
                        onlineResource = status.getOnlineResource();
451
                symbol = getSymbol(onlineResource);
452 11381 jaume
453 4222 jaume
                req.append(onlineResource).append(symbol).append("REQUEST=GetCapabilities&SERVICE=WMS&");
454 30324 jpiera
                req.append("VERSION=").append(getVersion());
455 4222 jaume
                return req.toString();
456 27881 jpiera
    }
457
458
     public void close() {
459
        // your code here
460
    }
461
462
     /**
463
          * @param status
464
          * The WMS status
465
          * @param protocolHandler
466
          * The handler to parse the requests
467
          * @return an object to send the GetMap requests
468
          */
469
         protected abstract WMSGetMapRequest createGetMapRequest(WMSStatus status);
470
471
         protected abstract WMSGetFeatureInfoRequest createGetFeatureInfoRequest(WMSStatus status, int x, int y);
472
473
         protected abstract WMSGetLegendGraphicRequest createGetLegendGraphicRequest(WMSStatus status, String layerName);
474 11381 jaume
475 30324 jpiera
         protected abstract WMSGetCapabilitiesRequest createGetCapabilitiesRequest(WMSStatus status);
476 27881 jpiera
477
         /**
478
     * <p>Parses the Request tag </p>
479
     */
480
    protected void parseRequestTag(KXmlParser parser) throws IOException, XmlPullParserException
481
    {
482
            int currentTag;
483
            boolean end = false;
484
485
            parser.require(KXmlParser.START_TAG, null, CapabilitiesTags.REQUEST);
486
            currentTag = parser.next();
487
488
            while (!end)
489
            {
490
                         switch(currentTag)
491
                         {
492
                                case KXmlParser.START_TAG:
493
                                        if (parser.getName().compareTo(CapabilitiesTags.GETCAPABILITIES)==0)
494
                                        {
495
                                                parserDcpType(parser, CapabilitiesTags.GETCAPABILITIES);
496
                                        }
497
                                        else if (parser.getName().compareTo(CapabilitiesTags.GETMAP)==0)
498
                                        {
499
                                                parseGetMapTag(parser);
500
                                        }
501
                                        else if (parser.getName().compareTo(CapabilitiesTags.GETFEATUREINFO)==0)
502
                                        {
503
                                                parseGetFeatureInfoTag(parser);
504
                                        }
505
                                        else if (parser.getName().compareTo(CapabilitiesTags.DESCRIBELAYER)==0)
506
                                        {
507
                                                parserDcpType(parser, CapabilitiesTags.DESCRIBELAYER);
508
                                        }
509
                                        else if (parser.getName().compareTo(CapabilitiesTags.GETLEGENDGRAPHIC)==0)
510
                                        {
511
                                                parseGetLegendGraphicTag(parser);
512
                                        }
513
                                        break;
514
                                case KXmlParser.END_TAG:
515
                                        if (parser.getName().compareTo(CapabilitiesTags.REQUEST) == 0)
516
                                                end = true;
517
                                        break;
518
                                case KXmlParser.TEXT:
519
                                break;
520
                         }
521
                         if(!end)
522
                                 currentTag = parser.next();
523
            }
524
            // TODO: does not get such a tag when arrives here!!!!!!
525
            //parser.require(KXmlParser.END_TAG, null, CapabilitiesTags.REQUEST);
526
    }
527
          /**
528
     * <p>Parses the GetMap tag </p>
529
     */
530
    protected void parseGetMapTag(KXmlParser parser) throws IOException, XmlPullParserException
531
    {
532
            int currentTag;
533
            boolean end = false;
534
535
            parser.require(KXmlParser.START_TAG, null, CapabilitiesTags.GETMAP);
536
            currentTag = parser.next();
537
538
            while (!end)
539
            {
540
                         switch(currentTag)
541
                         {
542
                                case KXmlParser.START_TAG:
543
                                        if (parser.getName().compareTo(CapabilitiesTags.FORMAT)==0)
544
                                        {
545
                                                serviceInfo.formats.add(parser.nextText());
546
                                        }
547
                                        else if (parser.getName().compareTo(CapabilitiesTags.DCPTYPE)==0)
548
                                        {
549
                                                parserDcpType(parser, CapabilitiesTags.GETMAP);
550
                                        }
551
                                        break;
552
                                case KXmlParser.END_TAG:
553
                                        if (parser.getName().compareTo(CapabilitiesTags.GETMAP) == 0)
554
                                                end = true;
555
                                        break;
556
                                case KXmlParser.TEXT:
557
                                break;
558
                         }
559
                         if(!end)
560
                                 currentTag = parser.next();
561
            }
562
    }
563
564 3345 ldiaz
    /**
565 27881 jpiera
     * <p>Parses the GetFeatureInfo tag </p>
566
     */
567
    protected void parseGetFeatureInfoTag(KXmlParser parser) throws IOException, XmlPullParserException
568
    {
569
            int currentTag;
570
            boolean end = false;
571
572
            parser.require(KXmlParser.START_TAG, null, CapabilitiesTags.GETFEATUREINFO);
573
            currentTag = parser.next();
574
575
            while (!end)
576
            {
577
                         switch(currentTag)
578
                         {
579
                                case KXmlParser.START_TAG:
580
                                        if (parser.getName().compareTo(CapabilitiesTags.FORMAT)==0)
581
                                        {
582
                                                //TODO:
583
                                                // add the supported formats by the GetFeatureInfo request
584
                                                //serviceInfo.formats.add(parser.nextText());
585
                                        }
586
                                        else if (parser.getName().compareTo(CapabilitiesTags.DCPTYPE)==0)
587
                                        {
588
                                                parserDcpType(parser, CapabilitiesTags.GETFEATUREINFO);
589
                                        }
590
                                        break;
591
                                case KXmlParser.END_TAG:
592
                                        if (parser.getName().compareTo(CapabilitiesTags.GETFEATUREINFO) == 0)
593
                                                end = true;
594
                                        break;
595
                                case KXmlParser.TEXT:
596
                                break;
597
                         }
598
                         if(!end)
599
                                 currentTag = parser.next();
600
            }
601
    }
602
603 3351 ldiaz
    /**
604 27881 jpiera
     * <p>Parses the GetLegendGraphic tag </p>
605
     */
606
    protected void parseGetLegendGraphicTag(KXmlParser parser) throws IOException, XmlPullParserException
607
    {
608
            int currentTag;
609
            boolean end = false;
610
611
            parser.require(KXmlParser.START_TAG, null, CapabilitiesTags.GETLEGENDGRAPHIC);
612
            currentTag = parser.next();
613
614
            while (!end)
615
            {
616
                         switch(currentTag)
617
                         {
618
                                case KXmlParser.START_TAG:
619
                                        if (parser.getName().compareTo(CapabilitiesTags.FORMAT)==0)
620
                                        {
621
                                                //TODO:
622
                                                // add the supported formats by the GetLegendGraphic request
623
                                                //serviceInfo.formats.add(parser.nextText());
624
                                        }
625
                                        else if (parser.getName().compareTo(CapabilitiesTags.DCPTYPE)==0)
626
                                        {
627
                                                parserDcpType(parser, CapabilitiesTags.GETLEGENDGRAPHIC);
628
                                        }
629
                                        break;
630
                                case KXmlParser.END_TAG:
631
                                        if (parser.getName().compareTo(CapabilitiesTags.GETLEGENDGRAPHIC) == 0)
632
                                                end = true;
633
                                        break;
634
                                case KXmlParser.TEXT:
635
                                break;
636
                         }
637
                         if(!end)
638
                                 currentTag = parser.next();
639
            }
640 7835 ldiaz
    }
641 3323 ldiaz
 }