public String getOsisID() { return keys.getOsisID(); }
@Override public void visitLeaf(Key key) { buffer.append(key.getOsisID()); buffer.append(AbstractPassage.REF_OSIS_DELIM); }
/** Ensure each verse has the appropriate OSIS verse tag. * * @param verse * @param plain * @return */ private String addVerseTag(Key verse, String plain) { String ret = plain; if (!plain.contains("<"+OSISUtil.OSIS_ELEMENT_VERSE)) { StringBuilder bldr = new StringBuilder(); bldr.append(VERSE_OPENING_TAG_START).append(verse.getOsisID()).append(VERSE_OPENING_TAG_END).append(plain).append(VERSE_CLOSING_TAG); ret = bldr.toString(); } return ret; }
public String getOsisID() { StringBuilder retcode = new StringBuilder(); Iterator<VerseRange> it = rangeIterator(RestrictionType.NONE); boolean hasNext = it.hasNext(); while (hasNext) { Key range = it.next(); retcode.append(range.getOsisID()); hasNext = it.hasNext(); if (hasNext) { retcode.append(AbstractPassage.REF_OSIS_DELIM); } } return retcode.toString(); }
public String locate(Key key) throws BookException { StringBuilder buf = new StringBuilder(); //FIXME(iteration should be pushed down for performanace gains for (Key currentKey : key) { String osisID = currentKey.getOsisID(); if (buf.length() > 0) { buf.append('\n'); } buf.append(book.getInitials()); buf.append(':'); buf.append(osisID); buf.append(" - "); String rawText = book.getRawText(currentKey); if (rawText != null && rawText.trim().length() > 0) { buf.append(rawText); } else { buf.append("Not found"); } } return buf.toString(); }
/** * Report a message against the current book and key. * * @param book * the book against which to report * @param key * the key against which to report * @param message * the police report. */ public static void report(Book book, Key key, String message) { if (!reporting) { return; } StringBuilder buf = new StringBuilder(); BookMetaData bmd = book.getBookMetaData(); if (bmd != null) { buf.append(bmd.getInitials()); } if (bmd != null && key != null) { buf.append(':'); } if (key != null) { buf.append(key.getOsisID()); } buf.append(": "); buf.append(message); LOGGER.info(buf.toString()); }
/** * 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); } } }
/** called during app close down to save state */ @Override public JSONObject getStateJson() throws JSONException { JSONObject object = new JSONObject(); if (currentDocument!=null) { Log.d(TAG, "Getting json state for "+getBookCategory().getName()); object.put("document", getCurrentDocument().getInitials()); if (this.getKey()!=null) { object.put("key", getKey().getOsisID()); } } return object; }
@Nullable @Override public View getView(int position, View convertView, ViewGroup parent) { Key item = getItem(position); // Pick up the TwoLineListItem defined in the xml file TextView view; if (convertView == null) { LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); view = (TextView) inflater.inflate(resource, parent, false); } else { view = (TextView) convertView; } // Set value for the first text field if (view != null) { String key = item.getOsisID(); // make all uppercase in Calvin's Institutes look nicer if (ABStringUtils.isAllUpperCaseWherePossible(key)) { key = WordUtils.capitalizeFully(key); } view.setText(key); } return view; } }
orig = book.getRawText(key); } catch (BookException ex) { log.warn("Failed to read: {}({}):{}", book.getInitials(), key.getOsisID(), ex.getMessage(), ex); return;
public void setAliasKey(Key alias, Key source) throws BookException { T state = null; try { state = initState(); setAliasKey(state, alias, source); } catch (IOException e) { throw new BookException(JSOtherMsg.lookupText("Unable to save {0}.", alias.getOsisID())); } finally { OpenFileStateManager.instance().release(state); } }
/** * 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 addOSIS(Key key, Element div, List<Content> osisContent) { // See if the text is marked up with verses // If it is then just add it. for (Content content : osisContent) { if (content instanceof Element) { Element ele = (Element) content; if (ele.getName().equals(OSISUtil.OSIS_ELEMENT_VERSE)) { super.addOSIS(key, div, osisContent); return; } } } // If we get here then the text is not marked up with verse // In this case we add the verse markup, if the verse is not 0. if (KeyUtil.getVerse(key).getVerse() == 0) { super.addOSIS(key, div, osisContent); } else { // In a SWORD module, the verse element is to be put // after the "preverse" material. Element everse = OSISUtil.factory().createVerse(); everse.setAttribute(OSISUtil.OSIS_ATTR_OSISID, key.getOsisID()); div.addContent(everse); super.addOSIS(key, everse, osisContent); } }
retVal = HtmlMessageFormatter.format(errorMsg); } else if (!bookContainsAnyOf(book, key)) { Log.w(TAG, "KEY:"+key.getOsisID()+" not found in doc:"+book); retVal = HtmlMessageFormatter.format(R.string.error_key_not_in_document); } else {
/** * 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(); }