/** * 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); } } }
/** * 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); }
/** * 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."); } } }
/** * 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())); }
osis = data.getOsisFragment(); } catch (BookException e) { errors.add(subkey);
/** * 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()); }
/** * 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; }
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<>(); } }
osis = data.getOsisFragment(false); } catch (BookException e) { errors.add(subkey);