Statistics
| Revision:

root / trunk / libraries / libRemoteServices / src / org / gvsig / remoteClient / wcs / wcs_1_0_0 / WCSProtocolHandler1_0_0.java @ 3483

History | View | Annotate | Download (11.4 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2005 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *  Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib??ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *      +34 963862235
28
 *   gvsig@gva.es
29
 *      www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   IVER T.I. S.A
34
 *   Salamanca 50
35
 *   46005 Valencia
36
 *   Spain
37
 *
38
 *   +34 963163400
39
 *   dac@iver.es
40
 */
41
package org.gvsig.remoteClient.wcs.wcs_1_0_0;
42

    
43
import java.io.File;
44
import java.io.FileNotFoundException;
45
import java.io.FileReader;
46
import java.io.IOException;
47

    
48
import org.gvsig.remoteClient.utils.CapabilitiesTags;
49
import org.gvsig.remoteClient.utils.DescribeCoverageTags;
50
import org.gvsig.remoteClient.wcs.WCSProtocolHandler;
51
import org.kxml2.io.KXmlParser;
52
import org.xmlpull.v1.XmlPullParserException;
53

    
54
/**
55
 * @author jaume
56
 *
57
 */
58
public class WCSProtocolHandler1_0_0 extends WCSProtocolHandler{
59

    
60
    /* (non-Javadoc)
61
     * @see org.gvsig.remoteClient.OGCProtocolHandler#parseCapabilities(java.io.File)
62
     */
63
    /**
64
     * <p>Parse the xml data retrieved from the WMS, it will parse the WMS Capabilities</p>
65
     * 
66
     */
67
    public void parseCapabilities(File f)
68
    {       
69
        FileReader reader = null;       
70
        try
71
        {
72
            reader = new FileReader(f);
73
        }
74
        catch(FileNotFoundException ex) {
75
            ex.printStackTrace();
76
        }
77
        
78
        int tag;
79
        KXmlParser parser = null;
80
        parser = new KXmlParser();
81
        try
82
        {
83
            parser.setInput(reader);        
84
            parser.nextTag();
85
            
86
            if ( parser.getEventType() != KXmlParser.END_DOCUMENT ) 
87
            {           
88
                parser.require(KXmlParser.START_TAG, null, CapabilitiesTags.CAPABILITIES_ROOT);             
89
                tag = parser.nextTag();
90
                while(tag != KXmlParser.END_DOCUMENT)
91
                {
92
                    switch(tag)
93
                    {
94
                        case KXmlParser.START_TAG:
95
                            if (parser.getName().compareTo(CapabilitiesTags.SERVICE )==0)
96
                            {
97
                                parseServiceTag(parser);
98
                            }   
99
                            else if (parser.getName().compareTo(CapabilitiesTags.CAPABILITY)==0)
100
                            {
101
                                parseCapabilityTag(parser);
102
                            } 
103
                            else if (parser.getName().compareTo(CapabilitiesTags.WCS_CONTENTMETADATA)==0)
104
                            {
105
                                parser.skipSubTree();
106
                            }
107
                            break;
108
                        case KXmlParser.END_TAG:                            
109
                            break;
110
                        case KXmlParser.TEXT:
111
                            System.out.println("[TEXT]["+parser.getText()+"]");                         
112
                            break;
113
                    }
114
                    tag = parser.next();
115
                }
116
                parser.require(KXmlParser.END_DOCUMENT, null, null);                
117
            }
118
        }
119
        catch(XmlPullParserException parser_ex){
120
            System.out.println(parser_ex.getMessage());
121
            parser_ex.printStackTrace();
122
            
123
        }
124
        catch (IOException ioe) {           
125
            ioe.printStackTrace();
126
            
127
        }           
128
    } 
129

    
130
    /* (non-Javadoc)
131
     * @see org.gvsig.remoteClient.wcs.WCSProtocolHandler#parseDescribeCoverage(java.io.File)
132
     */
133
    public void parseDescribeCoverage(File f) {
134
        FileReader reader = null;
135
        try {
136
            reader = new FileReader(f);
137
        } catch (FileNotFoundException e){
138
            e.printStackTrace();
139
        }
140
        int tag;
141
        KXmlParser parser = new KXmlParser();
142
        try {
143
            parser.setInput(reader);
144
            parser.nextTag();
145
            if (parser.getEventType() != KXmlParser.END_DOCUMENT){
146
                parser.require(KXmlParser.START_TAG, null, DescribeCoverageTags.COVERAGE_DESCRIPTION);
147
                tag = parser.nextTag();
148
                while (tag != KXmlParser.END_DOCUMENT){
149
                    switch (tag){
150
                        case KXmlParser.START_TAG:
151
                            if (parser.getName().compareTo(DescribeCoverageTags.COVERAGE_OFFERING)==0){
152
                                WCSLayer1_0_0 lyr = new WCSLayer1_0_0();
153
                                lyr.parse(parser);
154
                                if (lyr!=null){
155
                                    
156
                                }
157
                            }
158
                            break;
159
                    }
160
                    tag = parser.next();
161
                }
162
                parser.require(KXmlParser.END_DOCUMENT, null, null);
163
            }
164
        } catch (XmlPullParserException e) {
165
            System.out.println(e.getMessage());
166
            e.printStackTrace();
167
        }
168
        catch (IOException ioe) {           
169
            ioe.printStackTrace();
170
            
171
        }           
172
    }
173

    
174

    
175
    /**
176
     * <p>Parses the Capability Tag </p>
177
     */    
178
    private void parseCapabilityTag(KXmlParser parser) throws IOException, XmlPullParserException
179
    {   
180
        int currentTag;
181
        boolean end = false;
182
        
183
        parser.require(KXmlParser.START_TAG, null, CapabilitiesTags.CAPABILITY);
184
        currentTag = parser.next();
185
        
186
        while (!end) 
187
        {
188
             switch(currentTag)
189
             {
190
                case KXmlParser.START_TAG:
191
                    if (parser.getName().compareTo(CapabilitiesTags.REQUEST)==0)
192
                    {
193
                        parseRequestTag(parser); 
194
                    }   
195
                    else if (parser.getName().compareTo(CapabilitiesTags.EXCEPTION)==0)
196
                    {
197
                        //Parse exception tags...
198
                    }
199
                    else if ((parser.getName().compareTo(CapabilitiesTags.VENDORSPECIFICCAPABILITIES)==0) ||
200
                            (parser.getName().compareTo(CapabilitiesTags.USERDEFINEDSYMBOLIZATION )==0))
201
                    {
202
                        parser.skipSubTree();
203
                    }                   
204
                    break;
205
                case KXmlParser.END_TAG:
206
                    if (parser.getName().compareTo(CapabilitiesTags.CAPABILITY) == 0)
207
                        end = true;
208
                    break;
209
                case KXmlParser.TEXT:                   
210
                break;
211
             }
212
             currentTag = parser.next();
213
        }
214
    }
215

    
216

    
217
    /**
218
     * <p>Parses the Service Information </p>
219
     */    
220
    private void parseServiceTag(KXmlParser parser) throws IOException, XmlPullParserException 
221
    {
222
        int currentTag;
223
        boolean end = false;
224
        
225
        parser.require(KXmlParser.START_TAG, null, CapabilitiesTags.SERVICE);
226
        currentTag = parser.next();
227
        
228
        while (!end) 
229
        {
230
             switch(currentTag)
231
             {
232
                case KXmlParser.START_TAG:
233
                    if (parser.getName().compareTo(CapabilitiesTags.NAME)==0)
234
                    {
235
                        serviceInfo.name = parser.nextText(); 
236
                    }   
237
                    else if (parser.getName().compareTo(CapabilitiesTags.WCS_LABEL)==0)
238
                    {
239
                        serviceInfo.title = parser.nextText(); 
240
                    }
241
                    else if (parser.getName().compareTo(CapabilitiesTags.ABSTRACT)==0)
242
                    {
243
                        serviceInfo.abstr = parser.nextText(); 
244
                    }
245
                    else if (parser.getName().compareTo(CapabilitiesTags.WCS_KEYWORDS)==0) 
246
                    {
247
                        parser.skipSubTree();
248
                    }                   
249
                    else if (parser.getName().compareTo(CapabilitiesTags.ACCESSCONSTRAINTS)==0) 
250
                    {
251
                        parser.skipSubTree();
252
                    }                   
253
                    else if (parser.getName().compareTo(CapabilitiesTags.FEES)==0) 
254
                    {
255
                        parser.skipSubTree();
256
                    }                   
257
                    break;
258
                case KXmlParser.END_TAG:
259
                    if (parser.getName().compareTo(CapabilitiesTags.SERVICE) == 0)
260
                        end = true;
261
                    break;
262
                case KXmlParser.TEXT:                   
263
                break;
264
             }
265
             currentTag = parser.next();
266
        }
267
//      parser.require(KXmlParser.END_TAG, null, CapabilitiesTags.SERVICE);
268
    }
269
    
270
    /**
271
     * <p>Parses the Request tag </p>
272
     */ 
273
    private void parseRequestTag(KXmlParser parser) throws IOException, XmlPullParserException
274
    {   
275
        int currentTag;
276
        boolean end = false;
277
        
278
        parser.require(KXmlParser.START_TAG, null, CapabilitiesTags.REQUEST);
279
        currentTag = parser.next();
280
        
281
        while (!end) 
282
        {
283
             switch(currentTag)
284
             {
285
                case KXmlParser.START_TAG:
286
                    if (parser.getName().compareTo(CapabilitiesTags.GETCAPABILITIES)==0)
287
                    {
288
                    }   
289
                    else if (parser.getName().compareTo(CapabilitiesTags.GETMAP)==0)
290
                    {
291
                        currentTag = parser.nextTag();
292
                        parser.require(KXmlParser.START_TAG, null, CapabilitiesTags.FORMAT);  
293
                        while ((currentTag == KXmlParser.START_TAG) &&
294
                                (parser.getName().compareTo(CapabilitiesTags.FORMAT)==0))
295
                        {
296
                            parser.require(KXmlParser.START_TAG, null, CapabilitiesTags.FORMAT);
297
                            serviceInfo.formats.add(parser.nextText());
298
                            parser.nextTag();
299
                        }                                                                               
300
                    }
301
                    else if (parser.getName().compareTo(CapabilitiesTags.GETFEATUREINFO)==0)
302
                    {
303
                    }               
304
                    break;
305
                case KXmlParser.END_TAG:
306
                    if (parser.getName().compareTo(CapabilitiesTags.REQUEST) == 0)
307
                        end = true;
308
                    break;
309
                case KXmlParser.TEXT:                   
310
                break;
311
             }
312
             currentTag = parser.next();
313
        }
314
        // TODO: does not get such a tag when arrives here!!!!!!
315
        //parser.require(KXmlParser.END_TAG, null, CapabilitiesTags.REQUEST);       
316
    }
317
    
318

    
319
}