/** * Unregister a book from Sword registry. * * This used to delete the book but there is an mysterious bug in deletion (see below). * * @param book * the book to delete * @throws BookException */ private void unregisterBook(Book book) throws BookException { // this just seems to work so leave it here // I used to think that the next delete was better - what a mess // see this for potential problem: http://stackoverflow.com/questions/20437626/file-exists-returns-false-for-existing-file-in-android // does file.exists return an incorrect value? // To see the problem, reverse the commented lines below, and try downloading 2 or more Bibles that are already installed Books.installed().removeBook(book); // Avoid deleting all dir and files because "Java is known not to delete files immediately, so mkdir may fail sometimes" // http://stackoverflow.com/questions/617414/create-a-temporary-directory-in-java // // Actually do the delete // This should be a call on installer. //book.getDriver().delete(book); }
public void startListening() { Books.installed().addBooksListener(new BooksListener() { @Override public void bookAdded(BooksEvent ev) { Book book = ev.getBook(); initialiseRequiredMapping(book); } @Override public void bookRemoved(BooksEvent ev) { //NOOP } }); }
/** * This is an example of the different ways to select a Book from the * selection available. * * @see org.crosswire.common.config.Config * @see Books */ public void pickBible() { // The Default Bible - JSword does everything it can to make this work Book book = Books.installed().getBook(BIBLE_NAME); // And you can find out more too: System.out.println(book.getLanguage()); // If you want a greater selection of Books: List<Book> books = Books.installed().getBooks(); book = books.get(0); // Or you can narrow the range a bit books = Books.installed().getBooks(BookFilters.getOnlyBibles()); book = books.get(0); // There are implementations of BookFilter for all sorts of things in // the BookFilters class // If you are wanting to get really fancy you can implement your own // BookFilter easily List<Book> test = Books.installed().getBooks(new MyBookFilter("ESV")); book = test.get(0); if (book != null) { System.out.println(book.getInitials()); } // If you want to know about new books as they arrive: Books.installed().addBooksListener(new MyBooksListener()); }
/** * */ public StrongsAnalysis() { Book bible = Books.installed().getBook("KJV"); if (!bible.hasFeature(FeatureType.STRONGS_NUMBERS)) { bible = null; List<Book> bibles = Books.installed().getBooks(new BookFilters.BookFeatureFilter(FeatureType.STRONGS_NUMBERS)); if (!bibles.isEmpty()) { bible = bibles.get(0); } } if (bible == null) { return; } List<Key> errors = new ArrayList<Key>(); StrongsMapSet sms = new StrongsMapSet(); analyze(sms, bible, errors, bible.getGlobalKeyList()); }
if (Books.installed().getBook(initials) != null) { Books.installed().removeBook(book);
addBook(bookArray[j]); removeBook(book);
/** * Establish additional locations that Sword may hold books. * * @param theNewDirs * The new Sword directories * @throws BookException */ public static void setAugmentPath(File[] theNewDirs) throws BookException { File[] newDirs = theNewDirs; if (newDirs == null) { return; } SwordBookPath.augmentPath = newDirs.clone(); // Now we need to (re)register ourselves Books.installed().registerDriver(SwordBookDriver.instance()); }
/** * Add a Book to the current list of Books. This method should only be * called by BibleDrivers, it is not a method for general consumption. * * @param book the book to add to this book list */ public synchronized void addBook(Book book) { if (book != null && books.add(book)) { initials.put(book.getInitials(), book); names.put(book.getName(), book); fireBooksChanged(instance, book, true); } }
/** * Registers all the drivers known to the program. */ private void autoRegister() { // This will classload them all and they will register themselves. Class<? extends BookDriver>[] types = PluginUtil.getImplementors(BookDriver.class); log.debug("begin auto-registering {} drivers:", Integer.toString(types.length)); for (int i = 0; i < types.length; i++) { // job.setProgress(Msg.JOB_DRIVER.toString() + // ClassUtils.getShortClassName(types[i])); try { Method driverInstance = types[i].getMethod("instance", new Class[0]); BookDriver driver = (BookDriver) driverInstance.invoke(null, new Object[0]); // types[i].newInstance(); registerDriver(driver); } catch (NoSuchMethodException e) { Reporter.informUser(Books.class, e); } catch (IllegalArgumentException e) { Reporter.informUser(Books.class, e); } catch (IllegalAccessException e) { Reporter.informUser(Books.class, e); } catch (InvocationTargetException e) { Reporter.informUser(Books.class, e); } catch (BookException e) { Reporter.informUser(Books.class, e); } } }
/** * Different versions of a Book may contain different Bible books so flush cache if a Book may have been updated */ private void flushCacheIfBooksChange() { Books.installed().addBooksListener(new BooksListener() { @Override public void bookAdded(BooksEvent ev) { cache.evictAll(); } @Override public void bookRemoved(BooksEvent ev) { cache.evictAll(); } }); } }
/** * Remove a Book from the current list of Books. This method should only be * called by BibleDrivers, it is not a method for general consumption. * * @param book the book to be removed from this book list * @throws BookException when an error occurs when performing this method */ public synchronized void removeBook(Book book) throws BookException { // log.debug("unregistering book: {}", bmd.getName()); Activator.deactivate(book); boolean removed = books.remove(book); if (removed) { initials.remove(book.getInitials()); names.remove(book.getName()); fireBooksChanged(instance, book, false); } else { throw new BookException(JSOtherMsg.lookupText("Could not remove unregistered Book: {0}", book.getName())); } }
@Override public void delete(Book dead) throws BookException { SwordBookMetaData sbmd = (SwordBookMetaData) dead.getBookMetaData(); File confFile = sbmd.getConfigFile(); // We can only uninstall what we download into our download dir. if (confFile == null || !confFile.exists()) { // TRANSLATOR: Common error condition: The file could not be deleted. There can be many reasons. // {0} is a placeholder for the file. throw new BookException(JSMsg.gettext("Unable to delete: {0}", confFile)); } // Delete the conf List<File> failures = FileUtil.delete(confFile); if (failures.isEmpty()) { URI loc = sbmd.getLocation(); if (loc != null) { File bookDir = new File(loc.getPath()); failures = FileUtil.delete(bookDir); Books.installed().removeBook(dead); } } // TODO(DM): list all that failed if (!failures.isEmpty()) { // TRANSLATOR: Common error condition: The file could not be deleted. There can be many reasons. // {0} is a placeholder for the file. throw new BookException(JSMsg.gettext("Unable to delete: {0}", failures.get(0))); } }