Java Code Examples for org.springframework.context.support.ResourceBundleMessageSource#setBasename()

The following examples show how to use org.springframework.context.support.ResourceBundleMessageSource#setBasename() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JstlUtils.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
/**
 * 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(
		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;
}
 
Example 2
Source File: LoadedMessageSourceService.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
   public MessageSource getMessageService(String messageFilename) {
if (messageFilename != null) {
    MessageSource ms = messageServices.get(messageFilename);
    if (ms == null) {
	ResourceBundleMessageSource rbms = (ResourceBundleMessageSource) beanFactory
		.getBean(LOADED_MESSAGE_SOURCE_BEAN);
	rbms.setBasename(messageFilename);
	messageServices.put(messageFilename, rbms);
	ms = rbms;
    }
    return ms;
} else {
    return null;
}
   }
 
Example 3
Source File: JstlUtils.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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(
		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;
}
 
Example 4
Source File: JstlUtils.java    From java-technology-stack with MIT License 6 votes vote down vote up
/**
 * 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;
}
 
Example 5
Source File: MessageResourceExtension.java    From Spring-Boot-I18n-Pro with MIT License 6 votes vote down vote up
@PostConstruct
public void init() {
    logger.info("init MessageResourceExtension...");
    if (!StringUtils.isEmpty(baseFolder)) {
        try {
            this.setBasenames(getAllBaseNames(baseFolder));
        } catch (IOException e) {
            logger.error(e.getMessage());
        }
    }
    //设置父MessageSource
    ResourceBundleMessageSource parent = new ResourceBundleMessageSource();
    //是否是多个目录
    if (basename.indexOf(",") > 0) {
        parent.setBasenames(basename.split(","));
    } else {
        parent.setBasename(basename);
    }
    //设置文件编码
    parent.setDefaultEncoding("UTF-8");
    this.setParentMessageSource(parent);
}
 
Example 6
Source File: ResourceBundleThemeSource.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * 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;
}
 
Example 7
Source File: ValidationConfiguration.java    From edison-microservice with Apache License 2.0 5 votes vote down vote up
@Bean
public ResourceBundleMessageSource edisonValidationMessageSource() {
    ResourceBundleMessageSource source = new ResourceBundleMessageSource();
    source.setBasename("ValidationMessages");
    source.setUseCodeAsDefaultMessage(true);
    return source;
}
 
Example 8
Source File: DefaultIdentifierNotificationServiceTests.java    From openregistry with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
	ResourceBundleMessageSource ms = new ResourceBundleMessageSource();
	ms.setBasename("identifier-email-messages");
    this.notificationService = 
    	new DefaultIdentifierNotificationService
    		(mockPersonRepository,
    		new DefaultEmailIdentifierNotificationStrategy(new MockMailSender(), ms),
    		30);
}
 
Example 9
Source File: ResourceBundleThemeSource.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example 10
Source File: TemplateAwareMessageSourceIT.java    From errors-spring-boot-starter with Apache License 2.0 5 votes vote down vote up
@Bean
public MessageSource messageSource() {
    ResourceBundleMessageSource source = new ResourceBundleMessageSource();
    source.setBasename("templated_messages");

    return source;
}
 
Example 11
Source File: WebAppConfig.java    From SA47 with The Unlicense 5 votes vote down vote up
@Bean
public ResourceBundleMessageSource messageSource() {
	ResourceBundleMessageSource source = new ResourceBundleMessageSource();
	source.setBasename(env.getRequiredProperty("message.source.basename"));
	source.setUseCodeAsDefaultMessage(true);
	source.setDefaultEncoding("UTF-8");
	// # -1 : never reload, 0 always reload
	source.setCacheSeconds(0);
	return source;
}
 
Example 12
Source File: WebAppConfig.java    From SA47 with The Unlicense 5 votes vote down vote up
@Bean
public ResourceBundleMessageSource messageSource() {
	ResourceBundleMessageSource source = new ResourceBundleMessageSource();
	source.setBasename(env.getRequiredProperty("message.source.basename"));
	source.setUseCodeAsDefaultMessage(true);
	source.setDefaultEncoding("UTF-8");
	// # -1 : never reload, 0 always reload
	source.setCacheSeconds(0);
	return source;
}
 
Example 13
Source File: EnumListValidatorTest.java    From edison-microservice with Apache License 2.0 5 votes vote down vote up
private EnumListValidator createAndInitializeValidator(boolean ignoreCase, boolean allowNull) {
    ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
    messageSource.setBasename("ValidationMessages");
    messageSource.setUseCodeAsDefaultMessage(true);

    EnumListValidator enumListValidator = new EnumListValidator(messageSource);
    enumListValidator.initialize(createAnnotation(TestEnum.class, ignoreCase, allowNull));
    return enumListValidator;
}
 
Example 14
Source File: WebConfig.java    From maven-framework-project with MIT License 5 votes vote down vote up
@Bean
public ResourceBundleMessageSource messageSource() {
	ResourceBundleMessageSource source = new ResourceBundleMessageSource();
	source.setBasename(env.getRequiredProperty("message.source.basename"));
	source.setUseCodeAsDefaultMessage(true);
	return source;
}
 
Example 15
Source File: Application.java    From fluent-validator with Apache License 2.0 4 votes vote down vote up
@Bean
MessageSource messageSource() {
    ResourceBundleMessageSource resourceBundleMessageSource = new ResourceBundleMessageSource();
    resourceBundleMessageSource.setBasename("error-message");
    return resourceBundleMessageSource;
}
 
Example 16
Source File: DefaultPasswordStrategy.java    From cola with MIT License 4 votes vote down vote up
public DefaultPasswordStrategy(PasswordProperties properties) {
	this.properties = properties;
	ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
	messageSource.setBasename("messages");
	messages = new MessageSourceAccessor(messageSource);
}
 
Example 17
Source File: PWPConfiguration.java    From Spring-MVC-Blueprints with MIT License 4 votes vote down vote up
@Bean
public ResourceBundleMessageSource setMessageResource(){
	ResourceBundleMessageSource messageResource = new ResourceBundleMessageSource();
	messageResource.setBasename("config.errors");
	return messageResource;
}
 
Example 18
Source File: FabricExplorerAutoConfiguration.java    From spring-fabric-gateway with MIT License 4 votes vote down vote up
@Bean(name = "messageSource")
public ResourceBundleMessageSource getMessageResource() {
	ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
	messageSource.setBasename("i18n/messages");
	return messageSource;
}
 
Example 19
Source File: ApplicationConfiguration.java    From tutorials with MIT License 4 votes vote down vote up
@Bean
public ResourceBundleMessageSource resourceBundleMessageSource() {
    ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
    messageSource.setBasename("messages");
    return messageSource;
}
 
Example 20
Source File: EmailConfiguration.java    From tutorials with MIT License 4 votes vote down vote up
@Bean
public ResourceBundleMessageSource emailMessageSource() {
    final ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
    messageSource.setBasename("/mailMessages");
    return messageSource;
}