@Test public void should_return_the_message_when_the_key_is_present_in_the_bundle() throws UnsupportedEncodingException, IOException{ InputStream stream = getClass().getClassLoader().getResourceAsStream("com/github/dandelion/datatables/jsp/i18n/datatables_en.properties"); ResourceBundle bundle = new PropertyResourceBundle(new InputStreamReader(stream, "UTF-8")); pageContext = new MockPageContext(); pageContext.setAttribute(Config.FMT_LOCALIZATION_CONTEXT + ".page", new LocalizationContext(bundle, new Locale("en", "US"))); JstlMessageResolver messageResolver = new JstlMessageResolver(request); String message = messageResolver.getResource("global.msg.info", "default", pageContext); assertThat(message).isEqualTo("My infos"); }
public String getResource(String messageKey, String defaultValue, Object... params) { PageContext pageContext = (PageContext) params[0]; String message = null; ResourceBundle bundle = null; LocalizationContext localizationContext = BundleSupport.getLocalizationContext(pageContext); if (localizationContext != null) { bundle = localizationContext.getResourceBundle(); } if (bundle != null) { if (messageKey == null || StringUtils.isBlank(messageKey) && StringUtils.isNotBlank(defaultValue)) { message = StringUtils.capitalize(defaultValue); } else { try { message = bundle.getString(messageKey); } catch (MissingResourceException e) { logger.warn("No message found with the key The message key {} and locale {}.", messageKey, localizationContext.getLocale()); message = UNDEFINED_KEY + messageKey + UNDEFINED_KEY; } } } else { logger.warn("The bundle hasn't been retrieved. Please check your i18n configuration."); message = UNDEFINED_KEY + messageKey + UNDEFINED_KEY; } return message; }
JstlMessageResolver extends AbstractMessageResolver { public String getResource(String messageKey, String defaultValue, Object... params) { PageContext pageContext = (PageContext) params[0]; String message = null; ResourceBundle bundle = null; LocalizationContext localizationContext = BundleSupport.getLocalizationContext(pageContext); if (localizationContext != null) { bundle = localizationContext.getResourceBundle(); } if (bundle != null) { if (messageKey == null || StringUtils.isBlank(messageKey) && StringUtils.isNotBlank(defaultValue)) { message = StringUtils.capitalize(defaultValue); } else { try { message = bundle.getString(messageKey); } catch (MissingResourceException e) { logger.warn("No message found with the key The message key {} and locale {}.", messageKey, localizationContext.getLocale()); message = UNDEFINED_KEY + messageKey + UNDEFINED_KEY; } } } else { logger.warn("The bundle hasn't been retrieved. Please check your i18n configuration."); message = UNDEFINED_KEY + messageKey + UNDEFINED_KEY; } return message; } }
JstlMessageResolver extends AbstractMessageResolver { public String getResource(String messageKey, String defaultValue, Object... params) { PageContext pageContext = (PageContext) params[0]; String message = null; ResourceBundle bundle = null; LocalizationContext localizationContext = BundleSupport.getLocalizationContext(pageContext); if (localizationContext != null) { bundle = localizationContext.getResourceBundle(); } if (bundle != null) { if (messageKey == null || StringUtils.isBlank(messageKey) && StringUtils.isNotBlank(defaultValue)) { message = StringUtils.capitalize(defaultValue); } else { try { message = bundle.getString(messageKey); } catch (MissingResourceException e) { logger.warn("No message found with the key The message key {} and locale {}.", messageKey, localizationContext.getLocale()); message = UNDEFINED_KEY + messageKey + UNDEFINED_KEY; } } } else { logger.warn("The bundle hasn't been retrieved. Please check your i18n configuration."); message = UNDEFINED_KEY + messageKey + UNDEFINED_KEY; } return message; } JstlMessageResolver(HttpServletRequest request); }
JstlMessageResolver extends AbstractMessageResolver { public String getResource(String messageKey, String defaultValue, Object... params) { PageContext pageContext = (PageContext) params[0]; String message = null; ResourceBundle bundle = null; LocalizationContext localizationContext = BundleSupport.getLocalizationContext(pageContext); if (localizationContext != null) { bundle = localizationContext.getResourceBundle(); } if (bundle != null) { if (messageKey == null || StringUtils.isBlank(messageKey) && StringUtils.isNotBlank(defaultValue)) { message = StringUtils.capitalize(defaultValue); } else { try { message = bundle.getString(messageKey); } catch (MissingResourceException e) { logger.warn("No message found with the key The message key {} and locale {}.", messageKey, localizationContext.getLocale()); message = UNDEFINED_KEY + messageKey + UNDEFINED_KEY; } } } else { logger.warn("The bundle hasn't been retrieved. Please check your i18n configuration."); message = UNDEFINED_KEY + messageKey + UNDEFINED_KEY; } return message; } JstlMessageResolver(HttpServletRequest request); String getResource(String messageKey, String defaultValue, Object... params); }
JstlMessageResolver extends AbstractMessageResolver { public String getResource(String messageKey, String defaultValue, Object... params) { PageContext pageContext = (PageContext) params[0]; String message = null; ResourceBundle bundle = null; LocalizationContext localizationContext = BundleSupport.getLocalizationContext(pageContext); if (localizationContext != null) { bundle = localizationContext.getResourceBundle(); } if (bundle != null) { if (messageKey == null || StringUtils.isBlank(messageKey) && StringUtils.isNotBlank(defaultValue)) { message = StringUtils.capitalize(defaultValue); } else { try { message = bundle.getString(messageKey); } catch (MissingResourceException e) { logger.warn("No message found with the key The message key {} and locale {}.", messageKey, localizationContext.getLocale()); message = UNDEFINED_KEY + messageKey + UNDEFINED_KEY; } } } else { logger.warn("The bundle hasn't been retrieved. Please check your i18n configuration."); message = UNDEFINED_KEY + messageKey + UNDEFINED_KEY; } return message; } JstlMessageResolver(HttpServletRequest request); String getResource(String messageKey, String defaultValue, Object... params);  }