Statistics
| Revision:

root / trunk / libraries / libRemoteServices / src / org / gvsig / remoteClient / wms / WMSProtocolHandler.java @ 3323

History | View | Annotate | Download (5.08 KB)

1

    
2
package org.gvsig.remoteClient.wms;
3

    
4
import java.io.BufferedOutputStream;
5
import java.io.DataOutputStream;
6
import java.io.File;
7
import java.io.FileOutputStream;
8
import java.io.InputStream;
9
import java.net.URL;
10
import java.util.TreeMap;
11
import java.util.Vector;
12

    
13
/**
14
 * <p> Abstract class that represents handlers to comunicate via WMS protocol.
15
 * </p>
16
 * 
17
 */
18
public abstract class WMSProtocolHandler {
19

    
20
        // procotol handler name
21
    protected String name;
22
    // protocol handler version
23
    protected String version;
24
    //host of the WMS to conenct
25
    protected String host;
26
    // port number of the comunication channel of the WMS to connect
27
    protected String port;    
28
    //WMS metadata
29
    protected ServiceInformation serviceInfo;
30
    public TreeMap layers;
31

    
32
    // abstract methods to implement by the handlers that implement
33
    // the connection to a WMS with certain version.
34
    //    public abstract String getName();   
35
    //    public abstract String getVersion();
36
    
37
    /**
38
     * parses the data retrieved by the WMS in XML format. 
39
     * It will be mostly the WMS Capabilities, but the implementation
40
     * will be placed in the handler implementing certain version of the protocol.
41
     * 
42
     */
43
    public abstract void parse(File f);
44

    
45
    public String getName() {        
46
            return name;
47
    } 
48

    
49
    public String getVersion() {        
50
            return version;
51
    }    
52
    
53
    public ServiceInformation getServiceInformation() {        
54
        return serviceInfo;
55
    }  
56
    public String getHost ()
57
    {
58
            return host;
59
    }
60
    public void setHost(String _host)
61
    {
62
            host = _host;
63
    }
64
    public String getPort()
65
    {
66
            return port;
67
    }
68
    public void setPort(String _port)
69
    {
70
            port = _port;
71
    }
72

    
73
    /**
74
     * <p>Builds a GetMap request that is sent to the WMS
75
     * the response (image) will be redirect to the
76
     * WMS client</p>
77
     */
78
    
79
    public void getMap() {        
80
        // your code here
81
    } 
82

    
83
        /**
84
         * <p>Builds a GetCapabilities request that is sent to the WMS
85
         * the response will be parse to extract the data needed by the
86
         * WMS client</p>
87
         */
88
    public void getCapabilities()
89
    {                
90
                String ret = new String();
91
            URL query = null;
92
                
93
                ret = ret + getHost() + "REQUEST=GetCapabilities&SERVICE=WMS&";
94
                ret = ret + "VERSION=" + getVersion();
95
                ret += ("&EXCEPTIONS=XML");
96
                
97
                try
98
                {
99
                        query = new URL(ret);
100
                }
101
                catch(Exception e)
102
                {
103
                        // TODO something about the exceptionsssss....!!!
104
                }
105
                
106
                   File f = null;
107
                   f = new File("tochangethis.txt");
108
            
109
            if (!f.exists())
110
            {
111
                    try
112
                    {
113
                            DataOutputStream dos = new DataOutputStream( new BufferedOutputStream(new FileOutputStream(f)));
114
                            byte[] buffer = new byte[1024*256];
115
                            InputStream is = query.openStream();
116
                            long readed = 0;
117
                            for (int i = is.read(buffer); i>0; i = is.read(buffer)){
118
                                    dos.write(buffer, 0, i);
119
                                    readed += i;
120
                            }
121
                            dos.close();
122
                    }
123
                    catch(Exception e)
124
                    {}
125
            }
126
            parse(f);
127
            //return parse(f);
128
    }
129

    
130
/**
131
 * <p>It will send a GetFeatureInfo request to the WMS
132
 * Parsing the response and redirecting the info to the WMS client</p>
133
 */
134
    public String getFeatureInfo()
135
    {
136
            return null;
137
    }
138

    
139
    public void close() {        
140
        // your code here
141
    } 
142
    
143
    /**
144
     * Inner class that represents the description of the WMS metadata.
145
     * The first part of the capabilities will return the service information
146
     * from the WMS, this class will hold this information. 
147
     * 
148
     */
149
    public class ServiceInformation {
150

    
151
        public String online_resource;
152
        public String version;
153
        public String name;
154
        public String scope;
155
        public String title;
156
        public String abstr;
157
        public String keywords;
158
        public String fees;
159
        public String operationsInfo;
160
        public String personname;
161
        public String organization;
162
        public String function;
163
        public String addresstype;
164
        public String address;
165
        public String place;
166
        public String province;
167
        public String postcode;
168
        public String country;
169
        public String phone;
170
        public String fax;
171
        public String email;
172
        public Vector formats;
173
        
174
        public ServiceInformation()
175
        {
176
                online_resource = new String();
177
            version = new String();
178
            name = new String();
179
            scope = new String();
180
            title = new String();
181
            abstr = new String();
182
            keywords = new String();
183
            fees = new String();
184
            operationsInfo = new String();
185
            personname = new String();
186
            organization = new String();
187
            function = new String();
188
            addresstype = new String();
189
            address = new String();
190
            place = new String();
191
            province = new String();
192
            postcode = new String();
193
            country = new String();
194
            phone = new String();
195
            fax = new String();
196
            email = new String();
197
            formats = new Vector();               
198
        }
199
     }    
200
 }