[jsword-svn]
jsword/java/jsword/org/crosswire/jsword/book/install/sword s
jswordcvs at crosswire.org
jswordcvs at crosswire.org
Sun Aug 21 13:37:59 MST 2005
Update of /cvs/jsword/jsword/java/jsword/org/crosswire/jsword/book/install/sword
In directory www.crosswire.org:/tmp/cvs-serv23340/java/jsword/org/crosswire/jsword/book/install/sword
Modified Files:
Msg.java Msg.properties HttpSwordInstaller.java
AbstractSwordInstaller.java HttpSwordInstallerFactory.java
Log Message:
Willie Thean's laf changes.
Added ability to specify proxy for http download.
Changed default logging to INFO.
Index: AbstractSwordInstaller.java
===================================================================
RCS file: /cvs/jsword/jsword/java/jsword/org/crosswire/jsword/book/install/sword/AbstractSwordInstaller.java,v
retrieving revision 1.17
retrieving revision 1.18
diff -C2 -d -r1.17 -r1.18
*** AbstractSwordInstaller.java 27 Jul 2005 23:25:45 -0000 1.17
--- AbstractSwordInstaller.java 21 Aug 2005 20:37:56 -0000 1.18
***************
*** 65,68 ****
--- 65,69 ----
* The copyright to this program is held by it's authors.
* @author Joe Walker [joe at eireneh dot com]
+ * @author DM Smith [dmsmith555 at yahoo dot com]
*/
public abstract class AbstractSwordInstaller extends AbstractBookList implements Installer
***************
*** 78,81 ****
--- 79,103 ----
/* (non-Javadoc)
+ * @see org.crosswire.jsword.book.install.Installer#getURL()
+ */
+ public String getInstallerDefinition()
+ {
+ StringBuffer buf = new StringBuffer(host);
+ buf.append(',');
+ buf.append(directory);
+ buf.append(',');
+ if (proxyHost != null)
+ {
+ buf.append(proxyHost);
+ }
+ buf.append(',');
+ if (proxyPort != null)
+ {
+ buf.append(proxyPort);
+ }
+ return buf.toString();
+ }
+
+ /* (non-Javadoc)
* @see org.crosswire.jsword.book.install.Installer#isNewer(org.crosswire.jsword.book.BookMetaData)
*/
***************
*** 108,112 ****
URL remote = toRemoteURL(book);
! return NetUtil.isNewer(remote, configurl);
}
--- 130,134 ----
URL remote = toRemoteURL(book);
! return NetUtil.isNewer(remote, configurl, proxyHost, proxyPort);
}
***************
*** 368,371 ****
--- 390,425 ----
/**
+ * @return Returns the proxyHost.
+ */
+ public String getProxyHost()
+ {
+ return proxyHost;
+ }
+
+ /**
+ * @param proxyHost The proxyHost to set.
+ */
+ public void setProxyHost(String proxyHost)
+ {
+ this.proxyHost = proxyHost;
+ }
+
+ /**
+ * @return Returns the proxyPort.
+ */
+ public Integer getProxyPort()
+ {
+ return proxyPort;
+ }
+
+ /**
+ * @param proxyPort The proxyPort to set.
+ */
+ public void setProxyPort(Integer proxyPort)
+ {
+ this.proxyPort = proxyPort;
+ }
+
+ /**
* The URL for the cached index file for this installer
*/
***************
*** 471,474 ****
--- 525,538 ----
/**
+ * The remote proxy hostname.
+ */
+ protected String proxyHost;
+
+ /**
+ * The remote proxy port.
+ */
+ protected Integer proxyPort;
+
+ /**
* The directory containing books on the <code>host</code>.
*/
Index: Msg.properties
===================================================================
RCS file: /cvs/jsword/jsword/java/jsword/org/crosswire/jsword/book/install/sword/Msg.properties,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** Msg.properties 11 Jun 2005 20:41:05 -0000 1.3
--- Msg.properties 21 Aug 2005 20:37:56 -0000 1.4
***************
*** 23,25 ****
SwordInstallerFactory.URLAtCount=Too many @ symbols in url: {0}
SwordInstallerFactory.URLColonCount=Wrong number of : symbols in url: {0}
! HttpSwordInstaller.MissingFile=Unable to find book
\ No newline at end of file
--- 23,25 ----
SwordInstallerFactory.URLAtCount=Too many @ symbols in url: {0}
SwordInstallerFactory.URLColonCount=Wrong number of : symbols in url: {0}
! HttpSwordInstaller.MissingFile=Unable to find: {0}
\ No newline at end of file
Index: HttpSwordInstallerFactory.java
===================================================================
RCS file: /cvs/jsword/jsword/java/jsword/org/crosswire/jsword/book/install/sword/HttpSwordInstallerFactory.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** HttpSwordInstallerFactory.java 27 Jul 2005 23:25:45 -0000 1.7
--- HttpSwordInstallerFactory.java 21 Aug 2005 20:37:56 -0000 1.8
***************
*** 22,26 ****
package org.crosswire.jsword.book.install.sword;
- import org.crosswire.common.util.NetUtil;
import org.crosswire.jsword.book.install.Installer;
import org.crosswire.jsword.book.install.InstallerFactory;
--- 22,25 ----
***************
*** 33,36 ****
--- 32,36 ----
* @author Mark Goodwin [goodwinster at gmail dot com]
* @author Joe Walker [joe at eireneh dot com]
+ * @author DM Smith [dmsmith555 at yahoo dot com]
*/
public class HttpSwordInstallerFactory implements InstallerFactory
***************
*** 47,63 ****
* @see org.crosswire.jsword.book.install.InstallerFactory#createInstaller(java.lang.String)
*/
! public Installer createInstaller(String url)
{
! String[] parts = url.split(NetUtil.SEPARATOR, 4);
if (parts.length < 4)
{
! throw new IllegalArgumentException(Msg.INVALID_URL.toString(url));
}
HttpSwordInstaller reply = new HttpSwordInstaller();
! String part2 = parts[2];
! reply.setHost(part2);
! reply.setDirectory(NetUtil.SEPARATOR + parts[3]);
return reply;
--- 47,70 ----
* @see org.crosswire.jsword.book.install.InstallerFactory#createInstaller(java.lang.String)
*/
! public Installer createInstaller(String installerDefinition)
{
! String[] parts = installerDefinition.split(",", 4); //$NON-NLS-1$
if (parts.length < 4)
{
! throw new IllegalArgumentException(Msg.INVALID_DEFINITION.toString(installerDefinition));
}
HttpSwordInstaller reply = new HttpSwordInstaller();
! reply.setHost(parts[0]);
! reply.setDirectory(parts[1]);
! if (parts[2].length() > 0)
! {
! reply.setProxyHost(parts[2]);
! if (parts[5].length() > 0)
! {
! reply.setProxyPort(Integer.valueOf(parts[3]));
! }
! }
return reply;
Index: HttpSwordInstaller.java
===================================================================
RCS file: /cvs/jsword/jsword/java/jsword/org/crosswire/jsword/book/install/sword/HttpSwordInstaller.java,v
retrieving revision 1.26
retrieving revision 1.27
diff -C2 -d -r1.26 -r1.27
*** HttpSwordInstaller.java 18 Aug 2005 20:58:47 -0000 1.26
--- HttpSwordInstaller.java 21 Aug 2005 20:37:56 -0000 1.27
***************
*** 22,40 ****
package org.crosswire.jsword.book.install.sword;
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.OutputStream;
import java.net.MalformedURLException;
import java.net.URL;
- import org.apache.commons.httpclient.DefaultHttpMethodRetryHandler;
- import org.apache.commons.httpclient.HttpClient;
- import org.apache.commons.httpclient.HttpException;
- import org.apache.commons.httpclient.HttpStatus;
- import org.apache.commons.httpclient.methods.GetMethod;
- import org.apache.commons.httpclient.params.HttpMethodParams;
import org.crosswire.common.progress.Job;
! import org.crosswire.common.util.IOUtil;
import org.crosswire.common.util.NetUtil;
import org.crosswire.jsword.book.Book;
import org.crosswire.jsword.book.install.InstallException;
--- 22,32 ----
package org.crosswire.jsword.book.install.sword;
import java.net.MalformedURLException;
import java.net.URL;
import org.crosswire.common.progress.Job;
! import org.crosswire.common.util.LucidException;
import org.crosswire.common.util.NetUtil;
+ import org.crosswire.common.util.WebResource;
import org.crosswire.jsword.book.Book;
import org.crosswire.jsword.book.install.InstallException;
***************
*** 52,60 ****
{
/* (non-Javadoc)
! * @see org.crosswire.jsword.book.install.Installer#getURL()
*/
! public String getURL()
{
! return PROTOCOL_WEB + "://" + host + directory; //$NON-NLS-1$
}
--- 44,60 ----
{
/* (non-Javadoc)
! * @see org.crosswire.jsword.book.install.Installer#getType()
*/
! public String getType()
{
! return "sword-http"; //$NON-NLS-1$
! }
!
! /* (non-Javadoc)
! * @see org.crosswire.jsword.book.install.Installer#getSize(org.crosswire.jsword.book.Book)
! */
! public int getSize(Book book)
! {
! return NetUtil.getSize(toRemoteURL(book), proxyHost, proxyPort);
}
***************
*** 84,90 ****
copy(job, url, dest);
}
! catch (IOException ex)
{
! throw new InstallException(Msg.UNKNOWN_ERROR, ex);
}
}
--- 84,94 ----
copy(job, url, dest);
}
! catch (LucidException ex)
{
! throw new InstallException(Msg.MISSING_FILE, ex);
! }
! catch (MalformedURLException e)
! {
! assert false : e;
}
}
***************
*** 94,159 ****
* @param url
* @param dest
! * @throws IOException
*/
! private void copy(Job job, URL url, URL dest) throws IOException, InstallException
{
! InputStream in = null;
! OutputStream out = null;
!
! // Create an instance of HttpClient.
! HttpClient client = new HttpClient();
!
! // Create a method instance.
! GetMethod method = new GetMethod(url.toExternalForm());
!
! // Provide custom retry handler is necessary
! method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
! new DefaultHttpMethodRetryHandler(3, false));
!
! try
! {
! if (job != null)
! {
! job.setProgress(Msg.JOB_DOWNLOADING.toString());
! }
!
! // Execute the method.
! int statusCode = client.executeMethod(method);
!
! if (statusCode != HttpStatus.SC_OK)
! {
! throw new InstallException(Msg.MISSING_FILE, new Object [] { method.getStatusLine().toString() });
! }
!
! try
! {
! in = method.getResponseBodyAsStream();
! }
! catch (Exception exception)
! {
! throw new InstallException(Msg.MISSING_FILE, exception);
! }
!
! // Download the index file
! out = NetUtil.getOutputStream(dest);
!
! byte[] buf = new byte[4096];
! for (int count = 0; -1 != (count = in.read(buf));)
! {
! out.write(buf, 0, count);
! }
! }
! catch (HttpException e)
{
! throw new InstallException(Msg.MISSING_FILE, e);
}
! finally
! {
! // Release the connection.
! method.releaseConnection();
! // Close the streams
! IOUtil.close(in);
! IOUtil.close(out);
! }
}
--- 98,112 ----
* @param url
* @param dest
! * @throws LucidException
*/
! private void copy(Job job, URL url, URL dest) throws LucidException
{
! if (job != null)
{
! job.setProgress(Msg.JOB_DOWNLOADING.toString());
}
!
! WebResource wr = new WebResource(url, proxyHost, proxyPort);
! wr.copy(dest);
}
***************
*** 184,191 ****
return super.hashCode();
}
-
- /**
- * We need to be ablee to provide a URL as part of the API
- */
- private static final String PROTOCOL_WEB = "sword-http"; //$NON-NLS-1$
}
--- 137,139 ----
Index: Msg.java
===================================================================
RCS file: /cvs/jsword/jsword/java/jsword/org/crosswire/jsword/book/install/sword/Msg.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -C2 -d -r1.13 -r1.14
*** Msg.java 27 Jul 2005 23:25:45 -0000 1.13
--- Msg.java 21 Aug 2005 20:37:56 -0000 1.14
***************
*** 35,39 ****
static final Msg UNKNOWN_ERROR = new Msg("SwordInstaller.UnknownError"); //$NON-NLS-1$
static final Msg CACHE_ERROR = new Msg("SwordInstaller.CacheError"); //$NON-NLS-1$
! static final Msg INVALID_URL = new Msg("SwordInstaller.InvalidURL"); //$NON-NLS-1$
static final Msg INSTALLING = new Msg("SwordInstaller.Installing"); //$NON-NLS-1$
static final Msg JOB_INIT = new Msg("SwordInstaller.JobInit"); //$NON-NLS-1$
--- 35,39 ----
static final Msg UNKNOWN_ERROR = new Msg("SwordInstaller.UnknownError"); //$NON-NLS-1$
static final Msg CACHE_ERROR = new Msg("SwordInstaller.CacheError"); //$NON-NLS-1$
! static final Msg INVALID_DEFINITION = new Msg("SwordInstaller.InvalidURL"); //$NON-NLS-1$
static final Msg INSTALLING = new Msg("SwordInstaller.Installing"); //$NON-NLS-1$
static final Msg JOB_INIT = new Msg("SwordInstaller.JobInit"); //$NON-NLS-1$
More information about the jsword-svn
mailing list