root / trunk / extensions / extWFS2 / src / com / iver / cit / gvsig / fmap / layers / FLyrWFS.java @ 10422
History | View | Annotate | Download (22.4 KB)
1 |
package com.iver.cit.gvsig.fmap.layers; |
---|---|
2 |
|
3 |
import java.awt.geom.Rectangle2D; |
4 |
import java.io.IOException; |
5 |
import java.io.UnsupportedEncodingException; |
6 |
import java.net.ConnectException; |
7 |
import java.net.MalformedURLException; |
8 |
import java.net.URL; |
9 |
import java.net.URLEncoder; |
10 |
import java.util.HashMap; |
11 |
import java.util.Hashtable; |
12 |
import java.util.Map; |
13 |
import java.util.Vector; |
14 |
|
15 |
import javax.swing.ImageIcon; |
16 |
|
17 |
import org.gvsig.remoteClient.gml.schemas.XMLElement; |
18 |
import org.gvsig.remoteClient.gml.types.IXMLType; |
19 |
import org.gvsig.remoteClient.gml.types.XMLComplexType; |
20 |
import org.gvsig.remoteClient.wfs.WFSStatus; |
21 |
import org.gvsig.remoteClient.wfs.filters.AFilter; |
22 |
import org.gvsig.remoteClient.wfs.filters.FilterEncoding; |
23 |
|
24 |
import com.iver.andami.PluginServices; |
25 |
import com.iver.cit.gvsig.fmap.DriverException; |
26 |
import com.iver.cit.gvsig.fmap.crs.CRSFactory; |
27 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
28 |
import com.iver.cit.gvsig.fmap.drivers.VectorialDriver; |
29 |
import com.iver.cit.gvsig.fmap.drivers.WFSException; |
30 |
import com.iver.cit.gvsig.fmap.drivers.wfs.FMapWFSDriver; |
31 |
import com.iver.cit.gvsig.fmap.drivers.wfs.FMapWFSDriverFactory; |
32 |
import com.iver.cit.gvsig.fmap.drivers.wfs.filters.SQLExpressionFormat; |
33 |
import com.iver.cit.gvsig.fmap.rendering.LegendFactory; |
34 |
import com.iver.utiles.StringUtilities; |
35 |
import com.iver.utiles.XMLEntity; |
36 |
|
37 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
38 |
*
|
39 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
40 |
*
|
41 |
* This program is free software; you can redistribute it and/or
|
42 |
* modify it under the terms of the GNU General Public License
|
43 |
* as published by the Free Software Foundation; either version 2
|
44 |
* of the License, or (at your option) any later version.
|
45 |
*
|
46 |
* This program is distributed in the hope that it will be useful,
|
47 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
48 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
49 |
* GNU General Public License for more details.
|
50 |
*
|
51 |
* You should have received a copy of the GNU General Public License
|
52 |
* along with this program; if not, write to the Free Software
|
53 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
54 |
*
|
55 |
* For more information, contact:
|
56 |
*
|
57 |
* Generalitat Valenciana
|
58 |
* Conselleria d'Infraestructures i Transport
|
59 |
* Av. Blasco Ib??ez, 50
|
60 |
* 46010 VALENCIA
|
61 |
* SPAIN
|
62 |
*
|
63 |
* +34 963862235
|
64 |
* gvsig@gva.es
|
65 |
* www.gvsig.gva.es
|
66 |
*
|
67 |
* or
|
68 |
*
|
69 |
* IVER T.I. S.A
|
70 |
* Salamanca 50
|
71 |
* 46005 Valencia
|
72 |
* Spain
|
73 |
*
|
74 |
* +34 963163400
|
75 |
* dac@iver.es
|
76 |
*/
|
77 |
/* CVS MESSAGES:
|
78 |
*
|
79 |
* $Id: FLyrWFS.java 10422 2007-02-20 13:12:29Z ppiqueras $
|
80 |
* $Log$
|
81 |
* Revision 1.32 2007-02-20 13:12:29 ppiqueras
|
82 |
* Que no aplique filtro ni bounding box si son null
|
83 |
*
|
84 |
* Revision 1.31 2007/02/19 11:44:42 jorpiell
|
85 |
* A?adidos los filtros por ?rea
|
86 |
*
|
87 |
* Revision 1.30 2007/02/09 14:12:38 jorpiell
|
88 |
* Soporte para WFS 1.1 y WFS-T
|
89 |
*
|
90 |
* Revision 1.29 2007/01/12 13:09:41 jorpiell
|
91 |
* added searches by area
|
92 |
*
|
93 |
* Revision 1.28 2007/01/10 08:23:02 jorpiell
|
94 |
* If the parent element is selected is not necessary to select its children
|
95 |
*
|
96 |
* Revision 1.27 2006/12/26 10:25:37 ppiqueras
|
97 |
* Corregidas las dependencias con las nuevas ubicaciones de clases: IXMLType, XMLElement, IXMLComplexType, etc. (en libRemoteServices)
|
98 |
*
|
99 |
* Revision 1.26 2006/12/26 09:28:01 ppiqueras
|
100 |
* Cambiado "atttibutes" en todas las aparaciones en atributos, m?todos, clases, paquetes o comentarios por "fields". (S?lo a aquellas que afectan a clases dentro del proyecto extWFS2).
|
101 |
*
|
102 |
* Revision 1.24 2006/12/15 13:55:17 ppiqueras
|
103 |
* Almacena todos los campos y valores conocidos de la capa.
|
104 |
*
|
105 |
* Revision 1.23 2006/12/11 11:02:24 ppiqueras
|
106 |
* Corregido bug -> que se mantenga la frase de filtrado
|
107 |
*
|
108 |
* Revision 1.22 2006/11/28 08:04:51 jorpiell
|
109 |
* Se guarda la query para que pueda ser recuperada desde la ventana de propiedades
|
110 |
*
|
111 |
* Revision 1.21 2006/11/16 17:17:48 jorpiell
|
112 |
* Se guarda el filtro en el gvp
|
113 |
*
|
114 |
* Revision 1.20 2006/11/16 13:29:47 jorpiell
|
115 |
* Se ha reescrito losl m?todo para guardar y recuperar gvps
|
116 |
*
|
117 |
* Revision 1.19 2006/11/15 17:38:08 jorpiell
|
118 |
* Ya se puede guardar una capa en WFS.
|
119 |
*
|
120 |
* Revision 1.18 2006/10/31 12:24:04 jorpiell
|
121 |
* Comprobado el caso en el que los atributos no tienen tipo
|
122 |
*
|
123 |
* Revision 1.17 2006/10/31 09:55:28 jorpiell
|
124 |
* Se ha modificado el constructor del WFS desde cat?logo
|
125 |
*
|
126 |
* Revision 1.16 2006/10/31 09:38:15 jorpiell
|
127 |
* 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
|
128 |
*
|
129 |
* Revision 1.15 2006/10/23 07:37:04 jorpiell
|
130 |
* Ya funciona el filterEncoding
|
131 |
*
|
132 |
* Revision 1.14 2006/10/10 12:55:06 jorpiell
|
133 |
* Se ha a?adido el soporte de features complejas
|
134 |
*
|
135 |
* Revision 1.13 2006/10/02 12:54:35 jorpiell
|
136 |
* No se pod?a crear un mapa que tubiera la opci?n enlace vivo habilitada
|
137 |
*
|
138 |
* Revision 1.12 2006/10/02 09:09:45 jorpiell
|
139 |
* Cambios del 10 copiados al head
|
140 |
*
|
141 |
* Revision 1.10.2.3 2006/09/29 14:12:53 luisw2
|
142 |
* CRSFactory.getCRS substitutes ProjectionPool.get
|
143 |
*
|
144 |
* Revision 1.10.2.2 2006/09/28 08:54:01 jorpiell
|
145 |
* Ya se puede reproyectar
|
146 |
*
|
147 |
* Revision 1.10.2.1 2006/09/26 07:36:24 jorpiell
|
148 |
* El WFS no reproyectaba porque no se le asignaba a la capa un sistema de referencia. Ahora ya se hace.
|
149 |
*
|
150 |
* Revision 1.10 2006/09/05 15:41:52 jorpiell
|
151 |
* A?adida la funcionalidad de cargar WFS desde el cat?logo
|
152 |
*
|
153 |
* Revision 1.9 2006/07/05 12:05:41 jorpiell
|
154 |
* Se ha modificado para que avise si se han recuperado las mismas features que marca el campo buffer
|
155 |
*
|
156 |
* Revision 1.8 2006/06/21 12:52:10 jorpiell
|
157 |
* A?adido un icono para la capa WFS
|
158 |
*
|
159 |
* Revision 1.7 2006/06/21 12:35:45 jorpiell
|
160 |
* 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
|
161 |
*
|
162 |
* Revision 1.6 2006/06/15 11:17:06 jorpiell
|
163 |
* 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
|
164 |
*
|
165 |
* Revision 1.5 2006/06/14 07:57:19 jorpiell
|
166 |
* Ya no se usa la estrategia ni se usa geotools para hacer el getFeature. Ahora se usa ?nicamente para el parseo de GML
|
167 |
*
|
168 |
* Revision 1.4 2006/06/05 16:49:31 caballero
|
169 |
* poder editar y exportar
|
170 |
*
|
171 |
* Revision 1.3 2006/05/25 10:31:55 jorpiell
|
172 |
* Se ha renombrado la clase WFSFields por WFSAttributes porque era algo confusa
|
173 |
*
|
174 |
* Revision 1.2 2006/05/23 13:21:59 jorpiell
|
175 |
* Si hay alg?n problema en la carga se muestra un mensaje de error
|
176 |
*
|
177 |
* Revision 1.1 2006/05/19 12:54:11 jorpiell
|
178 |
* Creada la capa WFS
|
179 |
*
|
180 |
*
|
181 |
*/
|
182 |
/**
|
183 |
* FMap's WFS Layer class.
|
184 |
*
|
185 |
* @author Jorge Piera Llodr? (piera_jor@gva.es)
|
186 |
*/
|
187 |
public class FLyrWFS extends FLyrVect{ |
188 |
private URL host = null; |
189 |
private String onlineResource = null; |
190 |
private String name = null; |
191 |
private String layerName = null; |
192 |
private String nameSapce = null; |
193 |
private String userName = null; |
194 |
private String password = null; |
195 |
private String FieldsQuery = null; |
196 |
private Rectangle2D bbox = null; |
197 |
private String bboxPropertyName = null; |
198 |
private String visualFilterQuery = null; |
199 |
private Rectangle2D extent = null; |
200 |
private XMLElement[] fields = null; |
201 |
private int numfeatures = 100; |
202 |
private int timeout = 10000; |
203 |
private String srs = null; |
204 |
private FMapWFSDriver wfsDriver = null; |
205 |
private WFSLayerNode wfsLayerNode = null; |
206 |
private Map allFieldsAndValuesKnown = null; |
207 |
|
208 |
/**
|
209 |
* Constructor
|
210 |
*/
|
211 |
public FLyrWFS(){
|
212 |
super();
|
213 |
} |
214 |
|
215 |
/**
|
216 |
* Constructor to load a new layer from a catalog
|
217 |
* search
|
218 |
* @param args
|
219 |
* Params to load a new layer
|
220 |
* @throws WFSException
|
221 |
* @throws IOException
|
222 |
* @throws MalformedURLException
|
223 |
* @throws ConnectException
|
224 |
* @throws DriverIOException
|
225 |
*/
|
226 |
public FLyrWFS(Map args) throws WFSException, ConnectException, MalformedURLException, IOException, DriverIOException{ |
227 |
String[] sLayer = (String[])args.get("layer"); |
228 |
String[] sNamespace = (String[])args.get("namespace"); |
229 |
String user = (String)args.get("user"); |
230 |
String pwd = (String)args.get("pwd"); |
231 |
String host = (String)args.get("host"); |
232 |
String projection = (String)args.get("projection"); |
233 |
|
234 |
FMapWFSDriver driver = FMapWFSDriverFactory.getFMapDriverForURL(new URL(host)); |
235 |
WFSLayerNode[] layers = driver.getLayerList();
|
236 |
WFSLayerNode layer = driver.getLayerInfo(sLayer[0],sNamespace[0]); |
237 |
|
238 |
layer.setSelectedFields(layer.getFields()); |
239 |
|
240 |
Vector vAtts = new Vector(); |
241 |
if (layer.getFields().size() == 1){ |
242 |
XMLElement element = (XMLElement)layer.getFields().get(0);
|
243 |
if (element.getEntityType().getType() != IXMLType.COMPLEX){
|
244 |
vAtts.add(element); |
245 |
}else{
|
246 |
vAtts = ((XMLComplexType)element.getEntityType()).getAttributes(); |
247 |
} |
248 |
} |
249 |
for (int i=0 ; i<layer.getFields().size() ; i++){ |
250 |
XMLElement element = (XMLElement)layer.getFields().get(i); |
251 |
if (element.getEntityType().getType() != IXMLType.COMPLEX){
|
252 |
vAtts.add((XMLElement)layer.getFields().get(i)); |
253 |
}else{
|
254 |
|
255 |
} |
256 |
} |
257 |
|
258 |
XMLElement[] atts = new XMLElement[vAtts.size()]; |
259 |
for (int i=0 ; i<vAtts.size() ; i++){ |
260 |
atts[i] = (XMLElement)vAtts.get(i); |
261 |
} |
262 |
|
263 |
setHost(host); |
264 |
setName(sLayer[0]);
|
265 |
setLayerName(sLayer[0]);
|
266 |
setWfsLayerNode(layer); |
267 |
setFields(atts); |
268 |
setUserName(user); |
269 |
setPassword(pwd); |
270 |
setNumfeatures(10000);
|
271 |
setTimeout(10000);
|
272 |
setWfsDriver(driver); |
273 |
setProjection(CRSFactory.getCRS(projection)); |
274 |
|
275 |
load(); |
276 |
} |
277 |
|
278 |
|
279 |
/**
|
280 |
* Loads the features from the server
|
281 |
*/
|
282 |
public void load() throws DriverIOException{ |
283 |
WFSAdapter adapter = new WFSAdapter();
|
284 |
try {
|
285 |
wfsDriver.getFeature(getWFSStatus()); |
286 |
|
287 |
adapter.setDriver((VectorialDriver) wfsDriver); |
288 |
setSource(adapter); |
289 |
|
290 |
if (getLegend() == null){ |
291 |
setLegend(LegendFactory.createSingleSymbolLegend( |
292 |
getShapeType())); |
293 |
} |
294 |
} catch (Exception e){ |
295 |
e.printStackTrace(); |
296 |
throw new DriverIOException(e.getMessage()); |
297 |
} |
298 |
} |
299 |
|
300 |
/**
|
301 |
* Gets the WFS Status
|
302 |
* @return
|
303 |
*/
|
304 |
private WFSStatus getWFSStatus(){
|
305 |
WFSStatus status = new WFSStatus(getLayerName(),getNameSapce());
|
306 |
status.setUserName(getUserName()); |
307 |
status.setPassword(getPassword()); |
308 |
status.setBuffer(getNumfeatures()); |
309 |
status.setTimeout(getTimeout()); |
310 |
status.setFields(getFieldNames()); |
311 |
status.setOnlineResource(getOnlineResource()); |
312 |
status.setSrs(getSrs()); |
313 |
status.setBBox(getExtent()); |
314 |
//Filter Encoding transformation
|
315 |
if ((getFieldsQuery() != null) && (getBbox() != null)) { |
316 |
FilterEncoding fe = SQLExpressionFormat.createFilter(); |
317 |
fe.setQuery(getFieldsQuery()); |
318 |
fe.setBBox(getBbox(), getBboxPropertyName(), getSrs(), AFilter.BBOX_ENCLOSES); |
319 |
try {
|
320 |
status.setFilterQuery(URLEncoder.encode(fe.toString(),"8859_1")); |
321 |
} catch (UnsupportedEncodingException e) { |
322 |
status.setFilterQuery(fe.toString()); |
323 |
} |
324 |
} |
325 |
status.setFilterVisualText(getVisualFilterQuery()); |
326 |
return status;
|
327 |
} |
328 |
|
329 |
/**
|
330 |
* @return Returns the layerName.
|
331 |
*/
|
332 |
public String getLayerName() { |
333 |
return layerName;
|
334 |
} |
335 |
/**
|
336 |
* @param layerName The layerName to set.
|
337 |
*/
|
338 |
public void setLayerName(String layerName) { |
339 |
this.layerName = layerName;
|
340 |
} |
341 |
/**
|
342 |
* @return Returns the numfeatures.
|
343 |
*/
|
344 |
public int getNumfeatures() { |
345 |
return numfeatures;
|
346 |
} |
347 |
/**
|
348 |
* @param numfeatures The numfeatures to set.
|
349 |
*/
|
350 |
public void setNumfeatures(int numfeatures) { |
351 |
this.numfeatures = numfeatures;
|
352 |
} |
353 |
|
354 |
/**
|
355 |
* @return Returns the pwd.
|
356 |
*/
|
357 |
public String getPassword() { |
358 |
return password;
|
359 |
} |
360 |
/**
|
361 |
* @param pwd The pwd to set.
|
362 |
*/
|
363 |
public void setPassword(String password) { |
364 |
this.password = password;
|
365 |
} |
366 |
/**
|
367 |
* @return Returns the timeout.
|
368 |
*/
|
369 |
public int getTimeout() { |
370 |
return timeout;
|
371 |
} |
372 |
/**
|
373 |
* @param timeout The timeout to set.
|
374 |
*/
|
375 |
public void setTimeout(int timeout) { |
376 |
this.timeout = timeout;
|
377 |
} |
378 |
/**
|
379 |
* @return Returns the user.
|
380 |
*/
|
381 |
public String getUserName() { |
382 |
return userName;
|
383 |
} |
384 |
/**
|
385 |
* @param user The user to set.
|
386 |
*/
|
387 |
public void setUserName(String userName) { |
388 |
this.userName = userName;
|
389 |
} |
390 |
/**
|
391 |
* @return The visual filtering text from "Where"
|
392 |
*/
|
393 |
public String getVisualFilterQuery() { |
394 |
return visualFilterQuery;
|
395 |
} |
396 |
/**
|
397 |
* @param visualFilterQuery The visual filtering text from "Where"
|
398 |
*/
|
399 |
public void setVisualFilterQueyr(String visualFilterQuery) { |
400 |
this.visualFilterQuery = visualFilterQuery;
|
401 |
} |
402 |
/**
|
403 |
* @return Returns the fields.
|
404 |
*/
|
405 |
public XMLElement[] getFields() { |
406 |
if (fields == null){ |
407 |
return new XMLElement[0]; |
408 |
} |
409 |
return fields;
|
410 |
} |
411 |
|
412 |
/**
|
413 |
* Return the fields name
|
414 |
* @return
|
415 |
*/
|
416 |
public String[] getFieldNames(){ |
417 |
Vector vFields = new Vector(); |
418 |
Hashtable hashFields = new Hashtable(); |
419 |
for (int i=0 ; i<getFields().length ; i++){ |
420 |
//if is not the root element
|
421 |
if (getFields()[i].getParentElement() != null){ |
422 |
//If the parent node has been not added
|
423 |
if (hashFields.get(getFields()[i].getParentElement()) == null){ |
424 |
hashFields.put(getFields()[i],"");
|
425 |
vFields.add(getFields()[i].getFullName()); |
426 |
} |
427 |
} |
428 |
} |
429 |
String[] fields = new String[vFields.size()]; |
430 |
for (int i=0 ; i<vFields.size() ; i++){ |
431 |
fields[i] = (String)vFields.get(i);
|
432 |
} |
433 |
return fields;
|
434 |
} |
435 |
|
436 |
/**
|
437 |
* @param fields The fields to set.
|
438 |
*/
|
439 |
public void setFields(XMLElement[] fields) { |
440 |
this.fields = fields;
|
441 |
} |
442 |
/**
|
443 |
* @return Returns the name.
|
444 |
*/
|
445 |
public String getName() { |
446 |
return name;
|
447 |
} |
448 |
/**
|
449 |
* @param name The name to set.
|
450 |
*/
|
451 |
public void setName(String name) { |
452 |
this.name = name;
|
453 |
} |
454 |
/**
|
455 |
* @return Returns the host.
|
456 |
*/
|
457 |
public URL getHost() { |
458 |
return host;
|
459 |
} |
460 |
/**
|
461 |
* @param host The host to set.
|
462 |
*/
|
463 |
public void setHost(URL host) { |
464 |
this.host = host;
|
465 |
} |
466 |
|
467 |
/**
|
468 |
* @return Returns the wfs.
|
469 |
*/
|
470 |
public FMapWFSDriver getWfsDriver() {
|
471 |
return wfsDriver;
|
472 |
} |
473 |
|
474 |
/**
|
475 |
* @param wfs The wfs to set.
|
476 |
*/
|
477 |
public void setWfsDriver(FMapWFSDriver wfs) { |
478 |
this.wfsDriver = wfs;
|
479 |
} |
480 |
|
481 |
|
482 |
/*
|
483 |
* (non-Javadoc)
|
484 |
* @see com.iver.cit.gvsig.fmap.layers.FLyrDefault#getStrategy()
|
485 |
*/
|
486 |
// public Strategy getStrategy() {
|
487 |
// if (wfsStrategy == null){
|
488 |
// wfsStrategy = new WFSStrategy(this);
|
489 |
// }
|
490 |
// return wfsStrategy;
|
491 |
// }
|
492 |
|
493 |
/*
|
494 |
* (non-Javadoc)
|
495 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#getFullExtent()
|
496 |
*/
|
497 |
public Rectangle2D getFullExtent() throws DriverException { |
498 |
try {
|
499 |
Rectangle2D extent = wfsDriver.getFullExtent();
|
500 |
if (getCoordTrans() != null){ |
501 |
return getCoordTrans().convert(extent);
|
502 |
} |
503 |
return extent;
|
504 |
} catch (IOException e) { |
505 |
throw new DriverException(e.toString()); |
506 |
} |
507 |
} |
508 |
|
509 |
/**
|
510 |
* @return Returns the onlineResource.
|
511 |
*/
|
512 |
public String getOnlineResource() { |
513 |
return onlineResource;
|
514 |
} |
515 |
|
516 |
/**
|
517 |
* @param onlineResource The onlineResource to set.
|
518 |
*/
|
519 |
public void setOnlineResource(String onlineResource) { |
520 |
this.onlineResource = onlineResource;
|
521 |
} |
522 |
|
523 |
public HashMap getProperties() { |
524 |
HashMap info = new HashMap(); |
525 |
info.put("name", getName());
|
526 |
info.put("layerName", getLayerName());
|
527 |
info.put("layerText", getLayerText());
|
528 |
info.put("attributes", getFields());
|
529 |
info.put("host", getHost());
|
530 |
info.put("wfsLayerNode", getWfsLayerNode());
|
531 |
WFSStatus status = new WFSStatus(getLayerName(),getNameSapce());
|
532 |
status.setBuffer(getNumfeatures()); |
533 |
status.setTimeout(getTimeout()); |
534 |
status.setUserName(getUserName()); |
535 |
status.setPassword(getPassword()); |
536 |
status.setFilterQuery(getFieldsQuery()); |
537 |
status.setFilterVisualText(getVisualFilterQuery()); |
538 |
info.put("status",status);
|
539 |
return info;
|
540 |
|
541 |
} |
542 |
|
543 |
/**
|
544 |
* @return Returns the wfsLayerNode.
|
545 |
*/
|
546 |
public WFSLayerNode getWfsLayerNode() {
|
547 |
return wfsLayerNode;
|
548 |
} |
549 |
|
550 |
/**
|
551 |
* @param wfsLayerNode The wfsLayerNode to set.
|
552 |
*/
|
553 |
public void setWfsLayerNode(WFSLayerNode wfsLayerNode) { |
554 |
this.wfsLayerNode = wfsLayerNode;
|
555 |
} |
556 |
|
557 |
public void setHost(String host2) { |
558 |
try {
|
559 |
setHost(new URL(host2)); |
560 |
} catch (MalformedURLException e) { |
561 |
// TODO Auto-generated catch block
|
562 |
e.printStackTrace(); |
563 |
} |
564 |
} |
565 |
|
566 |
public ImageIcon getTocImageIcon() { |
567 |
return new ImageIcon(PluginServices.getPluginServices("com.iver.cit.gvsig.wfs2").getClassLoader().getResource("images/icoLayer.png")); |
568 |
} |
569 |
|
570 |
/*
|
571 |
* (non-Javadoc)
|
572 |
* @see com.iver.cit.gvsig.fmap.layers.FLyrVect#isPropertiesMenuVisible()
|
573 |
*/
|
574 |
public boolean isPropertiesMenuVisible(){ |
575 |
return false; |
576 |
} |
577 |
|
578 |
public String getSrs() { |
579 |
return srs;
|
580 |
} |
581 |
|
582 |
public void setSrs(String srs) { |
583 |
this.srs = srs;
|
584 |
} |
585 |
|
586 |
/**
|
587 |
* @return XMLEntity.
|
588 |
* @throws XMLException
|
589 |
*/
|
590 |
public XMLEntity getXMLEntity() throws XMLException { |
591 |
XMLEntity xml = super.getXMLEntity();
|
592 |
|
593 |
// Full extent
|
594 |
try {
|
595 |
xml.putProperty("fullExtent", StringUtilities.rect2String(getFullExtent()));
|
596 |
} catch (DriverException e) {
|
597 |
// TODO Auto-generated catch block
|
598 |
e.printStackTrace(); |
599 |
} |
600 |
|
601 |
// Host
|
602 |
xml.putProperty("host", host.toExternalForm());
|
603 |
|
604 |
// Layer name
|
605 |
xml.putProperty("layerName", getLayerName());
|
606 |
xml.putProperty("name", getName());
|
607 |
|
608 |
//Layer fields
|
609 |
XMLElement[] fields = getFields();
|
610 |
String strFields = ""; |
611 |
for (int i=0 ; i<fields.length ; i++){ |
612 |
//If is not the root node
|
613 |
if (fields[i].getParentElement() != null){ |
614 |
strFields = strFields + fields[i].getFullName(); |
615 |
if (i < fields.length - 1){ |
616 |
strFields = strFields + "~##SEP1##~";
|
617 |
} |
618 |
}else{
|
619 |
xml.putProperty("rootNode", true); |
620 |
} |
621 |
} |
622 |
xml.putProperty("fields", strFields);
|
623 |
|
624 |
// User name
|
625 |
xml.putProperty("user", getUserName());
|
626 |
|
627 |
// SRS
|
628 |
xml.putProperty("srs", getSrs());
|
629 |
|
630 |
// OnlineResources
|
631 |
xml.putProperty("onlineResource", getOnlineResource());
|
632 |
|
633 |
// TimeOut
|
634 |
xml.putProperty("timeout", getTimeout());
|
635 |
|
636 |
// Buffer
|
637 |
xml.putProperty("buffer", getNumfeatures());
|
638 |
|
639 |
//Projection
|
640 |
xml.putProperty("projection",getProjection().getAbrev());
|
641 |
|
642 |
//Filter
|
643 |
xml.putProperty("filterEncoding",getFieldsQuery());
|
644 |
|
645 |
return xml;
|
646 |
} |
647 |
|
648 |
/**
|
649 |
* @param xml XMLEntity
|
650 |
*
|
651 |
* @throws XMLException
|
652 |
* @throws DriverException
|
653 |
* @throws DriverI OException
|
654 |
*/
|
655 |
public void setXMLEntity(XMLEntity xml)throws XMLException { |
656 |
|
657 |
// Host
|
658 |
try {
|
659 |
host = new URL(xml.getStringProperty("host")); |
660 |
} catch (MalformedURLException e) { |
661 |
throw new XMLException(e); |
662 |
} |
663 |
|
664 |
// Layer name
|
665 |
setLayerName(xml.getStringProperty("layerName"));
|
666 |
setName(xml.getStringProperty("name"));
|
667 |
|
668 |
// User name
|
669 |
if (xml.contains("user")){ |
670 |
setUserName(xml.getStringProperty("user"));
|
671 |
} |
672 |
|
673 |
// SRS
|
674 |
if (xml.contains("srs")){ |
675 |
setSrs(xml.getStringProperty("srs"));
|
676 |
} |
677 |
|
678 |
// OnlineResources
|
679 |
if (xml.contains("onlineResource")){ |
680 |
setOnlineResource(xml.getStringProperty("onlineResource"));
|
681 |
} |
682 |
|
683 |
// TimeOut
|
684 |
if (xml.contains("timeout")){ |
685 |
setTimeout(xml.getIntProperty("timeout"));
|
686 |
} |
687 |
|
688 |
// Buffer
|
689 |
if (xml.contains("buffer")){ |
690 |
setNumfeatures(xml.getIntProperty("buffer"));
|
691 |
} |
692 |
|
693 |
//Projection
|
694 |
if (xml.contains("projection")){ |
695 |
setProjection(CRSFactory.getCRS(xml.getStringProperty("projection")));
|
696 |
} |
697 |
|
698 |
//Filter
|
699 |
if (xml.contains("filterEncoding")){ |
700 |
setFieldsQuery(xml.getStringProperty("filterEncoding"));
|
701 |
} |
702 |
|
703 |
// Layer fields
|
704 |
FMapWFSDriver driver; |
705 |
try {
|
706 |
driver = FMapWFSDriverFactory.getFMapDriverForURL(host); |
707 |
setWfsDriver(driver); |
708 |
WFSAdapter adapter = new WFSAdapter();
|
709 |
adapter.setDriver((VectorialDriver) wfsDriver); |
710 |
setSource(adapter); |
711 |
super.setXMLEntity(xml);
|
712 |
setLegend(LegendFactory.createFromXML(xml.getChild(0)));
|
713 |
} catch (Exception e) { |
714 |
throw new XMLException(e); |
715 |
} |
716 |
driver.getLayerList(); |
717 |
WFSLayerNode layer = driver.getLayerInfo(getLayerName(),getNameSapce()); |
718 |
XMLElement[] atts = null; |
719 |
|
720 |
// The root element always exists
|
721 |
XMLElement rootElement = (XMLElement)layer.getFields().get(0);
|
722 |
|
723 |
if (xml.contains("fields")) { |
724 |
String[] fields = xml.getStringProperty("fields").split("~##SEP1##~"); |
725 |
if ((fields.length == 1) && (fields[0].equals(""))){ |
726 |
fields = new String[0]; |
727 |
} |
728 |
//The root element always is a complex type
|
729 |
Vector allFields = ((XMLComplexType)rootElement.getEntityType()).getAttributes();
|
730 |
//If the root node has been selected
|
731 |
if (xml.contains("rootNode")){ |
732 |
if (xml.getBooleanProperty("rootNode")==true){ |
733 |
atts = new XMLElement[fields.length + 1]; |
734 |
atts[fields.length] = rootElement; |
735 |
}else{
|
736 |
atts = new XMLElement[fields.length];
|
737 |
} |
738 |
}else{
|
739 |
atts = new XMLElement[fields.length];
|
740 |
} |
741 |
//Adding the other fields
|
742 |
for (int i=0 ; i<fields.length ; i++){ |
743 |
for (int j=0 ; j<allFields.size() ; j++){ |
744 |
XMLElement field = (XMLElement)allFields.get(j); |
745 |
if (field != null){ |
746 |
XMLElement found = field.searchAttribute(fields[i]); |
747 |
if (found != null){ |
748 |
atts[i] = found; |
749 |
break;
|
750 |
} |
751 |
} |
752 |
} |
753 |
} |
754 |
}else{
|
755 |
if (xml.contains("rootNode")){ |
756 |
if (xml.getBooleanProperty("rootNode")==true){ |
757 |
atts = new XMLElement[1]; |
758 |
atts[0] = rootElement;
|
759 |
} |
760 |
} |
761 |
} |
762 |
layer.setSelectedFields(atts); |
763 |
setWfsLayerNode(layer); |
764 |
setFields(atts); |
765 |
setAvailable(true);
|
766 |
} |
767 |
|
768 |
/**
|
769 |
* @return Returns the fieldsQuery.
|
770 |
*/
|
771 |
public String getFieldsQuery() { |
772 |
return FieldsQuery;
|
773 |
} |
774 |
|
775 |
/**
|
776 |
* @param fieldsQuery The fieldsQuery to set.
|
777 |
*/
|
778 |
public void setFieldsQuery(String fieldsQuery) { |
779 |
FieldsQuery = fieldsQuery; |
780 |
} |
781 |
|
782 |
/**
|
783 |
* Sets all fields and values known about this layer
|
784 |
*
|
785 |
* @param _allFieldsAndValuesKnown A Map
|
786 |
*/
|
787 |
public void setAllFieldsAndValuesKnown(Map _allFieldsAndValuesKnown) { |
788 |
if (this.allFieldsAndValuesKnown == null) |
789 |
allFieldsAndValuesKnown = new HashMap(); |
790 |
|
791 |
allFieldsAndValuesKnown = _allFieldsAndValuesKnown; |
792 |
} |
793 |
|
794 |
/**
|
795 |
* Gets all fields and values known about this layer
|
796 |
*
|
797 |
* @return A Map
|
798 |
*/
|
799 |
public Map getAllFieldsAndValuesKnown() { |
800 |
return allFieldsAndValuesKnown;
|
801 |
} |
802 |
|
803 |
/**
|
804 |
* @return Returns the extent.
|
805 |
*/
|
806 |
public Rectangle2D getExtent() { |
807 |
return extent;
|
808 |
} |
809 |
|
810 |
/**
|
811 |
* @param extent The extent to set.
|
812 |
*/
|
813 |
public void setExtent(Rectangle2D extent) { |
814 |
this.extent = extent;
|
815 |
} |
816 |
|
817 |
/**
|
818 |
* @return Returns the nameSapce.
|
819 |
*/
|
820 |
public String getNameSapce() { |
821 |
return nameSapce;
|
822 |
} |
823 |
|
824 |
/**
|
825 |
* @param nameSapce The nameSapce to set.
|
826 |
*/
|
827 |
public void setNameSapce(String nameSapce) { |
828 |
this.nameSapce = nameSapce;
|
829 |
} |
830 |
|
831 |
/**
|
832 |
* @return Returns the bbox.
|
833 |
*/
|
834 |
public Rectangle2D getBbox() { |
835 |
return bbox;
|
836 |
} |
837 |
|
838 |
/**
|
839 |
* @param bbox The bounding box to set.
|
840 |
*/
|
841 |
public void setBbox(Rectangle2D bbox) { |
842 |
this.bbox = bbox;
|
843 |
} |
844 |
|
845 |
public String getBboxPropertyName() { |
846 |
return bboxPropertyName;
|
847 |
} |
848 |
|
849 |
public void setBboxPropertyName(String bboxPropertyName) { |
850 |
this.bboxPropertyName = bboxPropertyName;
|
851 |
} |
852 |
} |