svn-gvsig-desktop / branches / v10 / extensions / extWFS2 / src / com / iver / cit / gvsig / fmap / layers / FLyrWFS.java @ 8832
History | View | Annotate | Download (19.2 KB)
1 |
package com.iver.cit.gvsig.fmap.layers; |
---|---|
2 |
|
3 |
import java.awt.geom.Rectangle2D; |
4 |
import java.io.IOException; |
5 |
import java.net.ConnectException; |
6 |
import java.net.MalformedURLException; |
7 |
import java.net.URL; |
8 |
import java.util.HashMap; |
9 |
import java.util.Map; |
10 |
import java.util.Vector; |
11 |
|
12 |
import javax.swing.ImageIcon; |
13 |
|
14 |
import org.gvsig.remoteClient.gml.schemas.IXMLType; |
15 |
import org.gvsig.remoteClient.gml.schemas.XMLComplexType; |
16 |
import org.gvsig.remoteClient.gml.schemas.XMLElement; |
17 |
import org.gvsig.remoteClient.wfs.WFSStatus; |
18 |
import org.gvsig.remoteClient.wfs.filters.FilterEncoding; |
19 |
|
20 |
import com.iver.andami.PluginServices; |
21 |
import com.iver.cit.gvsig.fmap.DriverException; |
22 |
import com.iver.cit.gvsig.fmap.crs.CRSFactory; |
23 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
24 |
import com.iver.cit.gvsig.fmap.drivers.VectorialDriver; |
25 |
import com.iver.cit.gvsig.fmap.drivers.WFSException; |
26 |
import com.iver.cit.gvsig.fmap.drivers.wfs.FMapWFSDriver; |
27 |
import com.iver.cit.gvsig.fmap.drivers.wfs.FMapWFSDriverFactory; |
28 |
import com.iver.cit.gvsig.fmap.drivers.wfs.filters.SQLExpressionFormat; |
29 |
import com.iver.cit.gvsig.fmap.rendering.LegendFactory; |
30 |
import com.iver.utiles.StringUtilities; |
31 |
import com.iver.utiles.XMLEntity; |
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: FLyrWFS.java 8832 2006-11-16 17:15:59Z jorpiell $
|
76 |
* $Log$
|
77 |
* Revision 1.10.2.7 2006-11-16 17:15:59 jorpiell
|
78 |
* Ya se almacena y se recupera en un gvp un filtro
|
79 |
*
|
80 |
* Revision 1.10.2.6 2006/11/16 15:38:51 jorpiell
|
81 |
* Se han modificado los metodos para guargar y crear un XML a partir de una capa WFS.
|
82 |
*
|
83 |
* Revision 1.10.2.5 2006/11/15 00:08:20 jjdelcerro
|
84 |
* *** empty log message ***
|
85 |
*
|
86 |
* Revision 1.18 2006/10/31 12:24:04 jorpiell
|
87 |
* Comprobado el caso en el que los atributos no tienen tipo
|
88 |
*
|
89 |
* Revision 1.17 2006/10/31 09:55:28 jorpiell
|
90 |
* Se ha modificado el constructor del WFS desde cat?logo
|
91 |
*
|
92 |
* Revision 1.16 2006/10/31 09:38:15 jorpiell
|
93 |
* Se ha creado una factoria para crear la capa. De ese modo no se repite c?digo desde le panel de propiedades y desde el panel de la capa
|
94 |
*
|
95 |
* Revision 1.15 2006/10/23 07:37:04 jorpiell
|
96 |
* Ya funciona el filterEncoding
|
97 |
*
|
98 |
* Revision 1.14 2006/10/10 12:55:06 jorpiell
|
99 |
* Se ha a?adido el soporte de features complejas
|
100 |
*
|
101 |
* Revision 1.13 2006/10/02 12:54:35 jorpiell
|
102 |
* No se pod?a crear un mapa que tubiera la opci?n enlace vivo habilitada
|
103 |
*
|
104 |
* Revision 1.12 2006/10/02 09:09:45 jorpiell
|
105 |
* Cambios del 10 copiados al head
|
106 |
*
|
107 |
* Revision 1.10.2.3 2006/09/29 14:12:53 luisw2
|
108 |
* CRSFactory.getCRS substitutes ProjectionPool.get
|
109 |
*
|
110 |
* Revision 1.10.2.2 2006/09/28 08:54:01 jorpiell
|
111 |
* Ya se puede reproyectar
|
112 |
*
|
113 |
* Revision 1.10.2.1 2006/09/26 07:36:24 jorpiell
|
114 |
* El WFS no reproyectaba porque no se le asignaba a la capa un sistema de referencia. Ahora ya se hace.
|
115 |
*
|
116 |
* Revision 1.10 2006/09/05 15:41:52 jorpiell
|
117 |
* A?adida la funcionalidad de cargar WFS desde el cat?logo
|
118 |
*
|
119 |
* Revision 1.9 2006/07/05 12:05:41 jorpiell
|
120 |
* Se ha modificado para que avise si se han recuperado las mismas features que marca el campo buffer
|
121 |
*
|
122 |
* Revision 1.8 2006/06/21 12:52:10 jorpiell
|
123 |
* A?adido un icono para la capa WFS
|
124 |
*
|
125 |
* Revision 1.7 2006/06/21 12:35:45 jorpiell
|
126 |
* Se ha a?adido la ventana de propiedades. Esto implica a?adir listeners por todos los paneles. Adem?s no se muestra la geomatr?a en la lista de atributos y se muestran ?nicamnete los que se van a descargar
|
127 |
*
|
128 |
* Revision 1.6 2006/06/15 11:17:06 jorpiell
|
129 |
* Se ha encontrado la forma de comprobar cuando se prodicia un error de parseo al hacer un hasnext (en la feature). Se atrapa y se lanza la excepci?n hacia arriba
|
130 |
*
|
131 |
* Revision 1.5 2006/06/14 07:57:19 jorpiell
|
132 |
* Ya no se usa la estrategia ni se usa geotools para hacer el getFeature. Ahora se usa ?nicamente para el parseo de GML
|
133 |
*
|
134 |
* Revision 1.4 2006/06/05 16:49:31 caballero
|
135 |
* poder editar y exportar
|
136 |
*
|
137 |
* Revision 1.3 2006/05/25 10:31:55 jorpiell
|
138 |
* Se ha renombrado la clase WFSFields por WFSAttributes porque era algo confusa
|
139 |
*
|
140 |
* Revision 1.2 2006/05/23 13:21:59 jorpiell
|
141 |
* Si hay alg?n problema en la carga se muestra un mensaje de error
|
142 |
*
|
143 |
* Revision 1.1 2006/05/19 12:54:11 jorpiell
|
144 |
* Creada la capa WFS
|
145 |
*
|
146 |
*
|
147 |
*/
|
148 |
/**
|
149 |
* FMap's WFS Layer class.
|
150 |
*
|
151 |
* @author Jorge Piera Llodr? (piera_jor@gva.es)
|
152 |
*/
|
153 |
public class FLyrWFS extends FLyrVect{ |
154 |
private URL host = null; |
155 |
private String onlineResource = null; |
156 |
private String name = null; |
157 |
private String layerName = null; |
158 |
private String userName = null; |
159 |
private String password = null; |
160 |
private String AttributesQuery = null; |
161 |
private String CoordinatesQuery = null; |
162 |
private XMLElement[] fields = null; |
163 |
private int numfeatures = 100; |
164 |
private int timeout = 10000; |
165 |
private String srs = null; |
166 |
private FMapWFSDriver wfsDriver = null; |
167 |
private VectorialAdapter vectorialAdapter = null; |
168 |
private WFSLayerNode wfsLayerNode = null; |
169 |
|
170 |
/**
|
171 |
* Constructor
|
172 |
*/
|
173 |
public FLyrWFS(){
|
174 |
super();
|
175 |
} |
176 |
|
177 |
/**
|
178 |
* Constructor to load a new layer from a catalog
|
179 |
* search
|
180 |
* @param args
|
181 |
* Params to load a new layer
|
182 |
* @throws WFSException
|
183 |
* @throws IOException
|
184 |
* @throws MalformedURLException
|
185 |
* @throws ConnectException
|
186 |
* @throws DriverIOException
|
187 |
*/
|
188 |
public FLyrWFS(Map args) throws WFSException, ConnectException, MalformedURLException, IOException, DriverIOException{ |
189 |
String[] sLayer = (String[])args.get("layer"); |
190 |
String user = (String)args.get("user"); |
191 |
String pwd = (String)args.get("pwd"); |
192 |
String host = (String)args.get("host"); |
193 |
String projection = (String)args.get("projection"); |
194 |
|
195 |
FMapWFSDriver driver = FMapWFSDriverFactory.getFMapDriverForURL(new URL(host)); |
196 |
WFSLayerNode[] layers = driver.getLayerList();
|
197 |
WFSLayerNode layer = driver.getLayerInfo(sLayer[0]);
|
198 |
|
199 |
layer.setSelectedFields(layer.getFields()); |
200 |
|
201 |
Vector vAtts = new Vector(); |
202 |
if (layer.getFields().size() == 1){ |
203 |
XMLElement element = (XMLElement)layer.getFields().get(0);
|
204 |
if (element.getEntityType().getType() != IXMLType.COMPLEX){
|
205 |
vAtts.add(element); |
206 |
}else{
|
207 |
vAtts = ((XMLComplexType)element.getEntityType()).getAttributes(); |
208 |
} |
209 |
} |
210 |
for (int i=0 ; i<layer.getFields().size() ; i++){ |
211 |
XMLElement element = (XMLElement)layer.getFields().get(i); |
212 |
if (element.getEntityType().getType() != IXMLType.COMPLEX){
|
213 |
vAtts.add((XMLElement)layer.getFields().get(i)); |
214 |
}else{
|
215 |
|
216 |
} |
217 |
} |
218 |
|
219 |
XMLElement[] atts = new XMLElement[vAtts.size()]; |
220 |
for (int i=0 ; i<vAtts.size() ; i++){ |
221 |
atts[i] = (XMLElement)vAtts.get(i); |
222 |
} |
223 |
|
224 |
setHost(host); |
225 |
setName(sLayer[0]);
|
226 |
setLayerName(sLayer[0]);
|
227 |
setWfsLayerNode(layer); |
228 |
setFields(atts); |
229 |
setUserName(user); |
230 |
setPassword(pwd); |
231 |
setNumfeatures(10000);
|
232 |
setTimeout(10000);
|
233 |
setWfsDriver(driver); |
234 |
setProjection(CRSFactory.getCRS(projection)); |
235 |
|
236 |
load(); |
237 |
} |
238 |
|
239 |
|
240 |
/**
|
241 |
* Loads the features from the server
|
242 |
*/
|
243 |
public void load() throws DriverIOException{ |
244 |
WFSAdapter adapter = new WFSAdapter();
|
245 |
try {
|
246 |
wfsDriver.getFeature(getWFSStatus()); |
247 |
|
248 |
adapter.setDriver((VectorialDriver) wfsDriver); |
249 |
setSource(adapter); |
250 |
|
251 |
if (getLegend() == null){ |
252 |
setLegend(LegendFactory.createSingleSymbolLegend( |
253 |
getShapeType())); |
254 |
} |
255 |
} catch (Exception e){ |
256 |
e.printStackTrace(); |
257 |
throw new DriverIOException(e.getMessage()); |
258 |
} |
259 |
} |
260 |
|
261 |
/**
|
262 |
* Gets the WFS Status
|
263 |
* @return
|
264 |
*/
|
265 |
private WFSStatus getWFSStatus(){
|
266 |
WFSStatus status = new WFSStatus(getLayerName());
|
267 |
status.setUserName(getUserName()); |
268 |
status.setPassword(getPassword()); |
269 |
status.setBuffer(getNumfeatures()); |
270 |
status.setTimeout(getTimeout()); |
271 |
status.setFields(getFieldNames()); |
272 |
status.setOnlineResource(getOnlineResource()); |
273 |
status.setSrs(getSrs()); |
274 |
//Filter Encoding transformation
|
275 |
FilterEncoding fe = SQLExpressionFormat.createFilter(); |
276 |
fe.setQuery(getAttributesQuery()); |
277 |
status.setFilterQuery(fe.toString()); |
278 |
return status;
|
279 |
} |
280 |
|
281 |
/**
|
282 |
* Adds the vectorial adapter to the layer
|
283 |
* @param vectorialAdapter
|
284 |
*/
|
285 |
public void setSource(VectorialAdapter vectorialAdapter) { |
286 |
this.vectorialAdapter = vectorialAdapter;
|
287 |
super.setSource(vectorialAdapter);
|
288 |
} |
289 |
|
290 |
/**
|
291 |
* @return Returns the layerName.
|
292 |
*/
|
293 |
public String getLayerName() { |
294 |
return layerName;
|
295 |
} |
296 |
/**
|
297 |
* @param layerName The layerName to set.
|
298 |
*/
|
299 |
public void setLayerName(String layerName) { |
300 |
this.layerName = layerName;
|
301 |
} |
302 |
/**
|
303 |
* @return Returns the numfeatures.
|
304 |
*/
|
305 |
public int getNumfeatures() { |
306 |
return numfeatures;
|
307 |
} |
308 |
/**
|
309 |
* @param numfeatures The numfeatures to set.
|
310 |
*/
|
311 |
public void setNumfeatures(int numfeatures) { |
312 |
this.numfeatures = numfeatures;
|
313 |
} |
314 |
|
315 |
/**
|
316 |
* @return Returns the pwd.
|
317 |
*/
|
318 |
public String getPassword() { |
319 |
return password;
|
320 |
} |
321 |
/**
|
322 |
* @param pwd The pwd to set.
|
323 |
*/
|
324 |
public void setPassword(String password) { |
325 |
this.password = password;
|
326 |
} |
327 |
/**
|
328 |
* @return Returns the timeout.
|
329 |
*/
|
330 |
public int getTimeout() { |
331 |
return timeout;
|
332 |
} |
333 |
/**
|
334 |
* @param timeout The timeout to set.
|
335 |
*/
|
336 |
public void setTimeout(int timeout) { |
337 |
this.timeout = timeout;
|
338 |
} |
339 |
/**
|
340 |
* @return Returns the user.
|
341 |
*/
|
342 |
public String getUserName() { |
343 |
return userName;
|
344 |
} |
345 |
/**
|
346 |
* @param user The user to set.
|
347 |
*/
|
348 |
public void setUserName(String userName) { |
349 |
this.userName = userName;
|
350 |
} |
351 |
/**
|
352 |
* @return Returns the fields.
|
353 |
*/
|
354 |
public XMLElement[] getFields() { |
355 |
if (fields == null){ |
356 |
return new XMLElement[0]; |
357 |
} |
358 |
return fields;
|
359 |
} |
360 |
|
361 |
/**
|
362 |
* Return the attributes name
|
363 |
* @return
|
364 |
*/
|
365 |
public String[] getFieldNames(){ |
366 |
Vector vAttributes = new Vector(); |
367 |
for (int i=0 ; i<getFields().length ; i++){ |
368 |
if ((getFields()[i].getEntityType() == null) || |
369 |
(getFields()[i].getEntityType().getType() != IXMLType.COMPLEX)){ |
370 |
vAttributes.add(getFields()[i].getName()); |
371 |
} |
372 |
} |
373 |
String[] attributes = new String[vAttributes.size()]; |
374 |
for (int i=0 ; i<vAttributes.size() ; i++){ |
375 |
attributes[i] = (String)vAttributes.get(i);
|
376 |
} |
377 |
return attributes;
|
378 |
} |
379 |
|
380 |
/**
|
381 |
* @param fields The fields to set.
|
382 |
*/
|
383 |
public void setFields(XMLElement[] fields) { |
384 |
this.fields = fields;
|
385 |
} |
386 |
/**
|
387 |
* @return Returns the name.
|
388 |
*/
|
389 |
public String getName() { |
390 |
return name;
|
391 |
} |
392 |
/**
|
393 |
* @param name The name to set.
|
394 |
*/
|
395 |
public void setName(String name) { |
396 |
this.name = name;
|
397 |
} |
398 |
/**
|
399 |
* @return Returns the host.
|
400 |
*/
|
401 |
public URL getHost() { |
402 |
return host;
|
403 |
} |
404 |
/**
|
405 |
* @param host The host to set.
|
406 |
*/
|
407 |
public void setHost(URL host) { |
408 |
this.host = host;
|
409 |
} |
410 |
|
411 |
/**
|
412 |
* @return Returns the wfs.
|
413 |
*/
|
414 |
public FMapWFSDriver getWfsDriver() {
|
415 |
return wfsDriver;
|
416 |
} |
417 |
|
418 |
/**
|
419 |
* @param wfs The wfs to set.
|
420 |
*/
|
421 |
public void setWfsDriver(FMapWFSDriver wfs) { |
422 |
this.wfsDriver = wfs;
|
423 |
} |
424 |
|
425 |
|
426 |
/*
|
427 |
* (non-Javadoc)
|
428 |
* @see com.iver.cit.gvsig.fmap.layers.FLyrDefault#getStrategy()
|
429 |
*/
|
430 |
// public Strategy getStrategy() {
|
431 |
// if (wfsStrategy == null){
|
432 |
// wfsStrategy = new WFSStrategy(this);
|
433 |
// }
|
434 |
// return wfsStrategy;
|
435 |
// }
|
436 |
|
437 |
/*
|
438 |
* (non-Javadoc)
|
439 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#getFullExtent()
|
440 |
*/
|
441 |
public Rectangle2D getFullExtent() throws DriverException { |
442 |
try {
|
443 |
Rectangle2D extent = wfsDriver.getFullExtent();
|
444 |
if (getCoordTrans() != null){ |
445 |
return getCoordTrans().convert(extent);
|
446 |
} |
447 |
return extent;
|
448 |
} catch (IOException e) { |
449 |
throw new DriverException(e.toString()); |
450 |
} |
451 |
} |
452 |
|
453 |
/**
|
454 |
* @return Returns the onlineResource.
|
455 |
*/
|
456 |
public String getOnlineResource() { |
457 |
return onlineResource;
|
458 |
} |
459 |
|
460 |
/**
|
461 |
* @param onlineResource The onlineResource to set.
|
462 |
*/
|
463 |
public void setOnlineResource(String onlineResource) { |
464 |
this.onlineResource = onlineResource;
|
465 |
} |
466 |
|
467 |
public HashMap getProperties() { |
468 |
HashMap info = new HashMap(); |
469 |
info.put("name", getName());
|
470 |
info.put("layerName", getLayerName());
|
471 |
info.put("layerText", getLayerText());
|
472 |
info.put("attributes", getFields());
|
473 |
info.put("host", getHost());
|
474 |
info.put("wfsLayerNode", getWfsLayerNode());
|
475 |
WFSStatus status = new WFSStatus(getLayerName());
|
476 |
status.setBuffer(getNumfeatures()); |
477 |
status.setTimeout(getTimeout()); |
478 |
status.setUserName(getUserName()); |
479 |
status.setPassword(getPassword()); |
480 |
info.put("status",status);
|
481 |
return info;
|
482 |
|
483 |
} |
484 |
|
485 |
/**
|
486 |
* @return Returns the wfsLayerNode.
|
487 |
*/
|
488 |
public WFSLayerNode getWfsLayerNode() {
|
489 |
return wfsLayerNode;
|
490 |
} |
491 |
|
492 |
/**
|
493 |
* @param wfsLayerNode The wfsLayerNode to set.
|
494 |
*/
|
495 |
public void setWfsLayerNode(WFSLayerNode wfsLayerNode) { |
496 |
this.wfsLayerNode = wfsLayerNode;
|
497 |
} |
498 |
|
499 |
public void setHost(String host2) { |
500 |
try {
|
501 |
setHost(new URL(host2)); |
502 |
} catch (MalformedURLException e) { |
503 |
// TODO Auto-generated catch block
|
504 |
e.printStackTrace(); |
505 |
} |
506 |
} |
507 |
|
508 |
public ImageIcon getTocImageIcon() { |
509 |
return new ImageIcon(PluginServices.getPluginServices("com.iver.cit.gvsig.wfs2").getClassLoader().getResource("images/icoLayer.png")); |
510 |
} |
511 |
|
512 |
/*
|
513 |
* (non-Javadoc)
|
514 |
* @see com.iver.cit.gvsig.fmap.layers.FLyrVect#isPropertiesMenuVisible()
|
515 |
*/
|
516 |
public boolean isPropertiesMenuVisible(){ |
517 |
return false; |
518 |
} |
519 |
|
520 |
public String getSrs() { |
521 |
return srs;
|
522 |
} |
523 |
|
524 |
public void setSrs(String srs) { |
525 |
this.srs = srs;
|
526 |
} |
527 |
|
528 |
/**
|
529 |
* @return XMLEntity.
|
530 |
* @throws XMLException
|
531 |
*/
|
532 |
public XMLEntity getXMLEntity() throws XMLException { |
533 |
XMLEntity xml = super.getXMLEntity();
|
534 |
|
535 |
// Full extent
|
536 |
try {
|
537 |
xml.putProperty("fullExtent", StringUtilities.rect2String(getFullExtent()));
|
538 |
} catch (DriverException e) {
|
539 |
// TODO Auto-generated catch block
|
540 |
e.printStackTrace(); |
541 |
} |
542 |
|
543 |
// Host
|
544 |
xml.putProperty("host", host.toExternalForm());
|
545 |
|
546 |
// Layer name
|
547 |
xml.putProperty("layerName", getLayerName());
|
548 |
xml.putProperty("name", getName());
|
549 |
|
550 |
//Layer fields
|
551 |
XMLElement[] fields = getFields();
|
552 |
String strFields = ""; |
553 |
for (int i=0 ; i<fields.length ; i++){ |
554 |
//If is not the root node
|
555 |
if (fields[i].getParentElement() != null){ |
556 |
strFields = strFields + fields[i].getFullName(); |
557 |
if (i < fields.length - 1){ |
558 |
strFields = strFields + "~##SEP1##~";
|
559 |
} |
560 |
}else{
|
561 |
xml.putProperty("rootNode", true); |
562 |
} |
563 |
} |
564 |
xml.putProperty("fields", strFields);
|
565 |
|
566 |
// User name
|
567 |
xml.putProperty("user", getUserName());
|
568 |
|
569 |
// SRS
|
570 |
xml.putProperty("srs", getSrs());
|
571 |
|
572 |
// OnlineResources
|
573 |
xml.putProperty("onlineResource", getOnlineResource());
|
574 |
|
575 |
// TimeOut
|
576 |
xml.putProperty("timeout", getTimeout());
|
577 |
|
578 |
// Buffer
|
579 |
xml.putProperty("buffer", getNumfeatures());
|
580 |
|
581 |
//Projection
|
582 |
xml.putProperty("projection",getProjection().getAbrev());
|
583 |
|
584 |
//Filter
|
585 |
xml.putProperty("filterEncoding",getAttributesQuery());
|
586 |
|
587 |
return xml;
|
588 |
} |
589 |
|
590 |
/**
|
591 |
* @param xml XMLEntity
|
592 |
*
|
593 |
* @throws XMLException
|
594 |
* @throws DriverException
|
595 |
* @throws DriverI OException
|
596 |
*/
|
597 |
public void setXMLEntity(XMLEntity xml)throws XMLException { |
598 |
|
599 |
// Host
|
600 |
try {
|
601 |
host = new URL(xml.getStringProperty("host")); |
602 |
} catch (MalformedURLException e) { |
603 |
throw new XMLException(e); |
604 |
} |
605 |
|
606 |
// Layer name
|
607 |
setLayerName(xml.getStringProperty("layerName"));
|
608 |
setName(xml.getStringProperty("name"));
|
609 |
|
610 |
// User name
|
611 |
if (xml.contains("user")){ |
612 |
setUserName(xml.getStringProperty("user"));
|
613 |
} |
614 |
|
615 |
// SRS
|
616 |
if (xml.contains("srs")){ |
617 |
setSrs(xml.getStringProperty("srs"));
|
618 |
} |
619 |
|
620 |
// OnlineResources
|
621 |
if (xml.contains("onlineResource")){ |
622 |
setOnlineResource(xml.getStringProperty("onlineResource"));
|
623 |
} |
624 |
|
625 |
// TimeOut
|
626 |
if (xml.contains("timeout")){ |
627 |
setTimeout(xml.getIntProperty("timeout"));
|
628 |
} |
629 |
|
630 |
// Buffer
|
631 |
if (xml.contains("buffer")){ |
632 |
setNumfeatures(xml.getIntProperty("buffer"));
|
633 |
} |
634 |
|
635 |
//Projection
|
636 |
if (xml.contains("projection")){ |
637 |
setProjection(CRSFactory.getCRS(xml.getStringProperty("projection")));
|
638 |
} |
639 |
|
640 |
//Filter
|
641 |
if (xml.contains("filterEncoding")){ |
642 |
setAttributesQuery(xml.getStringProperty("filterEncoding"));
|
643 |
} |
644 |
|
645 |
// Layer fields
|
646 |
FMapWFSDriver driver; |
647 |
try {
|
648 |
driver = FMapWFSDriverFactory.getFMapDriverForURL(host); |
649 |
setWfsDriver(driver); |
650 |
WFSAdapter adapter = new WFSAdapter();
|
651 |
adapter.setDriver((VectorialDriver) wfsDriver); |
652 |
setSource(adapter); |
653 |
super.setXMLEntity(xml);
|
654 |
setLegend(LegendFactory.createFromXML(xml.getChild(0)));
|
655 |
} catch (Exception e) { |
656 |
throw new XMLException(e); |
657 |
} |
658 |
driver.getLayerList(); |
659 |
WFSLayerNode layer = driver.getLayerInfo(getLayerName()); |
660 |
XMLElement[] atts = null; |
661 |
|
662 |
// The root element always exists
|
663 |
XMLElement rootElement = (XMLElement)layer.getFields().get(0);
|
664 |
|
665 |
if (xml.contains("fields")) { |
666 |
String[] fields = xml.getStringProperty("fields").split("~##SEP1##~"); |
667 |
if ((fields.length == 1) && (fields[0].equals(""))){ |
668 |
fields = new String[0]; |
669 |
} |
670 |
//The root element always is a complex type
|
671 |
Vector allFields = ((XMLComplexType)rootElement.getEntityType()).getAttributes();
|
672 |
//If the root node has been selected
|
673 |
if (xml.contains("rootNode")){ |
674 |
if (xml.getBooleanProperty("rootNode")==true){ |
675 |
atts = new XMLElement[fields.length + 1]; |
676 |
atts[fields.length] = rootElement; |
677 |
}else{
|
678 |
atts = new XMLElement[fields.length];
|
679 |
} |
680 |
}else{
|
681 |
atts = new XMLElement[fields.length];
|
682 |
} |
683 |
//Adding the other fields
|
684 |
for (int i=0 ; i<fields.length ; i++){ |
685 |
for (int j=0 ; j<allFields.size() ; j++){ |
686 |
XMLElement attribute = (XMLElement)allFields.get(j); |
687 |
if (attribute != null){ |
688 |
XMLElement found = attribute.searchAttribute(fields[i]); |
689 |
if (found != null){ |
690 |
atts[i] = found; |
691 |
break;
|
692 |
} |
693 |
} |
694 |
} |
695 |
} |
696 |
}else{
|
697 |
if (xml.contains("rootNode")){ |
698 |
if (xml.getBooleanProperty("rootNode")==true){ |
699 |
atts = new XMLElement[1]; |
700 |
atts[0] = rootElement;
|
701 |
} |
702 |
} |
703 |
} |
704 |
layer.setSelectedFields(atts); |
705 |
setWfsLayerNode(layer); |
706 |
setFields(atts); |
707 |
setAvailable(true);
|
708 |
} |
709 |
|
710 |
/**
|
711 |
* @return Returns the attributesQuery.
|
712 |
*/
|
713 |
public String getAttributesQuery() { |
714 |
return AttributesQuery;
|
715 |
} |
716 |
|
717 |
/**
|
718 |
* @param attributesQuery The attributesQuery to set.
|
719 |
*/
|
720 |
public void setAttributesQuery(String attributesQuery) { |
721 |
AttributesQuery = attributesQuery; |
722 |
} |
723 |
|
724 |
/**
|
725 |
* @return Returns the coordinatesQuery.
|
726 |
*/
|
727 |
public String getCoordinatesQuery() { |
728 |
return CoordinatesQuery;
|
729 |
} |
730 |
|
731 |
/**
|
732 |
* @param coordinatesQuery The coordinatesQuery to set.
|
733 |
*/
|
734 |
public void setCoordinatesQuery(String coordinatesQuery) { |
735 |
CoordinatesQuery = coordinatesQuery; |
736 |
} |
737 |
} |