use of com.tyndalehouse.step.core.models.OsisWrapper in project step by STEPBible.
the class BibleInformationServiceImpl method getPassageText.
/**
* Gets the passage text.
*
* @param version the version
* @param reference the reference
* @param options the options
* @param interlinearVersion the interlinear version
* @param interlinearMode the interlinear mode
* @return the passage text
*/
// TODO: this could be optimized. last call to get options is very similar to 'getLookupOptions'
// as they share some of the same stuff.
@Override
@Timed(name = "passage-lookup", group = "service", rateUnit = TimeUnit.SECONDS, durationUnit = TimeUnit.MILLISECONDS)
public OsisWrapper getPassageText(final String version, final String reference, final String options, final String interlinearVersion, final String interlinearMode, final String userLanguage) {
final List<String> extraVersions = getExtraVersionsFromString(interlinearVersion);
final InterlinearMode desiredModeOfDisplay = this.optionsValidationService.getDisplayMode(interlinearMode, version, extraVersions);
OsisWrapper passageText;
final List<TrimmedLookupOption> removedOptions = new ArrayList<TrimmedLookupOption>(4);
final List<LookupOption> inputLookupOptions = this.optionsValidationService.getLookupOptions(options);
final InterlinearMode realModeOfDisplay = this.optionsValidationService.determineDisplayMode(inputLookupOptions, desiredModeOfDisplay, true);
final Set<LookupOption> lookupOptions = this.optionsValidationService.trim(inputLookupOptions, version, extraVersions, desiredModeOfDisplay, realModeOfDisplay, removedOptions);
if (INTERLINEAR != desiredModeOfDisplay && NONE != desiredModeOfDisplay) {
// split the versions
lookupOptions.add(LookupOption.VERSE_NUMBERS);
final String[] versions = getInterleavedVersions(version, interlinearVersion);
passageText = this.jswordPassage.getInterleavedVersions(versions, reference, new ArrayList<>(lookupOptions), desiredModeOfDisplay, userLanguage);
} else {
passageText = this.jswordPassage.getOsisText(version, reference, new ArrayList(lookupOptions), interlinearVersion, desiredModeOfDisplay);
}
passageText.setRemovedOptions(removedOptions);
passageText.setPreviousChapter(this.jswordPassage.getSiblingChapter(passageText.getOsisId(), version, true));
passageText.setNextChapter(this.jswordPassage.getSiblingChapter(passageText.getOsisId(), version, false));
passageText.setOptions(this.optionsValidationService.optionsToString(this.optionsValidationService.getAvailableFeaturesForVersion(version, extraVersions, interlinearMode, realModeOfDisplay).getOptions()));
// the passage lookup wasn't made with the removed options, however, the client needs to think these were selected.
passageText.setSelectedOptions(this.optionsValidationService.optionsToString(lookupOptions) + getRemovedOptions(removedOptions));
return passageText;
}
use of com.tyndalehouse.step.core.models.OsisWrapper in project step by STEPBible.
the class JSwordSearchServiceImpl method getPassagesForResults.
/**
* Looks up all passages represented by the key
*
* @param result the results that we will be returning
* @param versions the bibles under examination
* @param results the list of results
* @param context amount of context to add
* @param options to use to lookup the right parameterization of the text
* @return the list of entries found
*/
private void getPassagesForResults(SearchResult result, String[] versions, final Key results, final int context, final List<LookupOption> options, String interlinearMode) {
final List<SearchEntry> resultPassages = new ArrayList<SearchEntry>();
final Iterator<Key> iterator = ((Passage) results).iterator();
boolean interlinearModeCaptured = false;
int count = 0;
while (iterator.hasNext()) {
final Key verse = iterator.next();
final Key lookupKey;
if (verse instanceof Verse) {
// then we need to make it into a verse range
final Verse verseAsVerse = (Verse) verse;
final VerseRange vr = new VerseRange(verseAsVerse.getVersification(), verseAsVerse);
vr.blur(context, RestrictionType.NONE);
lookupKey = vr;
} else {
// assume blur is supported
verse.blur(context, RestrictionType.NONE);
lookupKey = verse;
}
if (count == 1) {
options.add(LookupOption.HIDE_COMPARE_HEADERS);
}
// TODO this is not very efficient so requires refactoring
final OsisWrapper peakOsisText = this.jsword.peakOsisText(versions, lookupKey, options, interlinearMode);
resultPassages.add(new VerseSearchEntry(peakOsisText.getReference(), peakOsisText.getValue(), peakOsisText.getOsisId()));
if (!interlinearModeCaptured) {
result.setInterlinearMode(peakOsisText.getInterlinearMode());
interlinearModeCaptured = true;
}
count++;
}
result.setResults(resultPassages);
}
use of com.tyndalehouse.step.core.models.OsisWrapper in project step by STEPBible.
the class JSwordPassageServiceImpl method getPassageByDisplayMode.
public OsisWrapper getPassageByDisplayMode(List<String> versionsInput, Key reference, List<LookupOption> options, final String interlinearMode) {
if (versionsInput.size() == 0) {
throw new StepInternalException("No versions specified - app error?");
}
final String masterVersion = versionsInput.get(0);
final List<String> extraVersions = this.getExtras(versionsInput);
final InterlinearMode desiredModeOfDisplay = this.optionsValidationService.getDisplayMode(interlinearMode, masterVersion, extraVersions);
final InterlinearMode realModeOfDisplay = this.optionsValidationService.determineDisplayMode(options, desiredModeOfDisplay, true);
if (InterlinearMode.INTERLINEAR.equals(desiredModeOfDisplay) && options.contains(LookupOption.CHAPTER_BOOK_VERSE_NUMBER)) {
// then we're in a search kind of lookup, so add proper verse numbers
options.add(LookupOption.VERSE_NUMBERS);
}
OsisWrapper passageText;
final Set<LookupOption> lookupOptions = this.optionsValidationService.trim(options, masterVersion, extraVersions, desiredModeOfDisplay, null);
if (INTERLINEAR != desiredModeOfDisplay && NONE != desiredModeOfDisplay) {
// split the versions
passageText = this.getInterleavedVersions(versionsInput.toArray(new String[versionsInput.size()]), reference, new ArrayList<LookupOption>(lookupOptions), desiredModeOfDisplay, "en");
} else {
final String extraVersionsAsString = this.getVersionsAsStrings(extraVersions);
passageText = this.getOsisText(masterVersion, reference, new ArrayList<LookupOption>(lookupOptions), extraVersionsAsString, desiredModeOfDisplay);
}
passageText.setOptions(this.optionsValidationService.optionsToString(this.optionsValidationService.getAvailableFeaturesForVersion(masterVersion, extraVersions, interlinearMode, realModeOfDisplay).getOptions()));
// The following 15 lines are a patch for the lack of the Book name, chapter and verse for the deutrocanon books
String tmp = passageText.getValue();
int pos1 = tmp.indexOf("<span class='verseNumber'></span>");
if (pos1 > -1) {
String curOsisId = passageText.getOsisId();
int pos2 = curOsisId.indexOf(".");
if (pos2 > 0) {
String OsisBookName = " " + curOsisId.substring(0, pos2).toLowerCase() + " ";
String otherBooks = " 1esd 2esd tob jdt addesth wis sir bar prazar sus bel prman 1macc 2macc esthgr addps 3macc 4macc ";
if (otherBooks.indexOf(OsisBookName) > -1) {
pos1 += 26;
passageText.setValue(tmp.substring(0, pos1) + curOsisId + tmp.substring(pos1));
}
}
}
passageText.setSelectedOptions(this.optionsValidationService.optionsToString(lookupOptions));
return passageText;
}
use of com.tyndalehouse.step.core.models.OsisWrapper in project step by STEPBible.
the class JSwordPassageServiceImpl method doInterleavedVersionsLookup.
private OsisWrapper doInterleavedVersionsLookup(String[] versions, final BookData data, final Versification v11n, final List<LookupOption> options, final InterlinearMode displayMode, final String userLanguage) {
Book[] books = data.getBooks();
try {
setUnaccenter(data, displayMode);
final TransformingSAXEventProvider transformer = executeStyleSheet(v11n, options, null, data, data.getSAXEventProvider(), displayMode, userLanguage);
String[] languages = new String[books.length];
for (int ii = 0; ii < books.length; ii++) {
languages[ii] = books[ii].getLanguage().getCode();
}
final Key key = data.getKey();
return new OsisWrapper(writeToString(transformer), key, languages, v11n, resolver.getShortName(versions[0]), displayMode, StringUtils.join(versions, 1));
} catch (final TransformerException e) {
throw new StepInternalException(e.getMessage(), e);
} catch (final SAXException e) {
throw new StepInternalException(e.getMessage(), e);
} catch (final BookException e) {
throw new LocalisedException(e, e.getMessage());
}
}
use of com.tyndalehouse.step.core.models.OsisWrapper in project step by STEPBible.
the class JSwordPassageServiceImpl method getTextForBookData.
/**
* Gets the osis text
*
* @param options the list of lookup options
* @param interlinearVersion the interlinear version if applicable
* @param bookData the bookdata to use to look up the required version/reference combo
* @param displayMode the mode to display the text with
* @return the html text
*/
private OsisWrapper getTextForBookData(final List<LookupOption> options, final String interlinearVersion, final BookData bookData, final InterlinearMode displayMode) {
// check we have a book in mind and a reference
notNull(bookData, "An internal error occurred", UserExceptionType.SERVICE_VALIDATION_ERROR);
notNull(bookData.getFirstBook(), "An internal error occurred", UserExceptionType.SERVICE_VALIDATION_ERROR);
Key key = bookData.getKey();
notNull(key, "An internal error occurred", UserExceptionType.SERVICE_VALIDATION_ERROR);
// the original book
final Book book = bookData.getFirstBook();
final Versification versification = this.versificationService.getVersificationForVersion(book);
try {
// first check whether the key is contained in the book
key = normalize(key, versification);
final SAXEventProvider osissep = bookData.getSAXEventProvider();
final TransformingSAXEventProvider htmlsep = executeStyleSheet(versification, options, interlinearVersion, bookData, osissep, displayMode, "en");
final OsisWrapper osisWrapper = new OsisWrapper(writeToString(htmlsep), key, getLanguages(book, displayMode, htmlsep, options), versification, resolver.getShortName(bookData.getFirstBook().getInitials()), displayMode, interlinearVersion);
if (key instanceof Passage) {
final Passage p = (Passage) key;
final boolean hasMultipleRanges = p.hasRanges(RestrictionType.NONE);
osisWrapper.setMultipleRanges(hasMultipleRanges);
if (hasMultipleRanges) {
// get the first "range" and set up the start and ends
final VerseRange r = p.rangeIterator(RestrictionType.NONE).next();
osisWrapper.setStartRange(versification.getOrdinal(r.getStart()));
osisWrapper.setEndRange(versification.getOrdinal(r.getEnd()));
} else {
Iterator<Key> keys = p.iterator();
Verse start = null;
Verse end = null;
while (keys.hasNext()) {
if (start == null) {
start = (Verse) keys.next();
} else {
end = (Verse) keys.next();
}
}
if (start != null) {
osisWrapper.setStartRange(start.getOrdinal());
}
if (end != null) {
osisWrapper.setEndRange(end.getOrdinal());
} else if (start != null) {
osisWrapper.setEndRange(start.getOrdinal());
}
}
} else if (key instanceof VerseRange) {
final VerseRange vr = (VerseRange) key;
osisWrapper.setStartRange(versification.getOrdinal(vr.getStart()));
osisWrapper.setEndRange(versification.getOrdinal(vr.getEnd()));
osisWrapper.setMultipleRanges(false);
}
return osisWrapper;
} catch (final BookException e) {
throw new LocalisedException(e, e.getMessage());
} catch (final SAXException e) {
throw new StepInternalException(e.getMessage(), e);
} catch (final TransformerException e) {
throw new StepInternalException(e.getMessage(), e);
} catch (final NoSuchKeyException e) {
throw new TranslatedException(e, "invalid_reference_in_book", bookData.getKey().getName(), book.getInitials());
}
}
Aggregations