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