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

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

Introduction

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

Prototype

ReloadableResourceBundleMessageSource

Source Link

Usage

From source file:com.surveypanel.form.InMemoryFormFactory.java

@Override
public MessageSource getMessageSource(long surveyId) {
    ReloadableResourceBundleMessageSource msg = new ReloadableResourceBundleMessageSource();
    msg.setBasename("messages");
    msg.setDefaultEncoding("UTF-8");
    msg.setCacheSeconds(10);//w  ww.  j  av  a  2  s . com
    msg.setUseCodeAsDefaultMessage(true);
    return msg;
}

From source file:org.obiba.onyx.spring.context.OnyxMessageSourceFactoryBean.java

public Object getObject() throws Exception {
    ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource();
    messageSource.setResourceLoader(resourceLoader);

    Set<String> basenames = new TreeSet<String>();
    if (this.resourceLoader instanceof ResourcePatternResolver) {
        findBasenames(basenames, onyxConfigPath, MESSAGES_PROPERTIES_SUFFIX);
        findBasenames(basenames, onyxConfigPath, MESSAGES_XML_SUFFIX);
    }//from ww w . j a  v  a 2  s . co m
    if (extraBasenames != null) {
        basenames.addAll(extraBasenames);
    }
    String[] basenamesArray = basenames.toArray(new String[] {});
    log.debug("MessageSource contains the following basenames: {}", Arrays.toString(basenamesArray));
    messageSource.setBasenames(basenamesArray);

    MessageSource moduleMessageSource = loadJarBundles();
    messageSource.setParentMessageSource(moduleMessageSource);

    return new StringReferenceFormatingMessageSource(messageSource);
}

From source file:com.mycompany.thymeleafspringapp.config.AppConfig.java

@Bean
public MessageSource messageSource() {
    ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource();
    messageSource.setBasename("WEB-INF/messages");
    messageSource.setDefaultEncoding("UTF-8");
    return messageSource;
}

From source file:net.rgielen.actionframeworks.springmvc.ApplicationConfig.java

@Bean
public MessageSource messageSource() {
    final ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource();
    messageSource.setDefaultEncoding("UTF-8");
    messageSource.setBasenames("classpath:messages", "classpath:net/rgielen/actionframeworks/domain/Actor");
    return messageSource;
}

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

/**
 * This bean tells the application which message bundle to use.
 * /*from w  w w  .  j  a v a  2 s  .co  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.jawr.web.resource.bundle.locale.message.GrailsMessageBundleScriptCreator.java

public Reader createScript(Charset charset) {

    // Determine wether this is run-app or run-war style of runtime. 
    boolean warDeployed = ((Boolean) this.servletContext.getAttribute(JawrConstant.GRAILS_WAR_DEPLOYED))
            .booleanValue();//from   www  .  j  a  va  2 s .  c o  m

    // Spring message bundle object, the same used by grails. 
    ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource();
    messageSource.setFallbackToSystemLocale(false);
    Set<String> allPropertyNames = null;

    // Read the properties files to find out the available message keys. It is done differently 
    // for run-app or run-war style of runtimes. 
    if (warDeployed) {
        allPropertyNames = getPropertyNamesFromWar();
        if (LOGGER.isDebugEnabled())
            LOGGER.debug("found a total of " + allPropertyNames.size() + " distinct message keys.");
        messageSource.setResourceLoader(new ServletContextResourceLoader(this.servletContext));
        messageSource.setBasename(PROPERTIES_DIR + configParam.substring(configParam.lastIndexOf('.') + 1));
    } else {
        ResourceBundle bundle;
        if (null != locale)
            bundle = ResourceBundle.getBundle(configParam, locale);
        else
            bundle = ResourceBundle.getBundle(configParam);
        allPropertyNames = new HashSet<String>();
        Enumeration<String> keys = bundle.getKeys();
        while (keys.hasMoreElements())
            allPropertyNames.add(keys.nextElement());
        String basename = "file:./" + configParam.replaceAll("\\.", "/");
        messageSource.setBasename(basename);
    }

    // Pass all messages to a properties file. 
    Properties props = new Properties();
    for (Iterator<String> it = allPropertyNames.iterator(); it.hasNext();) {
        String key = it.next();
        if (matchesFilter(key)) {
            try {
                // Use the property encoding of the file
                String msg = new String(
                        messageSource.getMessage(key, new Object[0], locale).getBytes(CHARSET_ISO_8859_1),
                        charset.displayName());
                props.put(key, msg);
            } catch (NoSuchMessageException e) {
                // This is expected, so it's OK to have an empty catch block. 
                if (LOGGER.isDebugEnabled())
                    LOGGER.debug("Message key [" + key + "] not found.");
            } catch (UnsupportedEncodingException e) {
                LOGGER.warn("Unable to convert value of message bundle associated to key '" + key
                        + "' because the charset is unknown");
            }
        }
    }

    return doCreateScript(props);
}

From source file:at.porscheinformatik.common.spring.web.extended.config.SpringWebExtendedConfig.java

@Bean
public MessageSource messageSource() {
    ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource();
    messageSource.setFallbackToSystemLocale(false);

    configurerConfig.configureMessageSource(messageSource);

    return messageSource;
}

From source file:org.pavlov.springmvcjavaconfig.config.WebConfig.java

@Bean
public MessageSource messageSource() {
    ReloadableResourceBundleMessageSource rrbm = new ReloadableResourceBundleMessageSource();
    rrbm.setBasename("locale/ApplicationMessageSource");
    rrbm.setDefaultEncoding("UTF-8");
    return rrbm;/*  w  w  w .j a v  a 2  s  .  c  o m*/
}

From source file:com.isalnikov.config.web.WebConfig.java

@Bean
public MessageSource messageSource() {
    ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource();
    messageSource.setUseCodeAsDefaultMessage(true);
    messageSource.setDefaultEncoding("UTF-8");
    messageSource.setBasenames("classpath:message");
    messageSource.setCacheSeconds(5);/*from  w ww  .j  a v  a2s .  c  om*/
    messageSource.setFallbackToSystemLocale(false);// ???
    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);/*from   ww  w. j a  va2 s  .c  om*/

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