/** * Construct an AbstractPassageBook given the BookMetaData and the AbstractBackend. * * @param bmd the metadata that describes the book * @param backend the means by which the resource is accessed */ public AbstractPassageBook(BookMetaData bmd, Backend backend) { super(bmd, backend); keyf = PassageKeyFactory.instance(); this.versification = bmd.getProperty(BookMetaData.KEY_VERSIFICATION); }
/** * 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; } }
private Key getReferenceKey() { Key key=null; try { if (noteType.equals(NoteType.TYPE_REFERENCE)) { String reference = StringUtils.isNotEmpty(osisRef) ? osisRef : noteText; key = PassageKeyFactory.instance().getValidKey(v11n, reference); } } catch (Exception e) { log.warn("Error getting note reference for osisRef "+osisRef, e); } 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;
/** * Cast a Key to a Passage. Only those keys that are a Passage or can * be held by a Passage (i.e. Verse and VerseRange) may be cast to one. * If you pass a null key into this method, you get a null Passage out. * * @param key The key to cast * @return The key cast to a Passage * @throws ClassCastException */ public static Passage getPassage(Key key) { if (key == null) { return null; } if (key instanceof Passage) { return (Passage) key; } if (key instanceof VerseKey) { VerseKey verseKey = (VerseKey) key; Key ref = PassageKeyFactory.instance().createEmptyKeyList(verseKey.getVersification()); ref.addAll(verseKey); return (Passage) ref; } throw new ClassCastException("Expected key to be a Verse, VerseRange or Passage"); }
public final Key getGlobalKeyList() { if (global == null) { try { global = getBackend().getGlobalKeyList(); return global; } catch (UnsupportedOperationException ex) { // fail silently, operation not supported by the backend log.debug(ex.getMessage()); } catch (BookException ex) { // failing silently, as previous behavior was to attempt to // return as much as we can using the slower method log.debug(ex.getMessage()); } Versification v11n = super.getVersification(); global = super.createEmptyKeyList(); Key all = PassageKeyFactory.instance().getGlobalKeyList(v11n); for (Key key : all) { if (contains(key)) { global.addAll(key); } } } return global; }
/** * Flexible converter for the generic Key base class. * Return the key in the required versification, mapping if necessary * Currently only handles Passage, RangedPassage, and Verse */ public Key convert(Key key, Versification toVersification) { try { if (key instanceof RangedPassage) { return convert((RangedPassage)key, toVersification); } else if (key instanceof VerseRange) { return convert((VerseRange)key, toVersification); } else if (key instanceof Passage) { return convert((Passage)key, toVersification); } else if (key instanceof Verse) { return convert((Verse)key, toVersification); } } catch (Exception e) { // unexpected problem during mapping Log.e(TAG, "JSword Versification mapper failed to map "+key.getOsisID()+" to "+toVersification.getName(), e); } return PassageKeyFactory.instance().createEmptyKeyList(toVersification); }
@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; }
PassageKeyFactory keyf = PassageKeyFactory.instance(); Passage ref = keyf.getKey(Versifications.instance().getVersification("KJV"), readings);
/** * 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(); }
/** 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)); } }