/** * Dummy display routine. We might want to add some XSL styling to this. * * @param ref * The passage to format for display * @throws BookException */ private void dummyDisplay(Passage ref) throws BookException { new BookData(book, ref).getOsisFragment(); }
/** * Perform a test read on a single key */ private static void testReadSingle(Book book, Key key, int entry) { Throwable oops = null; try { log.debug("reading: {}/{}:{}", book.getInitials(), Integer.toString(entry), key.getName()); BookData data = new BookData(book, key); if (data.getOsisFragment() == null) { log.warn("No output from: {},{}", book.getInitials(), key.getOsisID()); } // This might be a useful extra test, except that a failure gives // you no help at all. // data.validate(); } catch (BookException ex) { oops = ex; } if (oops != null) { ++count; if (count < 5) { log.error("Unexpected error reading: {}, {}, {}, {}", book.getInitials(), Integer.toString(entry), key.getOsisID(), key.getClass().getName(), oops); } } }
/** * Get just the canonical text of one or more book entries without any * markup. * * @param book * the book to use * @param key * a reference, appropriate for the book, of one or more entries */ public String getCanonicalText(Book book, Key key) throws NoSuchKeyException, BookException, ParseException { try { BookData data = new BookData(book, key); SAXEventProvider osissep = data.getSAXEventProvider(); ContentHandler osisHandler = new OsisToCanonicalTextSaxHandler(); osissep.provideSAXEvents(osisHandler); return osisHandler.toString(); } catch (Exception e) { Log.e(TAG, "Error getting text from book" , e); return BibleApplication.Companion.getApplication().getString(R.string.error_occurred); } }
/** * While Bible and Commentary are very similar, a Dictionary is read in a * slightly different way. It is also worth looking at the JavaDoc for Book * that has a way of treating Bible, Commentary and Dictionary the same. * * @throws BookException * @see Book */ public void readDictionary() throws BookException { // This just gets a list of all the known dictionaries and picks the // first. In a real world app you will probably have a better way // of doing this. List<Book> dicts = Books.installed().getBooks(BookFilters.getDictionaries()); Book dict = dicts.get(0); // If I want every key in the Dictionary then I do this (or something // like it - in the real world you want to call hasNext() on an iterator // before next() but the point is the same: Key keys = dict.getGlobalKeyList(); Key first = keys.iterator().next(); System.out.println("The first Key in the default dictionary is " + first); BookData data = new BookData(dict, first); System.out.println("And the text against that key is " + OSISUtil.getPlainText(data.getOsisFragment())); }
analyze(sms, book, errors, subkey); } else { data = new BookData(book, subkey); osis = null;
/** Get Footnotes and references from specified document page */ public List<Note> readFootnotesAndReferences(Book book, Key key) throws ParseException { List<Note> retVal = new ArrayList<>(); try { // based on standard JSword SAX handling method because few performance gains would be gained for the extra complexity of Streaming BookData data = new BookData(book, key); SAXEventProvider osissep = data.getSAXEventProvider(); if (osissep != null) { OsisToHtmlSaxHandler osisToHtml = getSaxHandler(book, key, true); osissep.provideSAXEvents(osisToHtml); retVal = osisToHtml.getNotesList(); } else { Log.e(TAG, "No osis SEP returned"); } return retVal; } catch (Exception e) { log.error("Parsing error", e); throw new ParseException("Parsing error", e); } }
/** * Get text to be spoken without any markup. * * @param book * the book to use * @param key * a reference, appropriate for the book, of one or more entries */ public String getTextToSpeak(Book book, Key key) { try { BookData data = new BookData(book, key); SAXEventProvider osissep = data.getSAXEventProvider(); boolean sayReferences = BookCategory.GENERAL_BOOK.equals(book.getBookCategory()); ContentHandler osisHandler = new OsisToSpeakTextSaxHandler(sayReferences); osissep.provideSAXEvents(osisHandler); return osisHandler.toString(); } catch (Exception e) { Log.e(TAG, "Error getting text from book" , e); return BibleApplication.Companion.getApplication().getString(R.string.error_occurred); } }
/** * Get just the canonical text of one or more book entries without any * markup. * * @param bookInitials * the book to use * @param reference * a reference, appropriate for the book, of one or more entries * @return the plain text for the reference * @throws BookException * @throws NoSuchKeyException */ public String getPlainText(String bookInitials, String reference) throws BookException, NoSuchKeyException { Book book = getBook(bookInitials); if (book == null) { return ""; } Key key = book.getKey(reference); BookData data = new BookData(book, key); return OSISUtil.getCanonicalText(data.getOsisFragment()); }
BookData bdata = new BookData(book, key); SAXEventProvider osissep = bdata.getSAXEventProvider(); try {
private ArrayList<SpeakCommand> getSpeakCommandsForVerse(SpeakSettings settings, Book book, Key key) { try { BookData data = new BookData(book, key); Element frag = data.getOsisFragment(false); Document doc = frag.getDocument(); if (doc == null) { doc = new Document(frag); } SAXEventProvider osissep = new JDOMSAXEventProvider(doc); ContentHandler osisHandler = new OsisToBibleSpeak(settings, book.getLanguage().getCode()); osissep.provideSAXEvents(osisHandler); return ((OsisToBibleSpeak) osisHandler).getSpeakCommands(); } catch (Exception e) { Log.e(TAG, "Error getting text from book" , e); return new ArrayList<>(); } }
protected String readHtmlTextStandardJSwordMethod(Book book, Key key, boolean asFragment) throws ParseException { log.debug("Using standard JSword to fetch document data"); String retVal; try { BookData data = new BookData(book, key); SAXEventProvider osissep = data.getSAXEventProvider(); if (osissep == null) { Log.e(TAG, "No osis SEP returned"); retVal = "Error fetching osis SEP"; } else { OsisToHtmlSaxHandler osisToHtml = getSaxHandler(book, key, asFragment); osissep.provideSAXEvents(osisToHtml); retVal = osisToHtml.toString(); } return retVal; } catch (Exception e) { log.error("Parsing error", e); throw new ParseException("Parsing error", e); } }
/** * An example of how to do a search and then get text for each range of * verses. * * @throws BookException * @throws SAXException */ void searchAndShow() throws BookException, SAXException { Book bible = Books.installed().getBook(BIBLE_NAME); // Search for words like Melchezedik Key key = bible.find("melchesidec~"); // Here is an example of how to iterate over the ranges and get the text // for each. // The key's iterator would have iterated over verses. // The following shows how to use a stylesheet of your own choosing String path = "org/crosswire/jsword/xml/html5.xsl"; URL xslurl = ResourceUtil.getResource(path); // Make ranges break on chapter Iterator<VerseRange> rangeIter = ((Passage) key).rangeIterator(RestrictionType.CHAPTER); // boundaries. while (rangeIter.hasNext()) { Key range = rangeIter.next(); BookData data = new BookData(bible, range); SAXEventProvider osissep = data.getSAXEventProvider(); SAXEventProvider htmlsep = new TransformingSAXEventProvider(NetUtil.toURI(xslurl), osissep); String text = XMLUtil.writeToString(htmlsep); System.out.println("The html text of " + range.getName() + " is " + text); } }
data = new BookData(book, subkey); osis = null;
BookData data = new BookData(book, key);
public void testReadESVJSwordMethod() throws Exception { Book esv = getBook("ESV2011"); BookData data = new BookData(esv, esv.getKey("Phil 1:3")); SAXEventProvider osissep = data.getSAXEventProvider();
public void testReadRST() throws Exception { Book rst = getBook("RST"); BookData data = new BookData(rst, rst.getKey("Col 1")); SAXEventProvider osissep = data.getSAXEventProvider();
System.out.println(verse); BookData data = new BookData(esvs, esvs.getKey("1 Tim 6:9-11")); SAXEventProvider osissep = data.getSAXEventProvider();
return new BookData(book, key);