Search in sources :

Example 1 with LocaleProvider

use of org.crosswire.jsword.internationalisation.LocaleProvider in project step by STEPBible.

the class StepServletConfig method configureJSword.

/**
 * Configure JSword.
 */
private void configureJSword() {
    BookName.setFullBookName(false);
    final Provider<ClientSession> provider = this.injector.getProvider(ClientSession.class);
    ConfigEntry.setConfigValueInterceptor(this.injector.getInstance(ConfigValueInterceptor.class));
    // set the locale resolution
    LocaleProviderManager.setLocaleProvider(new LocaleProvider() {

        @Override
        public Locale getUserLocale() {
            try {
                return provider.get().getLocale();
            } catch (final ProvisionException ex) {
                return Locale.ENGLISH;
            }
        }
    });
    if (Boolean.TRUE.equals(Boolean.getBoolean("step.development"))) {
        TransformingSAXEventProvider.setDevelopmentMode(true);
    }
}
Also used : Locale(java.util.Locale) ProvisionException(com.google.inject.ProvisionException) ConfigValueInterceptor(org.crosswire.jsword.book.sword.ConfigValueInterceptor) ClientSession(com.tyndalehouse.step.core.models.ClientSession) LocaleProvider(org.crosswire.jsword.internationalisation.LocaleProvider)

Example 2 with LocaleProvider

use of org.crosswire.jsword.internationalisation.LocaleProvider in project step by STEPBible.

the class XmlToOSIS method applyXslt.

private void applyXslt(final Document input, File output) throws Exception {
    TransformerFactory tFactory = TransformerFactory.newInstance();
    Transformer transformer = tFactory.newTransformer(new StreamSource(getClass().getResourceAsStream(String.format("/transform-%s.xsl", this.conversionType))));
    final DOMResult outputTarget = new DOMResult();
    transformer.setParameter("identifier", this.moduleName);
    transformer.setParameter("versification", this.versification);
    LocaleProviderManager.setLocaleProvider(new LocaleProvider() {

        @Override
        public Locale getUserLocale() {
            return new Locale(XmlToOSIS.this.languageCode);
        }
    });
    transformer.transform(new DOMSource(input), outputTarget);
    Document n = (Document) outputTarget.getNode();
    moveNodes(n);
    Transformer fileTransformer = tFactory.newTransformer();
    fileTransformer.transform(new DOMSource(n), new StreamResult(new FileOutputStream(output)));
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) TransformerFactory(javax.xml.transform.TransformerFactory) Transformer(javax.xml.transform.Transformer) DOMResult(javax.xml.transform.dom.DOMResult) StreamResult(javax.xml.transform.stream.StreamResult) StreamSource(javax.xml.transform.stream.StreamSource) LocaleProvider(org.crosswire.jsword.internationalisation.LocaleProvider) FileOutputStream(java.io.FileOutputStream) Document(org.w3c.dom.Document)

Aggregations

LocaleProvider (org.crosswire.jsword.internationalisation.LocaleProvider)2 ProvisionException (com.google.inject.ProvisionException)1 ClientSession (com.tyndalehouse.step.core.models.ClientSession)1 FileOutputStream (java.io.FileOutputStream)1 Locale (java.util.Locale)1 Transformer (javax.xml.transform.Transformer)1 TransformerFactory (javax.xml.transform.TransformerFactory)1 DOMResult (javax.xml.transform.dom.DOMResult)1 DOMSource (javax.xml.transform.dom.DOMSource)1 StreamResult (javax.xml.transform.stream.StreamResult)1 StreamSource (javax.xml.transform.stream.StreamSource)1 ConfigValueInterceptor (org.crosswire.jsword.book.sword.ConfigValueInterceptor)1 Document (org.w3c.dom.Document)1