/** * 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(); }
/** * 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; }
/** * Loops around contents and calls addText for a single element * * @param doDiffs true for calculating differences * @param newText the newText buffer used to compare one portion of text to another * @param contents the contents to be added */ private void addText(boolean doDiffs, StringBuilder newText, List<Content> contents) { for (Content c : contents) { addText(doDiffs, newText, c); } }
/** * 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; }
/** * 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); } }
passages[i] = VersificationsMapper.instance().map(KeyUtil.getPassage(key), getVersification(i)); doDiffs |= addHeaderAndSetShowDiffsState(row, showDiffs, i, ommittedVerses[i]); booksContents[i] = keyIteratorContentByVerse( getVersification(i), iters[i]); Key verseInRelavantBookContents = VersificationsMapper.instance().mapVerse(verseContent.getKey(), getVersification(i)); addText(doDiffs, newText, xmlContent); addContentSafely(cell, xmlContent); cellCount++;
return new BookData(book, key);
/** * Output the current data as a SAX stream. * * @return A way of posting SAX events * @throws BookException if there is any problem with this request */ public SAXEventProvider getSAXEventProvider() throws BookException { // If the fragment is already in a document, then use that. Element frag = getOsisFragment(); Document doc = frag.getDocument(); if (doc == null) { doc = new Document(frag); } return new JDOMSAXEventProvider(doc); }
/** * Accessor for the requested data in OSIS format. * * @return the fragment of the OSIS document representing this data * @throws BookException if there is any problem with this request */ public Element getOsisFragment() throws BookException { if (fragment == null) { fragment = getOsisContent(true); } return fragment; }
/** * JDOM will throw an exception if we try and add the content to multiple parents. * As a result, we take the opportunity to add it safely, and add a note indicating * this content appears twice. * * @param cell the element to be added * @param xmlContent the collector of content */ private void addContentSafely(final Element cell, final List<Content> xmlContent) { Element note = null; for (Content c : xmlContent) { if (c.getParent() == null) { cell.addContent(c); } else if (note != null) { note.addContent(c.clone()); } else { //we're in the situation where we have added this already. //add note. In this case, we wrap the content that has already been applied. note = appendVersificationNotice(cell, "duplicate"); note.addContent(c.clone()); } } }
/** 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); } }
/** * For when we want to add writing functionality. This does not work. * * @param key * @param bdata * @throws BookException */ public void setDocument(Key key, BookData bdata) throws BookException { // For all of the sections for (Content nextElem : OSISUtil.getFragment(bdata.getOsisFragment())) { if (nextElem instanceof Element) { Element div = (Element) nextElem; // For all of the Verses in the section for (Content data : div.getContent()) { if (data instanceof Element) { Element overse = (Element) data; String text = OSISUtil.getPlainText(overse); setRawText(key, text); } else { log.error("Ignoring non OSIS/Verse content of DIV."); } } } else { log.error("Ignoring non OSIS/Verse content of DIV."); } } }
/** * Accessor for the root OSIS element * * @param allowGenTitles whether to generate titles * @return the root of the document * @throws BookException if there is any problem with this request */ public Element getOsisFragment(boolean allowGenTitles) throws BookException { if (fragment == null) { fragment = getOsisContent(allowGenTitles); } return fragment; }
Element notice = this.appendVersificationNotice(cell, "omitted-verses"); notice.addContent(text); } else {
/** * 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()); }
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); } }
/** * 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); } } }
BookData bdata = new BookData(book, key); SAXEventProvider osissep = bdata.getSAXEventProvider(); try { buildEntryOpen(buf, key.getName(), XMLUtil.writeToString(osissep));
/** * 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())); }