root / branches / v05 / extensions / extWMS / src / com / iver / cit / gvsig / gui / wizards / WMSWizardData.java @ 4342
History | View | Annotate | Download (4.94 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 com.iver.cit.gvsig.gui.wizards; |
42 |
|
43 |
import java.awt.Component; |
44 |
import java.awt.geom.Rectangle2D; |
45 |
import java.io.IOException; |
46 |
import java.net.ConnectException; |
47 |
import java.net.URL; |
48 |
import java.util.ArrayList; |
49 |
import java.util.Hashtable; |
50 |
import java.util.Vector; |
51 |
|
52 |
import javax.swing.JOptionPane; |
53 |
|
54 |
import com.iver.andami.PluginServices; |
55 |
import com.iver.cit.gvsig.fmap.DriverException; |
56 |
import com.iver.cit.gvsig.fmap.drivers.wms.FMapWMSDriver; |
57 |
import com.iver.cit.gvsig.fmap.layers.WMSLayerNode; |
58 |
|
59 |
|
60 |
/**
|
61 |
* DOCUMENT ME!
|
62 |
*
|
63 |
* @author Fernando Gonz?lez Cort?s
|
64 |
*/
|
65 |
public class WMSWizardData { // should implemement any kind of wizard data interface? |
66 |
private String title; |
67 |
private String theAbstract; |
68 |
private WMSLayerNode layer;
|
69 |
private String[] formats; |
70 |
private String serverVersion; |
71 |
private FMapWMSDriver wms = null; |
72 |
private Hashtable onlineResources = null; |
73 |
|
74 |
/**
|
75 |
* @return Returns the serverVersion.
|
76 |
*/
|
77 |
public String getServerVersion() { |
78 |
return serverVersion;
|
79 |
} |
80 |
public String getHost(){ |
81 |
return wms.getHost();
|
82 |
} |
83 |
|
84 |
|
85 |
public void setHost(URL host, boolean override) throws DriverException{ |
86 |
wms = new FMapWMSDriver();
|
87 |
try {
|
88 |
wms.createClient(host); |
89 |
|
90 |
// Send a getCapabilities request;
|
91 |
if (!wms.connect(override))
|
92 |
throw new DriverException(PluginServices.getText(this, "cant_connect") + host.toString()); |
93 |
} catch (ConnectException e) { |
94 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), PluginServices.getText(this,"server_timeout")); |
95 |
e.printStackTrace(); |
96 |
return;
|
97 |
} catch (IOException e) { |
98 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), PluginServices.getText(this, "cant_connect")); |
99 |
e.printStackTrace(); |
100 |
return;
|
101 |
} |
102 |
if (wms.getAbstract() != null) |
103 |
theAbstract = wms.getAbstract(); |
104 |
|
105 |
|
106 |
|
107 |
Vector f = wms.getFormats();
|
108 |
ArrayList formatos = new ArrayList(); |
109 |
for (int i = 0; i < f.size(); i++) { |
110 |
if (isValidFormat((String)f.elementAt(i))) { |
111 |
formatos.add(f.elementAt(i)); |
112 |
} |
113 |
} |
114 |
formats = (String[]) formatos.toArray(new String[0]); |
115 |
serverVersion = wms.getVersion(); |
116 |
onlineResources = wms.getOnlineResources(); |
117 |
layer = wms.getLayersTree(); // LayersTree as they are defined in the Capabilities document
|
118 |
} |
119 |
|
120 |
/**
|
121 |
* M?todo para saber los formatos que admite la aplicaci?n
|
122 |
*
|
123 |
* @param format cadena con el formato a validar
|
124 |
*
|
125 |
* @return true si soportamos dicho formato y false en
|
126 |
* caso contrario
|
127 |
*/
|
128 |
private boolean isValidFormat(String format) { |
129 |
if (format.equalsIgnoreCase("image/png") || |
130 |
format.equalsIgnoreCase("image/jpg") ||
|
131 |
format.equalsIgnoreCase("image/tiff") ||
|
132 |
format.equalsIgnoreCase("image/jpeg") ||
|
133 |
format.equalsIgnoreCase("image/tif") ||
|
134 |
format.equalsIgnoreCase("image/gif")) {
|
135 |
return true; |
136 |
} |
137 |
|
138 |
return false; |
139 |
} |
140 |
|
141 |
public String getAbstract() { |
142 |
return theAbstract;
|
143 |
} |
144 |
|
145 |
public String[] getFormats() { |
146 |
return formats;
|
147 |
} |
148 |
|
149 |
public WMSLayerNode getLayer() {
|
150 |
return layer;
|
151 |
} |
152 |
|
153 |
public String getTitle() { |
154 |
return title;
|
155 |
} |
156 |
|
157 |
public String getServerType() { |
158 |
return "WMS "+serverVersion; |
159 |
} |
160 |
|
161 |
public Hashtable getOnlineResources() { |
162 |
return onlineResources;
|
163 |
} |
164 |
|
165 |
public Rectangle2D getBoundingBox(String[] layerNames, String srs) { |
166 |
return wms.getLayersExtent(layerNames, srs);
|
167 |
} |
168 |
|
169 |
public FMapWMSDriver getDriver() {
|
170 |
return wms;
|
171 |
} |
172 |
|
173 |
public boolean isQueryable() { |
174 |
return wms.isQueryable();
|
175 |
} |
176 |
|
177 |
} |