Example usage for org.springframework.context.support StaticMessageSource addMessages

List of usage examples for org.springframework.context.support StaticMessageSource addMessages

Introduction

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

Prototype

public void addMessages(Map<String, String> messages, Locale locale) 

Source Link

Document

Associate the given message values with the given keys as codes.

Usage

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

protected MessageSource loadJarBundles() throws IOException {
    ResourcePatternResolver resolver = (ResourcePatternResolver) this.resourceLoader;

    String bundlePattern = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX + "META-INF/" + MESSAGES_BUNDLENAME
            + "*" + MESSAGES_PROPERTIES_SUFFIX;

    Resource[] messageResources = resolver.getResources(bundlePattern);

    StaticMessageSource sms = new StaticMessageSource();
    for (int i = 0; i < messageResources.length; i++) {
        Resource resource = messageResources[i];
        Locale locale = extractLocale(resource, MESSAGES_PROPERTIES_SUFFIX);
        log.debug("Found module bundle resource {} with locale {}", resource.getDescription(), locale);

        Properties props = new Properties();
        props.load(resource.getInputStream());
        sms.addMessages(Maps.fromProperties(props), locale);
    }//from  w  w w  .  jav  a  2  s .c o  m
    return sms;
}