Revision 27

View differences:

org.gvsig.downloader/tags/org.gvsig.downloader-1.0.2/org.gvsig.downloader.main/pom.xml
1
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
2
  <modelVersion>4.0.0</modelVersion>
3
  <parent>
4
    <groupId>org.gvsig</groupId>
5
    <artifactId>org.gvsig.downloader</artifactId>
6
    <version>1.0.2</version>
7
  </parent>
8
  <artifactId>org.gvsig.downloader.main</artifactId>
9
  <name>org.gvsig.downloader.main</name>
10
</project>
org.gvsig.downloader/tags/org.gvsig.downloader-1.0.2/org.gvsig.downloader.lib/org.gvsig.downloader.lib.httpclient/src/main/resources/META-INF/services/org.gvsig.tools.library.Library
1
org.gvsig.downloader.lib.httpclient.HttpClientDownloaderLibrary
org.gvsig.downloader/tags/org.gvsig.downloader-1.0.2/org.gvsig.downloader.lib/org.gvsig.downloader.lib.httpclient/src/main/java/org/gvsig/downloader/lib/httpclient/HttpClientDownloader.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2014 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.httpclient;
25

  
26
import java.io.File;
27
import java.net.URL;
28
import org.gvsig.compat.se.net.downloader.Downloader;
29
import org.gvsig.compat.se.net.downloader.se.SEDownloader;
30

  
31
public class HttpClientDownloader extends SEDownloader {
32

  
33
    public HttpClientDownloader() {
34
        super();
35
    }
36

  
37
    protected Runnable createDownloaderTask(Downloader downloader, URL url, String data, File target, Object groupID) {
38
        return new HttpClientDownloaderTask(downloader, url, data, target, groupID);
39
    }
40

  
41
}
org.gvsig.downloader/tags/org.gvsig.downloader-1.0.2/org.gvsig.downloader.lib/org.gvsig.downloader.lib.httpclient/src/main/java/org/gvsig/downloader/lib/httpclient/HttpClientDownloaderAuthentication.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2014 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.httpclient;
25

  
26
import org.gvsig.downloader.lib.api.DownloaderAuthentication;
27
import org.gvsig.tools.ToolsLocator;
28
import org.gvsig.tools.dynobject.DynStruct;
29
import org.gvsig.tools.persistence.PersistenceManager;
30
import org.gvsig.tools.persistence.PersistentState;
31
import org.gvsig.tools.persistence.exception.PersistenceException;
32

  
33
/**
34
 * @author miguel
35
 */
