Search in sources :

Example 11 with LookupOption

use of com.tyndalehouse.step.core.models.LookupOption in project step by STEPBible.

the class JSwordPassageServiceImplTest method testComparing.

/**
 * tests that the XSLT transformation is handled correctly
 *
 * @throws BookException      uncaught exception
 * @throws NoSuchKeyException uncaught exception
 * @throws IOException        uncaught exception
 * @throws JDOMException      uncaught exception
 */
@Test
public void testComparing() throws BookException, NoSuchKeyException, JDOMException, IOException {
    final Book currentBook = Books.installed().getBook("ESV_th");
    final Book secondaryBook = Books.installed().getBook("KJV");
    final String reference = "Psalm.3";
    final BookData bookData = new BookData(new Book[] { currentBook, secondaryBook }, currentBook.getKey(reference), true);
    final Element osisFragment = bookData.getOsisFragment();
    final XMLOutputter xmlOutputter = new XMLOutputter(Format.getPrettyFormat());
    LOGGER.info(xmlOutputter.outputString(osisFragment));
    // do the test
    final List<LookupOption> options = new ArrayList<LookupOption>();
    final String osisText = this.jsi.getInterleavedVersions(new String[] { currentBook.getInitials(), secondaryBook.getInitials() }, reference, options, InterlinearMode.INTERLEAVED_COMPARE, "en").getValue();
    final SAXBuilder sb = new SAXBuilder();
    final Document d = sb.build(new StringReader(osisText));
    LOGGER.info("\n {}", xmlOutputter.outputString(d));
    Assert.assertTrue(osisText.contains("span"));
}
Also used : XMLOutputter(org.jdom2.output.XMLOutputter) SAXBuilder(org.jdom2.input.SAXBuilder) LookupOption(com.tyndalehouse.step.core.models.LookupOption) BibleBook(org.crosswire.jsword.versification.BibleBook) Book(org.crosswire.jsword.book.Book) Element(org.jdom2.Element) ArrayList(java.util.ArrayList) StringReader(java.io.StringReader) BookData(org.crosswire.jsword.book.BookData) Document(org.jdom2.Document) Test(org.junit.Test)

Example 12 with LookupOption

use of com.tyndalehouse.step.core.models.LookupOption in project step by STEPBible.

the class JSwordPassageServiceImpl method setOptions.

/**
 * This method sets up the options for the XSLT transformation. Note: the set of options is trimmed to those
 * actually available
 *
 * @param tsep    the xslt transformer
 * @param options the options available
 * @param books   the version to initialise a potential interlinear with
 */
protected void setOptions(final TransformingSAXEventProvider tsep, final List<LookupOption> options, final Book[] books) {
    final boolean isHebrew = JSwordUtils.isAncientHebrewBook(books);
    final boolean isGreek = JSwordUtils.isAncientGreekBook(books);
    for (final LookupOption lookupOption : options) {
        if (lookupOption.getXsltParameterName() != null) {
            tsep.setParameter(lookupOption.getXsltParameterName(), true);
            switch(lookupOption) {
                case VERSE_NUMBERS:
                    tsep.setParameter(LookupOption.TINY_VERSE_NUMBERS.getXsltParameterName(), true);
                    break;
                case CHAPTER_BOOK_VERSE_NUMBER:
                    tsep.setParameter(LookupOption.VERSE_NUMBERS.getXsltParameterName(), true);
                    break;
                case MORPHOLOGY:
                    tsep.setParameter("morphologyProvider", this.morphologyProvider);
                    break;
                case ENGLISH_VOCAB:
                case ZH_TW_VOCAB:
                case ZH_VOCAB:
                case ES_VOCAB:
                case TRANSLITERATION:
                case GREEK_VOCAB:
                case TRANSLITERATE_ORIGINAL:
                    tsep.setParameter("vocabProvider", this.vocabProvider);
                    break;
                case COLOUR_CODE:
                    tsep.setParameter("colorCodingProvider", this.colorCoder);
                    break;
                case GREEK_ACCENTS:
                    if (isGreek) {
                        tsep.setParameter("RemovePointing", "false");
                        tsep.setParameter("RemoveVowels", "false");
                    }
                    break;
                case HEBREW_VOWELS:
                    if (isHebrew) {
                        tsep.setParameter("RemoveVowels", "false");
                    }
                    break;
                case HEBREW_ACCENTS:
                    if (isHebrew) {
                        tsep.setParameter("RemovePointing", "false");
                        tsep.setParameter("RemoveVowels", "false");
                    }
                    break;
            }
        }
    }
    // if no greek or hebrew, then override to false
    if (!isGreek && !isHebrew) {
        tsep.setParameter("RemovePointing", false);
        tsep.setParameter("RemoveVowels", false);
    }
    if (!books[0].getBookMetaData().isLeftToRight()) {
        tsep.setParameter(LookupOption.VERSE_NEW_LINE.getXsltParameterName(), true);
    }
    tsep.setParameter("direction", books[0].getBookMetaData().isLeftToRight() ? "ltr" : "rtl");
    tsep.setParameter("baseVersion", this.resolver.getShortName(books[0].getInitials()));
}
Also used : LookupOption(com.tyndalehouse.step.core.models.LookupOption)

