Search in sources :

Example 6 with ResourceBundleMessageSource

use of org.springframework.context.support.ResourceBundleMessageSource in project spring-framework-debug by Joker-5.

the class ResourceBundleThemeSource method createMessageSource.

/**
 * Create a MessageSource for the given basename,
 * to be used as MessageSource for the corresponding theme.
 * <p>Default implementation creates a ResourceBundleMessageSource.
 * for the given basename. A subclass could create a specifically
 * configured ReloadableResourceBundleMessageSource, for example.
 * @param basename the basename to create a MessageSource for
 * @return the MessageSource
 * @see org.springframework.context.support.ResourceBundleMessageSource
 * @see org.springframework.context.support.ReloadableResourceBundleMessageSource
 */
protected MessageSource createMessageSource(String basename) {
    ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
    messageSource.setBasename(basename);
    if (this.defaultEncoding != null) {
        messageSource.setDefaultEncoding(this.defaultEncoding);
    }
    if (this.fallbackToSystemLocale != null) {
        messageSource.setFallbackToSystemLocale(this.fallbackToSystemLocale);
    }
    if (this.beanClassLoader != null) {
        messageSource.setBeanClassLoader(this.beanClassLoader);
    }
    return messageSource;
}
Also used : ResourceBundleMessageSource(org.springframework.context.support.ResourceBundleMessageSource)

Example 7 with ResourceBundleMessageSource

use of org.springframework.context.support.ResourceBundleMessageSource in project spring-framework-debug by Joker-5.

the class JstlUtils method getJstlAwareMessageSource.

/**
 * Checks JSTL's "javax.servlet.jsp.jstl.fmt.localizationContext"
 * context-param and creates a corresponding child message source,
 * with the provided Spring-defined MessageSource as parent.
 * @param servletContext the ServletContext we're running in
 * (to check JSTL-related context-params in {@code web.xml})
 * @param messageSource the MessageSource to expose, typically
 * the ApplicationContext of the current DispatcherServlet
 * @return the MessageSource to expose to JSTL; first checking the
 * JSTL-defined bundle, then the Spring-defined MessageSource
 * @see org.springframework.context.ApplicationContext
 */
public static MessageSource getJstlAwareMessageSource(@Nullable ServletContext servletContext, MessageSource messageSource) {
    if (servletContext != null) {
        String jstlInitParam = servletContext.getInitParameter(Config.FMT_LOCALIZATION_CONTEXT);
        if (jstlInitParam != null) {
            // Create a ResourceBundleMessageSource for the specified resource bundle
            // basename in the JSTL context-param in web.xml, wiring it with the given
            // Spring-defined MessageSource as parent.
            ResourceBundleMessageSource jstlBundleWrapper = new ResourceBundleMessageSource();
            jstlBundleWrapper.setBasename(jstlInitParam);
            jstlBundleWrapper.setParentMessageSource(messageSource);
            return jstlBundleWrapper;
        }
    }
    return messageSource;
}
Also used : ResourceBundleMessageSource(org.springframework.context.support.ResourceBundleMessageSource)

Example 8 with ResourceBundleMessageSource

use of org.springframework.context.support.ResourceBundleMessageSource in project nrich by croz-ltd.

the class RegistryTestConfiguration method messageSource.

@Bean
public MessageSource messageSource() {
    ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
    messageSource.setBasename("messages");
    return messageSource;
}
Also used : ResourceBundleMessageSource(org.springframework.context.support.ResourceBundleMessageSource) Bean(org.springframework.context.annotation.Bean) LocalContainerEntityManagerFactoryBean(org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean)

Example 9 with ResourceBundleMessageSource

use of org.springframework.context.support.ResourceBundleMessageSource in project spring-framework-5.2.9.RELEASE by somepeopleHavingDream.

the class JstlUtils method getJstlAwareMessageSource.

/**
 * Checks JSTL's "javax.servlet.jsp.jstl.fmt.localizationContext"
 * context-param and creates a corresponding child message source,
 * with the provided Spring-defined MessageSource as parent.
 * @param servletContext the ServletContext we're running in
 * (to check JSTL-related context-params in {@code web.xml})
 * @param messageSource the MessageSource to expose, typically
 * the ApplicationContext of the current DispatcherServlet
 * @return the MessageSource to expose to JSTL; first checking the
 * JSTL-defined bundle, then the Spring-defined MessageSource
 * @see org.springframework.context.ApplicationContext
 */
public static MessageSource getJstlAwareMessageSource(@Nullable ServletContext servletContext, MessageSource messageSource) {
    if (servletContext != null) {
        String jstlInitParam = servletContext.getInitParameter(Config.FMT_LOCALIZATION_CONTEXT);
        if (jstlInitParam != null) {
            // Create a ResourceBundleMessageSource for the specified resource bundle
            // basename in the JSTL context-param in web.xml, wiring it with the given
            // Spring-defined MessageSource as parent.
            ResourceBundleMessageSource jstlBundleWrapper = new ResourceBundleMessageSource();
            jstlBundleWrapper.setBasename(jstlInitParam);
            jstlBundleWrapper.setParentMessageSource(messageSource);
            return jstlBundleWrapper;
        }
    }
    return messageSource;
}
Also used : ResourceBundleMessageSource(org.springframework.context.support.ResourceBundleMessageSource)

Example 10 with ResourceBundleMessageSource

use of org.springframework.context.support.ResourceBundleMessageSource in project id-authentication by mosip.

the class IDAuthExceptionHandlerTest method before.

@Before
public void before() {
    ResourceBundleMessageSource source = new ResourceBundleMessageSource();
    source.setBasename("errormessages");
    ReflectionTestUtils.setField(handler, "servletRequest", servletRequest);
}
Also used : ResourceBundleMessageSource(org.springframework.context.support.ResourceBundleMessageSource) Before(org.junit.Before)

Aggregations

ResourceBundleMessageSource (org.springframework.context.support.ResourceBundleMessageSource)179 Bean (org.springframework.context.annotation.Bean)99 Before (org.junit.Before)16 MessageSourceAccessor (org.springframework.context.support.MessageSourceAccessor)13 LocalValidatorFactoryBean (org.springframework.validation.beanvalidation.LocalValidatorFactoryBean)9 ValidatorFactory (javax.validation.ValidatorFactory)6 ResourceBundleMessageInterpolator (org.hibernate.validator.messageinterpolation.ResourceBundleMessageInterpolator)6 PlatformResourceBundleLocator (org.hibernate.validator.resourceloading.PlatformResourceBundleLocator)6 Test (org.junit.Test)6 Test (org.junit.jupiter.api.Test)6 IOException (java.io.IOException)5 List (java.util.List)5 Locale (java.util.Locale)5 ReaderFactoryByMap (net.n2oapp.framework.config.selective.reader.ReaderFactoryByMap)5 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)5 MessageSource (org.springframework.context.MessageSource)5 ArrayList (java.util.ArrayList)4 N2oApplicationBuilder (net.n2oapp.framework.config.N2oApplicationBuilder)4 N2oEnvironment (net.n2oapp.framework.config.compile.pipeline.N2oEnvironment)4 PersisterFactoryByMap (net.n2oapp.framework.config.selective.persister.PersisterFactoryByMap)4