36
public class HttpClientDownloaderAuthentication implements
37
    DownloaderAuthentication {
38

  
39
  public static final String PERSISTENT_NAME = "org.gvsig.downloader.lib.httpclient.HttpClientDownloaderAuthentication";
40

  
41
  public static final String PERSISTENT_DESCRIPTION = "HttpClientDownloader Persistent";
42

  
43
  private String host;
44

  
45
  private int port;
46

  
47
  private String user;
48

  
49
  private String password;
50

  
51
  public HttpClientDownloaderAuthentication(String host, int port, String user,
52
      String password) {
53
    this.host = host;
54
    this.port = port;
55
    this.user = user;
56
    this.password = password;
57
  }
58

  
59
  public HttpClientDownloaderAuthentication() {
60
    this.host = "";
61
    this.port = 443;
62
    this.user = "";
63
    this.password = "";
64
  }
65

  
66
  public String getHost() {
67
    return this.host;
68
  }
69

  
70
  public String getUser() {
71
    return this.user;
72
  }
73

  
74
  public int getPort() {
75
    return this.port;
76
  }
77

  
78
  public void setPort(int port) {
79
    this.port = port;
80
  }
81

  
82
  public String getPassword() {
83
    return this.password;
84
  }
85

  
86
  public void setHost(String host) {
87
    this.host = host;
88
  }
89

  
90
  public void setUser(String user) {
91
    this.user = user;
92
  }
93

  
94
  public void setPassword(String password) {
95
    this.password = password;
96
  }
97

  
98
  public void saveToState(PersistentState state) throws PersistenceException {
99
    state.set("host", this.host);
100
    state.set("port", this.port);
101
    state.set("user", this.user);
102
    state.set("password", this.password);
103
  }
104

  
105
  public void loadFromState(PersistentState state) throws PersistenceException {
106
    this.host = state.getString("host");
107
    this.port = state.getInt("port");
108
    this.user = state.getString("user");
109
    this.password = state.getString("password");
110
  }
111

  
112
  public static void registerPersistence() {
113
    PersistenceManager manager = ToolsLocator.getPersistenceManager();
114
    DynStruct definition = manager.getDefinition(PERSISTENT_NAME);
115
    if (definition == null) {
116
      definition = manager.addDefinition(
117
          HttpClientDownloaderAuthentication.class, PERSISTENT_NAME,
118
          PERSISTENT_DESCRIPTION, null, null);
119
      definition.addDynFieldString("host").setMandatory(false);
120
      definition.addDynFieldInt("port").setMandatory(false);
121
      definition.addDynFieldString("user").setMandatory(false);
122
      definition.addDynFieldString("password").setMandatory(false);
123
    }
124
  }
125
}
org.gvsig.downloader/tags/org.gvsig.downloader-1.0.2/org.gvsig.downloader.lib/org.gvsig.downloader.lib.httpclient/src/main/java/org/gvsig/downloader/lib/httpclient/HttpClientDownloaderTask.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2014 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.httpclient;
25

  
26
import java.io.*;
27
import java.net.URL;
28
import java.security.*;
29

  
30
import org.apache.commons.lang3.StringUtils;
31
import org.apache.http.HttpEntity;
32
import org.apache.http.HttpHost;
33
import org.apache.http.client.*;
34
import org.apache.http.client.entity.EntityBuilder;
35
import org.apache.http.client.methods.*;
36
import org.apache.http.client.protocol.HttpClientContext;
37
import org.apache.http.conn.ssl.*;
38
import org.apache.http.impl.auth.BasicScheme;
39
import org.apache.http.impl.client.*;
40
import org.gvsig.compat.se.net.downloader.Downloader;
41
import org.gvsig.downloader.lib.api.DownloaderLocator;
42
import org.slf4j.Logger;
43
import org.slf4j.LoggerFactory;
44

  
45
final class HttpClientDownloaderTask implements Runnable {
46

  
47
    private URL url = null;
48

  
49
    private File dstFile = null;
50

  
51
    private Object groupID = null;
52

  
53
    private String data = null;
54

  
55
    private Downloader downloader = null;
56

  
57
    private static Logger LOG = LoggerFactory
58
        .getLogger(HttpClientDownloaderTask.class);
59

  
60
    public HttpClientDownloaderTask(Downloader downloader, URL url,
61
        String data, File dstFile, Object groupID) {
62
        this.url = url;
63
        this.data = data;
64
        this.dstFile = dstFile;
65
        this.groupID = groupID;
66
        this.downloader = downloader;
67
        downloader.setDownloadException(null);
68
    }
69

  
70
    public void run() {
71

  
72
        LOG.info("Downloading '" + url.toString() + "' to: "
73
            + dstFile.getAbsolutePath());
74

  
75
        if (data != null) {
76
            LOG.info("using POST, request = " + data);
77
        }
78

  
79
        HttpClientDownloaderManager manager =
80
            (HttpClientDownloaderManager) DownloaderLocator
81
                .getDownloaderManager();
82
        CredentialsProvider credsProvider =
83
            manager.getCredentialsProvider(url.getHost());
84

  
85
        HttpHost targetHost =
86
            new HttpHost(url.getHost(), url.getPort(), url.getProtocol());
87

  
88
        // MOVIDO A DownloaderManager
89
        // CredentialsProvider credsProvider = new BasicCredentialsProvider();
90
        // credsProvider.setCredentials(AuthScope.ANY,
91
        // new UsernamePasswordCredentials("prueba", "prueba"));
92

  
93
        AuthCache authCache = new BasicAuthCache();
94
        authCache.put(targetHost, new BasicScheme());
95

  
96
        // Add AuthCache to the execution context
97
        final HttpClientContext context = HttpClientContext.create();
98
        context.setCredentialsProvider(credsProvider);
99
        context.setAuthCache(authCache);
100

  
101
        HttpClient client = null;
102

  
103
        try {
104
            client = getHttpClient(url.getProtocol());
105
        } catch (Exception e) {
106
            LOG.info("Error handling certificate.", e);
107
            downloader.setDownloadException(e);
108
            return;
109
        }
110

  
111
        HttpEntity entity = null;
112
        HttpRequestBase request = null;
113
        if (StringUtils.isEmpty(data)) {
114
            HttpGet httpget = new HttpGet(url.getFile());
115
            request = httpget;
116
        } else {
117
            EntityBuilder builder = EntityBuilder.create();
118
            builder.setText(data);
119
            HttpPost postRequest = new HttpPost(url.getFile());
120
            HttpEntity postRequestEntity = builder.build();
121
            postRequest.setEntity(postRequestEntity);
122
            request = postRequest;
123
        }
124

  
125
        CloseableHttpResponse closeableHttpResponse = null;
126
        InputStream is = null;
127
        OutputStream os = null;
128
        try {
129
            closeableHttpResponse =
130
                (CloseableHttpResponse) client.execute(targetHost, request,
131
                    context);
132

  
133
            entity = closeableHttpResponse.getEntity();
134

  
135
            if (entity != null) {
136
                try {
137
                    os = new FileOutputStream(dstFile);
138
                    is = entity.getContent();
139
                    byte[] buffer = new byte[4096];
140
                    try {
141
                        int n = is.read(buffer);
142
                        while (n != -1) {
143
                            os.write(buffer, 0, n);
144
                            n = is.read(buffer);
145
                        }
146
                    } finally {
147
                        if (os != null) {
148
                            os.close();
149
                        }
150
                    }
151
                } catch (FileNotFoundException e) {
152
                    throw e;
153

  
154
                } catch (IllegalStateException e) {
155
                    throw e;
156

  
157
                } catch (IOException e) {
158
                    throw e;
159

  
160
                } finally {
161
                    if (is != null) {
162
                        is.close();
163
                    }
164
                }
165
            }
166
            if (closeableHttpResponse != null) {
167
                closeableHttpResponse.close();
168
            }
169
        } catch (Exception e) {
170
            LOG.info("Error downloading", e);
171
            downloader.setDownloadException(e);
172
        }
173
    }
174

  
175
    private HttpClient getHttpClient(String protocol)
176
        throws NoSuchAlgorithmException, KeyStoreException,
177
        KeyManagementException {
178

  
179
        CloseableHttpClient httpclient;
180

  
181
        if (protocol.equalsIgnoreCase("https")) {
182
            SSLContextBuilder builder = new SSLContextBuilder();
183
            builder.loadTrustMaterial(null, new TrustSelfSignedStrategy());
184
            SSLConnectionSocketFactory sslsf =
185
                new SSLConnectionSocketFactory(builder.build());
186
            httpclient =
187
                HttpClients.custom().setSSLSocketFactory(sslsf).build();
188
        } else {
189
            httpclient = HttpClientBuilder.create().build();
190
        }
191
        return httpclient;
192
    }
193
}
org.gvsig.downloader/tags/org.gvsig.downloader-1.0.2/org.gvsig.downloader.lib/org.gvsig.downloader.lib.httpclient/src/main/java/org/gvsig/downloader/lib/httpclient/HttpClientDownloaderLibrary.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2014 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.httpclient;
25

  
26
import org.gvsig.compat.CompatLibrary;
27
import org.gvsig.compat.CompatLocator;
28
import org.gvsig.downloader.lib.api.DownloaderLibrary;
29
import org.gvsig.downloader.lib.api.DownloaderLocator;
30
import org.gvsig.tools.library.AbstractLibrary;
31
import org.gvsig.tools.library.LibraryException;
32

  
33
/**
34
 * @author miguel
35
 */
