private void installSingleBook(String initials) { BookInstaller bookInstaller = new BookInstaller(); List<Book> books = (List<Book>) bookInstaller.getRepositoryBooks(REPOSITORY, BOOK_FILTER); for (Book book : books) { if (initials.equalsIgnoreCase(book.getInitials())) { String lang = book.getLanguage() == null ? " " : book.getLanguage().getCode(); System.out.println("Found in repo:" + lang + " " + book.getName()); try { if (Books.installed().getBook(book.getInitials()) != null) { System.out.println("Already installed:" + book.getInitials() + ":" + book.getName()); } else { System.out.println( "Downloading and installing:" + book.getInitials() + ":" + book.getName()); bookInstaller.installBook(REPOSITORY, book); waitToFinish(); } Book installedBook = bookInstaller.getInstalledBook(book.getInitials()); if (installedBook == null) { System.out.println("Not installed:" + book.getInitials() + " Name:" + book.getName()); } } catch (Exception e) { System.out.println("Error installing:" + book.getInitials()); e.printStackTrace(); } } } }
/* * (non-Javadoc) * * @see org.crosswire.jsword.book.BookList#getBook(java.lang.String) */ public synchronized Book getBook(String name) { // Check name first // First check for exact matches for (Book book : getBooks()) { if (name.equals(book.getName())) { return book; } } // Next check for case-insensitive matches for (Book book : getBooks()) { if (name.equalsIgnoreCase(book.getName())) { return book; } } // Then check initials // First check for exact matches for (Book book : getBooks()) { BookMetaData bmd = book.getBookMetaData(); if (name.equals(bmd.getInitials())) { return book; } } // Next check for case-insensitive matches for (Book book : getBooks()) { if (name.equalsIgnoreCase(book.getInitials())) { return book; } } return null; }
private void addPropertiesFile() { Properties indexProperties = new Properties(); indexProperties.put("version", "1"); indexProperties.put( "java.specification.version", System.getProperty("java.specification.version")); indexProperties.put("java.vendor", System.getProperty("java.vendor")); indexProperties.put( "lucene.specification.version", LucenePackage.get().getSpecificationVersion()); List<Book> books = (List<Book>) BookInstaller.getInstalledBooks(); for (Book book : books) { System.out.println( "Adding properties file:" + book.getInitials() + " name:" + book.getName()); String initials = book.getInitials(); File indexPropertiesFile = new File(LUCENE_INDEX_DIR_FILE, initials + "/index.properties"); FileOutputStream fos = null; try { fos = new FileOutputStream(indexPropertiesFile); indexProperties.store(fos, null); } catch (IOException ioe) { System.out.println(ioe.getMessage()); ioe.printStackTrace(); } finally { if (fos != null) { try { fos.close(); } catch (IOException e2) { e2.printStackTrace(); } } } } }
private void checkAllBooksInstalled() { BookInstaller bookInstaller = new BookInstaller(); List<Book> books = (List<Book>) bookInstaller.getRepositoryBooks(REPOSITORY, BOOK_FILTER); for (Book book : books) { try { Book installedBook = bookInstaller.getInstalledBook(book.getInitials()); if (installedBook == null) { System.out.println("Not installed:" + book.getInitials() + " Name:" + book.getName()); } else { Version versionObj = (Version) book.getProperty("Version"); String version = versionObj == null ? "No version" : versionObj.toString(); Version installedVersionObj = (Version) installedBook.getBookMetaData().getProperty("Version"); String installedVersion = installedVersionObj == null ? "No version" : installedVersionObj.toString(); if (!version.equals(installedVersion)) { System.out.println( "Incorrect version of " + book.getInitials() + " installed:" + installedVersion + " Repo:" + version); } else { System.out.println("Okay:" + book.getInitials() + " " + version); } } } catch (Exception e) { System.out.println("Error installing:" + book.getInitials()); e.printStackTrace(); } } }
private void showInstalledBooks() { List<Book> books = (List<Book>) BookInstaller.getInstalledBooks(); for (Book book : books) { System.out.println(book.getName()); } }
private Book getBook(String initials) { for (Book book : books) { if (book.getInitials().equals(initials)) { System.out.print("Found:" + book.getName()); return book; } } return null; }
private void showRepoBooks() { BookInstaller bookInstaller = new BookInstaller(); List<Book> books = (List<Book>) bookInstaller.getRepositoryBooks(REPOSITORY, BOOK_FILTER); for (Book book : books) { String lang = book.getLanguage() == null ? " " : book.getLanguage().getCode(); System.out.println(lang + " " + book.getName()); } }
/** @param book */ private void createZipFile(Book book) { System.out.println("Zipping file:" + book.getInitials() + " name:" + book.getName()); String initials = book.getInitials(); String version = book.getBookMetaData().getProperty("Version").toString(); String versionSuffix = version != null ? "-" + version : ""; File zipFile = new File(LUCENE_ZIP_DIR_FILE, initials + versionSuffix + ".zip"); File indexDir = new File(LUCENE_INDEX_DIR_FILE, initials); createZipFile(zipFile, indexDir); }
private void installRepoBooks() { BookInstaller bookInstaller = new BookInstaller(); List<Book> books = (List<Book>) bookInstaller.getRepositoryBooks(REPOSITORY, BOOK_FILTER); for (Book book : books) { try { if (Books.installed().getBook(book.getInitials()) != null) { System.out.println("Already installed:" + book.getInitials() + ":" + book.getName()); } else { System.out.println( "Downloading and installing:" + book.getInitials() + ":" + book.getName()); bookInstaller.installBook(REPOSITORY, book); waitToFinish(); } } catch (Exception e) { System.out.println("Error installing:" + book.getInitials()); e.printStackTrace(); } } }
private void deleteBook(Book book) { System.out.println("Deleting:" + book.getInitials() + " name:" + book.getName()); try { IndexManager imanager = IndexManagerFactory.getIndexManager(); if (imanager.isIndexed(book)) { imanager.deleteIndex(book); } book.getDriver().delete(book); } catch (Exception e) { System.out.println("Failed to delete " + book.getInitials() + ":" + e.getMessage()); e.printStackTrace(); } }
/** @param book */ private void indexBook(Book book) { System.out.println("Indexing:" + book.getInitials() + " name:" + book.getName()); try { BookIndexer bookIndexer = new BookIndexer(book); if (!bookIndexer.isIndexed()) { try { bookIndexer.createIndex(); waitToFinish(); } catch (Exception e) { System.out.println(e.getMessage()); e.printStackTrace(); } } else { System.out.println("Already indexed:" + book.getInitials()); } } catch (Exception e) { System.out.println("Failed to delete " + book.getInitials() + ":" + e.getMessage()); e.printStackTrace(); } }
/** Load the cached index file into memory */ private void loadCachedIndex() throws InstallException { // We need a sword book driver so the installer can use the driver // name to use in deciding where to put the index. BookDriver fake = SwordBookDriver.instance(); entries.clear(); URI cache = getCachedIndexFile(); if (!NetUtil.isFile(cache)) { reloadBookList(); } InputStream in = null; GZIPInputStream gin = null; TarInputStream tin = null; try { ConfigEntry.resetStatistics(); in = NetUtil.getInputStream(cache); gin = new GZIPInputStream(in); tin = new TarInputStream(gin); while (true) { TarEntry entry = tin.getNextEntry(); if (entry == null) { break; } String internal = entry.getName(); if (!entry.isDirectory()) { try { int size = (int) entry.getSize(); // Every now and then an empty entry sneaks in if (size == 0) { log.error("Empty entry: " + internal); continue; } byte[] buffer = new byte[size]; if (tin.read(buffer) != size) { // This should not happen, but if it does then skip // it. log.error("Did not read all that was expected " + internal); continue; } if (internal.endsWith(SwordConstants.EXTENSION_CONF)) { internal = internal.substring(0, internal.length() - 5); } else { log.error("Not a SWORD config file: " + internal); continue; } if (internal.startsWith(SwordConstants.DIR_CONF + '/')) { internal = internal.substring(7); } SwordBookMetaData sbmd = new SwordBookMetaData(buffer, internal); sbmd.setDriver(fake); Book book = new SwordBook(sbmd, null); entries.put(book.getName(), book); } catch (IOException ex) { log.error("Failed to load config for entry: " + internal, ex); } } } loaded = true; ConfigEntry.dumpStatistics(); } catch (IOException ex) { throw new InstallException(JSOtherMsg.lookupText("Error loading from cache"), ex); } finally { IOUtil.close(tin); IOUtil.close(gin); IOUtil.close(in); } }