List of usage examples for org.springframework.context.support ReloadableResourceBundleMessageSource setResourceLoader
@Override public void setResourceLoader(@Nullable ResourceLoader resourceLoader)
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 w ww .j ava2 s . com 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.acc.storefront.web.theme.StorefrontResourceBundleSource.java
protected AbstractMessageSource createMessageSource(final String basename) { final ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource(); messageSource.setBasename(basename); messageSource.setCacheSeconds(getCacheSeconds()); messageSource.setResourceLoader(getResourceLoader()); messageSource.setFallbackToSystemLocale(fallbackToSystemLocale); messageSource.setDefaultEncoding(getDefaultEncoding()); return messageSource; }
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 ww w .ja v a 2s.co 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); }