Statistics
| Revision:

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

History | View | Annotate | Download (4.22 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.io.IOException;
44
import java.net.MalformedURLException;
45
import java.net.ProtocolException;
46
import java.util.HashMap;
47
import java.util.Map;
48

    
49
import org.exolab.castor.xml.ValidationException;
50
import org.gvsig.i18n.Messages;
51

    
52
import com.iver.andami.PluginServices;
53
import com.iver.cit.gvsig.exceptions.layers.LoadLayerException;
54
import com.iver.cit.gvsig.exceptions.layers.UnsupportedVersionLayerException;
55
import com.iver.cit.gvsig.fmap.layers.FLayer;
56
import com.iver.cit.gvsig.project.documents.view.gui.View;
57
import com.iver.utiles.extensionPoints.ExtensionPoint;
58
import com.iver.utiles.extensionPoints.ExtensionPointsSingleton;
59

    
60
import es.gva.cit.catalogClient.schemas.discoverer.Resource;
61

    
62
/**
63
 * This class is used to load a WMS layer in gvSIG
64
 *
65
 * @author Jorge Piera Llodra (piera_jor@gva.es)
66
 */
67
public class WMSLayerLoader extends LayerLoader{
68

    
69

    
70
        public WMSLayerLoader(Resource resource) {
71
                super(resource);
72
                //load(getResource().getLinkage(),getResource().getName());
73
        }
74

    
75
        /**
76
         * This function loads a WMS resource
77
         * @param host
78
         * URL where the server is located
79
         * @param sLayer
80
         * Layer name
81
         * @param crs
82
         * Coordenates System
83
         * @throws LayerLoaderException
84
         */
85

    
86
        public void loadLayer() throws LoadLayerException {
87
                String host = getResource().getLinkage();
88
                String sLayer = getResource().getName();
89

    
90
                FLayer flayer;
91

    
92
                try {
93
                        flayer = createWMSLayer(host, sLayer);
94
                        addLayerToView(flayer);
95
                } catch (Exception e) {
96
                        throw new LoadLayerException(sLayer,e);
97
                }
98

    
99
        }
100

    
101
        /**
102
         * It retrieves a getCapabilities file and loads the layer in gvSIG
103
         * @param host
104
         * WMS URL
105
         * @param sLayer
106
         * Layer Name
107
         * @return
108
         * FLayer
109
         * @throws ServerOutOfOrderException
110
         * @throws ProtocolException
111
         * @throws MalformedURLException
112
         * @throws WMSException
113
         * @throws IOException
114
         * @throws UnsupportedVersionLayerException
115
         * @throws ValidationException
116
         * @throws IllegalStateException
117
         * @throws LayerLoaderException
118
         */
119
        private FLayer createWMSLayer(String host, String sLayer) throws  LoadLayerException{
120
                ExtensionPoint extensionPoint = (ExtensionPoint)ExtensionPointsSingleton.getInstance().get("CatalogLayers");
121
                Map args = new HashMap();
122
                args.put("host",host);
123
                args.put("layer",sLayer);
124
                View activeView =
125
                        (View) PluginServices.getMDIManager().getActiveWindow();
126
                args.put("SRS",activeView.getProjection().getAbrev());
127
                try {
128
                        return (FLayer)extensionPoint.create("OGC:WMS", args  );
129
                } catch(Exception e) {
130
                        throw new LoadLayerException(sLayer,e);
131
                }
132
        }
133

    
134
        /*
135
         *  (non-Javadoc)
136
         * @see es.gva.cit.gvsig.catalogClient.loaders.LayerLoader#getErrorMessage()
137
         */
138
        protected String getErrorMessage() {
139
                return Messages.getText("wmsError") + ".\n" +
140
                Messages.getText("server") + ": " +
141
                getResource().getLinkage() + "\n" +
142
                Messages.getText("layer") + ": " +
143
                getResource().getName();
144
        }
145

    
146
        /*
147
         *  (non-Javadoc)
148
         * @see es.gva.cit.gvsig.catalogClient.loaders.LayerLoader#getWindowMessage()
149
         */
150
        protected String getWindowMessage() {
151
                return Messages.getText("loadWMS");
152
        }
153
}