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