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