36
public class HttpClientDownloaderLibrary extends AbstractLibrary {
37

  
38
  @Override
39
  public void doRegistration() {
40
    super.doRegistration();
41
    registerAsImplementationOf(CompatLibrary.class);
42
    registerAsImplementationOf(DownloaderLibrary.class);
43
  }
44

  
45
  @Override
46
  protected void doInitialize() throws LibraryException {
47
    CompatLocator.registerDownloader(HttpClientDownloader.class);
48
    DownloaderLocator.registerDownloaderManager(HttpClientDownloaderManager.class);
49
  }
50

  
51
  @Override
52
  protected void doPostInitialize() throws LibraryException {
53
    HttpClientDownloaderAuthentication.registerPersistence();
54
  }
55
}
org.gvsig.downloader/tags/org.gvsig.downloader-1.0.2/org.gvsig.downloader.lib/org.gvsig.downloader.lib.httpclient/src/main/java/org/gvsig/downloader/lib/httpclient/HttpClientDownloaderManager.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2014 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.httpclient;
25

  
26
import java.io.File;
27
import java.net.URL;
28
import java.util.*;
29

  
30
import org.apache.http.auth.AuthScope;
31
import org.apache.http.auth.UsernamePasswordCredentials;
32
import org.apache.http.client.CredentialsProvider;
33
import org.apache.http.impl.client.BasicCredentialsProvider;
34
import org.gvsig.downloader.lib.api.*;
35

  
36
/**
37
 * @author miguel
38
 */
