org.crosswire.jsword.book.install.sword
Class AbstractSwordInstaller

java.lang.Object
  extended by org.crosswire.jsword.book.basic.AbstractBookList
      extended by org.crosswire.jsword.book.install.sword.AbstractSwordInstaller
All Implemented Interfaces:
Comparable<AbstractSwordInstaller>, BookList, Installer
Direct Known Subclasses:
HttpSwordInstaller

public abstract class AbstractSwordInstaller
extends AbstractBookList
implements Installer, Comparable<AbstractSwordInstaller>

Author:
DM Smith
See Also:
for license details.
The copyright to this program is held by it's authors.

Field Summary
protected  String catalogDirectory
          The directory containing the catalog of all books on the host.
protected static String DOWNLOAD_PREFIX
          When we cache a download index
protected  Map<String,Book> entries
          A map of the books in this download area
protected static String FILE_LIST_GZ
          The sword index file
protected  String host
          The remote hostname.
protected  String indexDirectory
          The directory containing the catalog of all books on the host.
protected  boolean loaded
          Do we need to reload the index file
protected static org.slf4j.Logger log
          The log stream
protected  String packageDirectory
          The directory containing zipped books on the host.
protected  String proxyHost
          The remote proxy hostname.
protected  Integer proxyPort
          The remote proxy port.
protected static String SEARCH_DIR
          The relative path of the dir holding the search index files
protected static String ZIP_SUFFIX
          The suffix of zip books on this server
 
Constructor Summary
AbstractSwordInstaller()
           
 
Method Summary
 int compareTo(AbstractSwordInstaller myClass)
           
protected abstract  void download(Progress job, String dir, String file, URI dest)
          Utility to download a file from a remote site
 void downloadSearchIndex(Book book, URI localDest)
          Download a search index for the given Book.
 boolean equals(Object object)
           
protected  boolean equals(String string1, String string2)
          Quick utility to check to see if 2 (potentially null) strings are equal
 Book getBook(String name)
          Get a Book matching the name from the local cache.
 List<Book> getBooks()
          Get a list of BookMetaData objects that represent downloadable books.
 List<Book> getBooks(BookFilter filter)
          Get a filtered list of all the Books.
protected  URI getCachedIndexFile()
          The URL for the cached index file for this installer
 String getCatalogDirectory()
           
 String getHost()
           
 String getIndexDirectory()
           
 String getInstallerDefinition()
          Accessor for the URI
 String getPackageDirectory()
           
 String getProxyHost()
           
 Integer getProxyPort()
           
private static String getTempFileExtension(String host, String catalogDir)
          What are we using as a temp filename?
 int hashCode()
           
 void install(Book book)
          Download and install a book locally.
 boolean isNewer(Book book)
          Return true if the book is not installed or there is a newer version to install.
private  void loadCachedIndex()
          Load the cached index file into memory
 void reloadBookList()
          Re-fetch a list of names from the remote source.
 void setCatalogDirectory(String catologDirectory)
           
 void setHost(String newHost)
           
 void setIndexDirectory(String indexDirectory)
           
 void setPackageDirectory(String newDirectory)
           
 void setProxyHost(String newProxyHost)
           
 void setProxyPort(Integer newProxyPort)
           
 
Methods inherited from class org.crosswire.jsword.book.basic.AbstractBookList
addBooksListener, fireBooksChanged, removeBooksListener
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.crosswire.jsword.book.install.Installer
getSize, getType, toRemoteURI
 
Methods inherited from interface org.crosswire.jsword.book.BookList
addBooksListener, removeBooksListener
 

Field Detail

entries

protected Map<String,Book> entries
A map of the books in this download area


host

protected String host
The remote hostname.


proxyHost

protected String proxyHost
The remote proxy hostname.


proxyPort

protected Integer proxyPort
The remote proxy port.


packageDirectory

protected String packageDirectory
The directory containing zipped books on the host.


catalogDirectory

protected String catalogDirectory
The directory containing the catalog of all books on the host.


indexDirectory

protected String indexDirectory
The directory containing the catalog of all books on the host.


loaded

protected boolean loaded
Do we need to reload the index file


FILE_LIST_GZ

protected static final String FILE_LIST_GZ
The sword index file

See Also:
Constant Field Values

ZIP_SUFFIX

protected static final String ZIP_SUFFIX
The suffix of zip books on this server

See Also:
Constant Field Values

SEARCH_DIR

protected static final String SEARCH_DIR
The relative path of the dir holding the search index files

See Also:
Constant Field Values

DOWNLOAD_PREFIX

protected static final String DOWNLOAD_PREFIX
When we cache a download index

See Also:
Constant Field Values

log

