Revision 40332

View differences:

branches/v2_0_0_prep/libraries/libCompat/src/org/gvsig/compat/se/net/SEDownloader.java
50 50
import java.io.OutputStreamWriter;
51 51
import java.net.ConnectException;
52 52
import java.net.HttpURLConnection;
53
import java.net.URI;
53 54
import java.net.URL;
54 55
import java.net.UnknownHostException;
55 56
import java.security.KeyManagementException;
......
90 91
	/**
91 92
	 * <b>key</b>: URL, <b>value</b>: path to the downloaded file.
92 93
	 */
93
	Hashtable downloadedFiles;
94
	Hashtable cachedURItoFile;
94 95
	Exception downloadException;
95 96
	final String tempDirectoryPath = System.getProperty("java.io.tmpdir")+"/tmp-andami";
96 97
    
......
128 129
	private File getPreviousDownloadedURL(URL url, String data) {
129 130
		if(data == null)
130 131
			return getPreviousDownloaded(url);
131
		return getPreviousDownloaded(url + data);
132
		return getPreviousDownloaded(url.toString() + data);
132 133
	}
133 134

  
134 135
	/**
......
142 143
	 * @param url
143 144
	 * @return File containing this URL's content or null if no file was found.
144 145
	 */
145
	private File getPreviousDownloaded(Object object) {
146
		File f = null;
147
		if (downloadedFiles != null && downloadedFiles.containsKey(object)) {
148
			String filePath = (String) downloadedFiles.get(object);
146
	private File getPreviousDownloaded(Object theurl) {
147
	    
148
        File f = null;
149
	    Object thekey = null;
150
        try {
151
            if (theurl instanceof URL) {
152
                thekey = ((URL) theurl).toURI();
153
            } else {
154
                thekey = theurl;
155
            }
156
        } catch (Exception e) {
157
            LOG.info("Warning: did not check url: " + theurl, e);
158
            return null;
159
        }
160
	    
161
		if (cachedURItoFile != null && cachedURItoFile.containsKey(thekey)) {
162
			String filePath = (String) cachedURItoFile.get(thekey);
149 163
			f = new File(filePath);
150 164
			if (!f.exists())
151 165
				return null;
......
162 176
	 * @param filePath
163 177
	 */
164 178
	void addDownloadedURL(URL url, String filePath) {
165
		if (downloadedFiles == null)
166
			downloadedFiles = new Hashtable();
167
		String fileName = (String) downloadedFiles.put(url, filePath);
179
		if (cachedURItoFile == null)
180
		    cachedURItoFile = new Hashtable();
181
		
182
		URI theuri = null;
183
		try {
184
            theuri = url.toURI();
185
        } catch (Exception e) {
186
            LOG.info("Warning: did not cache bad url: " + url, e);
187
            return;
188
        }
189
		
190
		String fileName = (String) cachedURItoFile.put(theuri, filePath);
168 191
		//JMV: No se puede eliminar el anterior porque puede que alguien lo
169 192
		// este usando
170 193
		/*
......
414 437
	 * @param request
415 438
	 */
416 439
	public void removeURL(URL url) {
417
		if (downloadedFiles != null && downloadedFiles.containsKey(url))
418
			downloadedFiles.remove(url);
440
	    
441
	    URI theuri = null;
442

  
443
        try {
444
            theuri = url.toURI();
445
        } catch (Exception e) {
446
            LOG.info("Warning: did not remove bad url: " + url, e);
447
            return;
448
        }
449
	    
450
	    
451
		if (cachedURItoFile != null && cachedURItoFile.containsKey(theuri))
452
		    cachedURItoFile.remove(theuri);
419 453
	}
420 454

  
421 455
	/**
......
424 458
	 * @param request
425 459
	 */
426 460
	public void removeURL(Object url) {
427
		if (downloadedFiles != null && downloadedFiles.containsKey(url))
428
			downloadedFiles.remove(url);
461
		if (cachedURItoFile != null && cachedURItoFile.containsKey(url))
462
		    cachedURItoFile.remove(url);
429 463
	}
430 464
}
431 465

  

Also available in: Unified diff