use of org.crosswire.jsword.book.install.InstallException in project step by STEPBible.
the class JSwordModuleServiceImpl method reloadInstallers.
@Override
public void reloadInstallers() {
boolean errors = false;
LOGGER.trace("About to reload installers");
final List<Installer> installers = getInstallers();
for (final Installer i : installers) {
try {
LOGGER.trace("Reloading installer [{}]", i.getInstallerDefinition());
i.reloadBookList();
} catch (final InstallException e) {
errors = true;
LOGGER.error(e.getMessage(), e);
}
}
if (errors) {
throw new StepInternalException("Errors occurred while trying to retrieve the latest installer information");
}
}
use of org.crosswire.jsword.book.install.InstallException in project step by STEPBible.
the class JSwordModuleServiceImpl method installFromInstallers.
private void installFromInstallers(final String initials, List<Installer> installers) {
LOGGER.debug("Installing module [{}]", initials);
notBlank(initials, "No version was found", SERVICE_VALIDATION_ERROR);
// check if already installed?
if (!isInstalled(initials)) {
LOGGER.debug("Book was not already installed, so kicking off installation process for [{}]", initials);
for (final Installer i : installers) {
// long initials
String longInitials = this.versionResolver.getLongName(initials);
final Book bookToBeInstalled = i.getBook(longInitials);
if (bookToBeInstalled != null) {
// then we can kick off installation and return
try {
i.install(bookToBeInstalled);
return;
} catch (final InstallException e) {
// we log error here,
LOGGER.error("An error occurred error, and we unable to use this installer for module" + initials, e);
// but go round the loop to see if more options are available
continue;
}
}
}
// if we get here, then we were unable to install the book
// since we couldn't find it.
LOGGER.error("Unable to install: [{}]", initials);
throw new TranslatedException("book_not_found", initials);
}
// if we get here then we had already installed the book - how come we're asking for this again?
LOGGER.warn("A request to install an already installed book was made for initials " + initials);
}
use of org.crosswire.jsword.book.install.InstallException in project step by STEPBible.
the class JSwordModuleServiceImpl method getAllModules.
@Override
public List<Book> getAllModules(int installerIndex, final BookCategory... bibleCategory) {
final List<Book> books = new ArrayList<Book>();
List<Installer> installers = getInstallers();
if (installerIndex != -1) {
// use a single installer
Installer installer = installers.get(installerIndex);
installers = new ArrayList<Installer>();
installers.add(installer);
}
for (final Installer installer : installers) {
try {
installer.reloadBookList();
final List<Book> installerBooks = installer.getBooks();
// - 4 items bigs, likely 2
for (final Book b : installerBooks) {
for (final BookCategory cat : bibleCategory) {
if (cat.equals(b.getBookCategory())) {
books.add(b);
break;
}
}
}
} catch (final InstallException e) {
// log an error
LOGGER.error("Unable to update installer", e);
}
}
return books;
}
use of org.crosswire.jsword.book.install.InstallException in project step by STEPBible.
the class DirectoryInstaller method download.
@Override
protected void download(final Progress job, final String packageDir, final String file, final URI dest) throws InstallException {
final File sourceFile = new File(super.getPackageDirectory(), file);
// copy two streams
InputStream source = null;
OutputStream target = null;
try {
target = new BufferedOutputStream(new FileOutputStream(new File(dest)));
source = new BufferedInputStream(new FileInputStream(sourceFile));
final byte[] buffer = new byte[1024];
int length = 0;
while ((length = source.read(buffer)) > 0) {
target.write(buffer, 0, length);
}
} catch (final FileNotFoundException e) {
throw new InstallException("File not found (either source or destination). Unable to open stream to copy file.", e);
} catch (final IOException e) {
throw new InstallException("General IOException. Can't read/write to specified files", e);
} finally {
IOUtil.close(source);
IOUtil.close(target);
}
}
use of org.crosswire.jsword.book.install.InstallException in project step by STEPBible.
the class DirectoryListingInstaller method reloadBookList.
/* (non-Javadoc)
* @see org.crosswire.jsword.book.install.Installer#reloadBookList()
*/
public void reloadBookList() throws InstallException {
// TRANSLATOR: Progress label for downloading one or more files.
String jobName = JSMsg.gettext("Downloading files");
Progress job = JobManager.createJob(Progress.RELOAD_BOOK_LIST, jobName, Thread.currentThread());
job.beginJob(jobName);
try {
loaded = false;
loadCachedIndex();
} catch (InstallException ex) {
job.cancel();
throw ex;
} finally {
job.done();
}
}
Aggregations