39
public class HttpClientDownloaderManager implements DownloaderManager {
40

  
41
  private static List<DownloaderAuthentication> authentications = new ArrayList<DownloaderAuthentication>();
42

  
43
  /*
44
   * (non-Javadoc)
45
   * @see org.gvsig.downloader.lib.api.DownloaderManager#download(java.io.File,
46
   * java.net.URL, java.lang.String)
47
   */
48
  public DownloaderProcess download(File target, URL url, String postdata)
49
      throws UnsupportedOperationException {
50
    // TODO Auto-generated method stub
51
    return null;
52
  }
53

  
54
  /*
55
   * (non-Javadoc)
56
   * @see
57
   * org.gvsig.downloader.lib.api.DownloaderManager#createAuthentication(java
58
   * .lang.String, java.lang.String, java.lang.String)
59
   */
60
  public DownloaderAuthentication createAuthentication(String host, int port,
61
                                                       String user,
62
                                                       String password) {
63
    HttpClientDownloaderAuthentication authentication = new HttpClientDownloaderAuthentication(
64
        host, port, user, password);
65
    return authentication;
66
  }
67

  
68
  /*
69
   * (non-Javadoc)
70
   * @see
71
   * org.gvsig.downloader.lib.api.DownloaderManager#createDownloader(java.io
72
   * .File, java.net.URL, java.lang.String)
73
   */
74
  public void createDownloader(File target, URL url, String postdata)
75
      throws UnsupportedOperationException {
76
    // TODO Auto-generated method stub
77
  }
78

  
79
  /*
80
   * (non-Javadoc)
81
   * @see org.gvsig.downloader.lib.api.DownloaderManager#getAuthentications()
82
   */
83
  public List<DownloaderAuthentication> getAuthentications() {
84
    return authentications;
85
  }
86

  
87
  /*
88
   * (non-Javadoc)
89
   * @see org.gvsig.downloader.lib.api.DownloaderManager#getDownloads()
90
   */
91
  public List<DownloaderProcess> getDownloads()
92
      throws UnsupportedOperationException {
93
    // TODO Auto-generated method stub
94
    return null;
95
  }
96

  
97
  public void setAuthentications(List<DownloaderAuthentication> authentications) {
98
    this.authentications = authentications;
99
  }
100

  
101
  public CredentialsProvider getCredentialsProvider(String host) {
102
    CredentialsProvider credsProvider = new BasicCredentialsProvider();
103
    for (Iterator<DownloaderAuthentication> iterator = authentications
104
        .iterator(); iterator.hasNext();) {
105
      DownloaderAuthentication downloaderAuthentication = (DownloaderAuthentication) iterator
106
          .next();
107
      if (downloaderAuthentication.getHost().equals(host)) {
108
        credsProvider.setCredentials(AuthScope.ANY,
109
            new UsernamePasswordCredentials(downloaderAuthentication.getUser(),
110
                downloaderAuthentication.getPassword()));
111
      }
112
    }
113
    return credsProvider;
114
  }
115
}
org.gvsig.downloader/tags/org.gvsig.downloader-1.0.2/org.gvsig.downloader.lib/org.gvsig.downloader.lib.httpclient/src/main/java/org/gvsig/downloader/lib/httpclient/HttpClientDownloaderProcess.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2014 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.httpclient;
25

  
26
import java.io.File;
27
import java.net.URL;
28

  
29
import org.gvsig.downloader.lib.api.DownloaderProcess;
30
import org.gvsig.tools.observer.Observer;
31
import org.gvsig.tools.task.TaskStatus;
32

  
33
/**
34
 * @author miguel
35
 */
36
public class HttpClientDownloaderProcess implements DownloaderProcess {
37

  
38
  /*
39
   * (non-Javadoc)
40
   * @see org.gvsig.tools.task.MonitorableTask#getTaskStatus()
41
   */
42
  public TaskStatus getTaskStatus() {
43
    // TODO Auto-generated method stub
44
    return null;
45
  }
46

  
47
  /*
48
   * (non-Javadoc)
49
   * @see org.gvsig.tools.task.CancellableTask#isCancellationRequested()
50
   */
51
  public boolean isCancellationRequested() {
52
    // TODO Auto-generated method stub
53
    return false;
54
  }
55

  
56
  /*
57
   * (non-Javadoc)
58
   * @see org.gvsig.tools.task.CancellableTask#cancelRequest()
59
   */
60
  public void cancelRequest() {
61
    // TODO Auto-generated method stub
62

  
63
  }
64

  
65
  /*
66
   * (non-Javadoc)
67
   * @see
68
   * org.gvsig.tools.observer.Observable#addObserver(org.gvsig.tools.observer
69
   * .Observer)
70
   */
71
  public void addObserver(Observer o) {
72
    // TODO Auto-generated method stub
73

  
74
  }
75

  
76
  /*
77
   * (non-Javadoc)
78
   * @see
79
   * org.gvsig.tools.observer.Observable#deleteObserver(org.gvsig.tools.observer
80
   * .Observer)
81
   */
82
  public void deleteObserver(Observer o) {
83
    // TODO Auto-generated method stub
84

  
85
  }
86

  
87
  /*
88
   * (non-Javadoc)
89
   * @see org.gvsig.tools.observer.Observable#deleteObservers()
90
   */
91
  public void deleteObservers() {
92
    // TODO Auto-generated method stub
93

  
94
  }
95

  
96
  /*
97
   * (non-Javadoc)
98
   * @see org.gvsig.downloader.lib.api.DownloaderProcess#getFile()
99
   */
100
  public File getFile() {
101
    // TODO Auto-generated method stub
102
    return null;
103
  }
104

  
105
  /*
106
   * (non-Javadoc)
107
   * @see org.gvsig.downloader.lib.api.DownloaderProcess#getUrl()
108
   */
109
  public URL getUrl() {
110
    // TODO Auto-generated method stub
111
    return null;
112
  }
113

  
114
  /*
115
   * (non-Javadoc)
116
   * @see org.gvsig.downloader.lib.api.DownloaderProcess#getID()
117
   */
118
  public String getID() {
119
    // TODO Auto-generated method stub
120
    return null;
121
  }
122

  
123
}
org.gvsig.downloader/tags/org.gvsig.downloader-1.0.2/org.gvsig.downloader.lib/org.gvsig.downloader.lib.httpclient/pom.xml
1
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
2
  <modelVersion>4.0.0</modelVersion>
3
  <parent>
4
    <groupId>org.gvsig</groupId>
