Revision 47845 trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.downloader/org.gvsig.downloader.lib/org.gvsig.downloader.lib.impl/src/main/java/org/gvsig/downloader/lib/impl/DownloaderManagerImpl.java
DownloaderManagerImpl.java | ||
---|---|---|
34 | 34 |
import java.util.Iterator; |
35 | 35 |
import java.util.List; |
36 | 36 |
import java.util.Map; |
37 |
import java.util.Objects; |
|
37 | 38 |
import org.apache.commons.lang3.StringUtils; |
38 | 39 |
import org.apache.http.entity.ContentType; |
39 | 40 |
import org.gvsig.compat.net.ICancellable; |
... | ... | |
145 | 146 |
|
146 | 147 |
@Override |
147 | 148 |
public DownloaderCredentials getCredentials(String url) { |
149 |
if (StringUtils.isBlank(url)) { |
|
150 |
return null; |
|
151 |
} |
|
152 |
|
|
148 | 153 |
for (DownloaderCredentials theCredentials : this.credentials) { |
149 | 154 |
if(urlStartsWith(url, theCredentials.getServiceUrl())){ |
150 | 155 |
return theCredentials; |
... | ... | |
155 | 160 |
return null; |
156 | 161 |
} |
157 | 162 |
for (DownloaderCredentials theCredentials : this.credentials) { |
158 |
DownloaderCredentials x = config.getCredentials(theCredentials);
|
|
163 |
DownloaderCredentials x = theCredentials.createCredentials(config);
|
|
159 | 164 |
if(x != null) { |
160 | 165 |
this.addOrReplaceCredentials(x); |
161 | 166 |
return x; |
... | ... | |
203 | 208 |
|
204 | 209 |
@Override |
205 | 210 |
public DownloaderAuthenticationConfig getAuthenticationConfigurationService(String baseUrl) { |
211 |
if (StringUtils.isBlank(baseUrl)) { |
|
212 |
return null; |
|
213 |
} |
|
214 |
|
|
206 | 215 |
for (DownloaderAuthenticationConfig theConfig : this.authenticationConfigurationServices) { |
207 |
if(urlStartsWith(baseUrl, theConfig.getServiceUrl())){
|
|
216 |
if (urlStartsWith(baseUrl, theConfig.getServiceUrl())) {
|
|
208 | 217 |
return theConfig; |
209 | 218 |
} |
210 | 219 |
} |
... | ... | |
256 | 265 |
|
257 | 266 |
@Override |
258 | 267 |
public synchronized File downloadFile(URL url, String method, ContentType contenttype, String data, String name, ICancellable cancel, int maxbytes) throws IOException, ConnectException, UnknownHostException { |
259 |
// File target = getPreviousDownloadedURL(url, data); |
|
260 |
// if(target != null){ |
|
261 |
// return target; |
|
262 |
// } |
|
268 |
return downloadFile(url, method, contenttype, data, name, cancel, maxbytes, true); |
|
269 |
} |
|
270 |
|
|
271 |
@Override |
|
272 |
public synchronized File downloadFile(URL url, String method, ContentType contenttype, String data, String name, ICancellable cancel, int maxbytes, boolean useCache) throws IOException, ConnectException, UnknownHostException { |
|
273 |
LOG.info("Download file " + Objects.toString(url)); |
|
274 |
if (useCache) { |
|
275 |
File target = getPreviousDownloadedURL(url, data); |
|
276 |
if (target != null) { |
|
277 |
LOG.info("CACHED "+url.toString() + " at '" + target.getAbsolutePath() + "'"); |
|
278 |
return target; |
|
279 |
} |
|
280 |
} |
|
263 | 281 |
File target = new File(name); |
264 | 282 |
if (!target.isAbsolute()){ |
265 | 283 |
target = getUniqueTemporaryFile(name); |
... | ... | |
269 | 287 |
} |
270 | 288 |
Runnable task = this.createDownloaderTask(this, url, method, contenttype, data, target, cancel.getID(), maxbytes); |
271 | 289 |
task.run(); |
272 |
|
|
273 | 290 |
return target; |
274 | 291 |
} |
275 | 292 |
|
293 |
public void propagateCredentials(String sourceServiceUrl, Collection<String> targetServicesUrls) { |
|
294 |
if(StringUtils.isBlank(sourceServiceUrl)){ |
|
295 |
return; |
|
296 |
} |
|
297 |
DownloaderAuthenticationConfig sourceConfig = this.getAuthenticationConfigurationService(sourceServiceUrl); |
|
298 |
if(sourceConfig == null){ |
|
299 |
return; |
|
300 |
} |
|
301 |
DownloaderCredentials sourceCredentials = this.getCredentials(sourceServiceUrl); |
|
302 |
for (String targetServiceUrl : targetServicesUrls) { |
|
303 |
if(StringUtils.isBlank(targetServiceUrl)){ |
|
304 |
continue; |
|
305 |
} |
|
306 |
DownloaderAuthenticationConfig targetConfig = this.getAuthenticationConfigurationService(targetServiceUrl); |
|
307 |
if(targetConfig == null) { |
|
308 |
targetConfig = sourceConfig.createAuthenticationConfig(targetServiceUrl); |
|
309 |
if(targetConfig != null) { |
|
310 |
this.registerAuthenticationConfigurationService(targetConfig); |
|
311 |
} |
|
312 |
} |
|
313 |
if(sourceCredentials != null) { |
|
314 |
DownloaderCredentials targetCredentials = this.getCredentials(targetServiceUrl); |
|
315 |
if(targetCredentials == null){ |
|
316 |
targetCredentials = sourceCredentials.createCredentials(targetServiceUrl); |
|
317 |
if(targetCredentials != null) { |
|
318 |
this.addOrReplaceCredentials(targetCredentials); |
|
319 |
} |
|
320 |
} |
|
321 |
} |
|
322 |
} |
|
323 |
|
|
324 |
|
|
325 |
} |
|
326 |
|
|
276 | 327 |
|
277 | 328 |
} |
Also available in: Unified diff