Search in sources :

Example 16 with StepInternalException

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;
}
Also used : StepInternalException(com.tyndalehouse.step.core.exceptions.StepInternalException) LookupOption(com.tyndalehouse.step.core.models.LookupOption) ArrayList(java.util.ArrayList) XMLUtil.writeToString(org.crosswire.common.xml.XMLUtil.writeToString) InterlinearMode(com.tyndalehouse.step.core.models.InterlinearMode) OsisWrapper(com.tyndalehouse.step.core.models.OsisWrapper)

Example 17 with StepInternalException

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());
    }
}
Also used : BookException(org.crosswire.jsword.book.BookException) XMLUtil.writeToString(org.crosswire.common.xml.XMLUtil.writeToString) SAXException(org.xml.sax.SAXException) LocalisedException(com.tyndalehouse.step.core.exceptions.LocalisedException) TransformingSAXEventProvider(org.crosswire.common.xml.TransformingSAXEventProvider) StepInternalException(com.tyndalehouse.step.core.exceptions.StepInternalException) BibleBook(org.crosswire.jsword.versification.BibleBook) Book(org.crosswire.jsword.book.Book) Key(org.crosswire.jsword.passage.Key) OsisWrapper(com.tyndalehouse.step.core.models.OsisWrapper) TransformerException(javax.xml.transform.TransformerException)

Example 18 with StepInternalException

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());
    }
}
Also used : VerseRange(org.crosswire.jsword.passage.VerseRange) TranslatedException(com.tyndalehouse.step.core.exceptions.TranslatedException) Versification(org.crosswire.jsword.versification.Versification) BookException(org.crosswire.jsword.book.BookException) RocketPassage(org.crosswire.jsword.passage.RocketPassage) Passage(org.crosswire.jsword.passage.Passage) SAXException(org.xml.sax.SAXException) LocalisedException(com.tyndalehouse.step.core.exceptions.LocalisedException) TransformingSAXEventProvider(org.crosswire.common.xml.TransformingSAXEventProvider) NoSuchKeyException(org.crosswire.jsword.passage.NoSuchKeyException) StepInternalException(com.tyndalehouse.step.core.exceptions.StepInternalException) BibleBook(org.crosswire.jsword.versification.BibleBook) Book(org.crosswire.jsword.book.Book) TransformingSAXEventProvider(org.crosswire.common.xml.TransformingSAXEventProvider) JDOMSAXEventProvider(org.crosswire.common.xml.JDOMSAXEventProvider) SAXEventProvider(org.crosswire.common.xml.SAXEventProvider) Key(org.crosswire.jsword.passage.Key) OsisWrapper(com.tyndalehouse.step.core.models.OsisWrapper) Verse(org.crosswire.jsword.passage.Verse) TransformerException(javax.xml.transform.TransformerException)

Example 19 with StepInternalException

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);
    }
}
Also used : KeyWrapper(com.tyndalehouse.step.core.models.KeyWrapper) StepInternalException(com.tyndalehouse.step.core.exceptions.StepInternalException) Versification(org.crosswire.jsword.versification.Versification)

Example 20 with StepInternalException

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.");
    }
}
Also used : StepInternalException(com.tyndalehouse.step.core.exceptions.StepInternalException) ParseException(org.apache.lucene.queryParser.ParseException)

Aggregations

StepInternalException (com.tyndalehouse.step.core.exceptions.StepInternalException)62 IOException (java.io.IOException)25 Book (org.crosswire.jsword.book.Book)9 Key (org.crosswire.jsword.passage.Key)7 EntityDoc (com.tyndalehouse.step.core.data.EntityDoc)5 OsisWrapper (com.tyndalehouse.step.core.models.OsisWrapper)4 InputStream (java.io.InputStream)4 ArrayList (java.util.ArrayList)4 ParseException (org.apache.lucene.queryParser.ParseException)4 BookException (org.crosswire.jsword.book.BookException)4 Versification (org.crosswire.jsword.versification.Versification)4 LocalisedException (com.tyndalehouse.step.core.exceptions.LocalisedException)3 TranslatedException (com.tyndalehouse.step.core.exceptions.TranslatedException)3 KeyWrapper (com.tyndalehouse.step.core.models.KeyWrapper)3 FileInputStream (java.io.FileInputStream)3 TransformingSAXEventProvider (org.crosswire.common.xml.TransformingSAXEventProvider)3 XMLUtil.writeToString (org.crosswire.common.xml.XMLUtil.writeToString)3 NoSuchKeyException (org.crosswire.jsword.passage.NoSuchKeyException)3 BibleBook (org.crosswire.jsword.versification.BibleBook)3 AllResultsCollector (com.tyndalehouse.step.core.data.AllResultsCollector)2