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