root / branches / v10 / extensions / extCatalogAndGazetteer / src / es / gva / cit / gvsig / catalog / loaders / WMSLayerLoader.java @ 16004
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.catalog.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.fmap.drivers.UnsupportedVersionException; |
54 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
55 |
import com.iver.cit.gvsig.project.documents.view.gui.View; |
56 |
import com.iver.utiles.extensionPoints.ExtensionPoint; |
57 |
import com.iver.utiles.extensionPoints.ExtensionPointsSingleton; |
58 |
|
59 |
import es.gva.cit.catalog.schemas.Resource; |
60 |
|
61 |
/**
|
62 |
* This class is used to load a WMS layer in gvSIG
|
63 |
*
|
64 |
* @author Jorge Piera Llodra (piera_jor@gva.es)
|
65 |
*/
|
66 |
public class WMSLayerLoader extends LayerLoader{ |
67 |
|
68 |
|
69 |
public WMSLayerLoader(Resource resource) {
|
70 |
super(resource);
|
71 |
//load(getResource().getLinkage(),getResource().getName());
|
72 |
} |
73 |
|
74 |
/**
|
75 |
* This function loads a WMS resource
|
76 |
* @param host
|
77 |
* URL where the server is located
|
78 |
* @param sLayer
|
79 |
* Layer name
|
80 |
* @param crs
|
81 |
* Coordenates System
|
82 |
* @throws LayerLoaderException
|
83 |
*/
|
84 |
|
85 |
public void loadLayer() throws LayerLoaderException { |
86 |
String host = getResource().getLinkage();
|
87 |
String sLayer = getResource().getName();
|
88 |
|
89 |
FLayer flayer; |
90 |
|
91 |
try {
|
92 |
flayer = createWMSLayer(host, sLayer); |
93 |
addLayerToView(flayer); |
94 |
} catch (Exception e) { |
95 |
throw new LayerLoaderException(e.getMessage(),getWindowMessage()); |
96 |
} |
97 |
|
98 |
} |
99 |
|
100 |
/**
|
101 |
* It retrieves a getCapabilities file and loads the layer in gvSIG
|
102 |
* @param host
|
103 |
* WMS URL
|
104 |
* @param sLayer
|
105 |
* Layer Name
|
106 |
* @return
|
107 |
* FLayer
|
108 |
* @throws ServerOutOfOrderException
|
109 |
* @throws ProtocolException
|
110 |
* @throws MalformedURLException
|
111 |
* @throws WMSException
|
112 |
* @throws IOException
|
113 |
* @throws UnsupportedVersionException
|
114 |
* @throws ValidationException
|
115 |
* @throws IllegalStateException
|
116 |
* @throws LayerLoaderException
|
117 |
*/
|
118 |
private FLayer createWMSLayer(String host, String sLayer) throws LayerLoaderException{ |
119 |
ExtensionPoint extensionPoint = (ExtensionPoint)ExtensionPointsSingleton.getInstance().get("CatalogLayers");
|
120 |
Map args = new HashMap(); |
121 |
args.put("host",host);
|
122 |
args.put("layer",sLayer);
|
123 |
View activeView =
|
124 |
(View) PluginServices.getMDIManager().getActiveWindow();
|
125 |
args.put("SRS",activeView.getProjection().getAbrev());
|
126 |
try {
|
127 |
return (FLayer)extensionPoint.create("OGC:WMS", args ); |
128 |
} catch(Exception e) { |
129 |
throw new LayerLoaderException(getErrorMessage(),getWindowMessage()); |
130 |
} |
131 |
} |
132 |
|
133 |
/*
|
134 |
* (non-Javadoc)
|
135 |
* @see es.gva.cit.gvsig.catalogClient.loaders.LayerLoader#getErrorMessage()
|
136 |
*/
|
137 |
protected String getErrorMessage() { |
138 |
return Messages.getText("wmsError") + ".\n" + |
139 |
Messages.getText("server") + ": " + |
140 |
getResource().getLinkage() + "\n" +
|
141 |
Messages.getText("layer") + ": " + |
142 |
getResource().getName(); |
143 |
} |
144 |
|
145 |
/*
|
146 |
* (non-Javadoc)
|
147 |
* @see es.gva.cit.gvsig.catalogClient.loaders.LayerLoader#getWindowMessage()
|
148 |
*/
|
149 |
protected String getWindowMessage() { |
150 |
return Messages.getText("loadWMS"); |
151 |
} |
152 |
} |