svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.downloader / org.gvsig.downloader.lib / org.gvsig.downloader.lib.api / src / main / java / org / gvsig / downloader / DownloaderManager.java @ 47840
History | View | Annotate | Download (3.88 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright ? 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 2
|
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 |
|
25 |
package org.gvsig.downloader; |
26 |
|
27 |
import java.net.MalformedURLException; |
28 |
import java.net.URL; |
29 |
import java.util.Collection; |
30 |
import org.apache.commons.lang3.StringUtils; |
31 |
import org.gvsig.compat.net.Downloader; |
32 |
|
33 |
/**
|
34 |
* Main class that defines the available Downlader services.
|
35 |
*
|
36 |
*/
|
37 |
public interface DownloaderManager extends Downloader { |
38 |
|
39 |
public static final String METHOD_PUT = "PUT"; |
40 |
public static final String METHOD_POST = "POST"; |
41 |
public static final String METHOD_GET = "GET"; |
42 |
public static final String METHOD_DELETE = "DELETE"; |
43 |
|
44 |
/**
|
45 |
* Comprueba si la URL url_s comienza por la URL prefix ignorando el protocolo y la query
|
46 |
*
|
47 |
* @param prefix
|
48 |
* @param url_s
|
49 |
* @return
|
50 |
*/
|
51 |
public static boolean urlStartsWith(String url_s, String prefix) { |
52 |
try {
|
53 |
URL baseUrl = new URL(prefix); |
54 |
URL url = new URL(url_s); |
55 |
if(!StringUtils.equals(baseUrl.getHost(), url.getHost())){
|
56 |
return false; |
57 |
} |
58 |
if(!StringUtils.startsWith(url.getPath(), baseUrl.getPath())){
|
59 |
return false; |
60 |
} |
61 |
return true; |
62 |
} catch (MalformedURLException ex) { |
63 |
return StringUtils.startsWith(url_s, prefix);
|
64 |
} |
65 |
} |
66 |
|
67 |
/**
|
68 |
* Compara dos URL ignorando el protocolo y la query
|
69 |
*
|
70 |
* @param url1_s
|
71 |
* @param url2_s
|
72 |
* @return
|
73 |
*/
|
74 |
public static boolean areSameURLs(String url1_s, String url2_s) { |
75 |
try {
|
76 |
URL url1 = new URL(url1_s); |
77 |
URL url2 = new URL(url2_s); |
78 |
if(!StringUtils.equals(url1.getHost(), url2.getHost())){
|
79 |
return false; |
80 |
} |
81 |
if(!StringUtils.equals(url1.getPath(), url2.getPath())){
|
82 |
return false; |
83 |
} |
84 |
return true; |
85 |
} catch (MalformedURLException ex) { |
86 |
return StringUtils.equals(url1_s, url2_s);
|
87 |
} |
88 |
} |
89 |
|
90 |
|
91 |
public void addOrReplaceCredentials(DownloaderCredentials credentials); |
92 |
|
93 |
public DownloaderAuthenticationConfig getAuthenticationConfigurationService(String baseUrl); |
94 |
|
95 |
public Collection<DownloaderAuthenticationConfig> getAuthenticationConfigurationServices(); |
96 |
|
97 |
public DownloaderAuthenticationFactory getDownloaderAuthenticationFactory(String providerName); |
98 |
|
99 |
public Collection<DownloaderAuthenticationFactory> getAuthenticationTypes(); |
100 |
|
101 |
public Collection<DownloaderCredentials> getCredentials(); |
102 |
|
103 |
public DownloaderCredentials getCredentials(URL url); |
104 |
|
105 |
public DownloaderCredentials getCredentials(String url); |
106 |
|
107 |
public void removeCredentials(DownloaderCredentials credentials); |
108 |
|
109 |
public void removeCredentials(String serviceURL); |
110 |
|
111 |
public void removeAuthenticationConfigurationService(DownloaderAuthenticationConfig config); |
112 |
|
113 |
public void registerAuthenticationConfigurationService(DownloaderAuthenticationConfig config); |
114 |
|
115 |
public void registerAuthenticationType(DownloaderAuthenticationFactory factory); |
116 |
|
117 |
} |