5
    <artifactId>org.gvsig.downloader.lib</artifactId>
6
    <version>1.0.2</version>
7
  </parent>
8
  <artifactId>org.gvsig.downloader.lib.httpclient</artifactId>
9
  <name>org.gvsig.downloader.lib.httpclient</name>
10
  <dependencies>
11
    <dependency>
12
      <groupId>org.gvsig</groupId>
13
      <artifactId>org.gvsig.downloader.lib.api</artifactId>
14
    </dependency>
15
    <dependency>
16
      <groupId>org.gvsig</groupId>
17
      <artifactId>org.gvsig.tools.lib</artifactId>
18
    </dependency>
19
    <dependency>
20
      <groupId>org.gvsig</groupId>
21
      <artifactId>org.gvsig.compat.api</artifactId>
22
    </dependency>
23
    <dependency>
24
      <groupId>org.gvsig</groupId>
25
      <artifactId>org.gvsig.compat.se</artifactId>
26
    </dependency>
27
    <dependency>
28
      <groupId>org.apache.httpcomponents</groupId>
29
      <artifactId>httpclient</artifactId>
30
    </dependency>
31
  </dependencies>
32
</project>
org.gvsig.downloader/tags/org.gvsig.downloader-1.0.2/org.gvsig.downloader.lib/pom.xml
1
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
2
  <modelVersion>4.0.0</modelVersion>
3
  <parent>
4
    <groupId>org.gvsig</groupId>
5
    <artifactId>org.gvsig.downloader</artifactId>
6
    <version>1.0.2</version>
7
  </parent>
8
  <artifactId>org.gvsig.downloader.lib</artifactId>
9
  <packaging>pom</packaging>
10
  <name>org.gvsig.downloader.lib</name>
11
  <modules>
12
  	<module>org.gvsig.downloader.lib.api</module>
13
  	<module>org.gvsig.downloader.lib.httpclient</module>
14
  </modules>
15
</project>
org.gvsig.downloader/tags/org.gvsig.downloader-1.0.2/org.gvsig.downloader.lib/org.gvsig.downloader.lib.api/pom.xml
1
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
2
  <modelVersion>4.0.0</modelVersion>
3
  <parent>
4
    <groupId>org.gvsig</groupId>
5
    <artifactId>org.gvsig.downloader.lib</artifactId>
6
    <version>1.0.2</version>
7
  </parent>
8
  <artifactId>org.gvsig.downloader.lib.api</artifactId>
9
  <name>org.gvsig.downloader.lib.api</name>
10
  <dependencies>
11
    <dependency>
12
      <groupId>org.gvsig</groupId>
13
      <artifactId>org.gvsig.tools.lib</artifactId>
14
    </dependency>
15
    <dependency>
16
      <groupId>org.apache.httpcomponents</groupId>
17
      <artifactId>httpclient</artifactId>
18
    </dependency>
19
  </dependencies>
20
  <dependencyManagement>
21
    <dependencies>
22
    </dependencies>
23
  </dependencyManagement>
24
</project>
org.gvsig.downloader/tags/org.gvsig.downloader-1.0.2/org.gvsig.downloader.lib/org.gvsig.downloader.lib.api/src/main/java/org/gvsig/downloader/lib/api/DownloaderLocator.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2014 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.api;
25

  
26
import org.gvsig.tools.locator.BaseLocator;
27
import org.gvsig.tools.locator.LocatorException;
28
/**
29
 * @author miguel
30
 */
31
public class DownloaderLocator extends BaseLocator {
32

  
33
  /**
34
   * The name and the description for the {@link Downloader manager} reference.
35
   */
36
  public static final String MANAGER_NAME = "Downloader.manager";
37

  
38
  public static final String DOWNLOADER_MANAGER_DESCRIPTION = "Downloader manager description";
39

  
40
  /**
41
   * Unique instance.
42
   */
43
  private static final DownloaderLocator instance = new DownloaderLocator();
44

  
45
  /**
46
   * Return the singleton instance.
47
   *
48
   * @return the singleton instance
49
   */
50
  public static DownloaderLocator getInstance() {
51
    return instance;
52
  }
53

  
54
  /**
55
   * Return a reference to Downloader manager.
56
   *
57
   * @return a reference to Downloader manager
58
   * @throws LocatorException if there is no access to the class or the class
59
   *           cannot be instantiated
60
   * @see Locator#get(String)
61
   */
62
  public static DownloaderManager getDownloaderManager() throws LocatorException {
63
    return (DownloaderManager) getInstance().get(MANAGER_NAME);
64
  }
65

  
66
  /**
67
   * Registers the Class implementing the Downloader manager interface.
68
   *
69
   * @param clazz implementing the Downloader manager interface
70
   */
71
  public static void registerDownloaderManager(Class clazz) {
72
    getInstance().register(MANAGER_NAME, DOWNLOADER_MANAGER_DESCRIPTION, clazz);
73
  }
74
}
org.gvsig.downloader/tags/org.gvsig.downloader-1.0.2/org.gvsig.downloader.lib/org.gvsig.downloader.lib.api/src/main/java/org/gvsig/downloader/lib/api/DownloaderLibrary.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2014 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.api;
25

  
26
import org.gvsig.tools.library.AbstractLibrary;
27
import org.gvsig.tools.library.LibraryException;
28
import org.gvsig.tools.locator.ReferenceNotRegisteredException;
29

  
30

  
31
/**
32
 * @author miguel
33
 */
