root / trunk / libraries / libRemoteServices / src / org / gvsig / remoteClient / OGCProtocolHandler.java @ 3483
History | View | Annotate | Download (3.76 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2005 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 org.gvsig.remoteClient; |
42 |
|
43 |
import java.io.BufferedOutputStream; |
44 |
import java.io.DataOutputStream; |
45 |
import java.io.File; |
46 |
import java.io.FileOutputStream; |
47 |
import java.io.IOException; |
48 |
import java.io.InputStream; |
49 |
import java.net.ConnectException; |
50 |
import java.net.URL; |
51 |
import java.net.UnknownHostException; |
52 |
|
53 |
import com.devx.io.TempFileManager; |
54 |
|
55 |
public abstract class OGCProtocolHandler { |
56 |
/**
|
57 |
* procotol handler name
|
58 |
*/
|
59 |
protected String name; |
60 |
/**
|
61 |
* protocol handler version
|
62 |
*/
|
63 |
protected String version; |
64 |
/**
|
65 |
* host of the WMS to connect
|
66 |
*/
|
67 |
protected String host; |
68 |
/**
|
69 |
* port number of the comunication channel of the WMS to connect
|
70 |
*/
|
71 |
protected String port; |
72 |
|
73 |
/**
|
74 |
* @return Returns the host.
|
75 |
*/
|
76 |
public String getHost() { |
77 |
return host;
|
78 |
} |
79 |
/**
|
80 |
* @param host The host to set.
|
81 |
*/
|
82 |
public void setHost(String host) { |
83 |
this.host = host;
|
84 |
} |
85 |
/**
|
86 |
* @return Returns the name.
|
87 |
*/
|
88 |
public String getName() { |
89 |
return name;
|
90 |
} |
91 |
/**
|
92 |
* @param name The name to set.
|
93 |
*/
|
94 |
public void setName(String name) { |
95 |
this.name = name;
|
96 |
} |
97 |
/**
|
98 |
* @return Returns the port.
|
99 |
*/
|
100 |
public String getPort() { |
101 |
return port;
|
102 |
} |
103 |
/**
|
104 |
* @param port The port to set.
|
105 |
*/
|
106 |
public void setPort(String port) { |
107 |
this.port = port;
|
108 |
} |
109 |
/**
|
110 |
* @return Returns the version.
|
111 |
*/
|
112 |
public String getVersion() { |
113 |
return version;
|
114 |
} |
115 |
/**
|
116 |
* @param version The version to set.
|
117 |
*/
|
118 |
public void setVersion(String version) { |
119 |
this.version = version;
|
120 |
} |
121 |
|
122 |
protected File downloadFile(URL url, String fileName) throws IOException,ConnectException, UnknownHostException{ |
123 |
File f = null; |
124 |
|
125 |
try{
|
126 |
f = TempFileManager.createTempFile(fileName, "tmp");
|
127 |
System.out.println("downloading '"+url.toString()+"' to: "+f.getAbsolutePath()); |
128 |
|
129 |
f.deleteOnExit(); |
130 |
|
131 |
} catch (IOException io) { |
132 |
io.printStackTrace(); |
133 |
} |
134 |
DataOutputStream dos = new DataOutputStream( new BufferedOutputStream(new FileOutputStream(f))); |
135 |
byte[] buffer = new byte[1024*256]; |
136 |
InputStream is = url.openStream();
|
137 |
long readed = 0; |
138 |
for (int i = is.read(buffer); i>0; i = is.read(buffer)){ |
139 |
dos.write(buffer, 0, i);
|
140 |
readed += i; |
141 |
} |
142 |
dos.close(); |
143 |
/*if (!isNotAnException(f))
|
144 |
// SI que es una excepci?n
|
145 |
throw new ServerErrorResponseException();*/
|
146 |
return f;
|
147 |
} |
148 |
|
149 |
|
150 |
/**
|
151 |
* parses the data retrieved by the Capabilities XML document
|
152 |
*
|
153 |
*/
|
154 |
public abstract void parseCapabilities(File f); |
155 |
|
156 |
} |