svn-gvsig-desktop / 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 @ 47821
History | View | Annotate | Download (4.6 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2023 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.downloader.lib.impl; |
25 |
|
26 |
import java.net.URL; |
27 |
import java.util.Collection; |
28 |
import java.util.HashMap; |
29 |
import java.util.Map; |
30 |
import org.apache.commons.lang3.StringUtils; |
31 |
import org.gvsig.compat.se.net.downloader.se.SEDownloader; |
32 |
import org.gvsig.downloader.DownloaderAuthenticationConfig; |
33 |
import org.gvsig.downloader.DownloaderAuthenticationFactory; |
34 |
import org.gvsig.downloader.DownloaderCredentials; |
35 |
import org.gvsig.downloader.DownloaderManager; |
36 |
import org.slf4j.Logger; |
37 |
import org.slf4j.LoggerFactory; |
38 |
|
39 |
|
40 |
|
41 |
@SuppressWarnings("UseSpecificCatch") |
42 |
public class DownloaderManagerImpl |
43 |
extends SEDownloader
|
44 |
implements DownloaderManager {
|
45 |
|
46 |
private static final Logger LOG = LoggerFactory.getLogger(DownloaderManagerImpl.class); |
47 |
|
48 |
private final Map<String,DownloaderCredentials> credentials; |
49 |
private final Map<String,DownloaderAuthenticationFactory> authenticationTypes; |
50 |
private final Map<String,DownloaderAuthenticationConfig> authenticationConfigurationServices; |
51 |
|
52 |
public DownloaderManagerImpl() {
|
53 |
super();
|
54 |
this.credentials = new HashMap<>(); |
55 |
this.authenticationTypes = new HashMap<>(); |
56 |
this.authenticationConfigurationServices = new HashMap<>(); |
57 |
} |
58 |
|
59 |
// protected Runnable createDownloaderTask(Downloader downloader, URL url, String data, File target, Object groupID, int maxbytes) {
|
60 |
// SEAuthDownloaderTask t = new SEAuthDownloaderTask(downloader, url, data, target, groupID);
|
61 |
// t.setMaxbytes(maxbytes);
|
62 |
// return t;
|
63 |
// }
|
64 |
|
65 |
@Override
|
66 |
public void addOrReplaceCredentials(DownloaderCredentials credentials) { |
67 |
this.credentials.put(credentials.getBaseUrl(), credentials);
|
68 |
} |
69 |
|
70 |
@Override
|
71 |
public void removeCredentials(DownloaderCredentials credentials) { |
72 |
this.credentials.remove(credentials.getBaseUrl());
|
73 |
} |
74 |
|
75 |
@Override
|
76 |
public void registerAuthenticationConfigurationService(DownloaderAuthenticationConfig config ) { |
77 |
authenticationConfigurationServices.put(config.getKey(), config); |
78 |
} |
79 |
|
80 |
@Override
|
81 |
public void removeAuthenticationConfigurationService(DownloaderAuthenticationConfig config) { |
82 |
authenticationConfigurationServices.remove(config.getKey()); |
83 |
} |
84 |
|
85 |
@Override
|
86 |
public void registerAuthenticationType(DownloaderAuthenticationFactory factory) { |
87 |
this.authenticationTypes.put(factory.getProviderName().toLowerCase(), factory);
|
88 |
} |
89 |
|
90 |
@Override
|
91 |
public DownloaderAuthenticationConfig getAuthenticationConfigurationService(String baseUrl) { |
92 |
for (DownloaderAuthenticationConfig config : this.authenticationConfigurationServices.values()) { |
93 |
if( StringUtils.startsWith(baseUrl, config.getBaseUrl()) ) {
|
94 |
return config;
|
95 |
} |
96 |
} |
97 |
return null; |
98 |
} |
99 |
|
100 |
@Override
|
101 |
public Collection<DownloaderAuthenticationFactory> getAuthenticationTypes() { |
102 |
return this.authenticationTypes.values(); |
103 |
} |
104 |
|
105 |
@Override
|
106 |
public Collection<DownloaderAuthenticationConfig> getAuthenticationConfigurationServices() { |
107 |
return this.authenticationConfigurationServices.values(); |
108 |
} |
109 |
|
110 |
@Override
|
111 |
public Collection<DownloaderCredentials> getCredentials() { |
112 |
return this.credentials.values(); |
113 |
} |
114 |
|
115 |
@Override
|
116 |
public DownloaderCredentials getCredentials(URL url) { |
117 |
for (DownloaderCredentials theCredentials : this.credentials.values()) { |
118 |
if( StringUtils.startsWith(url.toString(), theCredentials.getBaseUrl()) ) {
|
119 |
return theCredentials;
|
120 |
} |
121 |
} |
122 |
return null; |
123 |
} |
124 |
|
125 |
public DownloaderAuthenticationConfig requestAutenticationConfig(URL url) { // TODO: falta por implementar |
126 |
return null; |
127 |
} |
128 |
|
129 |
} |