svn-gvsig-desktop / branches / v10 / libraries / libRemoteServices / src / org / gvsig / remoteClient / wfs / wfs_1_0_0 / WFSProtocolHandler1_0_0.java @ 9917
History | View | Annotate | Download (12.4 KB)
1 |
package org.gvsig.remoteClient.wfs.wfs_1_0_0; |
---|---|
2 |
|
3 |
import java.io.BufferedReader; |
4 |
import java.io.File; |
5 |
import java.io.FileInputStream; |
6 |
import java.io.FileNotFoundException; |
7 |
import java.io.FileReader; |
8 |
import java.io.IOException; |
9 |
import java.util.Vector; |
10 |
|
11 |
import org.gvsig.remoteClient.gml.factories.XMLElementsFactory; |
12 |
import org.gvsig.remoteClient.gml.schemas.XMLElement; |
13 |
import org.gvsig.remoteClient.gml.schemas.XMLSchemaParser; |
14 |
import org.gvsig.remoteClient.utils.CapabilitiesTags; |
15 |
import org.gvsig.remoteClient.wfs.WFSProtocolHandler; |
16 |
import org.kxml2.io.KXmlParser; |
17 |
import org.xmlpull.v1.XmlPullParserException; |
18 |
|
19 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
20 |
*
|
21 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
22 |
*
|
23 |
* This program is free software; you can redistribute it and/or
|
24 |
* modify it under the terms of the GNU General Public License
|
25 |
* as published by the Free Software Foundation; either version 2
|
26 |
* of the License, or (at your option) any later version.
|
27 |
*
|
28 |
* This program is distributed in the hope that it will be useful,
|
29 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
30 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
31 |
* GNU General Public License for more details.
|
32 |
*
|
33 |
* You should have received a copy of the GNU General Public License
|
34 |
* along with this program; if not, write to the Free Software
|
35 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
36 |
*
|
37 |
* For more information, contact:
|
38 |
*
|
39 |
* Generalitat Valenciana
|
40 |
* Conselleria d'Infraestructures i Transport
|
41 |
* Av. Blasco Ib??ez, 50
|
42 |
* 46010 VALENCIA
|
43 |
* SPAIN
|
44 |
*
|
45 |
* +34 963862235
|
46 |
* gvsig@gva.es
|
47 |
* www.gvsig.gva.es
|
48 |
*
|
49 |
* or
|
50 |
*
|
51 |
* IVER T.I. S.A
|
52 |
* Salamanca 50
|
53 |
* 46005 Valencia
|
54 |
* Spain
|
55 |
*
|
56 |
* +34 963163400
|
57 |
* dac@iver.es
|
58 |
*/
|
59 |
/* CVS MESSAGES:
|
60 |
*
|
61 |
* $Id: WFSProtocolHandler1_0_0.java 9917 2007-01-25 16:13:00Z jorpiell $
|
62 |
* $Log$
|
63 |
* Revision 1.6.2.4 2007-01-25 16:13:00 jorpiell
|
64 |
* Se han sustituido las clases por las que hay en el nuevo driver de GML.
|
65 |
*
|
66 |
* Revision 1.6.2.3 2006/11/17 11:38:03 ppiqueras
|
67 |
* Corregidos bugs y a?adida nueva funcionalidad. Del HEAD.
|
68 |
*
|
69 |
* Revision 1.8 2006/10/31 09:36:51 jorpiell
|
70 |
* Se devuelve el tipo de la entidad completo, y no sus hijos
|
71 |
*
|
72 |
* Revision 1.7 2006/10/10 12:52:28 jorpiell
|
73 |
* Soporte para features complejas.
|
74 |
*
|
75 |
* Revision 1.6 2006/06/14 07:54:18 jorpiell
|
76 |
* Se parsea el online resource que antes se ignoraba
|
77 |
*
|
78 |
* Revision 1.5 2006/05/25 10:20:57 jorpiell
|
79 |
* Se ha cambiado el nombre de la clase WFSField por la clase WFSAttribute, porque resultaba confuso
|
80 |
*
|
81 |
* Revision 1.4 2006/05/23 13:23:22 jorpiell
|
82 |
* Se ha cambiado el final del bucle de parseado y se tiene en cuenta el online resource
|
83 |
*
|
84 |
* Revision 1.2 2006/04/20 16:39:16 jorpiell
|
85 |
* A?adida la operacion de describeFeatureType y el parser correspondiente.
|
86 |
*
|
87 |
* Revision 1.1 2006/04/19 12:51:35 jorpiell
|
88 |
* A?adidas algunas de las clases del servicio WFS
|
89 |
*
|
90 |
*
|
91 |
*/
|
92 |
/**
|
93 |
* @author Jorge Piera Llodr? (piera_jor@gva.es)
|
94 |
*/
|
95 |
public class WFSProtocolHandler1_0_0 extends WFSProtocolHandler{ |
96 |
public WFSProtocolHandler1_0_0(){
|
97 |
this.version = "1.0.0"; |
98 |
this.name = "WFS1.0.0"; |
99 |
} |
100 |
|
101 |
public boolean parseCapabilities(File f) { |
102 |
FileReader reader = null; |
103 |
try
|
104 |
{ |
105 |
reader = new FileReader(f); |
106 |
BufferedReader br = new BufferedReader(reader); |
107 |
char[] buffer = new char[100]; |
108 |
br.read(buffer); |
109 |
StringBuffer st = new StringBuffer(new String(buffer)); |
110 |
String searchText = "encoding=\""; |
111 |
int index = st.indexOf(searchText);
|
112 |
if (index>-1) { |
113 |
st.delete(0, index+searchText.length());
|
114 |
encoding = st.substring(0, st.indexOf("\"")); |
115 |
} |
116 |
} catch (FileNotFoundException ex) { |
117 |
ex.printStackTrace(); |
118 |
} catch (IOException e) { |
119 |
e.printStackTrace(); |
120 |
} |
121 |
|
122 |
int tag;
|
123 |
KXmlParser parser = null;
|
124 |
parser = new KXmlParser();
|
125 |
try
|
126 |
{ |
127 |
parser.setInput(new FileInputStream(f), encoding); |
128 |
parser.nextTag(); |
129 |
|
130 |
if ( parser.getEventType() != KXmlParser.END_DOCUMENT )
|
131 |
{ |
132 |
parser.require(KXmlParser.START_TAG, null, CapabilitiesTags.WFS_CAPABILITIES_ROOT1_0_0);
|
133 |
tag = parser.nextTag(); |
134 |
while(tag != KXmlParser.END_DOCUMENT)
|
135 |
{ |
136 |
switch(tag)
|
137 |
{ |
138 |
case KXmlParser.START_TAG:
|
139 |
if (parser.getName().compareTo(CapabilitiesTags.SERVICE)==0) |
140 |
{ |
141 |
parseServiceTag(parser); |
142 |
} |
143 |
else if (parser.getName().compareTo(CapabilitiesTags.CAPABILITY)==0) |
144 |
{ |
145 |
parseCapabilityTag(parser); |
146 |
} |
147 |
else if (parser.getName().compareTo(CapabilitiesTags.WFS_FEATURETYPELIST)==0) |
148 |
{ |
149 |
parseFeatureTypeListTag(parser); |
150 |
} |
151 |
break;
|
152 |
case KXmlParser.END_TAG:
|
153 |
break;
|
154 |
case KXmlParser.TEXT:
|
155 |
if (parser.getName()!=null) |
156 |
System.out.println("[TEXT]["+parser.getText().trim()+"]"); |
157 |
break;
|
158 |
} |
159 |
tag = parser.next(); |
160 |
} |
161 |
parser.require(KXmlParser.END_DOCUMENT, null, null); |
162 |
} |
163 |
} |
164 |
catch(XmlPullParserException parser_ex){
|
165 |
System.out.println(parser_ex.getMessage());
|
166 |
parser_ex.printStackTrace(); |
167 |
return false; |
168 |
} |
169 |
catch (IOException ioe) { |
170 |
ioe.printStackTrace(); |
171 |
return false; |
172 |
} |
173 |
return true; |
174 |
} |
175 |
|
176 |
/**
|
177 |
* <p>Parses the Service Information </p>
|
178 |
*/
|
179 |
private void parseServiceTag(KXmlParser parser) throws IOException, XmlPullParserException |
180 |
{ |
181 |
int currentTag;
|
182 |
boolean end = false; |
183 |
|
184 |
parser.require(KXmlParser.START_TAG, null, CapabilitiesTags.SERVICE);
|
185 |
currentTag = parser.next(); |
186 |
|
187 |
while (!end)
|
188 |
{ |
189 |
switch(currentTag)
|
190 |
{ |
191 |
case KXmlParser.START_TAG:
|
192 |
if (parser.getName().compareToIgnoreCase(CapabilitiesTags.NAME)==0) |
193 |
{ |
194 |
serviceInfo.name = parser.nextText(); |
195 |
} |
196 |
else if (parser.getName().compareTo(CapabilitiesTags.WFS_TITLE)==0) |
197 |
{ |
198 |
serviceInfo.title = parser.nextText(); |
199 |
} |
200 |
else if (parser.getName().compareTo(CapabilitiesTags.WFS_ABSTRACT)==0) |
201 |
{ |
202 |
serviceInfo.abstr = parser.nextText(); |
203 |
} |
204 |
else if (parser.getName().compareTo(CapabilitiesTags.ONLINERESOURCE)==0) |
205 |
{ |
206 |
serviceInfo.online_resource = parser.nextText(); |
207 |
|
208 |
} |
209 |
break;
|
210 |
case KXmlParser.END_TAG:
|
211 |
if (parser.getName().compareTo(CapabilitiesTags.SERVICE) == 0) |
212 |
end = true;
|
213 |
break;
|
214 |
case KXmlParser.TEXT:
|
215 |
break;
|
216 |
} |
217 |
if (!end){
|
218 |
currentTag = parser.next(); |
219 |
} |
220 |
} |
221 |
} |
222 |
|
223 |
private void parseCapabilityTag(KXmlParser parser) throws IOException, XmlPullParserException |
224 |
{ |
225 |
int currentTag;
|
226 |
boolean end = false; |
227 |
|
228 |
parser.require(KXmlParser.START_TAG, null, CapabilitiesTags.CAPABILITY);
|
229 |
currentTag = parser.next(); |
230 |
|
231 |
while (!end)
|
232 |
{ |
233 |
switch(currentTag)
|
234 |
{ |
235 |
case KXmlParser.START_TAG:
|
236 |
if (parser.getName().compareTo(CapabilitiesTags.REQUEST)==0) |
237 |
{ |
238 |
parseRequestTag(parser); |
239 |
} |
240 |
else if (parser.getName().compareTo(CapabilitiesTags.EXCEPTION)==0) |
241 |
{ |
242 |
//TODO Parse exception tags...
|
243 |
parser.skipSubTree(); |
244 |
} |
245 |
else if ((parser.getName().compareTo(CapabilitiesTags.VENDORSPECIFICCAPABILITIES)==0) || |
246 |
(parser.getName().compareTo(CapabilitiesTags.USERDEFINEDSYMBOLIZATION )==0))
|
247 |
{ |
248 |
parser.skipSubTree(); |
249 |
} |
250 |
break;
|
251 |
case KXmlParser.END_TAG:
|
252 |
if (parser.getName().compareTo(CapabilitiesTags.CAPABILITY) == 0) |
253 |
end = true;
|
254 |
break;
|
255 |
case KXmlParser.TEXT:
|
256 |
break;
|
257 |
} |
258 |
if (!end){
|
259 |
currentTag = parser.next(); |
260 |
} |
261 |
} |
262 |
} |
263 |
|
264 |
/**
|
265 |
* <p>Parses the Request tag </p>
|
266 |
*/
|
267 |
private void parseRequestTag(KXmlParser parser) throws IOException, XmlPullParserException |
268 |
{ |
269 |
int currentTag;
|
270 |
boolean end = false; |
271 |
|
272 |
parser.require(KXmlParser.START_TAG, null, CapabilitiesTags.REQUEST);
|
273 |
currentTag = parser.next(); |
274 |
|
275 |
while (!end)
|
276 |
{ |
277 |
switch(currentTag)
|
278 |
{ |
279 |
case KXmlParser.START_TAG:
|
280 |
if (parser.getName().compareTo(CapabilitiesTags.GETCAPABILITIES)==0) |
281 |
{ |
282 |
currentTag = parser.nextTag(); |
283 |
if (parser.getName().compareTo(CapabilitiesTags.DCPTYPE)==0) |
284 |
{ |
285 |
currentTag = parser.nextTag(); |
286 |
if(parser.getName().compareTo(CapabilitiesTags.HTTP)==0) |
287 |
{ |
288 |
currentTag = parser.nextTag(); |
289 |
if(parser.getName().compareTo(CapabilitiesTags.GET)==0) |
290 |
{ |
291 |
String value = null; |
292 |
for (int i=0 ; i<parser.getAttributeCount() ; i++){ |
293 |
if (parser.getAttributeName(i).toUpperCase().compareTo(CapabilitiesTags.ONLINERESOURCE.toUpperCase()) == 0){ |
294 |
value = parser.getAttributeValue(i); |
295 |
} |
296 |
} |
297 |
if (value == null){ |
298 |
serviceInfo.addOperation(WFSOperation.GETCAPABILITIES); |
299 |
}else{
|
300 |
serviceInfo.addOperation(WFSOperation.GETCAPABILITIES,value); |
301 |
} |
302 |
} |
303 |
} |
304 |
} |
305 |
|
306 |
} |
307 |
else if (parser.getName().compareTo(CapabilitiesTags.WFS_DESCRIBEFEATURETYPE)==0) |
308 |
{ |
309 |
currentTag = parser.nextTag(); |
310 |
if (parser.getName().compareTo(CapabilitiesTags.DCPTYPE)==0) |
311 |
{ |
312 |
currentTag = parser.nextTag(); |
313 |
if(parser.getName().compareTo(CapabilitiesTags.HTTP)==0) |
314 |
{ |
315 |
currentTag = parser.nextTag(); |
316 |
if(parser.getName().compareTo(CapabilitiesTags.GET)==0) |
317 |
{ |
318 |
String value = null; |
319 |
for (int i=0 ; i<parser.getAttributeCount() ; i++){ |
320 |
if (parser.getAttributeName(i).toUpperCase().compareTo(CapabilitiesTags.ONLINERESOURCE.toUpperCase()) == 0){ |
321 |
value = parser.getAttributeValue(i); |
322 |
} |
323 |
} |
324 |
if (value == null){ |
325 |
serviceInfo.addOperation(WFSOperation.DESCRIBEFEATURETYPE); |
326 |
}else{
|
327 |
serviceInfo.addOperation(WFSOperation.DESCRIBEFEATURETYPE,value); |
328 |
} |
329 |
} |
330 |
} |
331 |
} |
332 |
} |
333 |
else if (parser.getName().compareTo(CapabilitiesTags.WFS_GETFEATURE)==0) |
334 |
{ |
335 |
currentTag = parser.nextTag(); |
336 |
if (parser.getName().compareTo(CapabilitiesTags.DCPTYPE)==0) |
337 |
{ |
338 |
currentTag = parser.nextTag(); |
339 |
if(parser.getName().compareTo(CapabilitiesTags.HTTP)==0) |
340 |
{ |
341 |
currentTag = parser.nextTag(); |
342 |
if(parser.getName().compareTo(CapabilitiesTags.GET)==0) |
343 |
{ |
344 |
String value = null; |
345 |
for (int i=0 ; i<parser.getAttributeCount() ; i++){ |
346 |
if (parser.getAttributeName(i).toUpperCase().compareTo(CapabilitiesTags.ONLINERESOURCE.toUpperCase()) == 0){ |
347 |
value = parser.getAttributeValue(i); |
348 |
} |
349 |
} |
350 |
if (value == null){ |
351 |
serviceInfo.addOperation(WFSOperation.GETFEATURE); |
352 |
}else{
|
353 |
serviceInfo.addOperation(WFSOperation.GETFEATURE,value); |
354 |
} |
355 |
} |
356 |
} |
357 |
} |
358 |
} |
359 |
break;
|
360 |
case KXmlParser.END_TAG:
|
361 |
if (parser.getName().compareTo(CapabilitiesTags.REQUEST) == 0) |
362 |
end = true;
|
363 |
break;
|
364 |
case KXmlParser.TEXT:
|
365 |
break;
|
366 |
} |
367 |
if (!end){
|
368 |
currentTag = parser.next(); |
369 |
} |
370 |
} |
371 |
// TODO: does not get such a tag when arrives here!!!!!!
|
372 |
//parser.require(KXmlParser.END_TAG, null, CapabilitiesTags.REQUEST);
|
373 |
} |
374 |
|
375 |
|
376 |
private void parseFeatureTypeListTag(KXmlParser parser) throws IOException, XmlPullParserException |
377 |
{ |
378 |
int currentTag;
|
379 |
boolean end = false; |
380 |
|
381 |
parser.require(KXmlParser.START_TAG, null, CapabilitiesTags.WFS_FEATURETYPELIST);
|
382 |
currentTag = parser.next(); |
383 |
|
384 |
while (!end)
|
385 |
{ |
386 |
switch(currentTag)
|
387 |
{ |
388 |
case KXmlParser.START_TAG:
|
389 |
if (parser.getName().compareToIgnoreCase(CapabilitiesTags.WFS_FEATURETYPE)==0) |
390 |
{ |
391 |
WFSFeature1_0_0 feature = new WFSFeature1_0_0();
|
392 |
feature.parse(parser); |
393 |
features.put(feature.getName(),feature); |
394 |
} |
395 |
break;
|
396 |
case KXmlParser.END_TAG:
|
397 |
if (parser.getName().compareTo(CapabilitiesTags.WFS_FEATURETYPELIST) == 0) |
398 |
end = true;
|
399 |
break;
|
400 |
case KXmlParser.TEXT:
|
401 |
break;
|
402 |
} |
403 |
if (!end){
|
404 |
currentTag = parser.next(); |
405 |
} |
406 |
} |
407 |
} |
408 |
|
409 |
public boolean parseDescribeFeatureType(File f,String nameSpace) { |
410 |
XMLSchemaParser schemaParser = new XMLSchemaParser();
|
411 |
try {
|
412 |
schemaParser.parse(f,nameSpace); |
413 |
} catch (XmlPullParserException e) {
|
414 |
// TODO Auto-generated catch block
|
415 |
e.printStackTrace(); |
416 |
} catch (IOException e) { |
417 |
// TODO Auto-generated catch block
|
418 |
e.printStackTrace(); |
419 |
} |
420 |
|
421 |
String layerName = getCurrentFeature();
|
422 |
if (getCurrentFeature().split(":").length>1){ |
423 |
layerName = getCurrentFeature().split(":")[1]; |
424 |
} |
425 |
XMLElement entity = XMLElementsFactory.getElement(layerName); |
426 |
if (entity != null){ |
427 |
Vector vector = new Vector(); |
428 |
vector.add(entity); |
429 |
setFields(vector); |
430 |
} |
431 |
return true; |
432 |
} |
433 |
|
434 |
} |