34
public class DownloaderLibrary extends AbstractLibrary {
35

  
36
  public void doRegistration() {
37
    registerAsAPI(DownloaderLibrary.class);
38
  }
39

  
40
  @Override
41
  protected void doInitialize() throws LibraryException {
42

  
43
  }
44

  
45
  @Override
46
  protected void doPostInitialize() throws LibraryException {
47
     // Validate there is any implementation registered for the DownloaderManager.
48
     DownloaderManager downloaderManager = DownloaderLocator.getDownloaderManager();
49

  
50
     if (downloaderManager == null) {
51
     throw new ReferenceNotRegisteredException(DownloaderLocator.MANAGER_NAME,
52
         DownloaderLocator.getInstance());
53
     }
54

  
55

  
56
  }
57
}
org.gvsig.downloader/tags/org.gvsig.downloader-1.0.2/org.gvsig.downloader.lib/org.gvsig.downloader.lib.api/src/main/java/org/gvsig/downloader/lib/api/DownloaderManager.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2014 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.api;
25

  
26
import java.io.File;
27
import java.net.URL;
28
import java.util.List;
29

  
30
import org.apache.http.client.CredentialsProvider;
31

  
32
/**
33
 * @author miguel
34
 */
35
public interface DownloaderManager {
36

  
37
  public DownloaderProcess download(File target, URL url, String postdata)
38
      throws UnsupportedOperationException;
39

  
40
  public DownloaderAuthentication createAuthentication(String host, int port, String user, String password);
41

  
42
  public void createDownloader(File target, URL url, String postdata)
43
      throws UnsupportedOperationException;
44

  
45
  public List<DownloaderAuthentication> getAuthentications();
46

  
47
  public void setAuthentications(List<DownloaderAuthentication> authentications);
48

  
49
  public List<DownloaderProcess> getDownloads()
50
      throws UnsupportedOperationException;
51

  
52
  public CredentialsProvider getCredentialsProvider(String host);
53
}
org.gvsig.downloader/tags/org.gvsig.downloader-1.0.2/org.gvsig.downloader.lib/org.gvsig.downloader.lib.api/src/main/java/org/gvsig/downloader/lib/api/DownloaderProcess.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2014 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.api;
25

  
26
import java.io.File;
27
import java.net.URL;
28

  
29
import org.gvsig.tools.observer.Observable;
30
import org.gvsig.tools.task.MonitorableTask;
31

  
32
/**
33
 * @author miguel
34
 */
35
public interface DownloaderProcess extends MonitorableTask, Observable {
36

  
37
  /**
38
   * join() start() requestCancel() File getFile() URL getURL() String getID()
39
   * isTerminated isCanceled
40
   **/
41

  
42
  public File getFile();
43

  
44
  public URL getUrl();
45

  
46
  public String getID();
47

  
48
}
org.gvsig.downloader/tags/org.gvsig.downloader-1.0.2/org.gvsig.downloader.lib/org.gvsig.downloader.lib.api/src/main/java/org/gvsig/downloader/lib/api/DownloaderAuthentication.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2014 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.api;
25

  
26
import org.gvsig.tools.persistence.Persistent;
27

  
28
/**
29
 * @author miguel
30
 */
31
public interface DownloaderAuthentication extends Persistent {
32

  
33
  public String getHost();
34

  
35
  public int getPort();
36

  
37
  public String getUser();
38

  
39
  public String getPassword();
40

  
41
  public void setHost(String host);
42

  
43
  public void setPort(int port);
44

  
45
  public void setUser(String user);
46

  
47
  public void setPassword(String password);
48
}
org.gvsig.downloader/tags/org.gvsig.downloader-1.0.2/org.gvsig.downloader.lib/org.gvsig.downloader.lib.api/src/main/resources/META-INF/services/org.gvsig.tools.library.Library
1
org.gvsig.downloader.lib.api.DownloaderLibrary
org.gvsig.downloader/tags/org.gvsig.downloader-1.0.2/org.gvsig.downloader.swing/org.gvsig.downloader.swing.impl/src/main/resources/META-INF/services/org.gvsig.tools.library.Library
1
org.gvsig.downloader.swing.impl.DownloaderSwingImplLibrary
org.gvsig.downloader/tags/org.gvsig.downloader-1.0.2/org.gvsig.downloader.swing/org.gvsig.downloader.swing.impl/src/main/java/org/gvsig/downloader/swing/impl/DefaultDownloaderAuthenticationsPanel.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2014 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.swing.impl;
25

  
26
import java.awt.*;
27
import java.util.List;
28

  
29
import javax.swing.JComponent;
30
import javax.swing.JPanel;
31

  
32
import org.gvsig.downloader.lib.api.DownloaderAuthentication;
33
import org.gvsig.downloader.swing.api.DownloaderAuthenticationsPanel;
34

  
35
/**
36
 * @author paco
37
 *
38
 */
