svn-gvsig-desktop / trunk / extensions / extCatalogYNomenclator / src / es / gva / cit / gvsig / catalogClient / loaders / WMSLoader.java @ 3789
History | View | Annotate | Download (5.55 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.net.URL; |
47 |
import java.util.Vector; |
48 |
|
49 |
import org.exolab.castor.xml.ValidationException; |
50 |
|
51 |
import com.iver.cit.gvsig.fmap.drivers.UnsupportedVersionException; |
52 |
import com.iver.cit.gvsig.fmap.drivers.WMSException; |
53 |
import com.iver.cit.gvsig.fmap.drivers.wms.FMapWMSDriver; |
54 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
55 |
import com.iver.cit.gvsig.fmap.layers.FLyrWMS; |
56 |
import com.iver.cit.gvsig.fmap.layers.WMSLayerNode; |
57 |
|
58 |
import es.gva.cit.catalogClient.schemas.discoverer.Resource; |
59 |
import es.gva.cit.catalogClient.traductor.ITranslator; |
60 |
import es.gva.cit.catalogClient.traductor.Translator; |
61 |
import es.uji.lsi.wcs.client.ServerOutOfOrderException; |
62 |
|
63 |
/**
|
64 |
* This class is used to load a WMS layer in gvSIG
|
65 |
*
|
66 |
* @author Jorge Piera Llodra (piera_jor@gva.es)
|
67 |
*/
|
68 |
public class WMSLoader extends AbstractLoader{ |
69 |
|
70 |
public WMSLoader(Resource resource) {
|
71 |
super(resource);
|
72 |
// TODO Auto-generated constructor stub
|
73 |
} |
74 |
|
75 |
/**
|
76 |
* It loads the resource to the gvSIG view
|
77 |
*/
|
78 |
public boolean load() { |
79 |
return load(getResource().getLinkage(),getResource().getName());
|
80 |
} |
81 |
|
82 |
/**
|
83 |
* This function loads a WMS resource
|
84 |
* @param host
|
85 |
* URL where the server is located
|
86 |
* @param sLayer
|
87 |
* Layer name
|
88 |
* @param crs
|
89 |
* Coordenates System
|
90 |
*/
|
91 |
|
92 |
private boolean load(String host, String sLayer) { |
93 |
try {
|
94 |
FLayer flayer = createWMSLayer(host, sLayer); |
95 |
if (flayer == null){ |
96 |
return false; |
97 |
}else{
|
98 |
addLayerToView(flayer); |
99 |
return true; |
100 |
} |
101 |
|
102 |
} catch (IOException e) { |
103 |
// TODO Auto-generated catch block
|
104 |
e.printStackTrace(); |
105 |
} catch (ServerOutOfOrderException e) {
|
106 |
// TODO Auto-generated catch block
|
107 |
e.printStackTrace(); |
108 |
} catch (WMSException e) {
|
109 |
// TODO Auto-generated catch block
|
110 |
e.printStackTrace(); |
111 |
} catch (IllegalStateException e) { |
112 |
// TODO Auto-generated catch block
|
113 |
e.printStackTrace(); |
114 |
} catch (ValidationException e) {
|
115 |
// TODO Auto-generated catch block
|
116 |
e.printStackTrace(); |
117 |
} catch (UnsupportedVersionException e) {
|
118 |
// TODO Auto-generated catch block
|
119 |
e.printStackTrace(); |
120 |
} |
121 |
return false; |
122 |
} |
123 |
|
124 |
/**
|
125 |
* It retrieves a getCapabilities file and loads the layer in gvSIG
|
126 |
* @param host
|
127 |
* WMS URL
|
128 |
* @param sLayer
|
129 |
* Layer Name
|
130 |
* @return
|
131 |
* FLayer
|
132 |
* @throws ServerOutOfOrderException
|
133 |
* @throws ProtocolException
|
134 |
* @throws MalformedURLException
|
135 |
* @throws WMSException
|
136 |
* @throws IOException
|
137 |
* @throws UnsupportedVersionException
|
138 |
* @throws ValidationException
|
139 |
* @throws IllegalStateException
|
140 |
*/
|
141 |
private FLayer createWMSLayer(String host, String sLayer) throws ServerOutOfOrderException, ProtocolException, MalformedURLException, WMSException, IOException, IllegalStateException, ValidationException, UnsupportedVersionException { |
142 |
FMapWMSDriver drv = new FMapWMSDriver();
|
143 |
drv.createClient(new URL(host)); |
144 |
|
145 |
if (!drv.connect())
|
146 |
return null; |
147 |
|
148 |
WMSLayerNode wmsNode = drv.getLayer(sLayer); |
149 |
|
150 |
if (wmsNode == null){ |
151 |
return null; |
152 |
} |
153 |
|
154 |
String[] sLayers = sLayer.split(","); |
155 |
|
156 |
FLyrWMS flyr = new FLyrWMS();
|
157 |
flyr.setHost(new URL(host)); |
158 |
flyr.setFullExtent(drv.getLayersExtent(sLayers,(String)wmsNode.getAllSrs().get(0))); |
159 |
flyr.setFormat(getGreatFormat(drv.getFormats())); |
160 |
flyr.setLayerQuery(sLayer); |
161 |
flyr.setInfoLayerQuery("");
|
162 |
flyr.setSRS((String)wmsNode.getAllSrs().get(0)); |
163 |
flyr.setName(sLayer); |
164 |
|
165 |
return flyr;
|
166 |
|
167 |
} |
168 |
|
169 |
/**
|
170 |
* It choose the best format to load different maps if the server
|
171 |
* supports it. This format could be png, because it supports
|
172 |
* transparency.
|
173 |
* @param formats
|
174 |
* Array with all the formats supported by the server
|
175 |
* @return
|
176 |
*/
|
177 |
private String getGreatFormat(Vector formats){ |
178 |
for (int i=0 ; i<formats.size() ; i++){ |
179 |
String format = (String) formats.get(i); |
180 |
if (format.equals("image/png")){ |
181 |
return format;
|
182 |
} |
183 |
} |
184 |
|
185 |
return (String)formats.get(0); |
186 |
} |
187 |
|
188 |
public String getErrorMessage(ITranslator translator) { |
189 |
return Translator.getText(translator,"wmsError") + ".\n" + |
190 |
Translator.getText(translator,"server") + ": " + |
191 |
getResource().getLinkage() + "\n" +
|
192 |
Translator.getText(translator,"layer") + ": " + |
193 |
getResource().getName(); |
194 |
|
195 |
} |
196 |
|
197 |
public String getLoaderMessage(ITranslator translator) { |
198 |
return Translator.getText(translator,"loadWMS"); |
199 |
} |
200 |
|
201 |
|
202 |
|
203 |
} |