Statistics
| Revision:

root / trunk / extensions / extCatalogYNomenclator / src / es / gva / cit / gvsig / catalogClient / loaders / WFSLoader.java @ 3031

History | View | Annotate | Download (2.75 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
*
3
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
4
*
5
* This program is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU General Public License
7
* as published by the Free Software Foundation; either version 2
8
* of the License, or (at your option) any later version.
9
*
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
* GNU General Public License for more details.
14
*
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
*
19
* For more information, contact:
20
*
21
*  Generalitat Valenciana
22
*   Conselleria d'Infraestructures i Transport
23
*   Av. Blasco Ib??ez, 50
24
*   46010 VALENCIA
25
*   SPAIN
26
*
27
*      +34 963862235
28
*   gvsig@gva.es
29
*      www.gvsig.gva.es
30
*
31
*    or
32
*
33
*   IVER T.I. S.A
34
*   Salamanca 50
35
*   46005 Valencia
36
*   Spain
37
*
38
*   +34 963163400
39
*   dac@iver.es
40
*/
41
package es.gva.cit.gvsig.catalogClient.loaders;
42

    
43

    
44

    
45
import java.io.IOException;
46
import java.net.MalformedURLException;
47
import java.net.URL;
48

    
49
import com.iver.cit.gvsig.fmap.drivers.wfs.WFSDriver;
50
import com.iver.cit.gvsig.fmap.layers.FLayer;
51
import com.iver.cit.gvsig.fmap.layers.LayerFactory;
52
import com.iver.cit.gvsig.wfs.gui.wfswizard.WizardWFS;
53

    
54

    
55
/**
56
 * This class is used to load a WFS layer in gvSIG
57
 * 
58
 * @author Jorge Piera Llodra (piera_jor@gva.es)
59
 */
60
public class WFSLoader extends AbstractLoader{
61

    
62
    /**
63
         * This function loads a WFS resource 
64
         * @param host
65
         * URL where the server is located
66
         * @param layer
67
         * Layer name
68
         */
69
        
70
        public boolean load(String host, String layer) {
71
                FLayer flayer = null;
72
        try {
73
            flayer = createWFSLayer(host, layer);
74
        } catch (MalformedURLException e) {
75
            // TODO Auto-generated catch block
76
            e.printStackTrace();
77
        }
78
        if (flayer == null){
79
                    return false;
80
                }else{
81
                    addLayerToView(flayer);
82
                    return true;
83
                }
84
        }
85
        
86
        private FLayer createWFSLayer(String host, String sLayer) throws MalformedURLException{
87
            WizardWFS wfs = new WizardWFS();
88
                
89
                String layerName[] = new String[1];
90
                layerName[0] = sLayer;
91
                String user = "";
92
                String pwd = "";
93
                String url = host;
94
                boolean protocol=true;
95
                int numfeatures=100;
96
                int timeout=10000;
97
                        
98
                WFSDriver driver = new WFSDriver();
99
                try{
100
                        driver.setData(url,user,pwd,layerName,protocol,numfeatures,timeout,2);
101
                }catch (IOException e) {
102
                        return null;
103
                }
104
                
105
                return LayerFactory.createWFSLayer(sLayer,driver,new URL(url),
106
                                        wfs.getProjection());
107
                
108
                
109
        }
110
        
111
        
112
}