39
public class DefaultDownloaderAuthenticationsPanel extends JPanel implements
40
    DownloaderAuthenticationsPanel {
41

  
42
    /**
43
	 *
44
	 */
45
    private static final long serialVersionUID = -6287895281512523043L;
46
    // , ActionListener {
47

  
48
    List<DownloaderAuthentication> authentications;
49
    AuthenticationsList authenticationsList;
50

  
51
    public DefaultDownloaderAuthenticationsPanel(
52
        List<DownloaderAuthentication> authentications) {
53
        this.authentications = authentications;
54
        initComponents();
55

  
56
    }
57

  
58
    /*
59
     * (non-Javadoc)
60
     *
61
     * @see
62
     * org.gvsig.downloader.swing.api.DownloaderAuthenticationsPanel#asJComponent
63
     * ()
64
     */
65
    public JComponent asJComponent() {
66
        return this;
67
    }
68

  
69
    /*
70
     * (non-Javadoc)
71
     *
72
     * @see
73
     * org.gvsig.downloader.swing.api.DownloaderAuthenticationsPanel#doAccept()
74
     */
75
    public void doAccept() {
76
        // TODO Auto-generated method stub
77

  
78
    }
79

  
80
    /*
81
     * (non-Javadoc)
82
     *
83
     * @see
84
     * org.gvsig.downloader.swing.api.DownloaderAuthenticationsPanel#doCancel()
85
     */
86
    public void doCancel() {
87
        // TODO Auto-generated method stub
88

  
89
    }
90

  
91
    /*
92
     * (non-Javadoc)
93
     *
94
     * @see
95
     * org.gvsig.downloader.swing.api.DownloaderAuthenticationsPanel#doApply()
96
     */
97
    public void doApply() {
98
        // TODO Auto-generated method stub
99

  
100
    }
101

  
102
    private void initComponents() {
103

  
104
        setLayout(new GridBagLayout());
105
        GridBagConstraints c = new GridBagConstraints();
106
        c.insets = new Insets(2, 5, 0, 5);
107

  
108
        c.anchor = GridBagConstraints.CENTER;
109
        c.gridx = 0;
110
        c.gridy = 0;
111
        c.weightx = 1.0d;
112
        c.weighty = 1.0d;
113
        c.fill = GridBagConstraints.BOTH;
114
        add(getAuthenticationsList(), c);
115
        getAuthenticationsList().setAuthentications(this.authentications);
116
    }
117

  
118
    AuthenticationsList getAuthenticationsList() {
119
        if (this.authenticationsList == null) {
120
            this.authenticationsList = new AuthenticationsList();
121
        }
122
        return this.authenticationsList;
123
    }
124

  
125
    public List<DownloaderAuthentication> getAuthentications() {
126
        return this.authentications;
127
    }
128

  
129
    public void setAuthentications(
130
        List<DownloaderAuthentication> authentications) {
131
        this.authentications = authentications;
132
        getAuthenticationsList().setAuthentications(authentications);
133
    }
134

  
135
    /**
136
     * Devuelve true si el Panel debe estar en un BorderLayout centrado o false
137
     * si tiene un tama?o fijo.
138
     *
139
     * @return
140
     */
141
    public boolean isResizeable() {
142
        return true;
143
    }
144

  
145
}
org.gvsig.downloader/tags/org.gvsig.downloader-1.0.2/org.gvsig.downloader.swing/org.gvsig.downloader.swing.impl/src/main/java/org/gvsig/downloader/swing/impl/DefaultDownloaderSwingManager.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2014 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.swing.impl;
25

  
26
import java.util.List;
27

  
28
import javax.swing.*;
29

  
30
import org.gvsig.downloader.lib.api.DownloaderAuthentication;
31
import org.gvsig.downloader.swing.api.*;
32
import org.gvsig.tools.ToolsLocator;
33
import org.gvsig.tools.i18n.I18nManager;
34
import org.gvsig.tools.swing.api.ToolsSwingLocator;
35
import org.gvsig.tools.swing.icontheme.IconTheme;
36

  
37
/**
38
 *
39
 */
40

  
41
/**
42
 * @author paco
43
 *
44
 */