Example 13 with LookupOption

use of com.tyndalehouse.step.core.models.LookupOption in project step by STEPBible.

the class JSwordSearchServiceImpl method getResultsFromTrimmedKeys.

public SearchResult getResultsFromTrimmedKeys(final SearchQuery sq, final String[] versions, final int total, final Key newResults, final LookupOption... options) {
    final long startRefRetrieval = System.currentTimeMillis();
    // if context > 0, then we need to add verse numbers:
    final List<LookupOption> lookupOptions = new ArrayList<LookupOption>();
    Collections.addAll(lookupOptions, options);
    lookupOptions.add(LookupOption.CHAPTER_BOOK_VERSE_NUMBER);
    lookupOptions.add(LookupOption.HEBREW_VOWELS);
    lookupOptions.add(LookupOption.GREEK_ACCENTS);
    // lookupOptions.add(LookupOption.HEBREW_ACCENTS); Removed because we want to show Hebrew accents only if the user has selected this option.
    final SearchResult r = new SearchResult();
    getPassagesForResults(r, versions, newResults, sq.getContext(), lookupOptions, sq.getInterlinearMode());
    return getSearchResult(r, total, System.currentTimeMillis() - startRefRetrieval);
}
Also used : LookupOption(com.tyndalehouse.step.core.models.LookupOption) SearchResult(com.tyndalehouse.step.core.models.search.SearchResult)

Example 14 with LookupOption

use of com.tyndalehouse.step.core.models.LookupOption in project step by STEPBible.

the class JSwordPassageServiceImplTest method testXslTransformation.

/**
 * tests that the XSLT transformation is handled correctly
 *
 * @throws BookException      uncaught exception
 * @throws NoSuchKeyException uncaught exception
 * @throws IOException        uncaught exception
 * @throws JDOMException      uncaught exception
 */
@Test
public void testXslTransformation() throws BookException, NoSuchKeyException, JDOMException, IOException {
    final Book currentBook = Books.installed().getBook("KJV");
    final BookData bookData = new BookData(currentBook, currentBook.getKey("Romans 1:4"));
    final Element osisFragment = bookData.getOsisFragment();
    final XMLOutputter xmlOutputter = new XMLOutputter(Format.getPrettyFormat());
    LOGGER.trace(xmlOutputter.outputString(osisFragment));
    // do the test
    final List<LookupOption> options = new ArrayList<LookupOption>();
    final String osisText = this.jsi.getOsisText("KJV", "Romans 1:4", options, "", InterlinearMode.NONE).getValue();
    final SAXBuilder sb = new SAXBuilder();
    final Document d = sb.build(new StringReader(osisText));
    LOGGER.trace("\n {}", xmlOutputter.outputString(d));
    Assert.assertTrue(osisText.contains("span"));
}
Also used : XMLOutputter(org.jdom2.output.XMLOutputter) SAXBuilder(org.jdom2.input.SAXBuilder) LookupOption(com.tyndalehouse.step.core.models.LookupOption) BibleBook(org.crosswire.jsword.versification.BibleBook) Book(org.crosswire.jsword.book.Book) Element(org.jdom2.Element) ArrayList(java.util.ArrayList) StringReader(java.io.StringReader) BookData(org.crosswire.jsword.book.BookData) Document(org.jdom2.Document) Test(org.junit.Test)

