svn-gvsig-desktop / branches / v2_0_0_prep / libraries / libRemoteServices / src / org / gvsig / remoteclient / wfs / wfs_1_1_0 / WFSProtocolHandler1_1_0.java @ 34026
History | View | Annotate | Download (17.2 KB)
1 |
package org.gvsig.remoteclient.wfs.wfs_1_1_0; |
---|---|
2 |
|
3 |
import java.io.File; |
4 |
import java.io.FileNotFoundException; |
5 |
import java.io.IOException; |
6 |
|
7 |
import org.kxml2.io.KXmlParser; |
8 |
import org.xmlpull.v1.XmlPullParserException; |
9 |
|
10 |
import org.gvsig.compat.CompatLocator; |
11 |
import org.gvsig.compat.lang.StringUtils; |
12 |
import org.gvsig.remoteclient.utils.CapabilitiesTags; |
13 |
import org.gvsig.remoteclient.wfs.WFSOperation; |
14 |
import org.gvsig.remoteclient.wfs.WFSProtocolHandler; |
15 |
import org.gvsig.remoteclient.wfs.WFSStatus; |
16 |
import org.gvsig.remoteclient.wfs.edition.WFSTTags; |
17 |
import org.gvsig.remoteclient.wfs.edition.WFSTTransaction; |
18 |
import org.gvsig.remoteclient.wfs.exceptions.ExceptionsFactory; |
19 |
import org.gvsig.remoteclient.wfs.exceptions.WFSException; |
20 |
import org.gvsig.remoteclient.wfs.exceptions.WFSGetFeatureException; |
21 |
import org.gvsig.remoteclient.wfs.request.WFSDescribeFeatureTypeRequest; |
22 |
import org.gvsig.remoteclient.wfs.request.WFSGetFeatureRequest; |
23 |
import org.gvsig.remoteclient.wfs.request.WFSGetFeatureRequestInformation; |
24 |
import org.gvsig.remoteclient.wfs.request.WFSTLockFeatureRequest; |
25 |
import org.gvsig.remoteclient.wfs.schema.XMLSchemaParser; |
26 |
import org.gvsig.remoteclient.wfs.wfs_1_1_0.request.WFSDescribeFeatureTypeRequest1_1_0; |
27 |
import org.gvsig.remoteclient.wfs.wfs_1_1_0.request.WFSGetFeatureRequest1_1_0; |
28 |
import org.gvsig.remoteclient.wfs.wfs_1_1_0.request.WFSTLockFeatureRequest1_1_0; |
29 |
|
30 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
31 |
*
|
32 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
33 |
*
|
34 |
* This program is free software; you can redistribute it and/or
|
35 |
* modify it under the terms of the GNU General Public License
|
36 |
* as published by the Free Software Foundation; either version 2
|
37 |
* of the License, or (at your option) any later version.
|
38 |
*
|
39 |
* This program is distributed in the hope that it will be useful,
|
40 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
41 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
42 |
* GNU General Public License for more details.
|
43 |
*
|
44 |
* You should have received a copy of the GNU General Public License
|
45 |
* along with this program; if not, write to the Free Software
|
46 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
47 |
*
|
48 |
* For more information, contact:
|
49 |
*
|
50 |
* Generalitat Valenciana
|
51 |
* Conselleria d'Infraestructures i Transport
|
52 |
* Av. Blasco Ib??ez, 50
|
53 |
* 46010 VALENCIA
|
54 |
* SPAIN
|
55 |
*
|
56 |
* +34 963862235
|
57 |
* gvsig@gva.es
|
58 |
* www.gvsig.gva.es
|
59 |
*
|
60 |
* or
|
61 |
*
|
62 |
* IVER T.I. S.A
|
63 |
* Salamanca 50
|
64 |
* 46005 Valencia
|
65 |
* Spain
|
66 |
*
|
67 |
* +34 963163400
|
68 |
* dac@iver.es
|
69 |
*/
|
70 |
/* CVS MESSAGES:
|
71 |
*
|
72 |
* $Id: WFSProtocolHandler1_1_0.java 34026 2010-11-08 13:06:02Z jpiera $
|
73 |
* $Log$
|
74 |
* Revision 1.1 2007-02-09 14:11:01 jorpiell
|
75 |
* Primer piloto del soporte para WFS 1.1 y para WFS-T
|
76 |
*
|
77 |
*
|
78 |
*/
|
79 |
/**
|
80 |
* @author Jorge Piera Llodr? (piera_jor@gva.es)
|
81 |
*/
|
82 |
public class WFSProtocolHandler1_1_0 extends WFSProtocolHandler{ |
83 |
|
84 |
private static final StringUtils stringUtils = CompatLocator.getStringUtils(); |
85 |
|
86 |
public WFSProtocolHandler1_1_0(){
|
87 |
this.version = "1.1.0"; |
88 |
this.name = "WFS1.1.0"; |
89 |
} |
90 |
|
91 |
/*
|
92 |
* (non-Javadoc)
|
93 |
* @see org.gvsig.remoteClient.OGCProtocolHandler#parseCapabilities(java.io.File)
|
94 |
*/
|
95 |
public boolean parseCapabilities(File f) { |
96 |
int tag;
|
97 |
XMLSchemaParser parser = null;
|
98 |
parser = new XMLSchemaParser();
|
99 |
try
|
100 |
{ |
101 |
parser.setInput(f); |
102 |
parser.nextTag(); |
103 |
|
104 |
if ( parser.getEventType() != KXmlParser.END_DOCUMENT )
|
105 |
{ |
106 |
parser.require(KXmlParser.START_TAG, null, CapabilitiesTags.WFS_CAPABILITIES_ROOT1_0_0);
|
107 |
//Parses the Namespaces...
|
108 |
parseNamespaces(parser); |
109 |
tag = parser.nextTag(); |
110 |
while(tag != KXmlParser.END_DOCUMENT)
|
111 |
{ |
112 |
switch(tag)
|
113 |
{ |
114 |
case KXmlParser.START_TAG:
|
115 |
if (parser.getName().compareTo(CapabilitiesTags.SERVICE_IDENTIFICATION)==0) |
116 |
{ |
117 |
parseServiceIdentification(parser); |
118 |
} |
119 |
else if (parser.getName().compareTo(CapabilitiesTags.SERVICE_PROVIDER)==0) |
120 |
{ |
121 |
parseServiceProvider(parser); |
122 |
} |
123 |
else if (parser.getName().compareTo(CapabilitiesTags.OPERATIONS_METADATA)==0) |
124 |
{ |
125 |
parseOperationsMetadata(parser); |
126 |
} |
127 |
else if (parser.getName().compareTo(CapabilitiesTags.FEATURE_TYPE_LIST)==0) |
128 |
{ |
129 |
parseFeatureTypeList(parser); |
130 |
} |
131 |
else if (parser.getName().compareTo(CapabilitiesTags.FILTER_CAPABILITIES)==0) |
132 |
{ |
133 |
parseFilterCapabilities(parser); |
134 |
} |
135 |
break;
|
136 |
case KXmlParser.END_TAG:
|
137 |
break;
|
138 |
case KXmlParser.TEXT:
|
139 |
if (parser.getName()!=null) |
140 |
|
141 |
break;
|
142 |
} |
143 |
tag = parser.next(); |
144 |
} |
145 |
parser.require(KXmlParser.END_DOCUMENT, null, null); |
146 |
} |
147 |
} |
148 |
catch(XmlPullParserException parser_ex){
|
149 |
parser_ex.printStackTrace(); |
150 |
return false; |
151 |
} |
152 |
catch (IOException ioe) { |
153 |
ioe.printStackTrace(); |
154 |
return false; |
155 |
} |
156 |
return true; |
157 |
} |
158 |
|
159 |
/**
|
160 |
* <p>Parses the Service Identification </p>
|
161 |
*/
|
162 |
private void parseServiceIdentification(KXmlParser parser) throws IOException, XmlPullParserException { |
163 |
int currentTag;
|
164 |
boolean end = false; |
165 |
|
166 |
currentTag = parser.next(); |
167 |
|
168 |
while (!end)
|
169 |
{ |
170 |
switch(currentTag)
|
171 |
{ |
172 |
case KXmlParser.START_TAG:
|
173 |
if (parser.getName().compareTo(CapabilitiesTags.WFS_TITLE)==0) |
174 |
{ |
175 |
serviceInfo.title = parser.nextText(); |
176 |
} |
177 |
else if (parser.getName().compareTo(CapabilitiesTags.WFS_ABSTRACT)==0) |
178 |
{ |
179 |
serviceInfo.abstr = parser.nextText(); |
180 |
} |
181 |
break;
|
182 |
case KXmlParser.END_TAG:
|
183 |
if (parser.getName().compareTo(CapabilitiesTags.SERVICE_IDENTIFICATION) == 0) |
184 |
end = true;
|
185 |
break;
|
186 |
case KXmlParser.TEXT:
|
187 |
break;
|
188 |
} |
189 |
if (!end){
|
190 |
currentTag = parser.next(); |
191 |
} |
192 |
} |
193 |
} |
194 |
|
195 |
/**
|
196 |
* <p>Parses the Service Provider </p>
|
197 |
*/
|
198 |
private void parseServiceProvider(KXmlParser parser) throws IOException, XmlPullParserException { |
199 |
int currentTag;
|
200 |
boolean end = false; |
201 |
|
202 |
currentTag = parser.next(); |
203 |
|
204 |
while (!end)
|
205 |
{ |
206 |
switch(currentTag)
|
207 |
{ |
208 |
case KXmlParser.START_TAG:
|
209 |
|
210 |
break;
|
211 |
case KXmlParser.END_TAG:
|
212 |
if (parser.getName().compareTo(CapabilitiesTags.SERVICE_PROVIDER) == 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 |
* <p>Parses the Operations Metadata </p>
|
225 |
*/
|
226 |
private void parseOperationsMetadata(KXmlParser parser) throws IOException, XmlPullParserException { |
227 |
int currentTag;
|
228 |
boolean end = false; |
229 |
|
230 |
currentTag = parser.next(); |
231 |
|
232 |
while (!end)
|
233 |
{ |
234 |
switch(currentTag)
|
235 |
{ |
236 |
case KXmlParser.START_TAG:
|
237 |
if (parser.getName().compareTo(CapabilitiesTags.OPERATION)==0) |
238 |
{ |
239 |
parseOperation(parser); |
240 |
} |
241 |
break;
|
242 |
case KXmlParser.END_TAG:
|
243 |
if (parser.getName().compareTo(CapabilitiesTags.OPERATIONS_METADATA) == 0) |
244 |
end = true;
|
245 |
break;
|
246 |
case KXmlParser.TEXT:
|
247 |
break;
|
248 |
} |
249 |
if (!end){
|
250 |
currentTag = parser.next(); |
251 |
} |
252 |
} |
253 |
} |
254 |
|
255 |
private void parseOperation(KXmlParser parser) throws IOException, XmlPullParserException { |
256 |
int currentTag;
|
257 |
boolean end = false; |
258 |
|
259 |
currentTag = parser.getEventType(); |
260 |
|
261 |
while (!end)
|
262 |
{ |
263 |
switch(currentTag)
|
264 |
{ |
265 |
case KXmlParser.START_TAG:
|
266 |
if (parser.getName().compareTo(CapabilitiesTags.OPERATION)==0) |
267 |
{ |
268 |
String operation = null; |
269 |
for (int i=0 ; i<parser.getAttributeCount() ; i++){ |
270 |
if (parser.getAttributeName(i).compareTo(CapabilitiesTags.OPERATION_NAME)==0){ |
271 |
operation = parser.getAttributeValue(i); |
272 |
} |
273 |
} |
274 |
currentTag = parser.nextTag(); |
275 |
if (parser.getName().compareTo(CapabilitiesTags.DCP)==0) |
276 |
{ |
277 |
currentTag = parser.nextTag(); |
278 |
if(parser.getName().compareTo(CapabilitiesTags.HTTP)==0) |
279 |
{ |
280 |
currentTag = parser.nextTag(); |
281 |
if(parser.getName().compareTo(CapabilitiesTags.GET)==0) |
282 |
{ |
283 |
String value = null; |
284 |
for (int i=0 ; i<parser.getAttributeCount() ; i++){ |
285 |
if (parser.getAttributeName(i).compareTo(CapabilitiesTags.HREF) == 0){ |
286 |
value = parser.getAttributeValue(i); |
287 |
} |
288 |
} |
289 |
if (operation != null){ |
290 |
if (value == null){ |
291 |
serviceInfo.addOperation(operation, WFSOperation.PROTOCOL_GET); |
292 |
}else{
|
293 |
serviceInfo.addOperation(operation, WFSOperation.PROTOCOL_GET, value); |
294 |
} |
295 |
} |
296 |
} |
297 |
} |
298 |
}else if(CapabilitiesTags.CONSTRAINT.equals(parser.getName())){ |
299 |
for (int i=0 ; i<parser.getAttributeCount() ; i++){ |
300 |
if (parser.getAttributeName(i).compareTo(CapabilitiesTags.OPERATION_NAME)==0){ |
301 |
String constraint = parser.getAttributeValue(i);
|
302 |
if (CapabilitiesTags.DEFAULTMAXFEATURES.equals(constraint)){
|
303 |
currentTag = parser.nextTag(); |
304 |
if(CapabilitiesTags.VALUE.equals(parser.getName())){
|
305 |
try{
|
306 |
Integer defaultMaxFeatures = new Integer(parser.nextText()); |
307 |
this.serviceInfo.setMaxFeatures(defaultMaxFeatures);
|
308 |
}catch(Exception e){ |
309 |
LOG.error("Error parsing the DefaultMaxFeatures attribute", e);
|
310 |
} |
311 |
} |
312 |
} |
313 |
} |
314 |
} |
315 |
} |
316 |
} |
317 |
break;
|
318 |
case KXmlParser.END_TAG:
|
319 |
if (parser.getName().compareTo(CapabilitiesTags.OPERATION) == 0) |
320 |
end = true;
|
321 |
break;
|
322 |
case KXmlParser.TEXT:
|
323 |
break;
|
324 |
} |
325 |
if (!end){
|
326 |
currentTag = parser.next(); |
327 |
} |
328 |
} |
329 |
} |
330 |
|
331 |
/**
|
332 |
* <p>Parses the Feature Type List </p>
|
333 |
*/
|
334 |
private void parseFeatureTypeList(KXmlParser parser) throws IOException, XmlPullParserException { |
335 |
int currentTag;
|
336 |
boolean end = false; |
337 |
|
338 |
currentTag = parser.next(); |
339 |
|
340 |
while (!end)
|
341 |
{ |
342 |
switch(currentTag)
|
343 |
{ |
344 |
case KXmlParser.START_TAG:
|
345 |
if (parser.getName().compareToIgnoreCase(CapabilitiesTags.WFS_FEATURETYPE)==0) |
346 |
{ |
347 |
//Parse the namespaces...
|
348 |
parseNamespaces(parser); |
349 |
WFSFeature1_1_0 feature = new WFSFeature1_1_0(serviceInfo);
|
350 |
feature.parse(parser); |
351 |
features.put(feature.getName(),feature); |
352 |
} |
353 |
break;
|
354 |
case KXmlParser.END_TAG:
|
355 |
if (parser.getName().compareTo(CapabilitiesTags.FEATURE_TYPE_LIST) == 0) |
356 |
end = true;
|
357 |
break;
|
358 |
case KXmlParser.TEXT:
|
359 |
break;
|
360 |
} |
361 |
if (!end){
|
362 |
currentTag = parser.next(); |
363 |
} |
364 |
} |
365 |
} |
366 |
/**
|
367 |
* <p>Parses the Filter Capabilities </p>
|
368 |
*/
|
369 |
private void parseFilterCapabilities(KXmlParser parser) throws IOException, XmlPullParserException { |
370 |
int currentTag;
|
371 |
boolean end = false; |
372 |
|
373 |
currentTag = parser.next(); |
374 |
|
375 |
while (!end)
|
376 |
{ |
377 |
switch(currentTag)
|
378 |
{ |
379 |
case KXmlParser.START_TAG:
|
380 |
|
381 |
break;
|
382 |
case KXmlParser.END_TAG:
|
383 |
if (parser.getName().compareTo(CapabilitiesTags.FILTER_CAPABILITIES) == 0) |
384 |
end = true;
|
385 |
break;
|
386 |
case KXmlParser.TEXT:
|
387 |
break;
|
388 |
} |
389 |
if (!end){
|
390 |
currentTag = parser.next(); |
391 |
} |
392 |
} |
393 |
} |
394 |
|
395 |
/*
|
396 |
* (non-Javadoc)
|
397 |
* @see org.gvsig.remoteClient.wfs.WFSProtocolHandler#parseGetFeature(java.io.File, java.lang.String)
|
398 |
*/
|
399 |
protected boolean parseGetFeature(File f, String nameSpace) throws WFSException{ |
400 |
XMLSchemaParser parser = null;
|
401 |
parser = new XMLSchemaParser();
|
402 |
try
|
403 |
{ |
404 |
parser.setInput(f); |
405 |
parser.nextTag(); |
406 |
if (parser.getName().equals(CapabilitiesTags.SERVICE_EXCEPTION_REPORT)){
|
407 |
throw ExceptionsFactory.parseExceptionReport(parser);
|
408 |
} |
409 |
if (parser.getName().equals(CapabilitiesTags.WFS_FEATURE_COLLECTION)){
|
410 |
WFSGetFeatureRequestInformation requestInformation = |
411 |
(WFSGetFeatureRequestInformation)getLastWfsRequestInformation(); |
412 |
for (int i=0 ; i<parser.getAttributeCount() ; i++){ |
413 |
String attName = parser.getAttributeName(i);
|
414 |
if (WFSTTags.WFS_NUMBER_OF_FEATURES.equals(attName)){
|
415 |
requestInformation.setNumberOfFeatures(new Integer(parser.getAttributeValue(i)).intValue()); |
416 |
}else if (WFSTTags.WFS_TIME_STAMP.equals(attName)){ |
417 |
requestInformation.setTimeStamp(parser.getAttributeValue(i)); |
418 |
} |
419 |
} |
420 |
} |
421 |
} catch (FileNotFoundException e) { |
422 |
e.printStackTrace(); |
423 |
throw new WFSGetFeatureException(e); |
424 |
} catch (XmlPullParserException e) {
|
425 |
e.printStackTrace(); |
426 |
throw new WFSGetFeatureException(e); |
427 |
} catch (IOException e) { |
428 |
e.printStackTrace(); |
429 |
throw new WFSGetFeatureException(e); |
430 |
} |
431 |
|
432 |
return true; |
433 |
} |
434 |
|
435 |
/*
|
436 |
* (non-Javadoc)
|
437 |
* @see org.gvsig.remoteClient.wfs.WFSProtocolHandler#parseTransaction(java.io.File, java.lang.String)
|
438 |
*/
|
439 |
protected boolean parseTransaction(File f, String nameSpace, WFSTTransaction transaction) { |
440 |
return false; |
441 |
} |
442 |
|
443 |
/*
|
444 |
* (non-Javadoc)
|
445 |
* @see org.gvsig.remoteClient.wfs.WFSProtocolHandler#parseLockFeature(java.io.File, java.lang.String)
|
446 |
*/
|
447 |
protected boolean parseLockFeature(File f, String nameSpace, WFSStatus status) throws WFSException { |
448 |
return false; |
449 |
} |
450 |
|
451 |
/*
|
452 |
* (non-Javadoc)
|
453 |
* @see org.gvsig.remoteClient.wfs.WFSProtocolHandler#createDescribeFeatureTypeRequest(org.gvsig.remoteClient.wfs.WFSStatus)
|
454 |
*/
|
455 |
protected WFSDescribeFeatureTypeRequest createDescribeFeatureTypeRequest(
|
456 |
WFSStatus status) { |
457 |
return new WFSDescribeFeatureTypeRequest1_1_0(status, this); |
458 |
} |
459 |
|
460 |
/*
|
461 |
* (non-Javadoc)
|
462 |
* @see org.gvsig.remoteClient.wfs.WFSProtocolHandler#createGetFeatureRequest(org.gvsig.remoteClient.wfs.WFSStatus)
|
463 |
*/
|
464 |
protected WFSGetFeatureRequest createGetFeatureRequest(WFSStatus status) {
|
465 |
return new WFSGetFeatureRequest1_1_0(status, this); |
466 |
} |
467 |
|
468 |
/*
|
469 |
* (non-Javadoc)
|
470 |
* @see org.gvsig.remoteClient.wfs.WFSProtocolHandler#createLockFeatureRequest(org.gvsig.remoteClient.wfs.WFSStatus)
|
471 |
*/
|
472 |
protected WFSTLockFeatureRequest createLockFeatureRequest(WFSStatus status) {
|
473 |
return new WFSTLockFeatureRequest1_1_0(status, this); |
474 |
} |
475 |
} |