Statistics
| Revision:

root / trunk / extensions / extWMS / src / com / iver / cit / gvsig / gui / wizards / WMSWizardData.java @ 37961

History | View | Annotate | Download (5 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.geom.Rectangle2D;
44
import java.io.IOException;
45
import java.net.ConnectException;
46
import java.net.URL;
47
import java.util.ArrayList;
48
import java.util.Hashtable;
49
import java.util.Vector;
50

    
51
import org.gvsig.remoteClient.wms.ICancellable;
52

    
53
import com.iver.andami.PluginServices;
54
import com.iver.cit.gvsig.exceptions.layers.ConnectionErrorLayerException;
55
import com.iver.cit.gvsig.fmap.drivers.wms.FMapWMSDriver;
56
import com.iver.cit.gvsig.fmap.drivers.wms.FMapWMSDriverFactory;
57
import com.iver.cit.gvsig.fmap.layers.WMSLayerNode;
58

    
59

    
60
/**
61
 * Class holding the data shown at the wms wizards
62
 *
63
 * @author Jaume Dominguez Faus
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[] formatsGetFeatureInfo;
71
    private String serverVersion;
72
    private FMapWMSDriver wms = null;
73
    private Hashtable onlineResources = null;
74

    
75
    /**
76
     * @return Returns the serverVersion.
77
     */
78
    public String getServerVersion() {
79
        return serverVersion;
80
    }
81
    public String getHost(){
82
        return wms.getHost();
83
    }
84

    
85
    public void setHost(URL host, boolean override, ICancellable cancel) throws ConnectionErrorLayerException{
86
        try {
87
                wms = FMapWMSDriverFactory.getFMapDriverForURL(host);
88

    
89
                // Send a getCapabilities request;
90
                if (!wms.connect(override, cancel))
91
                        throw new ConnectionErrorLayerException(layer.getName(),null);
92
        } catch (ConnectException e) {
93
                throw new ConnectionErrorLayerException(layer.getName(),e);
94
                //JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), PluginServices.getText(this,"server_timeout"));
95
                        //return;
96
                } catch (IOException e) {
97
                        throw new ConnectionErrorLayerException(layer.getName(),e);
98
                        //JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), PluginServices.getText(this, "wms_cant_connect"));
99
                        //return;
100
                }
101
        if (wms.getAbstract()  != null)
102
            theAbstract = wms.getAbstract();
103
        
104
        if (wms.getServiceTitle()  != null)
105
            title = wms.getServiceTitle();
106

    
107
        Vector f = wms.getFormats();
108
        ArrayList formatos = new ArrayList();
109
        for (int i = 0; i < f.size(); i++) {
110
                formatos.add(f.elementAt(i));
111
        }
112
        formats = (String[]) formatos.toArray(new String[0]);
113
        
114
        Vector f2 = wms.getInfoFormats();
115
        ArrayList formatosInfo = new ArrayList();
116
        for (int i = 0; i < f2.size(); i++) {
117
                formatosInfo.add(f2.elementAt(i));
118
        }
119
        formatsGetFeatureInfo = (String[]) formatosInfo.toArray(new String[0]);
120
        
121
        serverVersion = (wms.getVersion() == null) ? "" : wms.getVersion();
122
        onlineResources = wms.getOnlineResources();
123
        layer = wms.getLayersTree(); // LayersTree as they are defined in the Capabilities document
124
        layer.setTitle(PluginServices.getText(null, layer.getTitle()));
125
    }
126

    
127
    public String getAbstract() {
128
        return theAbstract;
129
    }
130

    
131
    public String[] getFormats() {
132
        return formats;
133
    }
134

    
135
    public String[] getInfoFormats() {
136
        return formatsGetFeatureInfo;
137
    }
138

    
139
    public WMSLayerNode getLayer() {
140
        return layer;
141
    }
142

    
143
    public String getTitle() {
144
        return title;
145
    }
146

    
147
    public String getServerType() {
148
            if (serverVersion==null) return "WMS";
149
        return "WMS "+serverVersion;
150
    }
151

    
152
    public Hashtable getOnlineResources() {
153
                return onlineResources;
154
        }
155

    
156
    public Rectangle2D getBoundingBox(String[] layerNames, String srs) {
157
        return wms.getLayersExtent(layerNames, srs);
158
    }
159

    
160
        public FMapWMSDriver getDriver() {
161
                return wms;
162
        }
163

    
164
    public boolean isQueryable() {
165
            return wms.isQueryable();
166
    }
167

    
168
}