Example 15 with LookupOption

use of com.tyndalehouse.step.core.models.LookupOption in project step by STEPBible.

the class JSwordPassageServiceImplTest method testInterlinearTransformation.

/**
 * tests what happens when we select interlinear
 *
 * @throws NoSuchKeyException uncaught exceptions
 * @throws BookException      uncaught exception
 * @throws IOException        uncaught exception
 * @throws JDOMException      uncaught exception
 */
@Test
public void testInterlinearTransformation() throws NoSuchKeyException, BookException, JDOMException, IOException {
    final Book currentBook = Books.installed().getBook("OSMHB");
    final BookData bookData = new BookData(currentBook, currentBook.getKey("Ps.51"));
    final Element osisFragment = bookData.getOsisFragment();
    final XMLOutputter xmlOutputter = new XMLOutputter(Format.getPrettyFormat());
    LOGGER.trace(xmlOutputter.outputString(osisFragment));
    // do the test
    final List<LookupOption> options = new ArrayList<LookupOption>();
    // options.add(INTERLINEAR);
    final String osisText = this.jsi.getOsisText("OSMHB", "Ps.51", options, "ESV_th", InterlinearMode.INTERLINEAR).getValue();
    final SAXBuilder sb = new SAXBuilder();
    final Document d = sb.build(new StringReader(osisText));
    LOGGER.trace("\n {}", xmlOutputter.outputString(d));
    Assert.assertTrue(osisText.contains("span class='interlinear'"));
}
Also used : XMLOutputter(org.jdom2.output.XMLOutputter) SAXBuilder(org.jdom2.input.SAXBuilder) LookupOption(com.tyndalehouse.step.core.models.LookupOption) BibleBook(org.crosswire.jsword.versification.BibleBook) Book(org.crosswire.jsword.book.Book) Element(org.jdom2.Element) ArrayList(java.util.ArrayList) StringReader(java.io.StringReader) BookData(org.crosswire.jsword.book.BookData) Document(org.jdom2.Document) Test(org.junit.Test)

Aggregations

LookupOption (com.tyndalehouse.step.core.models.LookupOption)20 ArrayList (java.util.ArrayList)11 OsisWrapper (com.tyndalehouse.step.core.models.OsisWrapper)7 Book (org.crosswire.jsword.book.Book)7 BookData (org.crosswire.jsword.book.BookData)6 SAXBuilder (org.jdom2.input.SAXBuilder)6 XMLOutputter (org.jdom2.output.XMLOutputter)6 Test (org.junit.Test)6 TrimmedLookupOption (com.tyndalehouse.step.core.models.TrimmedLookupOption)5 StringReader (java.io.StringReader)5 Document (org.jdom2.Document)5 Element (org.jdom2.Element)5 BibleBook (org.crosswire.jsword.versification.BibleBook)4 EnrichedLookupOption (com.tyndalehouse.step.core.models.EnrichedLookupOption)3 InterlinearMode (com.tyndalehouse.step.core.models.InterlinearMode)3 StepInternalException (com.tyndalehouse.step.core.exceptions.StepInternalException)2 JSwordPassageServiceImpl (com.tyndalehouse.step.core.service.jsword.impl.JSwordPassageServiceImpl)2 HashSet (java.util.HashSet)2 AbstractPassageBook (org.crosswire.jsword.book.basic.AbstractPassageBook)2 Key (org.crosswire.jsword.passage.Key)2