protected static final org.slf4j.Logger log
The log stream

Constructor Detail

AbstractSwordInstaller

public AbstractSwordInstaller()
Method Detail

download

protected abstract void download(Progress job,
                                 String dir,
                                 String file,
                                 URI dest)
                          throws InstallException
Utility to download a file from a remote site

Parameters:
job - The way of noting progress
dir - The directory from which to download the file
file - The file to download
Throws:
InstallException

getInstallerDefinition

public String getInstallerDefinition()
Description copied from interface: Installer
Accessor for the URI

Specified by:
getInstallerDefinition in interface Installer
Returns:
the source URI

isNewer

public boolean isNewer(Book book)
Description copied from interface: Installer
Return true if the book is not installed or there is a newer version to install.

Specified by:
isNewer in interface Installer
Parameters:
book - The book meta-data to check on.
Returns:
whether there is a newer version to install

getBooks

public List<Book> getBooks()
Description copied from interface: Installer
Get a list of BookMetaData objects that represent downloadable books. If no list has been retrieved from the remote source using reloadIndex() then we should just return an empty list and not attempt to contact the remote source. See notes on reload for more information.

Specified by:
getBooks in interface BookList
Specified by:
getBooks in interface Installer
See Also:
Installer.reloadBookList()

getBook

public Book getBook(String name)
Description copied from interface: Installer
Get a Book matching the name from the local cache. Null if none is found.

Specified by:
getBook in interface Installer

getBooks

public List<Book> getBooks(BookFilter filter)
Description copied from interface: BookList
Get a filtered list of all the Books.

Specified by:
getBooks in interface BookList
Overrides:
getBooks in class AbstractBookList
See Also:
BookFilters

install

public void install(Book book)
Description copied from interface: Installer
Download and install a book locally. The name should be one from an index list retrieved from getIndex() or reloadIndex()

Specified by:
install in interface Installer
Parameters:
book - The book to install

reloadBookList

public void reloadBookList()
                    throws InstallException
Description copied from interface: Installer
Re-fetch a list of names from the remote source. It would make sense if the user was warned about the implications of this action. If the user lives in a country that persecutes Christians then this action might give the game away.

Specified by:
reloadBookList in interface Installer
Throws:
InstallException

downloadSearchIndex

public void downloadSearchIndex(Book book,
                                URI localDest)
                         throws InstallException
Description copied from interface: Installer
Download a search index for the given Book. The installation of the search index is the responsibility of the BookIndexer.

Specified by:
downloadSearchIndex in interface Installer
Parameters:
book - The book to download a search index for.
localDest - A temporary URI for downloading to. Passed to the BookIndexer for installation.
Throws:
InstallException

loadCachedIndex

private void loadCachedIndex()
                      throws InstallException
Load the cached index file into memory

Throws:
InstallException

getCatalogDirectory

public String getCatalogDirectory()
Returns:
the catologDirectory

setCatalogDirectory

public void setCatalogDirectory(String catologDirectory)
Parameters:
catologDirectory - the catologDirectory to set

getPackageDirectory

public String getPackageDirectory()
Returns:
Returns the directory.

setPackageDirectory

public void setPackageDirectory(String newDirectory)
Parameters:
newDirectory - The directory to set.

getIndexDirectory

public String getIndexDirectory()
Returns:
the indexDirectory

setIndexDirectory

public void setIndexDirectory(String indexDirectory)
Parameters:
indexDirectory - the indexDirectory to set

getHost

public String getHost()
Returns:
Returns the host.

setHost

public void setHost(String newHost)
Parameters:
newHost - The host to set.

getProxyHost

public String getProxyHost()
Returns:
Returns the proxyHost.

setProxyHost

public void setProxyHost(String newProxyHost)
Parameters:
newProxyHost - The proxyHost to set.

getProxyPort

public Integer getProxyPort()
Returns:
Returns the proxyPort.

setProxyPort

public void setProxyPort(Integer newProxyPort)
Parameters:
newProxyPort - The proxyPort to set.

getCachedIndexFile

protected URI getCachedIndexFile()
                          throws InstallException
The URL for the cached index file for this installer

Throws:
InstallException

getTempFileExtension

private static String getTempFileExtension(String host,
                                           String catalogDir)
What are we using as a temp filename?


equals

public boolean equals(Object object)
Overrides:
equals in class Object

compareTo

public int compareTo(AbstractSwordInstaller myClass)
Specified by:
compareTo in interface Comparable<AbstractSwordInstaller>

hashCode

public int hashCode()
Overrides:
hashCode in class Object

equals

protected boolean equals(String string1,
                         String string2)
Quick utility to check to see if 2 (potentially null) strings are equal


Copyright ? 2003-2011