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