Revision 46151
tags/org.gvsig.desktop-2.0.349/org.gvsig.desktop.compat.cdc/org.gvsig.compat/org.gvsig.compat.se/src/main/java/org/gvsig/compat/se/net/downloader/se/SEDownloaderTask.java | ||
---|---|---|
1 |
package org.gvsig.compat.se.net.downloader.se; |
|
2 |
|
|
3 |
import java.io.BufferedOutputStream; |
|
4 |
import java.io.DataInputStream; |
|
5 |
import java.io.DataOutputStream; |
|
6 |
import java.io.File; |
|
7 |
import java.io.FileOutputStream; |
|
8 |
import java.io.OutputStreamWriter; |
|
9 |
import java.net.HttpURLConnection; |
|
10 |
import java.net.URL; |
|
11 |
import java.security.KeyManagementException; |
|
12 |
import java.security.NoSuchAlgorithmException; |
|
13 |
import java.util.prefs.Preferences; |
|
14 |
import javax.net.ssl.HttpsURLConnection; |
|
15 |
import javax.net.ssl.SSLContext; |
|
16 |
import javax.net.ssl.TrustManager; |
|
17 |
import javax.net.ssl.X509TrustManager; |
|
18 |
import org.gvsig.compat.se.net.downloader.Downloader; |
|
19 |
import org.slf4j.Logger; |
|
20 |
import org.slf4j.LoggerFactory; |
|
21 |
|
|
22 |
final class SEDownloaderTask implements Runnable { |
|
23 |
|
|
24 |
private URL url = null; |
|
25 |
private File dstFile = null; |
|
26 |
private Object groupID = null; |
|
27 |
private String data = null; |
|
28 |
private Downloader downloader = null; |
|
29 |
private static Logger LOG = LoggerFactory.getLogger(SEDownloaderTask.class); |
|
30 |
private int maxbytes = -1; |
|
31 |
|
|
32 |
public SEDownloaderTask(Downloader downloader, URL url, String data, File dstFile, Object groupID) { |
|
33 |
this.url = url; |
|
34 |
this.data = data; |
|
35 |
this.dstFile = dstFile; |
|
36 |
this.groupID = groupID; |
|
37 |
this.downloader = downloader; |
|
38 |
downloader.setDownloadException(null); |
|
39 |
} |
|
40 |
|
|
41 |
public void setMaxbytes(int maxbytes) { |
|
42 |
this.maxbytes = maxbytes; |
|
43 |
} |
|
44 |
|
|
45 |
public int getMaxbytes() { |
|
46 |
return maxbytes; |
|
47 |
} |
|
48 |
|
|
49 |
|
|
50 |
public void run() { |
|
51 |
LOG.info("downloading '" + url.toString() + "' to: " + dstFile.getAbsolutePath()); |
|
52 |
if (data != null) { |
|
53 |
LOG.info("using POST, request = " + data); |
|
54 |
} |
|
55 |
// getting timeout from preferences in milliseconds. |
|
56 |
Preferences prefs = Preferences.userRoot().node("gvsig.downloader"); |
|
57 |
// by default 1 minute (60000 milliseconds. |
|
58 |
int timeout = prefs.getInt("timeout", 60000); |
|
59 |
|
|
60 |
DataOutputStream dos; |
|
61 |
try { |
|
62 |
DataInputStream is; |
|
63 |
OutputStreamWriter os = null; |
|
64 |
HttpURLConnection connection = null; |
|
65 |
//If the used protocol is HTTPS |
|
66 |
if (url.getProtocol().equals("https")) { |
|
67 |
disableHttsValidation(); |
|
68 |
} |
|
69 |
connection = (HttpURLConnection) url.openConnection(); |
|
70 |
connection.setUseCaches(false); |
|
71 |
connection.setRequestProperty("User-Agent", "Mozilla/5.0 (gvSIG) like Gecko"); |
|
72 |
connection.setConnectTimeout(timeout); |
|
73 |
//If it uses a HTTP POST |
|
74 |
if (data != null) { |
|
75 |
connection.setRequestProperty("SOAPAction", "post"); |
|
76 |
connection.setRequestMethod("POST"); |
|
77 |
connection.setDoOutput(true); |
|
78 |
connection.setRequestProperty("Content-Type", "text/xml; charset=UTF-8"); |
|
79 |
os = new OutputStreamWriter(connection.getOutputStream()); |
|
80 |
os.write(data); |
|
81 |
os.flush(); |
|
82 |
} |
|
83 |
is = new DataInputStream(connection.getInputStream()); |
|
84 |
|
|
85 |
dos = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(dstFile))); |
|
86 |
byte[] buffer = new byte[1024 * 4]; |
|
87 |
|
|
88 |
long readed = 0; |
|
89 |
for (int i = is.read(buffer); !downloader.getCanceled(groupID) && i > 0; i = is.read(buffer)) { |
|
90 |
dos.write(buffer, 0, i); |
|
91 |
readed += i; |
|
92 |
if( maxbytes>0 && readed>maxbytes ) { |
|
93 |
break; |
|
94 |
} |
|
95 |
|
|
96 |
} |
|
97 |
if (os != null) { |
|
98 |
os.close(); |
|
99 |
} |
|
100 |
dos.close(); |
|
101 |
is.close(); |
|
102 |
is = null; |
|
103 |
dos = null; |
|
104 |
if (downloader.getCanceled(groupID)) { |
|
105 |
LOG.info("[RemoteServices] '" + url + "' CANCELED."); |
|
106 |
dstFile.delete(); |
|
107 |
dstFile = null; |
|
108 |
} else { |
|
109 |
downloader.addDownloadedURL(url, dstFile.getAbsolutePath()); |
|
110 |
} |
|
111 |
} catch (Exception e) { |
|
112 |
LOG.info("Error downloading", e); |
|
113 |
downloader.setDownloadException(e); |
|
114 |
} |
|
115 |
} |
|
116 |
|
|
117 |
/** |
|
118 |
* This method disables the Https certificate validation. |
|
119 |
* |
|
120 |
* @throws KeyManagementException |
|
121 |
* @throws NoSuchAlgorithmException |
|
122 |
*/ |
|
123 |
private void disableHttsValidation() throws KeyManagementException, NoSuchAlgorithmException { |
|
124 |
// Create a trust manager that does not validate certificate chains |
|
125 |
TrustManager[] trustAllCerts = new TrustManager[]{ |
|
126 |
new X509TrustManager() { |
|
127 |
public java.security.cert.X509Certificate[] getAcceptedIssuers() { |
|
128 |
return null; |
|
129 |
} |
|
130 |
|
|
131 |
public void checkClientTrusted( |
|
132 |
java.security.cert.X509Certificate[] certs, String authType) { |
|
133 |
} |
|
134 |
|
|
135 |
public void checkServerTrusted( |
|
136 |
java.security.cert.X509Certificate[] certs, String authType) { |
|
137 |
} |
|
138 |
} |
|
139 |
}; |
|
140 |
|
|
141 |
// Install the all-trusting trust manager |
|
142 |
SSLContext sc = SSLContext.getInstance("SSL"); |
|
143 |
sc.init(null, trustAllCerts, new java.security.SecureRandom()); |
|
144 |
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); |
|
145 |
} |
|
146 |
} |
tags/org.gvsig.desktop-2.0.349/org.gvsig.desktop.compat.cdc/org.gvsig.compat/org.gvsig.compat.se/src/main/java/org/gvsig/compat/se/net/downloader/se/SEMonitor.java | ||
---|---|---|
1 |
package org.gvsig.compat.se.net.downloader.se; |
|
2 |
|
|
3 |
import org.gvsig.compat.net.ICancellable; |
|
4 |
import org.gvsig.compat.se.net.downloader.Downloader; |
|
5 |
import org.slf4j.Logger; |
|
6 |
import org.slf4j.LoggerFactory; |
|
7 |
|
|
8 |
final class SEMonitor implements Runnable { |
|
9 |
|
|
10 |
ICancellable c; |
|
11 |
private volatile boolean finish = false; |
|
12 |
Downloader downloader; |
|
13 |
private static Logger LOG = LoggerFactory.getLogger(SEMonitor.class); |
|
14 |
|
|
15 |
public SEMonitor(Downloader downloader, ICancellable cancel) { |
|
16 |
downloader.setCanceled(cancel.getID(), false); |
|
17 |
this.c = cancel; |
|
18 |
this.downloader = downloader; |
|
19 |
} |
|
20 |
|
|
21 |
public void run() { |
|
22 |
while (!c.isCanceled() && !getFinish()) { |
|
23 |
try { |
|
24 |
Thread.sleep(downloader.getLatency()); |
|
25 |
} catch (InterruptedException e) { |
|
26 |
LOG.error("Error", e); |
|
27 |
} |
|
28 |
} |
|
29 |
|
|
30 |
/* WARNING!! This works because only one download is being processed at once. |
|
31 |
* You could prefer to start several transfers simultaneously. If so, you |
|
32 |
* should consideer using a non-static variable such is Utilities.canceled to |
|
33 |
* control when and which transfer in particular has been canceled. |
|
34 |
* |
|
35 |
* The feature of transfer several files is at the moment under study. We are |
|
36 |
* planning to add an intelligent system that will give you a lot of services |
|
37 |
* and ease-of-use. So, we encourage you to wait for it instead of write your |
|
38 |
* own code. |
|
39 |
*/ |
|
40 |
if (c.isCanceled()) { |
|
41 |
downloader.setCanceled(c.getID(), true); |
|
42 |
} |
|
43 |
} |
|
44 |
|
|
45 |
public synchronized void setFinish(boolean value) { |
|
46 |
finish = value; |
|
47 |
} |
|
48 |
|
|
49 |
public synchronized boolean getFinish() { |
|
50 |
return finish; |
|
51 |
} |
|
52 |
} |
tags/org.gvsig.desktop-2.0.349/org.gvsig.desktop.compat.cdc/org.gvsig.compat/org.gvsig.compat.se/src/main/java/org/gvsig/compat/se/net/downloader/se/SEDownloader.java | ||
---|---|---|
1 |
/** |
|
2 |
* gvSIG. Desktop Geographic Information System. |
|
3 |
* |
|
4 |
* Copyright (C) 2007-2013 gvSIG Association. |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or modify it under |
|
7 |
* the terms of the GNU General Public License as published by the Free Software |
|
8 |
* Foundation; either version 3 of the License, or (at your option) any later |
|
9 |
* version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
|
13 |
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
|
14 |
* details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License along with |
|
17 |
* this program; if not, write to the Free Software Foundation, Inc., 51 |
|
18 |
* Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
19 |
* |
|
20 |
* For any additional information, do not hesitate to contact us at info AT |
|
21 |
* gvsig.com, or visit our website www.gvsig.com. |
|
22 |
*/ |
|
23 |
package org.gvsig.compat.se.net.downloader.se; |
|
24 |
|
|
25 |
import java.io.File; |
|
26 |
import java.io.FileNotFoundException; |
|
27 |
import java.io.IOException; |
|
28 |
import java.net.ConnectException; |
|
29 |
import java.net.URI; |
|
30 |
import java.net.URL; |
|
31 |
import java.net.UnknownHostException; |
|
32 |
import java.util.HashMap; |
|
33 |
import java.util.Map; |
|
34 |
import org.apache.commons.io.FileUtils; |
|
35 |
|
|
36 |
import org.slf4j.Logger; |
|
37 |
import org.slf4j.LoggerFactory; |
|
38 |
|
|
39 |
import org.gvsig.compat.net.ICancellable; |
|
40 |
import org.gvsig.compat.se.net.downloader.Downloader; |
|
41 |
import org.gvsig.tools.ToolsLocator; |
|
42 |
import org.gvsig.tools.folders.FoldersManager; |
|
43 |
|
|
44 |
/** |
|
45 |
* Clase con m?todos de utilidad en el protocolo WMS |
|
46 |
* |
|
47 |
*/ |
|
48 |
public class SEDownloader implements Downloader { |
|
49 |
|
|
50 |
// private boolean canceled; |
|
51 |
private final long latency = 500; |
|
52 |
private static final Logger LOG = LoggerFactory.getLogger(SEDownloader.class); |
|
53 |
|
|
54 |
/** |
|
55 |
* Used to cancel a group of files |
|
56 |
* <b>key</b>: Group id, <b>value</b>: Boolean (true if the group has to be |
|
57 |
* canceled. Otherwise it is false) |
|
58 |
*/ |
|
59 |
private final Map<Object,Boolean> canceledGroup = new HashMap(); |
|
60 |
/** |
|
61 |
* <b>key</b>: URL, <b>value</b>: path to the downloaded file. |
|
62 |
*/ |
|
63 |
private Map<Object,String> cachedURItoFile; |
|
64 |
private Exception downloadException; |
|
65 |
|
|
66 |
public SEDownloader() { |
|
67 |
super(); |
|
68 |
} |
|
69 |
|
|
70 |
/** |
|
71 |
* Return the content of a file that has been created from a URL using the |
|
72 |
* HTTP GET protocol |
|
73 |
* |
|
74 |
* @param url The URL |
|
75 |
* @return File containing this URL's content or null if no file was found. |
|
76 |
*/ |
|
77 |
private File getPreviousDownloadedURL(URL url) { |
|
78 |
return getPreviousDownloaded(url); |
|
79 |
} |
|
80 |
|
|
81 |
/** |
|
82 |
* Return the content of a file that has been created from a URL using the |
|
83 |
* HTTP POST protocol |
|
84 |
* |
|
85 |
* @param url The URL |
|
86 |
* @param data The data to send on the query |
|
87 |
* @return File containing this URL's content or null if no file was found. |
|
88 |
*/ |
|
89 |
private File getPreviousDownloadedURL(URL url, String data) { |
|
90 |
if (data == null) { |
|
91 |
return getPreviousDownloaded(url); |
|
92 |
} |
|
93 |
return getPreviousDownloaded(url.toString() + data); |
|
94 |
} |
|
95 |
|
|
96 |
/** |
|
97 |
* Returns the content of a URL as a file from the file system.<br> |
|
98 |
* <p> |
|
99 |
* If the URL has been already downloaded in this session and notified to |
|
100 |
* the system using the static <b>Utilities.addDownloadedURL(URL)</b> |
|
101 |
* method, it can be restored faster from the file system avoiding to |
|
102 |
* download it again. |
|
103 |
* </p> |
|
104 |
* |
|
105 |
* @param theurl |
|
106 |
* @return File containing this URL's content or null if no file was found. |
|
107 |
*/ |
|
108 |
private File getPreviousDownloaded(Object theurl) { |
|
109 |
|
|
110 |
File f = null; |
|
111 |
Object thekey; |
|
112 |
try { |
|
113 |
if (theurl instanceof URL) { |
|
114 |
thekey = ((URL) theurl).toURI(); |
|
115 |
} else { |
|
116 |
thekey = theurl; |
|
117 |
} |
|
118 |
} catch (Exception e) { |
|
119 |
LOG.info("Warning: did not check url: " + theurl, e); |
|
120 |
return null; |
|
121 |
} |
|
122 |
|
|
123 |
if (cachedURItoFile != null && cachedURItoFile.containsKey(thekey)) { |
|
124 |
String filePath = (String) cachedURItoFile.get(thekey); |
|
125 |
f = new File(filePath); |
|
126 |
if (!f.exists()) { |
|
127 |
return null; |
|
128 |
} |
|
129 |
} |
|
130 |
return f; |
|
131 |
} |
|
132 |
|
|
133 |
/** |
|
134 |
* Adds an URL to the table of downloaded files for further uses. If the URL |
|
135 |
* already exists in the table its filePath value is updated to the new one |
|
136 |
* and the old file itself is removed from the file system. |
|
137 |
* |
|
138 |
* @param url |
|
139 |
* @param filePath |
|
140 |
*/ |
|
141 |
@Override |
|
142 |
public void addDownloadedURL(URL url, String filePath) { |
|
143 |
if (cachedURItoFile == null) { |
|
144 |
cachedURItoFile = new HashMap(); |
|
145 |
} |
|
146 |
|
|
147 |
URI theuri; |
|
148 |
try { |
|
149 |
theuri = url.toURI(); |
|
150 |
} catch (Exception e) { |
|
151 |
LOG.info("Warning: did not cache bad url: " + url, e); |
|
152 |
return; |
|
153 |
} |
|
154 |
|
|
155 |
String fileName = (String) cachedURItoFile.put(theuri, filePath); |
|
156 |
//JMV: No se puede eliminar el anterior porque puede que alguien lo |
|
157 |
// este usando |
|
158 |
/* |
|
159 |
if (fileName!=null){ |
|
160 |
File f = new File(fileName); |
|
161 |
if (f.exists()) |
|
162 |
f.delete(); |
|
163 |
} |
|
164 |
*/ |
|
165 |
} |
|
166 |
|
|
167 |
/** |
|
168 |
* Downloads an URL into a temporary file that is removed the next time the |
|
169 |
* tempFileManager class is called, which means the next time gvSIG is |
|
170 |
* launched. |
|
171 |
* |
|
172 |
* @param url |
|
173 |
* @param name |
|
174 |
* @return |
|
175 |
* @throws IOException |
|
176 |
* @throws ConnectException |
|
177 |
* @throws UnknownHostException |
|
178 |
*/ |
|
179 |
@Override |
|
180 |
public synchronized File downloadFile(URL url, String name, ICancellable cancel) throws IOException, ConnectException, UnknownHostException { |
|
181 |
File f; |
|
182 |
|
|
183 |
if ((f = getPreviousDownloadedURL(url)) == null) { |
|
184 |
f = getUniqueTemporaryFile(name); |
|
185 |
|
|
186 |
if (cancel == null) { |
|
187 |
cancel = new ICancellable() { |
|
188 |
@Override |
|
189 |
public boolean isCanceled() { |
|
190 |
return false; |
|
191 |
} |
|
192 |
|
|
193 |
@Override |
|
194 |
public Object getID() { |
|
195 |
return SEDownloader.class.getName(); |
|
196 |
} |
|
197 |
}; |
|
198 |
} |
|
199 |
|
|
200 |
SEMonitor monitorObj = new SEMonitor(this, cancel); |
|
201 |
Thread downloader = new Thread(createDownloaderTask(this, url, null, f, cancel.getID().getClass(),-1)); |
|
202 |
Thread monitor = new Thread(monitorObj); |
|
203 |
|
|
204 |
monitor.start(); |
|
205 |
downloader.start(); |
|
206 |
while (!getCanceled(cancel.getID()) && downloader.isAlive()) { |
|
207 |
try { |
|
208 |
Thread.sleep(latency); |
|
209 |
} catch (InterruptedException e) { |
|
210 |
LOG.error("Error", e); |
|
211 |
} |
|
212 |
} |
|
213 |
|
|
214 |
try { |
|
215 |
monitorObj.setFinish(true); |
|
216 |
monitor.join(); |
|
217 |
downloader.join(); |
|
218 |
} catch (InterruptedException e1) { |
|
219 |
LOG.warn(e1.getMessage()); |
|
220 |
} |
|
221 |
downloader = null; |
|
222 |
monitor = null; |
|
223 |
|
|
224 |
if (getCanceled(cancel.getID())) { |
|
225 |
return null; |
|
226 |
} |
|
227 |
downloader = null; |
|
228 |
monitor = null; |
|
229 |
if (this.downloadException != null) { |
|
230 |
Exception e = this.downloadException; |
|
231 |
if (e instanceof FileNotFoundException) { |
|
232 |
throw (IOException) e; |
|
233 |
} else if (e instanceof IOException) { |
|
234 |
throw (IOException) e; |
|
235 |
} else if (e instanceof ConnectException) { |
|
236 |
throw (ConnectException) e; |
|
237 |
} else if (e instanceof UnknownHostException) { |
|
238 |
throw (UnknownHostException) e; |
|
239 |
} |
|
240 |
} |
|
241 |
} else { |
|
242 |
LOG.info(url.toString() + " cached at '" + f.getAbsolutePath() + "'"); |
|
243 |
} |
|
244 |
|
|
245 |
return f; |
|
246 |
} |
|
247 |
|
|
248 |
/** |
|
249 |
* Downloads a URL using the HTTP Post protocol |
|
250 |
* |
|
251 |
* @param url The server URL |
|
252 |
* @param data The data to send in the request |
|
253 |
* @param name A common name for all the retrieved files |
|
254 |
* @param cancel Used to cancel the downloads |
|
255 |
* @return The retrieved file |
|
256 |
* @throws IOException |
|
257 |
* @throws ConnectException |
|
258 |
* @throws UnknownHostException |
|
259 |
*/ |
|
260 |
@Override |
|
261 |
public synchronized File downloadFile(URL url, String data, String name, ICancellable cancel) throws IOException, ConnectException, UnknownHostException { |
|
262 |
return downloadFile(url, data, name, cancel, -1); |
|
263 |
} |
|
264 |
|
|
265 |
@Override |
|
266 |
public synchronized File downloadFile(URL url, String data, String name, ICancellable cancel,int maxbytes) throws IOException, ConnectException, UnknownHostException { |
|
267 |
File f; |
|
268 |
|
|
269 |
if ((f = getPreviousDownloadedURL(url, data)) == null) { |
|
270 |
f = getUniqueTemporaryFile(name); |
|
271 |
|
|
272 |
if (cancel == null) { |
|
273 |
cancel = new ICancellable() { |
|
274 |
@Override |
|
275 |
public boolean isCanceled() { |
|
276 |
return false; |
|
277 |
} |
|
278 |
|
|
279 |
@Override |
|
280 |
public Object getID() { |
|
281 |
return SEDownloader.class.getName(); |
|
282 |
} |
|
283 |
}; |
|
284 |
} |
|
285 |
SEMonitor monitorObj = new SEMonitor(this, cancel); |
|
286 |
Thread downloader = new Thread( |
|
287 |
createDownloaderTask(this, url, data, f, cancel.getID(),maxbytes) |
|
288 |
); |
|
289 |
|
|
290 |
Thread monitor = new Thread(monitorObj); |
|
291 |
monitor.start(); |
|
292 |
downloader.start(); |
|
293 |
while (!getCanceled(cancel.getID()) && downloader.isAlive()) { |
|
294 |
try { |
|
295 |
Thread.sleep(latency); |
|
296 |
} catch (InterruptedException e) { |
|
297 |
LOG.error("Error", e); |
|
298 |
} |
|
299 |
} |
|
300 |
|
|
301 |
try { |
|
302 |
monitorObj.setFinish(true); |
|
303 |
monitor.join(); |
|
304 |
downloader.join(); |
|
305 |
} catch (InterruptedException e1) { |
|
306 |
LOG.warn(e1.getMessage()); |
|
307 |
} |
|
308 |
downloader = null; |
|
309 |
monitor = null; |
|
310 |
|
|
311 |
if (getCanceled(cancel.getID())) { |
|
312 |
return null; |
|
313 |
} |
|
314 |
if (this.downloadException != null) { |
|
315 |
Exception e = this.downloadException; |
|
316 |
if (e instanceof FileNotFoundException) { |
|
317 |
throw (IOException) e; |
|
318 |
} else if (e instanceof IOException) { |
|
319 |
throw (IOException) e; |
|
320 |
} else if (e instanceof ConnectException) { |
|
321 |
throw (ConnectException) e; |
|
322 |
} else if (e instanceof UnknownHostException) { |
|
323 |
throw (UnknownHostException) e; |
|
324 |
} |
|
325 |
} |
|
326 |
} else { |
|
327 |
LOG.info(url.toString() + " cached at '" + f.getAbsolutePath() + "'"); |
|
328 |
} |
|
329 |
|
|
330 |
return f; |
|
331 |
} |
|
332 |
|
|
333 |
/** |
|
334 |
* Try if a group of downloads has been canceled |
|
335 |
* |
|
336 |
* @param groupId Group id |
|
337 |
* @return If the group has been canceled |
|
338 |
*/ |
|
339 |
@Override |
|
340 |
public boolean getCanceled(Object groupId) { |
|
341 |
Boolean obj = canceledGroup.get(groupId); |
|
342 |
if (obj != null) { |
|
343 |
return obj; |
|
344 |
} |
|
345 |
return false; |
|
346 |
} |
|
347 |
|
|
348 |
/** |
|
349 |
* Cancel a group of downloads |
|
350 |
* |
|
351 |
* @param groupId Group id |
|
352 |
* @param isCanceled if the group has to be canceled |
|
353 |
*/ |
|
354 |
@Override |
|
355 |
public void setCanceled(Object groupId, boolean isCanceled) { |
|
356 |
if (groupId == null) { |
|
357 |
groupId = SEDownloader.class.getName(); |
|
358 |
} |
|
359 |
canceledGroup.put(groupId, isCanceled); |
|
360 |
} |
|
361 |
|
|
362 |
/** |
|
363 |
* Remove an URL from the system cache. The file will remain in the file |
|
364 |
* system for further eventual uses. |
|
365 |
* |
|
366 |
* @param url |
|
367 |
*/ |
|
368 |
@Override |
|
369 |
public void removeURL(URL url) { |
|
370 |
|
|
371 |
URI theuri = null; |
|
372 |
|
|
373 |
try { |
|
374 |
theuri = url.toURI(); |
|
375 |
} catch (Exception e) { |
|
376 |
LOG.info("Warning: did not remove bad url: " + url, e); |
|
377 |
return; |
|
378 |
} |
|
379 |
|
|
380 |
if (cachedURItoFile != null && cachedURItoFile.containsKey(theuri)) { |
|
381 |
cachedURItoFile.remove(theuri); |
|
382 |
} |
|
383 |
} |
|
384 |
|
|
385 |
/** |
|
386 |
* Remove an URL from the system cache. The file will remain in the file |
|
387 |
* system for further eventual uses. |
|
388 |
* |
|
389 |
* @param url |
|
390 |
*/ |
|
391 |
@Override |
|
392 |
public void removeURL(Object url) { |
|
393 |
if (cachedURItoFile != null && cachedURItoFile.containsKey(url)) { |
|
394 |
cachedURItoFile.remove(url); |
|
395 |
} |
|
396 |
} |
|
397 |
|
|
398 |
@Override |
|
399 |
public void setDownloadException(Exception exception) { |
|
400 |
this.downloadException = exception; |
|
401 |
} |
|
402 |
|
|
403 |
@Override |
|
404 |
public long getLatency() { |
|
405 |
return this.latency; |
|
406 |
} |
|
407 |
|
|
408 |
protected Runnable createDownloaderTask(Downloader downloader, URL url, String data, File target, Object groupID,int maxbytes){ |
|
409 |
SEDownloaderTask t = new SEDownloaderTask(downloader, url, data, target, groupID); |
|
410 |
t.setMaxbytes(maxbytes); |
|
411 |
return t; |
|
412 |
|
|
413 |
} |
|
414 |
|
|
415 |
/** |
|
416 |
* Cleans every temporal file previously downloaded. |
|
417 |
*/ |
|
418 |
@Override |
|
419 |
public void cleanUpTempFiles() { |
|
420 |
FoldersManager foldersManager = ToolsLocator.getFoldersManager(); |
|
421 |
File folder = foldersManager.getTemporaryFile("downloader"); |
|
422 |
try { |
|
423 |
FileUtils.cleanDirectory(folder); |
|
424 |
} catch (IOException ex) { |
|
425 |
LOG.warn("Can't clean folder '"+folder.getAbsolutePath()+"'.",ex); |
|
426 |
} |
|
427 |
} |
|
428 |
|
|
429 |
private File getUniqueTemporaryFile(String name) { |
|
430 |
FoldersManager foldersManager = ToolsLocator.getFoldersManager(); |
|
431 |
File folder = foldersManager.getTemporaryFile("downloader"); |
|
432 |
if( !folder.exists() ) { |
|
433 |
folder.mkdirs(); |
|
434 |
} |
|
435 |
File f = foldersManager.getUniqueTemporaryFile("downloader",name); |
|
436 |
return f; |
|
437 |
} |
|
438 |
} |
|
0 | 439 |
tags/org.gvsig.desktop-2.0.349/org.gvsig.desktop.compat.cdc/org.gvsig.compat/org.gvsig.compat.se/src/main/java/org/gvsig/compat/se/net/downloader/Downloader.java | ||
---|---|---|
1 |
package org.gvsig.compat.se.net.downloader; |
|
2 |
|
|
3 |
import java.net.URL; |
|
4 |
|
|
5 |
public interface Downloader extends org.gvsig.compat.net.Downloader { |
|
6 |
|
|
7 |
public void setDownloadException(Exception exception); |
|
8 |
|
|
9 |
public boolean getCanceled(Object groupId); |
|
10 |
|
|
11 |
void addDownloadedURL(URL url, String filePath); |
|
12 |
|
|
13 |
long getLatency(); |
|
14 |
|
|
15 |
void setCanceled(Object groupId, boolean isCanceled); |
|
16 |
|
|
17 |
} |
tags/org.gvsig.desktop-2.0.349/org.gvsig.desktop.compat.cdc/org.gvsig.compat/org.gvsig.compat.se/src/main/java/org/gvsig/compat/se/print/SePrintAttributes.java | ||
---|---|---|
1 |
/** |
|
2 |
* gvSIG. Desktop Geographic Information System. |
|
3 |
* |
|
4 |
* Copyright (C) 2007-2013 gvSIG Association. |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 3 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
* For any additional information, do not hesitate to contact us |
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
23 |
*/ |
|
24 |
package org.gvsig.compat.se.print; |
|
25 |
|
|
26 |
import org.gvsig.compat.print.PrintAttributes; |
|
27 |
|
|
28 |
/** |
|
29 |
* JSE (Desktop Java) implementation of {@link PrintAttributes} |
|
30 |
* |
|
31 |
* @author Juan Lucas Dominguez Rubio jldominguez at prodevelop.es |
|
32 |
* |
|
33 |
* @see PrintAttributes |
|
34 |
* |
|
35 |
*/ |
|
36 |
public class SePrintAttributes implements PrintAttributes{ |
|
37 |
|
|
38 |
int pq = 0; |
|
39 |
|
|
40 |
public int getPrintQuality() { |
|
41 |
return pq; |
|
42 |
} |
|
43 |
|
|
44 |
public void setPrintQuality(int pq) { |
|
45 |
this.pq=pq; |
|
46 |
|
|
47 |
} |
|
48 |
|
|
49 |
} |
|
0 | 50 |
tags/org.gvsig.desktop-2.0.349/org.gvsig.desktop.compat.cdc/org.gvsig.compat/org.gvsig.compat.se/src/main/java/org/gvsig/compat/se/SECompatLibrary.java | ||
---|---|---|
1 |
/** |
|
2 |
* gvSIG. Desktop Geographic Information System. |
|
3 |
* |
|
4 |
* Copyright (C) 2007-2013 gvSIG Association. |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 3 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
* For any additional information, do not hesitate to contact us |
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
23 |
*/ |
|
24 |
package org.gvsig.compat.se; |
|
25 |
|
|
26 |
import org.gvsig.compat.CompatLibrary; |
|
27 |
import org.gvsig.compat.CompatLocator; |
|
28 |
import org.gvsig.compat.se.lang.SEGraphUtils; |
|
29 |
import org.gvsig.compat.se.lang.SEMathUtils; |
|
30 |
import org.gvsig.compat.se.lang.StandardStringUtils; |
|
31 |
import org.gvsig.compat.se.net.downloader.se.SEDownloader; |
|
32 |
import org.gvsig.tools.library.AbstractLibrary; |
|
33 |
import org.gvsig.tools.library.LibraryException; |
|
34 |
|
|
35 |
/** |
|
36 |
* Initialization of the libCompat library, Java Standard Edition |
|
37 |
* implementation. |
|
38 |
* |
|
39 |
* @author <a href="mailto:cordin@disid.com">C?sar Ordi?ana</a> |
|
40 |
*/ |
|
41 |
public class SECompatLibrary extends AbstractLibrary { |
|
42 |
|
|
43 |
public void doRegistration() { |
|
44 |
registerAsImplementationOf(CompatLibrary.class); |
|
45 |
} |
|
46 |
|
|
47 |
protected void doInitialize() throws LibraryException { |
|
48 |
CompatLocator.registerStringUtils(StandardStringUtils.class); |
|
49 |
CompatLocator.registerMathUtils(SEMathUtils.class); |
|
50 |
CompatLocator.registerGraphicsUtils(SEGraphUtils.class); |
|
51 |
CompatLocator.registerDownloader(SEDownloader.class); |
|
52 |
} |
|
53 |
|
|
54 |
protected void doPostInitialize() throws LibraryException { |
|
55 |
} |
|
56 |
} |
tags/org.gvsig.desktop-2.0.349/org.gvsig.desktop.compat.cdc/org.gvsig.compat/org.gvsig.compat.se/src/main/java/org/gvsig/compat/se/lang/SEMathUtils.java | ||
---|---|---|
1 |
/** |
|
2 |
* gvSIG. Desktop Geographic Information System. |
|
3 |
* |
|
4 |
* Copyright (C) 2007-2013 gvSIG Association. |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 3 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
* For any additional information, do not hesitate to contact us |
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
23 |
*/ |
|
24 |
package org.gvsig.compat.se.lang; |
|
25 |
|
|
26 |
import org.gvsig.compat.lang.MathUtils; |
|
27 |
|
|
28 |
/** |
|
29 |
* JSE (Desktop Java) implementation of {@link MathUtils} |
|
30 |
* |
|
31 |
* @author Juan Lucas Dominguez Rubio jldominguez at prodevelop.es |
|
32 |
* |
|
33 |
* @see MathUtils |
|
34 |
* |
|
35 |
*/ |
|
36 |
public class SEMathUtils implements MathUtils{ |
|
37 |
|
|
38 |
public double log10(double value) { |
|
39 |
return Math.log10(value); |
|
40 |
} |
|
41 |
|
|
42 |
} |
|
0 | 43 |
tags/org.gvsig.desktop-2.0.349/org.gvsig.desktop.compat.cdc/org.gvsig.compat/org.gvsig.compat.se/src/main/java/org/gvsig/compat/se/lang/StandardStringUtils.java | ||
---|---|---|
1 |
/** |
|
2 |
* gvSIG. Desktop Geographic Information System. |
|
3 |
* |
|
4 |
* Copyright (C) 2007-2013 gvSIG Association. |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 3 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
* For any additional information, do not hesitate to contact us |
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
23 |
*/ |
|
24 |
package org.gvsig.compat.se.lang; |
|
25 |
|
|
26 |
import java.text.Collator; |
|
27 |
|
|
28 |
import org.gvsig.compat.lang.StringUtils; |
|
29 |
|
|
30 |
/** |
|
31 |
* String utilities implementation for Java Standard Edition. |
|
32 |
* |
|
33 |
* @author <a href="mailto:cordin@disid.com">C?sar Ordi?ana</a> |
|
34 |
*/ |
|
35 |
public class StandardStringUtils implements StringUtils { |
|
36 |
|
|
37 |
public String[] split(String input, String regex) { |
|
38 |
return input == null ? null : input.split(regex); |
|
39 |
} |
|
40 |
|
|
41 |
public String[] split(String input, String regex, int limit) { |
|
42 |
return input == null ? null : input.split(regex, limit); |
|
43 |
} |
|
44 |
|
|
45 |
public String replaceAll(String input, String regex, String replacement) { |
|
46 |
return input == null ? null : input.replaceAll(regex, replacement); |
|
47 |
} |
|
48 |
|
|
49 |
public String replaceFirst(String input, String regex, String replacement) { |
|
50 |
return input == null ? null : input.replaceFirst(regex, replacement); |
|
51 |
} |
|
52 |
|
|
53 |
public int compare(String source, String target, boolean localized) { |
|
54 |
if (localized) { |
|
55 |
Collator collator = Collator.getInstance(); |
|
56 |
collator.setStrength(Collator.PRIMARY); |
|
57 |
return collator.compare(source, target); |
|
58 |
} else { |
|
59 |
return source.compareTo(target); |
|
60 |
} |
|
61 |
} |
|
62 |
|
|
63 |
} |
|
0 | 64 |
tags/org.gvsig.desktop-2.0.349/org.gvsig.desktop.compat.cdc/org.gvsig.compat/org.gvsig.compat.se/src/main/java/org/gvsig/compat/se/lang/SEGraphUtils.java | ||
---|---|---|
1 |
/** |
|
2 |
* gvSIG. Desktop Geographic Information System. |
|
3 |
* |
|
4 |
* Copyright (C) 2007-2013 gvSIG Association. |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 3 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
* For any additional information, do not hesitate to contact us |
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
23 |
*/ |
|
24 |
package org.gvsig.compat.se.lang; |
|
25 |
|
|
26 |
import java.awt.Font; |
|
27 |
import java.awt.Graphics2D; |
|
28 |
import java.awt.RenderingHints; |
|
29 |
import java.awt.Toolkit; |
|
30 |
import java.awt.image.BufferedImage; |
|
31 |
import java.util.prefs.Preferences; |
|
32 |
|
|
33 |
import org.gvsig.compat.lang.GraphicsUtils; |
|
34 |
import org.gvsig.compat.print.PrintAttributes; |
|
35 |
import org.gvsig.compat.se.print.SePrintAttributes; |
|
36 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
|
37 |
|
|
38 |
/** |
|
39 |
* JSE (Desktop Java) implementation of {@link GraphicsUtils} |
|
40 |
* |
|
41 |
* @see GraphicsUtils |
|
42 |
* |
|
43 |
*/ |
|
44 |
public class SEGraphUtils implements GraphicsUtils{ |
|
45 |
|
|
46 |
@Override |
|
47 |
public BufferedImage copyBufferedImage(BufferedImage img) { |
|
48 |
BufferedImage newImage = |
|
49 |
ToolsSwingLocator.getToolsSwingManager() |
|
50 |
.copyBufferedImage(img); |
|
51 |
return newImage; |
|
52 |
} |
|
53 |
|
|
54 |
public BufferedImage createBufferedImage(int w, int h, int type) { |
|
55 |
return ToolsSwingLocator.getToolsSwingManager().createBufferedImage(w, h, type); |
|
56 |
} |
|
57 |
|
|
58 |
public PrintAttributes createPrintAttributes() { |
|
59 |
return new SePrintAttributes(); |
|
60 |
} |
|
61 |
|
|
62 |
public Font deriveFont(Font srcfont, float newheight) { |
|
63 |
return srcfont.deriveFont(newheight); |
|
64 |
} |
|
65 |
|
|
66 |
/** |
|
67 |
* Tries to use DPI value from gvSIG preferences. If this does not exist, gets |
|
68 |
* value from Java Toolkit. |
|
69 |
*/ |
|
70 |
public int getScreenDPI() { |
|
71 |
|
|
72 |
Preferences prefsResolution = Preferences.userRoot().node("gvsig.configuration.screen"); |
|
73 |
Toolkit kit = Toolkit.getDefaultToolkit(); |
|
74 |
int dpi = prefsResolution.getInt("dpi", kit.getScreenResolution()); |
|
75 |
return dpi; |
|
76 |
} |
|
77 |
|
|
78 |
public void translate(Graphics2D g, double x, double y) { |
|
79 |
g.translate(x, y); |
|
80 |
|
|
81 |
} |
|
82 |
|
|
83 |
public void setRenderingHintsForDrawing(Graphics2D g) { |
|
84 |
|
|
85 |
RenderingHints renderHints = new RenderingHints( |
|
86 |
RenderingHints.KEY_ANTIALIASING, |
|
87 |
RenderingHints.VALUE_ANTIALIAS_ON); |
|
88 |
renderHints.put(RenderingHints.KEY_RENDERING, |
|
89 |
RenderingHints.VALUE_RENDER_QUALITY); |
|
90 |
renderHints.put(RenderingHints.KEY_TEXT_ANTIALIASING, |
|
91 |
RenderingHints.VALUE_TEXT_ANTIALIAS_ON); |
|
92 |
g.setRenderingHints(renderHints); |
|
93 |
|
|
94 |
} |
|
95 |
|
|
96 |
public void setRenderingHintsForPrinting(Graphics2D g) { |
|
97 |
|
|
98 |
RenderingHints renderHints = new RenderingHints( |
|
99 |
RenderingHints.KEY_ANTIALIASING, |
|
100 |
RenderingHints.VALUE_ANTIALIAS_ON); |
|
101 |
renderHints.put(RenderingHints.KEY_RENDERING, |
|
102 |
RenderingHints.VALUE_RENDER_QUALITY); |
|
103 |
g.setRenderingHints(renderHints); |
|
104 |
|
|
105 |
} |
|
106 |
|
|
107 |
} |
|
0 | 108 |
tags/org.gvsig.desktop-2.0.349/org.gvsig.desktop.compat.cdc/org.gvsig.compat/org.gvsig.compat.se/src/main/resources/META-INF/services/org.gvsig.tools.library.Library | ||
---|---|---|
1 |
org.gvsig.compat.se.SECompatLibrary |
tags/org.gvsig.desktop-2.0.349/org.gvsig.desktop.compat.cdc/org.gvsig.compat/org.gvsig.compat.se/src/test/resources/log4j.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="UTF-8" ?> |
|
2 |
<!-- |
|
3 |
|
|
4 |
gvSIG. Desktop Geographic Information System. |
|
5 |
|
|
6 |
Copyright (C) 2007-2013 gvSIG Association. |
|
7 |
|
|
8 |
This program is free software; you can redistribute it and/or |
|
9 |
modify it under the terms of the GNU General Public License |
|
10 |
as published by the Free Software Foundation; either version 3 |
|
11 |
of the License, or (at your option) any later version. |
|
12 |
|
|
13 |
This program is distributed in the hope that it will be useful, |
|
14 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
16 |
GNU General Public License for more details. |
|
17 |
|
|
18 |
You should have received a copy of the GNU General Public License |
|
19 |
along with this program; if not, write to the Free Software |
|
20 |
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
21 |
MA 02110-1301, USA. |
|
22 |
|
|
23 |
For any additional information, do not hesitate to contact us |
|
24 |
at info AT gvsig.com, or visit our website www.gvsig.com. |
|
25 |
|
|
26 |
--> |
|
27 |
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd"> |
|
28 |
|
|
29 |
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"> |
|
30 |
|
|
31 |
<appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender"> |
|
32 |
<layout class="org.apache.log4j.PatternLayout"> |
|
33 |
<param name="ConversionPattern" value="%d{HH:mm:ss,SSS} %-5p [%c{2}.%M()]\n %m%n" /> |
|
34 |
</layout> |
|
35 |
</appender> |
|
36 |
|
|
37 |
<category name="org.gvsig.tools"> |
|
38 |
<priority value="DEBUG" /> |
|
39 |
</category> |
|
40 |
<category name="org.gvsig.compat"> |
|
41 |
<priority value="DEBUG" /> |
|
42 |
</category> |
|
43 |
|
|
44 |
<root> |
|
45 |
<priority value="INFO" /> |
|
46 |
<appender-ref ref="CONSOLE" /> |
|
47 |
</root> |
|
48 |
</log4j:configuration> |
|
0 | 49 |
tags/org.gvsig.desktop-2.0.349/org.gvsig.desktop.compat.cdc/org.gvsig.compat/org.gvsig.compat.se/src/test/java/org/gvsig/compat/se/SECompatLibraryTest.java | ||
---|---|---|
1 |
/** |
|
2 |
* gvSIG. Desktop Geographic Information System. |
|
3 |
* |
|
4 |
* Copyright (C) 2007-2013 gvSIG Association. |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 3 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
* For any additional information, do not hesitate to contact us |
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
23 |
*/ |
|
24 |
package org.gvsig.compat.se; |
|
25 |
|
|
26 |
import junit.framework.TestCase; |
|
27 |
|
|
28 |
import org.gvsig.compat.CompatLocator; |
|
29 |
import org.gvsig.compat.se.lang.StandardStringUtils; |
|
30 |
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer; |
|
31 |
|
|
32 |
/** |
|
33 |
* Unit tests for the {@link SECompatLibrary} class. |
|
34 |
* |
|
35 |
* @author <a href="mailto:cordin@disid.com">C?sar Ordi?ana</a> |
|
36 |
*/ |
|
37 |
public class SECompatLibraryTest extends TestCase { |
|
38 |
|
|
39 |
/** |
|
40 |
* Test method for {@link org.gvsig.compat.se.SECompatLibrary#initialize()}. |
|
41 |
*/ |
|
42 |
public void testInitialize() { |
|
43 |
new DefaultLibrariesInitializer().fullInitialize(); |
|
44 |
|
|
45 |
// Check if the correct implementation is returned |
|
46 |
assertEquals(StandardStringUtils.class, CompatLocator.getStringUtils() |
|
47 |
.getClass()); |
|
48 |
} |
|
49 |
|
|
50 |
} |
|
0 | 51 |
tags/org.gvsig.desktop-2.0.349/org.gvsig.desktop.compat.cdc/org.gvsig.compat/org.gvsig.compat.se/src/test/java/org/gvsig/compat/se/lang/SEMathUtilsTest.java | ||
---|---|---|
1 |
/** |
|
2 |
* gvSIG. Desktop Geographic Information System. |
|
3 |
* |
|
4 |
* Copyright (C) 2007-2013 gvSIG Association. |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 3 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
* For any additional information, do not hesitate to contact us |
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
23 |
*/ |
|
24 |
package org.gvsig.compat.se.lang; |
|
25 |
|
|
26 |
import org.gvsig.compat.lang.MathUtils; |
|
27 |
import org.gvsig.compat.lang.MathUtilsTestParent; |
|
28 |
|
|
29 |
public class SEMathUtilsTest extends MathUtilsTestParent{ |
|
30 |
|
|
31 |
protected MathUtils createUtils() { |
|
32 |
return new SEMathUtils(); |
|
33 |
} |
|
34 |
|
|
35 |
} |
|
0 | 36 |
tags/org.gvsig.desktop-2.0.349/org.gvsig.desktop.compat.cdc/org.gvsig.compat/org.gvsig.compat.se/src/test/java/org/gvsig/compat/se/lang/StandardStringUtilsTest.java | ||
---|---|---|
1 |
/** |
|
2 |
* gvSIG. Desktop Geographic Information System. |
|
3 |
* |
|
4 |
* Copyright (C) 2007-2013 gvSIG Association. |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 3 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
* For any additional information, do not hesitate to contact us |
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
23 |
*/ |
|
24 |
package org.gvsig.compat.se.lang; |
|
25 |
|
|
26 |
import org.gvsig.compat.lang.StringUtils; |
|
27 |
import org.gvsig.compat.lang.StringUtilsTestParent; |
|
28 |
|
|
29 |
/** |
|
30 |
* Unit tests for the {@link org.gvsig.compat.se.lang.StandardStringUtils} |
|
31 |
* class. |
|
32 |
* |
|
33 |
* @author <a href="mailto:cordin@disid.com">C?sar Ordi?ana</a> |
|
34 |
*/ |
|
35 |
public class StandardStringUtilsTest extends StringUtilsTestParent { |
|
36 |
|
|
37 |
protected StringUtils createUtils() { |
|
38 |
return new StandardStringUtils(); |
|
39 |
} |
|
40 |
|
|
41 |
} |
|
0 | 42 |
tags/org.gvsig.desktop-2.0.349/org.gvsig.desktop.compat.cdc/org.gvsig.compat/org.gvsig.compat.se/src/test/java/org/gvsig/compat/CompatLibraryTest.java | ||
---|---|---|
1 |
/** |
|
2 |
* gvSIG. Desktop Geographic Information System. |
|
3 |
* |
|
4 |
* Copyright (C) 2007-2013 gvSIG Association. |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 3 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
* For any additional information, do not hesitate to contact us |
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
23 |
*/ |
|
24 |
package org.gvsig.compat; |
|
25 |
|
|
26 |
import junit.framework.TestCase; |
|
27 |
|
|
28 |
import org.gvsig.tools.library.Library; |
|
29 |
|
|
30 |
/** |
|
31 |
* Unit tests for the {@link CompatLibrary} class. |
|
32 |
* |
|
33 |
* @author <a href="mailto:cordin@disid.com">C?sar Ordi?ana</a> |
|
34 |
*/ |
|
35 |
public class CompatLibraryTest extends TestCase { |
|
36 |
|
|
37 |
/** |
|
38 |
* Test method for {@link org.gvsig.compat.se.SECompatLibrary#initialize()}. |
|
39 |
*/ |
|
40 |
public void testInitialize() { |
|
41 |
Library api = new CompatLibrary(); |
|
42 |
|
|
43 |
// 1: Initialize the Library |
|
44 |
api.initialize(); |
|
45 |
|
|
46 |
// 2: postInitialize them |
|
47 |
// as we don't initialize an implementation library, |
|
48 |
// the postInitialization must throw an Exception |
|
49 |
try { |
|
50 |
api.postInitialize(); |
|
51 |
fail("Library postInitialization is not checking " |
|
52 |
+ "for implementation availability"); |
|
53 |
} catch (Exception ex) { |
|
54 |
// Good |
|
55 |
} |
|
56 |
} |
|
57 |
|
|
58 |
} |
|
0 | 59 |
tags/org.gvsig.desktop-2.0.349/org.gvsig.desktop.compat.cdc/org.gvsig.compat/org.gvsig.compat.se/src/test/java/org/gvsig/compat/lang/StringUtilsTestParent.java | ||
---|---|---|
1 |
/** |
|
2 |
* gvSIG. Desktop Geographic Information System. |
|
3 |
* |
|
4 |
* Copyright (C) 2007-2013 gvSIG Association. |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 3 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
* For any additional information, do not hesitate to contact us |
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
23 |
*/ |
|
24 |
package org.gvsig.compat.lang; |
|
25 |
|
|
26 |
import java.util.Arrays; |
|
27 |
import java.util.List; |
|
28 |
|
|
29 |
import junit.framework.TestCase; |
|
30 |
|
|
31 |
/** |
|
32 |
* Parent class for Unit tests for {@link org.gvsig.compat.lang.StringUtils} |
|
33 |
* implementations. |
|
34 |
* |
|
35 |
* @author <a href="mailto:cordin@disid.com">C?sar Ordi?ana</a> |
|
36 |
*/ |
|
37 |
public abstract class StringUtilsTestParent extends TestCase { |
|
38 |
|
|
39 |
private StringUtils utils; |
|
40 |
|
|
41 |
protected void setUp() throws Exception { |
|
42 |
super.setUp(); |
|
43 |
utils = createUtils(); |
|
44 |
} |
|
45 |
|
|
46 |
/** |
|
47 |
* Return a new instance of an implementation of the StringUtils interface. |
|
48 |
* |
|
49 |
* @return a new StringUtils instance |
|
50 |
*/ |
|
51 |
protected abstract StringUtils createUtils(); |
|
52 |
|
|
53 |
/** |
|
54 |
* Test method for |
|
55 |
* {@link org.gvsig.compat.se.lang.StandardStringUtils#split(java.lang.String, java.lang.String)} |
|
56 |
* . |
|
57 |
*/ |
|
58 |
public void testSplitString() { |
|
59 |
// Check the result is the same as the returned with the String.split |
|
60 |
// method. |
|
61 |
List list1; |
|
62 |
List list2; |
|
63 |
|
|
64 |
String testString = "En un lugar de la Mancha"; |
|
65 |
String regex = " "; |
|
66 |
|
|
67 |
list1 = Arrays.asList(new String[] { "En", "un", "lugar", "de", "la", |
|
68 |
"Mancha" }); |
|
69 |
|
|
70 |
list2 = Arrays.asList(utils.split(testString, regex)); |
|
71 |
|
|
72 |
assertEquals(list1, list2); |
|
73 |
|
|
74 |
list1 = Arrays.asList(new String[] { "En", "un lugar de la Mancha" }); |
|
75 |
|
|
76 |
list2 = Arrays.asList(utils.split(testString, regex, 2)); |
|
77 |
|
|
78 |
assertEquals(list1, list2); |
|
79 |
} |
|
80 |
|
|
81 |
/** |
|
82 |
* Test method for |
|
83 |
* {@link org.gvsig.compat.se.lang.StandardStringUtils#replaceAll(java.lang.String, java.lang.String, java.lang.String)} |
|
84 |
* . |
|
85 |
*/ |
|
86 |
public void testReplaceAll() { |
|
87 |
// Check the result is the same as the returned with the |
|
88 |
// String.replaceAll method. |
|
89 |
String testString = "En un lugar de la Mancha"; |
|
90 |
String regex = " "; |
|
91 |
String replacement = "_"; |
|
92 |
|
|
93 |
assertEquals("En_un_lugar_de_la_Mancha", |
|
94 |
utils.replaceAll(testString, regex, replacement)); |
|
95 |
|
|
96 |
// Check replaceFirst |
|
97 |
assertEquals("En_un lugar de la Mancha", |
|
98 |
utils.replaceFirst(testString, regex, replacement)); |
|
99 |
} |
|
100 |
|
|
101 |
/** |
|
102 |
* Test method for |
|
103 |
* {@link org.gvsig.compat.se.lang.StandardStringUtils#compare(String, String, boolean)} |
|
104 |
* . |
|
105 |
*/ |
|
106 |
public void testCompare() { |
|
107 |
String avion = "Avi?n"; |
|
108 |
String avionaccent = "Avion"; |
|
109 |
String barco = "Barco"; |
|
110 |
|
|
111 |
// Same value |
|
112 |
assertEquals(avion + " is not equal to " + avion, 0, |
|
113 |
utils.compare(avion, avion, false)); |
|
114 |
assertEquals(avion + " is not equal to " + avion, 0, |
|
115 |
utils.compare(avion, avion, true)); |
|
116 |
|
|
117 |
// Non localized comparison |
|
118 |
assertTrue(utils.compare(avion, barco, false) < 0); |
|
119 |
assertTrue(utils.compare(avion, avionaccent, false) > 0); |
|
120 |
assertTrue(utils.compare(barco, avion, false) > 0); |
|
121 |
assertTrue(utils.compare(avionaccent, avion, false) < 0); |
|
122 |
|
|
123 |
// Localized comparison, so accents must not be taken into account |
|
124 |
assertTrue(utils.compare(avion, barco, true) < 0); |
|
125 |
assertEquals(0, utils.compare(avion, avionaccent, true)); |
|
126 |
assertTrue(utils.compare(barco, avion, true) > 0); |
|
127 |
assertEquals(0, utils.compare(avionaccent, avion, true)); |
|
128 |
} |
|
129 |
} |
|
0 | 130 |
tags/org.gvsig.desktop-2.0.349/org.gvsig.desktop.compat.cdc/org.gvsig.compat/org.gvsig.compat.se/src/test/java/org/gvsig/compat/lang/MathUtilsTestParent.java | ||
---|---|---|
1 |
/** |
|
2 |
* gvSIG. Desktop Geographic Information System. |
|
3 |
* |
|
4 |
* Copyright (C) 2007-2013 gvSIG Association. |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 3 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
Also available in: Unified diff