Statistics
| Revision:

svn-gvsig-desktop / trunk / extensions / extCatalogAndGazetteer / src / es / gva / cit / gvsig / catalog / loaders / WFSLayerLoader.java @ 15557

History | View | Annotate | Download (3.79 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.catalog.loaders;
42

    
43
import java.net.MalformedURLException;
44
import java.util.HashMap;
45
import java.util.Map;
46

    
47
import org.gvsig.i18n.Messages;
48

    
49
import com.iver.andami.PluginServices;
50
import com.iver.cit.gvsig.fmap.layers.FLayer;
51
import com.iver.cit.gvsig.project.documents.view.gui.View;
52
import com.iver.utiles.extensionPoints.ExtensionPoint;
53
import com.iver.utiles.extensionPoints.ExtensionPointsSingleton;
54

    
55
import es.gva.cit.catalog.schemas.Resource;
56

    
57

    
58
/**
59
 * This class is used to load a WFS layer in gvSIG
60
 * 
61
 * @author Jorge Piera Llodra (piera_jor@gva.es)
62
 */
63
public class WFSLayerLoader extends LayerLoader{
64
        
65
        
66
        
67
        public WFSLayerLoader(Resource resource) {
68
                super(resource);
69
        }
70
        
71
        /**
72
         * This function loads a WFS resource 
73
         * @param host
74
         * URL where the server is located
75
         * @param layer
76
         * Layer name
77
         * @throws LayerLoaderException 
78
         */
79
        
80
        public void loadLayer() throws LayerLoaderException {
81
                FLayer flayer = null;
82
                String host = getResource().getLinkage();
83
                String layer = getResource().getName();
84
                try {
85
                        flayer = createWFSLayer(host, layer);
86
                        addLayerToView(flayer);
87
                } catch (MalformedURLException e) {
88
                        throw new LayerLoaderException(e.getMessage(),getWindowMessage());
89
                } catch (Exception e) {
90
                        // TODO Auto-generated catch block
91
                        e.printStackTrace();
92
                        throw new LayerLoaderException(e.getMessage(),getWindowMessage());
93
                }                
94
        }
95
        
96
        private FLayer createWFSLayer(String host, String sLayer) throws Exception{
97
                ExtensionPoint extensionPoint = (ExtensionPoint)ExtensionPointsSingleton.getInstance().get("CatalogLayers");
98
                Map args = new HashMap();
99
                args.put("host",host);
100
                String layerName[] = new String[1];
101
                layerName[0] = sLayer;
102
                args.put("layer",layerName);
103
                args.put("user","");
104
                args.put("pwd","");
105
                View activeView = 
106
                        (View) PluginServices.getMDIManager().getActiveWindow();
107
                args.put("projection",activeView.getProjection().getAbrev());
108
                try {
109
                        return (FLayer)extensionPoint.create("OGC:WFS", args  );
110
                } catch(Exception e) {
111
                        e.printStackTrace();
112
                        throw new LayerLoaderException(getErrorMessage(),getWindowMessage());
113
                }                
114
        }
115
        
116
        /*
117
         *  (non-Javadoc)
118
         * @see es.gva.cit.gvsig.catalogClient.loaders.LayerLoader#getErrorMessage()
119
         */
120
        protected String getErrorMessage() {
121
                return Messages.getText("wfsError") + ".\n" +
122
                Messages.getText("server") + ": " + 
123
                getResource().getLinkage() + "\n" +
124
                Messages.getText("layer") + ": " +
125
                getResource().getName();                
126
        }
127
        
128
        /*
129
         *  (non-Javadoc)
130
         * @see es.gva.cit.gvsig.catalogClient.loaders.LayerLoader#getWindowMessage()
131
         */
132
        protected String getWindowMessage() {
133
                return Messages.getText("wfsLoad");
134
        }
135
        
136
        
137
}