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 @ 40769
History | View | Annotate | Download (16.8 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 |
/**
|
55 |
* @author Jorge Piera Llodr? (piera_jor@gva.es)
|
56 |
*/
|
57 |
public class WFSProtocolHandler1_1_0 extends WFSProtocolHandler1_0_0{ |
58 |
|
59 |
private static final StringUtils stringUtils = CompatLocator.getStringUtils(); |
60 |
|
61 |
public WFSProtocolHandler1_1_0(){
|
62 |
this.version = "1.1.0"; |
63 |
this.name = "WFS1.1.0"; |
64 |
} |
65 |
|
66 |
/*
|
67 |
* (non-Javadoc)
|
68 |
* @see org.gvsig.remoteClient.OGCProtocolHandler#parseCapabilities(java.io.File)
|
69 |
*/
|
70 |
public boolean parseCapabilities(File f) { |
71 |
int tag;
|
72 |
XMLSchemaParser parser = null;
|
73 |
parser = new XMLSchemaParser();
|
74 |
try
|
75 |
{ |
76 |
parser.setInput(f); |
77 |
parser.nextTag(); |
78 |
|
79 |
if ( parser.getEventType() != KXmlParser.END_DOCUMENT )
|
80 |
{ |
81 |
parser.require(KXmlParser.START_TAG, null, CapabilitiesTags.WFS_CAPABILITIES_ROOT1_0_0);
|
82 |
//Parses the Namespaces...
|
83 |
parseNamespaces(parser); |
84 |
tag = parser.nextTag(); |
85 |
while(tag != KXmlParser.END_DOCUMENT)
|
86 |
{ |
87 |
switch(tag)
|
88 |
{ |
89 |
case KXmlParser.START_TAG:
|
90 |
if (parser.getName().compareTo(CapabilitiesTags.SERVICE_IDENTIFICATION)==0) |
91 |
{ |
92 |
parseServiceIdentification(parser); |
93 |
} |
94 |
else if (parser.getName().compareTo(CapabilitiesTags.SERVICE_PROVIDER)==0) |
95 |
{ |
96 |
parseServiceProvider(parser); |
97 |
} |
98 |
else if (parser.getName().compareTo(CapabilitiesTags.OPERATIONS_METADATA)==0) |
99 |
{ |
100 |
parseOperationsMetadata(parser); |
101 |
} |
102 |
else if (parser.getName().compareTo(CapabilitiesTags.FEATURE_TYPE_LIST)==0) |
103 |
{ |
104 |
parseFeatureTypeList(parser); |
105 |
} |
106 |
else if (parser.getName().compareTo(CapabilitiesTags.FILTER_CAPABILITIES)==0) |
107 |
{ |
108 |
parseFilterCapabilities(parser); |
109 |
} |
110 |
break;
|
111 |
case KXmlParser.END_TAG:
|
112 |
break;
|
113 |
case KXmlParser.TEXT:
|
114 |
if (parser.getName()!=null) |
115 |
|
116 |
break;
|
117 |
} |
118 |
tag = parser.next(); |
119 |
} |
120 |
parser.require(KXmlParser.END_DOCUMENT, null, null); |
121 |
} |
122 |
} |
123 |
catch(XmlPullParserException parser_ex){
|
124 |
parser_ex.printStackTrace(); |
125 |
return false; |
126 |
} |
127 |
catch (IOException ioe) { |
128 |
ioe.printStackTrace(); |
129 |
return false; |
130 |
} |
131 |
return true; |
132 |
} |
133 |
|
134 |
/**
|
135 |
* <p>Parses the Service Identification </p>
|
136 |
*/
|
137 |
private void parseServiceIdentification(KXmlParser parser) throws IOException, XmlPullParserException { |
138 |
int currentTag;
|
139 |
boolean end = false; |
140 |
|
141 |
currentTag = parser.next(); |
142 |
|
143 |
while (!end)
|
144 |
{ |
145 |
switch(currentTag)
|
146 |
{ |
147 |
case KXmlParser.START_TAG:
|
148 |
if (parser.getName().compareTo(CapabilitiesTags.WFS_TITLE)==0) |
149 |
{ |
150 |
serviceInfo.title = parser.nextText(); |
151 |
} |
152 |
else if (parser.getName().compareTo(CapabilitiesTags.WFS_ABSTRACT)==0) |
153 |
{ |
154 |
serviceInfo.abstr = parser.nextText(); |
155 |
} |
156 |
break;
|
157 |
case KXmlParser.END_TAG:
|
158 |
if (parser.getName().compareTo(CapabilitiesTags.SERVICE_IDENTIFICATION) == 0) |
159 |
end = true;
|
160 |
break;
|
161 |
case KXmlParser.TEXT:
|
162 |
break;
|
163 |
} |
164 |
if (!end){
|
165 |
currentTag = parser.next(); |
166 |
} |
167 |
} |
168 |
} |
169 |
|
170 |
/**
|
171 |
* <p>Parses the Service Provider </p>
|
172 |
*/
|
173 |
private void parseServiceProvider(KXmlParser parser) throws IOException, XmlPullParserException { |
174 |
int currentTag;
|
175 |
boolean end = false; |
176 |
|
177 |
currentTag = parser.next(); |
178 |
|
179 |
while (!end)
|
180 |
{ |
181 |
switch(currentTag)
|
182 |
{ |
183 |
case KXmlParser.START_TAG:
|
184 |
|
185 |
break;
|
186 |
case KXmlParser.END_TAG:
|
187 |
if (parser.getName().compareTo(CapabilitiesTags.SERVICE_PROVIDER) == 0) |
188 |
end = true;
|
189 |
break;
|
190 |
case KXmlParser.TEXT:
|
191 |
break;
|
192 |
} |
193 |
if (!end){
|
194 |
currentTag = parser.next(); |
195 |
} |
196 |
} |
197 |
} |
198 |
/**
|
199 |
* <p>Parses the Operations Metadata </p>
|
200 |
*/
|
201 |
private void parseOperationsMetadata(KXmlParser parser) throws IOException, XmlPullParserException { |
202 |
int currentTag;
|
203 |
boolean end = false; |
204 |
|
205 |
currentTag = parser.next(); |
206 |
|
207 |
while (!end)
|
208 |
{ |
209 |
switch(currentTag)
|
210 |
{ |
211 |
case KXmlParser.START_TAG:
|
212 |
if (parser.getName().compareTo(CapabilitiesTags.OPERATION)==0) |
213 |
{ |
214 |
parseOperation(parser); |
215 |
} |
216 |
break;
|
217 |
case KXmlParser.END_TAG:
|
218 |
if (parser.getName().compareTo(CapabilitiesTags.OPERATIONS_METADATA) == 0) |
219 |
end = true;
|
220 |
break;
|
221 |
case KXmlParser.TEXT:
|
222 |
break;
|
223 |
} |
224 |
if (!end){
|
225 |
currentTag = parser.next(); |
226 |
} |
227 |
} |
228 |
} |
229 |
|
230 |
private void parseOperation(KXmlParser parser) throws IOException, XmlPullParserException { |
231 |
int currentTag;
|
232 |
boolean end = false; |
233 |
|
234 |
currentTag = parser.getEventType(); |
235 |
|
236 |
while (!end)
|
237 |
{ |
238 |
switch(currentTag)
|
239 |
{ |
240 |
case KXmlParser.START_TAG:
|
241 |
if (parser.getName().compareTo(CapabilitiesTags.OPERATION)==0) |
242 |
{ |
243 |
String operation = null; |
244 |
for (int i=0 ; i<parser.getAttributeCount() ; i++){ |
245 |
if (parser.getAttributeName(i).compareTo(CapabilitiesTags.OPERATION_NAME)==0){ |
246 |
operation = parser.getAttributeValue(i); |
247 |
} |
248 |
} |
249 |
currentTag = parser.nextTag(); |
250 |
if (parser.getName().compareTo(CapabilitiesTags.DCP)==0) |
251 |
{ |
252 |
currentTag = parser.nextTag(); |
253 |
if(parser.getName().compareTo(CapabilitiesTags.HTTP)==0) |
254 |
{ |
255 |
currentTag = parser.nextTag(); |
256 |
if(parser.getName().compareTo(CapabilitiesTags.GET)==0) |
257 |
{ |
258 |
String value = null; |
259 |
for (int i=0 ; i<parser.getAttributeCount() ; i++){ |
260 |
if (parser.getAttributeName(i).compareTo(CapabilitiesTags.HREF) == 0){ |
261 |
value = parser.getAttributeValue(i); |
262 |
} |
263 |
} |
264 |
if (operation != null){ |
265 |
if (value == null){ |
266 |
serviceInfo.addOperation(operation, WFSOperation.PROTOCOL_GET); |
267 |
}else{
|
268 |
serviceInfo.addOperation(operation, WFSOperation.PROTOCOL_GET, value); |
269 |
} |
270 |
} |
271 |
} |
272 |
} |
273 |
}else if(CapabilitiesTags.CONSTRAINT.equals(parser.getName())){ |
274 |
for (int i=0 ; i<parser.getAttributeCount() ; i++){ |
275 |
if (parser.getAttributeName(i).compareTo(CapabilitiesTags.OPERATION_NAME)==0){ |
276 |
String constraint = parser.getAttributeValue(i);
|
277 |
if (CapabilitiesTags.DEFAULTMAXFEATURES.equals(constraint)){
|
278 |
currentTag = parser.nextTag(); |
279 |
if(CapabilitiesTags.VALUE.equals(parser.getName())){
|
280 |
Integer defaultMaxFeatures = new Integer(parser.nextText()); |
281 |
this.serviceInfo.setMaxFeatures(defaultMaxFeatures.intValue());
|
282 |
} |
283 |
} |
284 |
} |
285 |
} |
286 |
} |
287 |
} |
288 |
break;
|
289 |
case KXmlParser.END_TAG:
|
290 |
if (parser.getName().compareTo(CapabilitiesTags.OPERATION) == 0) |
291 |
end = true;
|
292 |
break;
|
293 |
case KXmlParser.TEXT:
|
294 |
break;
|
295 |
} |
296 |
if (!end){
|
297 |
currentTag = parser.next(); |
298 |
} |
299 |
} |
300 |
} |
301 |
|
302 |
/**
|
303 |
* <p>Parses the Feature Type List </p>
|
304 |
*/
|
305 |
private void parseFeatureTypeList(KXmlParser parser) throws IOException, XmlPullParserException { |
306 |
int currentTag;
|
307 |
boolean end = false; |
308 |
|
309 |
currentTag = parser.next(); |
310 |
|
311 |
while (!end)
|
312 |
{ |
313 |
switch(currentTag)
|
314 |
{ |
315 |
case KXmlParser.START_TAG:
|
316 |
if (parser.getName().compareToIgnoreCase(CapabilitiesTags.WFS_FEATURETYPE)==0) |
317 |
{ |
318 |
//Parse the namespaces...
|
319 |
parseNamespaces(parser); |
320 |
WFSFeature1_1_0 feature = new WFSFeature1_1_0(serviceInfo);
|
321 |
feature.parse(parser); |
322 |
features.put(feature.getName(),feature); |
323 |
} |
324 |
break;
|
325 |
case KXmlParser.END_TAG:
|
326 |
if (parser.getName().compareTo(CapabilitiesTags.FEATURE_TYPE_LIST) == 0) |
327 |
end = true;
|
328 |
break;
|
329 |
case KXmlParser.TEXT:
|
330 |
break;
|
331 |
} |
332 |
if (!end){
|
333 |
currentTag = parser.next(); |
334 |
} |
335 |
} |
336 |
} |
337 |
/**
|
338 |
* <p>Parses the Filter Capabilities </p>
|
339 |
*/
|
340 |
private void parseFilterCapabilities(KXmlParser parser) throws IOException, XmlPullParserException { |
341 |
int currentTag;
|
342 |
boolean end = false; |
343 |
|
344 |
currentTag = parser.next(); |
345 |
|
346 |
while (!end)
|
347 |
{ |
348 |
switch(currentTag)
|
349 |
{ |
350 |
case KXmlParser.START_TAG:
|
351 |
|
352 |
break;
|
353 |
case KXmlParser.END_TAG:
|
354 |
if (parser.getName().compareTo(CapabilitiesTags.FILTER_CAPABILITIES) == 0) |
355 |
end = true;
|
356 |
break;
|
357 |
case KXmlParser.TEXT:
|
358 |
break;
|
359 |
} |
360 |
if (!end){
|
361 |
currentTag = parser.next(); |
362 |
} |
363 |
} |
364 |
} |
365 |
|
366 |
/*
|
367 |
* (non-Javadoc)
|
368 |
* @see org.gvsig.remoteClient.wfs.WFSProtocolHandler#parseGetFeature(java.io.File, java.lang.String)
|
369 |
*/
|
370 |
protected boolean parseGetFeature(File f, String nameSpace) throws WFSException{ |
371 |
XMLSchemaParser parser = null;
|
372 |
parser = new XMLSchemaParser();
|
373 |
try
|
374 |
{ |
375 |
parser.setInput(f); |
376 |
parser.nextTag(); |
377 |
if (parser.getName().equals(CapabilitiesTags.SERVICE_EXCEPTION_REPORT)){
|
378 |
throw ExceptionsFactory.parseServiceExceptionReport(parser);
|
379 |
} |
380 |
|
381 |
if (parser.getName().equals(CapabilitiesTags.WFS_FEATURE_COLLECTION)
|
382 |
|| parser.getName().equals(CapabilitiesTags.WFS_RESULT_COLLECTION)){ |
383 |
WFSGetFeatureRequestInformation requestInformation = |
384 |
(WFSGetFeatureRequestInformation)getLastWfsRequestInformation(); |
385 |
for (int i=0 ; i<parser.getAttributeCount() ; i++){ |
386 |
String attName = parser.getAttributeName(i);
|
387 |
if (WFSTTags.WFS_NUMBER_OF_FEATURES.equals(attName)){
|
388 |
requestInformation.setNumberOfFeatures(new Integer(parser.getAttributeValue(i)).intValue()); |
389 |
}else if (WFSTTags.WFS_TIME_STAMP.equals(attName)){ |
390 |
requestInformation.setTimeStamp(parser.getAttributeValue(i)); |
391 |
} |
392 |
} |
393 |
} |
394 |
} catch (FileNotFoundException e) { |
395 |
e.printStackTrace(); |
396 |
throw new WFSGetFeatureException(e); |
397 |
} catch (XmlPullParserException e) {
|
398 |
e.printStackTrace(); |
399 |
throw new WFSGetFeatureException(e); |
400 |
} catch (IOException e) { |
401 |
e.printStackTrace(); |
402 |
throw new WFSGetFeatureException(e); |
403 |
} |
404 |
|
405 |
return true; |
406 |
} |
407 |
|
408 |
|
409 |
protected boolean parseTransaction(File f, WFSStatus status) throws WFSException { |
410 |
return super.parseTransaction(f, status); |
411 |
} |
412 |
|
413 |
/*
|
414 |
* (non-Javadoc)
|
415 |
* @see org.gvsig.remoteClient.wfs.WFSProtocolHandler#parseLockFeature(java.io.File, java.lang.String)
|
416 |
*/
|
417 |
protected boolean parseLockFeature(File f, String nameSpace, WFSStatus status) throws WFSException { |
418 |
return false; |
419 |
} |
420 |
|
421 |
/*
|
422 |
* (non-Javadoc)
|
423 |
* @see org.gvsig.remoteClient.wfs.WFSProtocolHandler#createDescribeFeatureTypeRequest(org.gvsig.remoteClient.wfs.WFSStatus)
|
424 |
*/
|
425 |
protected WFSDescribeFeatureTypeRequest createDescribeFeatureTypeRequest(
|
426 |
WFSStatus status) { |
427 |
return new WFSDescribeFeatureTypeRequest1_1_0(status, this); |
428 |
} |
429 |
|
430 |
/*
|
431 |
* (non-Javadoc)
|
432 |
* @see org.gvsig.remoteClient.wfs.WFSProtocolHandler#createGetFeatureRequest(org.gvsig.remoteClient.wfs.WFSStatus)
|
433 |
*/
|
434 |
protected WFSGetFeatureRequest createGetFeatureRequest(WFSStatus status) {
|
435 |
return new WFSGetFeatureRequest1_1_0(status, this); |
436 |
} |
437 |
|
438 |
/*
|
439 |
* (non-Javadoc)
|
440 |
* @see org.gvsig.remoteClient.wfs.WFSProtocolHandler#createLockFeatureRequest(org.gvsig.remoteClient.wfs.WFSStatus)
|
441 |
*/
|
442 |
protected WFSTLockFeatureRequest createLockFeatureRequest(WFSStatus status) {
|
443 |
return new WFSTLockFeatureRequest1_1_0(status, this); |
444 |
} |
445 |
|
446 |
protected WFSTransactionRequest createTransactionRequest(WFSStatus status) {
|
447 |
return new WFSTransactionRequest1_1_0(status, this); |
448 |
} |
449 |
} |