45
public class DefaultDownloaderSwingManager implements DownloaderSwingManager {
46

  
47
    public DownloaderAuthenticationsPanel createAuthenticationsPanel(
48
        List<DownloaderAuthentication> authentications) {
49
        DownloaderAuthenticationsPanel authenticationsPanel =
50
            new DefaultDownloaderAuthenticationsPanel(authentications);
51
        return authenticationsPanel;
52
    }
53

  
54
    public DownloaderAuthenticationPanel createAuthenticationPanel(
55
        DownloaderAuthentication authentication) {
56
        DefaultDownloaderAuthenticationPanel authenticationPanel =
57
            new DefaultDownloaderAuthenticationPanel(authentication);
58
        return authenticationPanel;
59
    }
60

  
61
    public DownloaderAuthenticationDialog createAuthenticationDialog(
62
        DownloaderAuthentication authentication) {
63

  
64
        DownloaderAuthenticationDialog authenticationDialog =
65
            new DefaultDownloaderAuthenticationDialog(authentication);
66

  
67
        return authenticationDialog;
68
    }
69

  
70
    public JButton getButtonFor(Action action, String icon, String txt) {
71

  
72
        JButton button = new JButton(action);
73
        I18nManager i18nManager = ToolsLocator.getI18nManager();
74

  
75
        String text = i18nManager.getTranslation(txt);
76
        if (icon != null && !"".equals(icon)) {
77
            ImageIcon iconImage = null;
78
            IconTheme iconTheme =
79
                ToolsSwingLocator.getIconThemeManager().getCurrent();
80
            if (iconTheme.exists(icon)) {
81
                iconImage = iconTheme.get(icon);
82
                button.setIcon(iconImage);
83
                button.setText("");
84
            } else {
85
                if (text != null && !"".equals(text)) {
86
                    button.setText(text);
87
                }
88
            }
89
        }
90
        if (text != null && !"".equals(text)) {
91
            button.setToolTipText(text);
92
        }
93
        return button;
94
    }
95

  
96
}
org.gvsig.downloader/tags/org.gvsig.downloader-1.0.2/org.gvsig.downloader.swing/org.gvsig.downloader.swing.impl/src/main/java/org/gvsig/downloader/swing/impl/AuthenticationsTableModel.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2014 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.swing.impl;
25

  
26
import java.util.*;
27

  
28
import javax.swing.table.AbstractTableModel;
29

  
30
import org.slf4j.Logger;
31
import org.slf4j.LoggerFactory;
32

  
33
import org.gvsig.downloader.lib.api.DownloaderAuthentication;
34

  
35
/**
36
 * @author paco
37
 *
38
 */
39
public class AuthenticationsTableModel extends AbstractTableModel {
40

  
41
	/**
42
	 *
43
	 */
44
	private static final long serialVersionUID = -3220767776435465823L;
45

  
46
	private static final Logger LOGGER = LoggerFactory
47
			.getLogger(AuthenticationsTableModel.class);
48

  
49
	private int rowCount = 0;
50
	private String[] columnNames = null;
51
	private List<String[]> data = null;
52

  
53
	public AuthenticationsTableModel(String[] columnNames) {
54
		if (columnNames == null) {
55
			throw new IllegalArgumentException("parameters cannot be null");
56
		}
57
		this.columnNames = columnNames;
58
	}
59

  
60
	/*
61
	 * (non-Javadoc)
62
	 *
63
	 * @see javax.swing.table.TableModel#getRowCount()
64
	 */
65
	public int getRowCount() {
66
		return rowCount;
67
	}
68

  
69
	/*
70
	 * (non-Javadoc)
71
	 *
72
	 * @see javax.swing.table.TableModel#getColumnCount()
73
	 */
74
	public int getColumnCount() {
75
		return columnNames.length;
76
	}
77

  
78
	/*
79
	 * (non-Javadoc)
80
	 *
81
	 * @see javax.swing.table.TableModel#getValueAt(int, int)
82
	 */
83
	public Object getValueAt(int rowIndex, int columnIndex) {
84
		if (data == null) {
85
			return "";
86
		}
87
		return data.get(rowIndex)[columnIndex];
88
	}
89

  
90
	/**
91
	 * Loads data from List of {@link DownloaderAuthentication}.
92
	 *
93
	 * @param data
94
	 * @param formatter
95
	 *            (optional) to use to format the Map to a String array
96
	 */
97
	public void loadData(List<DownloaderAuthentication> data) {
98
		if (data != null) {
99
			int fsSize = data.size();
100
			final List<String[]> tmpData = new ArrayList<String[]>(fsSize);
101
			// Default formatter
102
			RowFormatter formatter = new RowFormatter() {
103

  
104
				public String[] formatRow(
105
						DownloaderAuthentication authentication) {
106
					String[] result = new String[4];
107
					result[0] = authentication.getHost();
108
					result[1] = Integer.toString(authentication.getPort());
109
					result[2] = authentication.getUser();
110
					result[3] = authentication.getPassword();
111
					return result;
112
				}
113
			};
114
			final RowFormatter currentFormatter = formatter;
115

  
116
			// Visits all features and fills references and data temporal lists
117
			for (DownloaderAuthentication row : data) {
118
				tmpData.add(currentFormatter.formatRow(row));
119
			}
120

  
121
			this.data = Collections.unmodifiableList(tmpData);
122
			rowCount = data.size();
123
			fireTableDataChanged();
124
		}
125
	}
126

  
127
	/**
128
	 * Generates a String array from {@link Feature} values to use it as a row
129
	 * of {@link PickupPointsTableModel}
130
	 *
131
	 * @author jmvivo
132
	 *
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff