public String getProperty(String key) { return bmd.getProperty(key); }
public static String getBookIdentifierPropSuffix(BookMetaData meta) { String moduleVer = null; if (meta.getProperty("Version") != null) { moduleVer = '[' + meta.getProperty("Version") + ']'; } return meta.getInitials() + moduleVer; }
/** * Construct an AbstractPassageBook given the BookMetaData and the AbstractBackend. * * @param bmd the metadata that describes the book * @param backend the means by which the resource is accessed */ public AbstractPassageBook(BookMetaData bmd, Backend backend) { super(bmd, backend); keyf = PassageKeyFactory.instance(); this.versification = bmd.getProperty(BookMetaData.KEY_VERSIFICATION); }
private String normalizeForSearch(String internalKey) { BookMetaData bmd = getBookMetaData(); String keytitle = internalKey; String caseSensitive = bmd.getProperty(SwordBookMetaData.KEY_CASE_SENSITIVE_KEYS); if (!"true".equalsIgnoreCase(caseSensitive) && !BookCategory.DAILY_DEVOTIONS.equals(bmd.getBookCategory())) { return keytitle.toUpperCase(Locale.US); } return keytitle; }
protected String getRawText(DataEntry entry) { String cipherKeyString = getBookMetaData().getProperty(SwordBookMetaData.KEY_CIPHER_KEY); byte[] cipherKeyBytes = null; if (cipherKeyString != null) { try { cipherKeyBytes = cipherKeyString.getBytes(getBookMetaData().getBookCharset()); } catch (UnsupportedEncodingException e) { cipherKeyBytes = cipherKeyString.getBytes(); } } return entry.getRawText(cipherKeyBytes); }
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; } }
/** * @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 void decipher(byte[] data) { String cipherKeyString = getBookMetaData().getProperty(SwordBookMetaData.KEY_CIPHER_KEY); if (cipherKeyString != null) { Sapphire cipherEngine = new Sapphire(cipherKeyString.getBytes()); for (int i = 0; i < data.length; i++) { data[i] = cipherEngine.cipher(data[i]); } // destroy any evidence! cipherEngine.burn(); } }
public Versification getVersification() { if (this.versificationSystem == null) { this.versificationSystem = Versifications.instance().getVersification(getBookMetaData().getProperty(BookMetaData.KEY_VERSIFICATION)); } return versificationSystem; }
/** * Read all the books that we can get our hands on. * * @param args * @throws IOException */ public static void main(String[] args) throws IOException { out = new PrintWriter(new BufferedWriter(new FileWriter("passages.log"))); // Loop through all the Books log.warn("*** Reading all known Books"); BookFilter filter = BookFilters.getCustom("GlobalOptionFilter=ThMLScripref;Category=Biblical Texts"); List<Book> comments = Books.installed().getBooks(filter); for (Book book : comments) { if (!book.isLocked()) { BookMetaData bmd = book.getBookMetaData(); // Skip PlainText as they do not have references marked up if (bmd.getProperty("SourceType") != null) { Key set = book.getGlobalKeyList(); readBook(book, set); } } } out.flush(); out.close(); }
private void prepopulateIndexFiles(RawFileBackendState state) throws IOException { String v11nName = getBookMetaData().getProperty(BookMetaData.KEY_VERSIFICATION); Versification v11n = Versifications.instance().getVersification(v11nName); int otCount = v11n.getCount(Testament.OLD); int ntCount = v11n.getCount(Testament.NEW) + 1; BufferedOutputStream otIdxBos = new BufferedOutputStream(new FileOutputStream(state.getIdxFile(Testament.OLD), false)); try { for (int i = 0; i < otCount; i++) { writeInitialIndex(otIdxBos); } } finally { otIdxBos.close(); } BufferedOutputStream ntIdxBos = new BufferedOutputStream(new FileOutputStream(state.getIdxFile(Testament.NEW), false)); try { for (int i = 0; i < ntCount; i++) { writeInitialIndex(ntIdxBos); } } finally { ntIdxBos.close(); } }
/** * Returns where the book should be located * @param bookMetaData meta information about the book * @return the URI locating the resource * @throws BookException thrown if an issue is encountered, e.g. missing data files. */ public static URI getExpandedDataPath(BookMetaData bookMetaData) throws BookException { URI loc = NetUtil.lengthenURI(bookMetaData.getLibrary(), bookMetaData.getProperty(SwordBookMetaData.KEY_DATA_PATH)); if (loc == null) { // FIXME(DMS): missing parameter throw new BookException(JSOtherMsg.lookupText("Missing data files for old and new testaments in {0}.")); } return loc; }
/** * Iterate all books checking if document contains a verse from the book */ private Set<BibleBook> calculateBibleBookList() { final BookMetaData bookMetaData = this.getBookMetaData(); final VerseKey scope = (VerseKey) getScope(); if (scope == null) { return new HashSet<BibleBook>(); } final Set<BibleBook> bookList = new LinkedHashSet<BibleBook>(); // iterate over all book possible in this document final Versification v11n = Versifications.instance().getVersification(bookMetaData.getProperty(BookMetaData.KEY_VERSIFICATION)); final Iterator<BibleBook> v11nBookIterator = v11n.getBookIterator(); while (v11nBookIterator.hasNext()) { BibleBook bibleBook = v11nBookIterator.next(); // test some random verses - normally ch1 v 1 is sufficient - but we don't want to miss any if (scope.contains(new Verse(v11n, bibleBook, 1, 1)) || scope.contains(new Verse(v11n, bibleBook, 1, 2))) { bookList.add(bibleBook); } } return bookList; }
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); }
/** * Obtains the set of bible books from the internal configuration file, creating it if required. * @return the bible books relevant to this module. */ private Set<BibleBook> getBibleBooksInternal() { String list = this.getBookMetaData().getProperty(BookMetaData.KEY_BOOKLIST); Set<BibleBook> books; if (list == null) { //calculate and store books = calculateBibleBookList(); String listOfBooks = toString(books); this.putProperty(BookMetaData.KEY_BOOKLIST, listOfBooks); } else { //iterate through each item and get the books as a bible books books = fromString(list); } return books; }
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 String readRawContent(RawBackendState state, Key key) throws IOException { String v11nName = getBookMetaData().getProperty(BookMetaData.KEY_VERSIFICATION); Versification v11n = Versifications.instance().getVersification(v11nName); Verse verse = KeyUtil.getVerse(key); int index = verse.getOrdinal(); Testament testament = v11n.getTestament(index); index = v11n.getTestamentOrdinal(index); RawBackendState initState = null; try { initState = initState(); return getEntry(state, verse.getName(), testament, index); } catch (BookException e) { return ""; } finally { OpenFileStateManager.instance().release(initState); } }
public void setAliasKey(RawFileBackendState state, Key alias, Key source) throws IOException { String v11nName = getBookMetaData().getProperty(BookMetaData.KEY_VERSIFICATION); Versification v11n = Versifications.instance().getVersification(v11nName); Verse aliasVerse = KeyUtil.getVerse(alias); Verse sourceVerse = KeyUtil.getVerse(source); int aliasIndex = aliasVerse.getOrdinal(); Testament testament = v11n.getTestament(aliasIndex); aliasIndex = v11n.getTestamentOrdinal(aliasIndex); RandomAccessFile idxRaf = state.getIdxRaf(testament); int sourceOIndex = sourceVerse.getOrdinal(); sourceOIndex = v11n.getTestamentOrdinal(sourceOIndex); DataIndex dataIndex = getIndex(idxRaf, sourceOIndex); // Only the index is updated to point to the same place as what is // linked. updateIndexFile(idxRaf, aliasIndex, dataIndex.getOffset()); }
public void setRawText(RawFileBackendState state, Key key, String text) throws BookException, IOException { String v11nName = getBookMetaData().getProperty(BookMetaData.KEY_VERSIFICATION); Versification v11n = Versifications.instance().getVersification(v11nName); Verse verse = KeyUtil.getVerse(key); int index = verse.getOrdinal(); Testament testament = v11n.getTestament(index); index = v11n.getTestamentOrdinal(index); RandomAccessFile idxRaf = state.getIdxRaf(testament); RandomAccessFile txtRaf = state.getTextRaf(testament); File txtFile = state.getTextFile(testament); DataIndex dataIndex = getIndex(idxRaf, index); File dataFile; if (dataIndex.getSize() == 0) { dataFile = createDataTextFile(state.getIncfileValue()); updateIndexFile(idxRaf, index, txtRaf.length()); updateDataFile(state.getIncfileValue(), txtFile); checkAndIncrementIncfile(state, state.getIncfileValue()); } else { dataFile = getDataTextFile(txtRaf, dataIndex); } byte[] textData = text.getBytes("UTF-8"); encipher(textData); writeTextDataFile(dataFile, textData); }
@Override public int getRawTextLength(Key key) { String v11nName = getBookMetaData().getProperty(BookMetaData.KEY_VERSIFICATION); Versification v11n = Versifications.instance().getVersification(v11nName); Verse verse = KeyUtil.getVerse(key); RawBackendState initState = null; try { int index = verse.getOrdinal(); Testament testament = v11n.getTestament(index); index = v11n.getTestamentOrdinal(index); initState = initState(); RandomAccessFile idxRaf = initState.getIdxRaf(testament); // If this is a single testament Bible, return nothing. if (idxRaf == null) { return 0; } DataIndex dataIndex = getIndex(idxRaf, index); return dataIndex.getSize(); } catch (IOException ex) { return 0; } catch (BookException e) { return 0; } finally { OpenFileStateManager.instance().release(initState); } }