Search in sources :

Example 1 with XslConversionType

use of com.tyndalehouse.step.core.xsl.XslConversionType in project step by STEPBible.

the class JSwordPassageServiceImpl method executeStyleSheet.

/**
 * Executes the stylesheet
 *
 * @param masterVersification the versification of the top line
 * @param options             the list of options to pass in
 * @param interlinearVersion  the interlinear version(s)
 * @param bookData            the book data, containing book and reference
 * @param osissep             the XML SAX provider
 * @param displayMode         the display mode
 * @return a Transforming SAX event provider, from which can be transformed into HTML
 * @throws TransformerException an exception in the stylesheet that is being executed
 */
private TransformingSAXEventProvider executeStyleSheet(final Versification masterVersification, final List<LookupOption> options, final String interlinearVersion, final BookData bookData, final SAXEventProvider osissep, final InterlinearMode displayMode, final String userLanguage) throws TransformerException {
    final XslConversionType requiredTransformation = identifyStyleSheet(options, displayMode);
    return (TransformingSAXEventProvider) new Converter() {

        @Override
        public SAXEventProvider convert(final SAXEventProvider provider) throws TransformerException {
            try {
                final String file = requiredTransformation.getFile();
                final URI resourceURI = getClass().getResource(file).toURI();
                final TransformingSAXEventProvider tsep = new TransformingSAXEventProvider(resourceURI, osissep);
                // set parameters here
                String changeVersion = "";
                if (userLanguage.toLowerCase().startsWith("es"))
                    changeVersion = "SpaRV1909";
                else if (userLanguage.equalsIgnoreCase("zh"))
                    changeVersion = "CUns";
                else if (userLanguage.equalsIgnoreCase("zh_tw"))
                    changeVersion = "CUn";
                else if (userLanguage.toLowerCase().startsWith("bg"))
                    changeVersion = "BulProtRev";
                else if (userLanguage.toLowerCase().startsWith("hi"))
                    changeVersion = "HinULB";
                if (changeVersion.length() > 0) {
                    tsep.setParameter("defaultVersion", changeVersion);
                }
                setOptions(tsep, options, bookData.getBooks());
                setInterlinearOptions(tsep, bookData.getBooks()[0].getInitials(), masterVersification, getInterlinearVersion(interlinearVersion), bookData.getKey().getOsisID(), displayMode, bookData.getKey(), options);
                setInterleavingOptions(tsep, displayMode, bookData);
                return tsep;
            } catch (final URISyntaxException e) {
                throw new StepInternalException("Failed to load resource correctly", e);
            }
        }
    }.convert(osissep);
}
Also used : TransformingSAXEventProvider(org.crosswire.common.xml.TransformingSAXEventProvider) StepInternalException(com.tyndalehouse.step.core.exceptions.StepInternalException) Converter(org.crosswire.common.xml.Converter) TransformingSAXEventProvider(org.crosswire.common.xml.TransformingSAXEventProvider) JDOMSAXEventProvider(org.crosswire.common.xml.JDOMSAXEventProvider) SAXEventProvider(org.crosswire.common.xml.SAXEventProvider) XMLUtil.writeToString(org.crosswire.common.xml.XMLUtil.writeToString) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) XslConversionType(com.tyndalehouse.step.core.xsl.XslConversionType)

Aggregations

StepInternalException (com.tyndalehouse.step.core.exceptions.StepInternalException)1 XslConversionType (com.tyndalehouse.step.core.xsl.XslConversionType)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 Converter (org.crosswire.common.xml.Converter)1 JDOMSAXEventProvider (org.crosswire.common.xml.JDOMSAXEventProvider)1 SAXEventProvider (org.crosswire.common.xml.SAXEventProvider)1 TransformingSAXEventProvider (org.crosswire.common.xml.TransformingSAXEventProvider)1 XMLUtil.writeToString (org.crosswire.common.xml.XMLUtil.writeToString)1