Search in sources :

Example 1 with PassageKeyFactory

use of org.crosswire.jsword.passage.PassageKeyFactory in project step by STEPBible.

the class JSwordPassageServiceImpl method getAllReferencesAndCounts.

/**
 * @param references a list of references to be parsed
 * @param version    the version against which the refs are parsed
 * @return a String representing all the references
 */
@Override
public StringAndCount getAllReferencesAndCounts(final String references, final String version) {
    int count = 0;
    // TODO - can be refactored to optimize the reference query when used in subject searches...
    final PassageKeyFactory keyFactory = PassageKeyFactory.instance();
    final Versification av11n = this.versificationService.getVersificationForVersion(version);
    final StringBuilder referenceString = new StringBuilder(1024);
    try {
        final Key k = keyFactory.getKey(av11n, references);
        final Iterator<Key> iterator = k.iterator();
        while (iterator.hasNext()) {
            referenceString.append(iterator.next().getOsisID());
            count++;
            if (iterator.hasNext()) {
                referenceString.append(' ');
            }
        }
        return new StringAndCount(referenceString.toString(), count);
    } catch (final NoSuchKeyException e) {
        throw new TranslatedException(e, "invalid_reference_in_book", references, version);
    }
}
Also used : NoSuchKeyException(org.crosswire.jsword.passage.NoSuchKeyException) StringAndCount(com.tyndalehouse.step.core.models.StringAndCount) PassageKeyFactory(org.crosswire.jsword.passage.PassageKeyFactory) TranslatedException(com.tyndalehouse.step.core.exceptions.TranslatedException) Versification(org.crosswire.jsword.versification.Versification) Key(org.crosswire.jsword.passage.Key)

Aggregations

TranslatedException (com.tyndalehouse.step.core.exceptions.TranslatedException)1 StringAndCount (com.tyndalehouse.step.core.models.StringAndCount)1 Key (org.crosswire.jsword.passage.Key)1 NoSuchKeyException (org.crosswire.jsword.passage.NoSuchKeyException)1 PassageKeyFactory (org.crosswire.jsword.passage.PassageKeyFactory)1 Versification (org.crosswire.jsword.versification.Versification)1