Example usage for org.springframework.context.support ReloadableResourceBundleMessageSource setAlwaysUseMessageFormat

List of usage examples for org.springframework.context.support ReloadableResourceBundleMessageSource setAlwaysUseMessageFormat

Introduction

In this page you can find the example usage for org.springframework.context.support ReloadableResourceBundleMessageSource setAlwaysUseMessageFormat.

Prototype

public void setAlwaysUseMessageFormat(boolean alwaysUseMessageFormat) 

Source Link

Document

Set whether to always apply the MessageFormat rules, parsing even messages without arguments.

Usage

From source file:net.sf.sze.config.WebMvcConfig.java

/**
 * Initiates the message resolver.//from  www  .j a v a  2s . c o  m
 *
 * @return a message source.
 */
@Bean(name = "messageSource")
public MessageSource configureMessageSource() {
    ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource();
    messageSource.setBasenames(MESSAGE_SOURCE, APP_MESSAGE_SOURCE, HELP_MESSAGE_SOURCE, MESSAGE_SOURCE_OVAL);
    messageSource.setCacheSeconds(MESSAGE_CACHE);
    messageSource.setFallbackToSystemLocale(false);
    // Make sure Apostrophs must always be doubled..
    messageSource.setAlwaysUseMessageFormat(true);
    // This persister doubles Apostoph
    messageSource.setPropertiesPersister(
            new RecursivePropertiesPersister(new ApostropheEscapingPropertiesPersister()));

    final Class<?>[] classes = URL.class.getDeclaredClasses();
    final UrlDefinitionsToMessages urlDefinitions = new UrlDefinitionsToMessages(classes);
    urlDefinitions.addParamGroupAsMessages();
    urlDefinitions.addParamsAsMessages();
    urlDefinitions.addUrlsAsMessagesWithNamedParameters();
    Properties staticMessages = urlDefinitions.getMessages();
    final EntityPropertiesToMessages epm = new EntityPropertiesToMessages("net.sf.sze.model");
    staticMessages.putAll(epm.getProperties());
    final String version = buildNr.replace("SNAPSHOT", Long.toString(System.currentTimeMillis()));
    staticMessages.put("app.version", version);
    messageSource.setCommonMessages(staticMessages);
    return messageSource;
}