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