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

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

Introduction

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

Prototype

public void setBasename(String basename) 

Source Link

Document

Set a single basename, following the basic ResourceBundle convention of not specifying file extension or language codes.

Usage

From source file:com.castlemock.war.config.MvcConfig.java

/**
 * Creates a Reloadable resource bundle message source. The resource is responsible for keeping track of the basename and
 * which encoding will be used on the application.
 * @return Returns a new Reloadable resource bundle message source
 *///from  w w w  . j  a  va  2  s  .c o  m
@Bean
public MessageSource messageSource() {
    final ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource();
    messageSource.setBasename("classpath:language/messages");
    messageSource.setDefaultEncoding("UTF-8");
    return messageSource;
}

From source file:com.tkmtwo.rest.config.RestConfig.java

@Bean
public MessageSource httpErrorMessageSource() {
    ReloadableResourceBundleMessageSource m = new ReloadableResourceBundleMessageSource();
    //m.setBasename("classpath:/aisp/exhandler/messages");
    m.setBasename(env.getProperty("messagesource.basename"));
    m.setDefaultEncoding("UTF-8");
    return m;//  ww w  .  ja  v  a2s. c  o  m
}

From source file:com.springsource.greenhouse.config.WebConfig.java

public Validator getValidator() {
    LocalValidatorFactoryBean factory = new LocalValidatorFactoryBean();
    ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource();
    messageSource.setBasename("/WEB-INF/messages/validation");
    if (environment.acceptsProfiles("embedded")) {
        messageSource.setCacheSeconds(0);
    }/*from   w w w  .  java 2s . c om*/
    factory.setValidationMessageSource(messageSource);
    return factory;
}

From source file:com.springsource.greenhouse.config.WebConfig.java

/**
 * Messages to support internationalization/localization.
 *///from w  w  w  . j  a v  a 2 s  . c  o  m
@Bean
public MessageSource messageSource() {
    ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource();
    messageSource.setBasename("/WEB-INF/messages/messages");
    if (environment.acceptsProfiles("embedded")) {
        messageSource.setCacheSeconds(0);
    }
    return messageSource;
}

From source file:se.kth.csc.config.WebMvcConfig.java

@Bean(name = "messageSource")
public MessageSource messageSource() {
    ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource();

    // Configure the location of messages
    messageSource.setBasename(MESSAGE_SOURCE);

    // Cache messages for a while, but make sure that they can be edited at run-time
    messageSource.setCacheSeconds(5);// w  w  w . j a  v  a 2  s  .c o  m

    log.info("Creating message source reading from {} that caches for 5 seconds", MESSAGE_SOURCE);
    return messageSource;
}

From source file:nu.yona.server.CoreConfiguration.java

/**
 * This bean tells the application which message bundle to use.
 * /*www.ja  v  a 2 s. c  o m*/
 * @return The message bundle source
 */
@Bean(name = "messageSource")
public ReloadableResourceBundleMessageSource messageSource() {
    ReloadableResourceBundleMessageSource messageBundle = new ReloadableResourceBundleMessageSource();

    messageBundle.setFallbackToSystemLocale(false);
    messageBundle.setBasename("classpath:messages/messages");
    messageBundle.setDefaultEncoding("UTF-8");

    return messageBundle;
}

From source file:net.sf.yal10n.analyzer.ExploratoryEncodingTest.java

/**
 * Test to load a resource bundle via Spring's message source when the file is
 * encoded with a BOM and starts with a blank line.
 * @throws Exception any error//from  w ww  .  j av  a2 s . c o m
 */
@Test
public void testSpringMessageSourceBOMandBlankLine() throws Exception {
    ReloadableResourceBundleMessageSource source = new ReloadableResourceBundleMessageSource();
    source.setBasename("UTF8BOMwithBlankLine");
    source.setDefaultEncoding("UTF-8");
    source.setFallbackToSystemLocale(false);

    Assert.assertEquals("first key", source.getMessage("testkey1", null, Locale.ROOT));
    Assert.assertEquals("second key", source.getMessage("testkey2", null, Locale.ROOT));
    Assert.assertEquals("This file is encoded as UTF-8 with BOM .",
            source.getMessage("description", null, Locale.ROOT));
}

From source file:net.sf.yal10n.analyzer.ExploratoryEncodingTest.java

/**
 * Test to load a resource bundle via Spring's message source when the file
 * is encoded with a BOM and the correct encoding is used.
 * @throws Exception any error/*  w  w w .  j  av a  2  s  . co  m*/
 */
@Test
public void testSpringMessageSourceBOM() throws Exception {
    ReloadableResourceBundleMessageSource source = new ReloadableResourceBundleMessageSource();
    source.setBasename("UTF8BOM");
    source.setDefaultEncoding("UTF-8-BOM");
    source.setFallbackToSystemLocale(false);

    Assert.assertEquals("first key", source.getMessage("testkey1", null, Locale.ROOT));
    Assert.assertEquals("second key", source.getMessage("testkey2", null, Locale.ROOT));
    Assert.assertEquals("This file is encoded as UTF-8 with BOM .",
            source.getMessage("description", null, Locale.ROOT));
}

From source file:net.sf.yal10n.analyzer.ExploratoryEncodingTest.java

/**
 * Test to load a resource bundle via Spring's message source when the file
 * is encoded with a BOM and starts with a comment. 
 * @throws Exception any error//w ww  .  j av  a  2s. c o  m
 */
@Test
public void testSpringMessageSourceBOMandComment() throws Exception {
    ReloadableResourceBundleMessageSource source = new ReloadableResourceBundleMessageSource();
    source.setBasename("UTF8BOMwithComment");
    source.setDefaultEncoding("UTF-8");
    source.setFallbackToSystemLocale(false);

    Assert.assertEquals("", source.getMessage("\ufeff#abc", null, Locale.ROOT));
    Assert.assertEquals("first key", source.getMessage("testkey1", null, Locale.ROOT));
    Assert.assertEquals("second key", source.getMessage("testkey2", null, Locale.ROOT));
    Assert.assertEquals("This file is encoded as UTF-8 with BOM .",
            source.getMessage("description", null, Locale.ROOT));
}

From source file:net.sf.yal10n.analyzer.ExploratoryEncodingTest.java

/**
 * Test to load a resource bundle via Spring's message source when the file is
 * encoded with a BOM./* w  w w  .  j av a  2s. c  om*/
 * @throws Exception any error
 */
@Test
public void testSpringMessageSourceBOMDefault() throws Exception {
    ReloadableResourceBundleMessageSource source = new ReloadableResourceBundleMessageSource();
    source.setBasename("UTF8BOM");
    source.setDefaultEncoding("UTF-8");
    source.setFallbackToSystemLocale(false);

    // Assert.assertEquals("first key", source.getMessage("testkey1", null, Locale.ROOT));
    // note: utf-8 bom read as first character
    Assert.assertEquals("first key", source.getMessage("\ufefftestkey1", null, Locale.ROOT));
    Assert.assertEquals("second key", source.getMessage("testkey2", null, Locale.ROOT));
    Assert.assertEquals("This file is encoded as UTF-8 with BOM .",
            source.getMessage("description", null, Locale.ROOT));
}