@Override public boolean equals(Object obj) { // Since this can not be null if (obj == null) { return false; } // We might consider checking for equality against all Books? // However currently we don't. // Check that that is the same as this // Don't use instanceof since that breaks inheritance if (!obj.getClass().equals(this.getClass())) { return false; } // The real bit ... Book that = (Book) obj; return bmd.equals(that.getBookMetaData()); }
@Override public boolean isDeletable(Book dead) { SwordBookMetaData sbmd = (SwordBookMetaData) dead.getBookMetaData(); File confFile = sbmd.getConfigFile(); // We can only uninstall what we download into our download dir. return confFile != null && confFile.exists(); }
public int compareTo(Book obj) { return this.bmd.compareTo(obj.getBookMetaData()); }
public void storeRepoNameInMetaData(List<Book> bookList) { for (Book book : bookList) { // SwordBookMetaData must not persist these properties because many downloadable books may have the same name, // and we set the props every time so they do not need to be persisted if (book instanceof SwordBook) { ((SwordBookMetaData)book.getBookMetaData()).setProperty(DownloadManager.REPOSITORY_KEY, getRepoName()); } else { book.getBookMetaData().putProperty(DownloadManager.REPOSITORY_KEY, getRepoName()); } } }
private Book getLatest(Book previous, Book current) { if (previous==null) { return current; } // SBMD defaults t0 1.0.0 if version does not exist Version previousVersion = new Version(previous.getBookMetaData().getProperty("Version")); Version currentVersion = new Version(current.getBookMetaData().getProperty("Version")); if (previousVersion.compareTo(currentVersion)<0) { return current; } else { return previous; } }
public boolean isNewer(final Book book) { SwordBookMetaData sbmd = (SwordBookMetaData) book.getBookMetaData(); File conf = sbmd.getConfigFile(); // The conf may not exist in our download dir. // In this case we say that it should not be downloaded again. if (conf == null || !conf.exists()) { return false; } URI configURI = NetUtil.getURI(conf); URI remote = toRemoteURI(book); return NetUtil.isNewer(remote, configURI, proxyHost, proxyPort); }
/** * @param i the current position in the array of books * @return the versification of the book. */ private Versification getVersification(final int i) { return Versifications.instance().getVersification( books[i].getBookMetaData().getProperty(BookMetaData.KEY_VERSIFICATION)); }
public float getLatestIndexVersion(Book b) { if (b == null) { return getLatestIndexVersion(); } String value = props.get(PREFIX_LATEST_INDEX_VERSION_BOOK_OVERRIDE + IndexMetadata.getBookIdentifierPropSuffix(b.getBookMetaData()), props.get(LATEST_INDEX_VERSION)); return Float.parseFloat(value); }
public float getInstalledIndexVersion(Book b) { if (b == null) { return getInstalledIndexDefaultVersion(); } // e.g. look for Installed.Index.Version.Book.ESV[1.0.1] , else use // Installed.Index.DefaultVersion String value = props.get(PREFIX_INSTALLED_INDEX_VERSION_BOOK_OVERRIDE + IndexMetadata.getBookIdentifierPropSuffix(b.getBookMetaData()), props.get(INSTALLED_INDEX_DEFAULT_VERSION)); if (value == null) { return DEFAULT_INSTALLED_INDEX_VERSION; } return Float.parseFloat(value); }
public String getFontForBook(Book book) { String font = null; try { if (book!=null) { // sometimes an error occurs on following line - maybe due to missing language info in book metadata String langCode = book.getBookMetaData().getLanguage().getCode(); // is there a font for the book final String abbreviation = book.getAbbreviation(); font = fontProperties.getProperty(abbreviation); // is there a font for the language code if (StringUtils.isEmpty(font)) { font = fontProperties.getProperty(langCode); } log.debug("Book:" + abbreviation + " Language code:" + langCode + " Font:" + font); } } catch (Exception e) { // sometimes get here if a book has no initials - so do not attempt to print a books initials in the error log.warn("Problem getting font for book", e); } return font; }
/** * Clients can use this to determine if book's index is stale and needs to re-indexed or downloaded. * Assumes index exists: Client must use isIndexed() prior to using this method * * @return true, if Latest.Index.Version.xxx > Installed.Index.Version.xxx * @see org.crosswire.jsword.index.IndexManager#needsReindexing(org.crosswire.jsword.book.Book) */ public boolean needsReindexing(Book book) { //check for index version //should Clients use IndexStatus.INVALID float installedV = InstalledIndex.instance().getInstalledIndexVersion(book); if (installedV < IndexMetadata.instance().getLatestIndexVersion(book)) { log.info("{}: needs reindexing, Installed index version @{}", book.getBookMetaData().getInitials(), Float.toString(installedV)); return true; } return false; }
private void handleAbout(List<Book> documents) { Book document = documents.get(0); try { // ensure repo key is retained but reload sbmd to ensure About text is loaded SwordBookMetaData sbmd = (SwordBookMetaData)document.getBookMetaData(); String repoKey = sbmd.getProperty(DownloadManager.REPOSITORY_KEY); sbmd.reload(); sbmd.setProperty(DownloadManager.REPOSITORY_KEY, repoKey); showAbout(document); } catch (BookException e) { Log.e(TAG, "Error expanding SwordBookMetaData for " + document, e); Dialogs.getInstance().showErrorMsg(R.string.error_occurred, e); } }
/** * Determine where an index should be stored * * @param book * The book to be indexed * @return A URI to store stuff in * @throws IOException * If there is a problem in finding where to store stuff */ protected URI getStorageArea(Book book) throws IOException { BookMetaData bmd = book.getBookMetaData(); String driverName = bmd.getDriverName(); String bookName = bmd.getInitials(); assert driverName != null; assert bookName != null; //URI driver = NetUtil.lengthenURI(baseFolderURI, driverName); return NetUtil.lengthenURI(baseFolderURI, driverName + NetUtil.SEPARATOR + bookName); }
public void storeInstalledIndexMetadata(Book b, String installedIndexVersionToStore) throws IOException { synchronized (writeLock) { props.put(PREFIX_INSTALLED_INDEX_VERSION_BOOK_OVERRIDE + IndexMetadata.getBookIdentifierPropSuffix(b.getBookMetaData()), installedIndexVersionToStore); NetUtil.storeProperties(props, getPropertyFileURI(), metadataFileComment); } }
public void removeFromInstalledIndexMetadata(Book b) throws IOException { synchronized (writeLock) { props.remove(PREFIX_INSTALLED_INDEX_VERSION_BOOK_OVERRIDE + IndexMetadata.getBookIdentifierPropSuffix(b.getBookMetaData())); NetUtil.storeProperties(props, getPropertyFileURI(), metadataFileComment); } }
public void storeLatestVersionAsInstalledIndexMetadata(Book b) throws IOException { synchronized (writeLock) { props.put(PREFIX_INSTALLED_INDEX_VERSION_BOOK_OVERRIDE + IndexMetadata.getBookIdentifierPropSuffix(b.getBookMetaData()), String.valueOf(IndexMetadata.instance().getLatestIndexVersion(b))); NetUtil.storeProperties(props, getPropertyFileURI(), metadataFileComment); } }
public boolean isIndexDownloadAvailable(Book document) throws InstallException, BookException { // not sure how to integrate reuse this in JSword index download String version = document.getBookMetaData().getProperty("Version"); String versionSuffix = version!=null ? "-" + new Version(version).toString() : ""; String url = "http://www.crosswire.org/and-bible/indices/v1/"+document.getInitials()+versionSuffix+".zip"; return CommonUtils.isHttpUrlAvailable(url); }
/** * Accessor for the root OSIS element * * @return the root of the OSIS document representing this data * @throws BookException if there is any problem with this request */ public Element getOsis() throws BookException { if (osis == null) { // TODO(DMS): Determine the proper representation of the OSISWork // name for multiple books. osis = OSISUtil.createOsisFramework(getFirstBook().getBookMetaData()); Element text = osis.getChild(OSISUtil.OSIS_ELEMENT_OSISTEXT); Element div = getOsisFragment(); text.addContent(div); } return osis; }
public void downloadDocument(Book document) throws LucidException { Log.d(TAG, "Download requested"); // ensure SBMD is fully, not just partially, loaded BookMetaData bmd = document.getBookMetaData(); if (bmd!=null && bmd instanceof SwordBookMetaData) { // load full bmd but must retain repo key String repoKey = bmd.getProperty(DownloadManager.REPOSITORY_KEY); ((SwordBookMetaData)bmd).reload(); bmd.setProperty(DownloadManager.REPOSITORY_KEY, repoKey); } if (!downloadQueue.isInQueue(document)) { // the download happens in another thread RepoBase repo = repoFactory.getRepoForBook(document); downloadQueue.addDocumentToDownloadQueue(document, repo); // if a font is required then download that too String font = fontControl.getFontForBook(document); if (!StringUtils.isEmpty(font) && !fontControl.exists(font)) { // the download happens in another thread fontControl.downloadFont(font); } } }
public LuceneAnalyzer(Book book) { // The default analysis analyzer = new PerFieldAnalyzerWrapper(new SimpleAnalyzer()); if (InstalledIndex.instance().getInstalledIndexDefaultVersion() > IndexMetadata.INDEX_VERSION_1_1) { // Content is analyzed using natural language analyzer // (stemming, stopword etc) Analyzer myNaturalLanguageAnalyzer = AnalyzerFactory.getInstance().createAnalyzer(book); analyzer.addAnalyzer(LuceneIndex.FIELD_BODY, myNaturalLanguageAnalyzer); //analyzer.addAnalyzer(LuceneIndex.FIELD_HEADING, myNaturalLanguageAnalyzer); //heading to use same analyzer as BODY //analyzer.addAnalyzer(LuceneIndex.FIELD_INTRO, myNaturalLanguageAnalyzer); log.debug("{}: Using languageAnalyzer: {}", book.getBookMetaData().getInitials(), myNaturalLanguageAnalyzer.getClass().getName()); } // Keywords are normalized to osisIDs analyzer.addAnalyzer(LuceneIndex.FIELD_KEY, new KeyAnalyzer()); // Strong's Numbers are normalized to a consistent representation analyzer.addAnalyzer(LuceneIndex.FIELD_STRONG, new StrongsNumberAnalyzer()); // Strong's Numbers and Robinson's morphological codes are normalized to a consistent representation analyzer.addAnalyzer(LuceneIndex.FIELD_MORPHOLOGY, new MorphologyAnalyzer()); // XRefs are normalized from ranges into a list of osisIDs analyzer.addAnalyzer(LuceneIndex.FIELD_XREF, new XRefAnalyzer()); }