Statistics
| Revision:

svn-gvsig-desktop / trunk / extensions / extCatalogYNomenclator / src / es / gva / cit / gvsig / catalogClient / loaders / WFSLayerLoader.java @ 10626

History | View | Annotate | Download (3.63 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
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.exceptions.layers.LoadLayerException;
51
import com.iver.cit.gvsig.fmap.layers.FLayer;
52
import com.iver.cit.gvsig.project.documents.view.gui.View;
53
import com.iver.utiles.extensionPoints.ExtensionPoint;
54
import com.iver.utiles.extensionPoints.ExtensionPointsSingleton;
55

    
56
import es.gva.cit.catalogClient.schemas.discoverer.Resource;
57

    
58

    
59
/**
60
 * This class is used to load a WFS layer in gvSIG
61
 *
62
 * @author Jorge Piera Llodra (piera_jor@gva.es)
63
 */
64
public class WFSLayerLoader extends LayerLoader{
65

    
66

    
67

    
68
        public WFSLayerLoader(Resource resource) {
69
                super(resource);
70
        }
71

    
72
        /**
73
         * This function loads a WFS resource
74
         * @param host
75
         * URL where the server is located
76
         * @param layer
77
         * Layer name
78
         * @throws LayerLoaderException
79
         */
80

    
81
        public void loadLayer() throws LoadLayerException {
82
                FLayer flayer = null;
83
                String host = getResource().getLinkage();
84
                String layer = getResource().getName();
85
                try {
86
                        flayer = createWFSLayer(host, layer);
87
                        addLayerToView(flayer);
88
                } catch (Exception e) {
89
                        e.printStackTrace();
90
                        throw new LoadLayerException(layer,e);
91
                }
92
        }
93

    
94
        private FLayer createWFSLayer(String host, String sLayer) throws LoadLayerException{
95
                ExtensionPoint extensionPoint = (ExtensionPoint)ExtensionPointsSingleton.getInstance().get("CatalogLayers");
96
                Map args = new HashMap();
97
                args.put("host",host);
98
                String layerName[] = new String[1];
99
                layerName[0] = sLayer;
100
                args.put("layer",layerName);
101
                args.put("user","");
102
                args.put("pwd","");
103
                View activeView =
104
                        (View) PluginServices.getMDIManager().getActiveWindow();
105
                args.put("projection",activeView.getProjection().getAbrev());
106
                try {
107
                        return (FLayer)extensionPoint.create("OGC:WFS", args  );
108
                } catch(Exception e) {
109
                        throw new LoadLayerException(sLayer,e);
110
                }
111
        }
112

    
113
        /*
114
         *  (non-Javadoc)
115
         * @see es.gva.cit.gvsig.catalogClient.loaders.LayerLoader#getErrorMessage()
116
         */
117
        protected String getErrorMessage() {
118
                return Messages.getText("wfsError") + ".\n" +
119
                Messages.getText("server") + ": " +
120
                getResource().getLinkage() + "\n" +
121
                Messages.getText("layer") + ": " +
122
                getResource().getName();
123
        }
124

    
125
        /*
126
         *  (non-Javadoc)
127
         * @see es.gva.cit.gvsig.catalogClient.loaders.LayerLoader#getWindowMessage()
128
         */
129
        protected String getWindowMessage() {
130
                return Messages.getText("wfsLoad");
131
        }
132

    
133

    
134
}