use of com.tyndalehouse.step.core.exceptions.StepInternalException 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.exceptions.StepInternalException 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.exceptions.StepInternalException 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());
}
}
use of com.tyndalehouse.step.core.exceptions.StepInternalException in project step by STEPBible.
the class JSwordVersificationServiceImpl method convertReference.
@Override
public KeyWrapper convertReference(final String reference, final String sourceVersion, final String targetVersion) {
final Versification source = this.getVersificationForVersion(sourceVersion);
final Versification target = this.getVersificationForVersion(targetVersion);
try {
Passage p = PassageKeyFactory.instance().getKey(source, reference);
return new KeyWrapper(VersificationsMapper.instance().map(p, target));
} catch (NoSuchKeyException e) {
throw new StepInternalException(e.getMessage(), e);
}
}
use of com.tyndalehouse.step.core.exceptions.StepInternalException in project step by STEPBible.
the class SubjectSearchServiceImpl method getExtendedNaveDocs.
/**
* Return the docs for the extended naves
*
* @param sq the search query
* @return entity docs matching the extended nave search
*/
private EntityDoc[] getExtendedNaveDocs(SearchQuery sq) {
String queryBody = QueryParser.escape(sq.getCurrentSearch().getQuery());
// construct query
StringBuilder query = new StringBuilder(256);
query.append("+(");
query.append("rootStem:");
query.append(queryBody);
query.append(" fullHeaderAnalyzed:");
query.append(queryBody);
query.append(") ");
query.append(this.getInputReferenceForNaveSearch(sq.getCurrentSearch().getVersions(), sq.getCurrentSearch().getMainRange()).getValue());
try {
return this.naves.search(this.naves.getQueryParser(false, true, "rootStem").parse(query.toString()), Integer.MAX_VALUE, NAVE_SORT, null);
} catch (ParseException ex) {
throw new StepInternalException("Unable to parse generated query.");
}
}
Aggregations