/** * Convert the passageReference into a Passage. This is the recommended * form for application constructed references and user input. Both of * these should have a fully qualified first reference. * * @param v11n * The Versification to which this Passage belongs. * @param passageReference * A String containing the text for the Passage * @return a new Passage filled with the desired Verses * @throws NoSuchKeyException * If the passageReference has anything that could not be understood as a Verse */ public Passage getKey(Versification v11n, String passageReference) throws NoSuchKeyException { return getKey(v11n, passageReference, null); }
/** * Convert the passageReference into a Passage or an empty Passage, * if there is an error. Note, this is not recommended as it throws * away the error. * * @param v11n * The Versification to which this Passage belongs. * @param passageReference * A String containing the text of the Passage * @param basis * The basis by which to interpret passageReference * @return a new Passage filled with the desired Verses or an empty Passage */ public Key getValidKey(Versification v11n, String passageReference, Key basis) { try { return getKey(v11n, passageReference, basis); } catch (NoSuchKeyException e) { return createEmptyKeyList(v11n); } }
/** * Return a Key representing the passage passed in or an empty passage if it can't be parsed. * @param passage Textual ref * @return */ public Key getKey(String passage) { Key key = null; try { // spaces confuse the osis parser passage = passage.trim(); // If expecting OSIS then use OSIS parser key = osisParser.parseOsisRef(v11n, passage); // OSIS parser is strict so try treating as normal ref if osis parser fails if (key==null) { Log.d(TAG, "Non OSIS Reading plan passage:"+passage); key = PassageKeyFactory.instance().getKey(v11n, passage); } } catch (Exception e) { Log.e(TAG, "Invalid passage reference in reading plan:"+passage); } // If all else fails return an empty passage to prevent NPE if (key==null) { key = PassageKeyFactory.instance().createEmptyKeyList(v11n); } return key; } }
public final Key getKey(String text) throws NoSuchKeyException { return PassageKeyFactory.instance().getKey(Versifications.instance().getVersification(versification), text); }
result.append("</a>"); } else { Passage ref = (Passage) PassageKeyFactory.instance().getKey(parameters.getDocumentVersification(), reference); boolean isSingleVerse = ref.countVerses()==1; boolean hasContent = content.length()>0;
@Override public void processContent(Book book, Key key, Element ele) { String refstr = ele.getValue(); try { if (ele.getAttribute(OSISUtil.OSIS_ATTR_REF) == null) { Passage ref = PassageKeyFactory.instance().getKey(KeyUtil.getVersification(key), refstr, key); String osisname = ref.getOsisRef(); ele.setAttribute(OSISUtil.OSIS_ATTR_REF, osisname); } } catch (NoSuchKeyException ex) { DataPolice.report(book, key, "scripRef has no passage attribute, unable to guess: (" + refstr + ") due to " + ex.getMessage()); } } }
@Override public Element processTag(Book book, Key key, Element ele, Attributes attrs) { Element reference = null; String refstr = attrs.getValue("passage"); if (refstr != null) { Passage ref = null; try { ref = PassageKeyFactory.instance().getKey(KeyUtil.getVersification(key), refstr, key); } catch (NoSuchKeyException ex) { DataPolice.report(book, key, "Unparsable passage: (" + refstr + ") due to " + ex.getMessage()); } // If we don't have a Passage then use the original string String osisname = ref != null ? ref.getOsisRef() : refstr; reference = OSISUtil.factory().createReference(); reference.setAttribute(OSISUtil.OSIS_ATTR_REF, osisname); } else { // The reference will be filled in by processContent reference = OSISUtil.factory().createReference(); } if (ele != null) { ele.addContent(reference); } return reference; }
/** * A space separate string containing osisID from the reference element. * We pass book and key because the xref may not be valid and it needs to be reported. * * @param book the book to which the references refer * @param key the verse containing the cross references * @param v11n the versification * @param root the osis element in question * @return The references in the text */ public static String getReferences(Book book, Key key, Versification v11n, Element root) { PassageKeyFactory keyf = PassageKeyFactory.instance(); Key collector = keyf.createEmptyKeyList(v11n); for (Content content : getDeepContent(root, OSISUtil.OSIS_ELEMENT_REFERENCE)) { Element ele = (Element) content; String attr = ele.getAttributeValue(OSISUtil.OSIS_ATTR_REF); if (attr != null) { try { collector.addAll(keyf.getKey(v11n, attr)); } catch (NoSuchKeyException e) { DataPolice.report(book, key, "Unable to parse: " + attr + " - No such reference:" + e.getMessage()); } } } return collector.getOsisID(); }
Passage ref = keyf.getKey(Versifications.instance().getVersification("KJV"), readings);
/** user has selected a Bible verse link */ private void showBible(String keyText) throws NoSuchKeyException { CurrentPageManager pageManager = getCurrentPageManager(); Book bible = pageManager.getCurrentBible().getCurrentDocument(); // get source versification Versification sourceDocumentVersification; Book currentDoc = pageManager.getCurrentPage().getCurrentDocument(); if (currentDoc instanceof AbstractPassageBook) { sourceDocumentVersification = ((AbstractPassageBook)currentDoc).getVersification(); } else { // default to v11n of current Bible. //TODO av11n issue. GenBooks have no v11n and this default would be used for links from GenBooks which would only sometimes be correct sourceDocumentVersification = ((AbstractPassageBook)bible).getVersification(); } // create Passage with correct source Versification Key key = PassageKeyFactory.instance().getKey(sourceDocumentVersification, keyText); // Bible not specified so use the default Bible version showLink(null, key); return; }
public void testTrickyWebChapters() throws Exception { { OSISInputStream osisInputStream = new OSISInputStream(webBook, PassageKeyFactory.instance().getKey(Versifications.instance().getVersification("KJV"), "Ps 1")); String chapter = convertStreamToString(osisInputStream); int numOpeningLs = count(chapter, "<l>") + count(chapter, "<l "); int numClosingLs = count(chapter, "</l>"); System.out.println(chapter); assertThat("wrong number of Ls", numOpeningLs, equalTo(numClosingLs)); } { OSISInputStream osisInputStream = new OSISInputStream(webBook, PassageKeyFactory.instance().getKey(Versifications.instance().getVersification("KJV"), "Gen 49")); String chapter = convertStreamToString(osisInputStream); int numOpeningLs = count(chapter, "<l>") + count(chapter, "<l "); int numClosingLs = count(chapter, "</l>"); System.out.println(chapter); assertThat("wrong number of Ls", numOpeningLs, equalTo(numClosingLs)); } }