/** * Obtain a SAX event provider for the OSIS document representation of one * or more book entries. * * @param bookInitials * the book to use * @param reference * a reference, appropriate for the book, of one or more entries */ private SAXEventProvider getOSISProvider(String bookInitials, String reference, int start, int count) throws BookException, NoSuchKeyException { BookData data = getBookData(bookInitials, reference, start, count); SAXEventProvider provider = null; if (data != null) { provider = data.getSAXEventProvider(); } return provider; }
/** * 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); } }
/** 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); } }
SAXEventProvider osissep = bdata.getSAXEventProvider(); try { buildEntryOpen(buf, key.getName(), XMLUtil.writeToString(osissep));
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); } }
return data.getSAXEventProvider();
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();
SAXEventProvider osissep = data.getSAXEventProvider();