Java Code Examples for org.springframework.context.support.MessageSourceResourceBundle

The following examples show how to use org.springframework.context.support.MessageSourceResourceBundle. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
/**
 * Expose current Spring-managed Locale and MessageSource to JasperReports i18n
 * ($R expressions etc). The MessageSource should only be exposed as JasperReports
 * resource bundle if no such bundle is defined in the report itself.
 * <p>The default implementation exposes the Spring RequestContext Locale and a
 * MessageSourceResourceBundle adapter for the Spring ApplicationContext,
 * analogous to the {@code JstlUtils.exposeLocalizationContext} method.
 * @see org.springframework.web.servlet.support.RequestContextUtils#getLocale
 * @see org.springframework.context.support.MessageSourceResourceBundle
 * @see #getApplicationContext()
 * @see net.sf.jasperreports.engine.JRParameter#REPORT_LOCALE
 * @see net.sf.jasperreports.engine.JRParameter#REPORT_RESOURCE_BUNDLE
 * @see org.springframework.web.servlet.support.JstlUtils#exposeLocalizationContext
 */
protected void exposeLocalizationContext(Map<String, Object> model, HttpServletRequest request) {
	RequestContext rc = new RequestContext(request, getServletContext());
	Locale locale = rc.getLocale();
	if (!model.containsKey(JRParameter.REPORT_LOCALE)) {
		model.put(JRParameter.REPORT_LOCALE, locale);
	}
	TimeZone timeZone = rc.getTimeZone();
	if (timeZone != null && !model.containsKey(JRParameter.REPORT_TIME_ZONE)) {
		model.put(JRParameter.REPORT_TIME_ZONE, timeZone);
	}
	JasperReport report = getReport();
	if ((report == null || report.getResourceBundle() == null) &&
			!model.containsKey(JRParameter.REPORT_RESOURCE_BUNDLE)) {
		model.put(JRParameter.REPORT_RESOURCE_BUNDLE,
				new MessageSourceResourceBundle(rc.getMessageSource(), locale));
	}
}
 
Example 2
/**
 * Expose current Spring-managed Locale and MessageSource to JasperReports i18n
 * ($R expressions etc). The MessageSource should only be exposed as JasperReports
 * resource bundle if no such bundle is defined in the report itself.
 * <p>The default implementation exposes the Spring RequestContext Locale and a
 * MessageSourceResourceBundle adapter for the Spring ApplicationContext,
 * analogous to the {@code JstlUtils.exposeLocalizationContext} method.
 * @see org.springframework.web.servlet.support.RequestContextUtils#getLocale
 * @see org.springframework.context.support.MessageSourceResourceBundle
 * @see #getApplicationContext()
 * @see net.sf.jasperreports.engine.JRParameter#REPORT_LOCALE
 * @see net.sf.jasperreports.engine.JRParameter#REPORT_RESOURCE_BUNDLE
 * @see org.springframework.web.servlet.support.JstlUtils#exposeLocalizationContext
 */
protected void exposeLocalizationContext(Map<String, Object> model, HttpServletRequest request) {
	RequestContext rc = new RequestContext(request, getServletContext());
	Locale locale = rc.getLocale();
	if (!model.containsKey(JRParameter.REPORT_LOCALE)) {
		model.put(JRParameter.REPORT_LOCALE, locale);
	}
	TimeZone timeZone = rc.getTimeZone();
	if (timeZone != null && !model.containsKey(JRParameter.REPORT_TIME_ZONE)) {
		model.put(JRParameter.REPORT_TIME_ZONE, timeZone);
	}
	JasperReport report = getReport();
	if ((report == null || report.getResourceBundle() == null) &&
			!model.containsKey(JRParameter.REPORT_RESOURCE_BUNDLE)) {
		model.put(JRParameter.REPORT_RESOURCE_BUNDLE,
				new MessageSourceResourceBundle(rc.getMessageSource(), locale));
	}
}
 
Example 3
Source Project: spring-analysis-note   Source File: JstlUtils.java    License: MIT License 5 votes vote down vote up
@Override
public ResourceBundle getResourceBundle() {
	HttpSession session = this.request.getSession(false);
	if (session != null) {
		Object lcObject = Config.get(session, Config.FMT_LOCALIZATION_CONTEXT);
		if (lcObject instanceof LocalizationContext) {
			ResourceBundle lcBundle = ((LocalizationContext) lcObject).getResourceBundle();
			return new MessageSourceResourceBundle(this.messageSource, getLocale(), lcBundle);
		}
	}
	return new MessageSourceResourceBundle(this.messageSource, getLocale());
}
 
Example 4
Source Project: java-technology-stack   Source File: JstlUtils.java    License: MIT License 5 votes vote down vote up
@Override
public ResourceBundle getResourceBundle() {
	HttpSession session = this.request.getSession(false);
	if (session != null) {
		Object lcObject = Config.get(session, Config.FMT_LOCALIZATION_CONTEXT);
		if (lcObject instanceof LocalizationContext) {
			ResourceBundle lcBundle = ((LocalizationContext) lcObject).getResourceBundle();
			return new MessageSourceResourceBundle(this.messageSource, getLocale(), lcBundle);
		}
	}
	return new MessageSourceResourceBundle(this.messageSource, getLocale());
}
 
Example 5
Source Project: lams   Source File: JstlUtils.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public ResourceBundle getResourceBundle() {
	HttpSession session = this.request.getSession(false);
	if (session != null) {
		Object lcObject = Config.get(session, Config.FMT_LOCALIZATION_CONTEXT);
		if (lcObject instanceof LocalizationContext) {
			ResourceBundle lcBundle = ((LocalizationContext) lcObject).getResourceBundle();
			return new MessageSourceResourceBundle(this.messageSource, getLocale(), lcBundle);
		}
	}
	return new MessageSourceResourceBundle(this.messageSource, getLocale());
}
 
Example 6
Source Project: spring4-understanding   Source File: JstlUtils.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public ResourceBundle getResourceBundle() {
	HttpSession session = this.request.getSession(false);
	if (session != null) {
		Object lcObject = Config.get(session, Config.FMT_LOCALIZATION_CONTEXT);
		if (lcObject instanceof LocalizationContext) {
			ResourceBundle lcBundle = ((LocalizationContext) lcObject).getResourceBundle();
			return new MessageSourceResourceBundle(this.messageSource, getLocale(), lcBundle);
		}
	}
	return new MessageSourceResourceBundle(this.messageSource, getLocale());
}
 
Example 7
@Override
public void postHandle(
    HttpServletRequest request,
    HttpServletResponse response,
    Object handler,
    ModelAndView modelAndView) {
  if (modelAndView != null) {
    String viewName = modelAndView.getViewName();
    if (viewName == null || !viewName.startsWith("forward:")) {
      // use programmatic transaction instead of transaction annotation since we only want to
      // start a read-only transaction when a modelAndView exists
      TransactionTemplate transactionTemplate = new TransactionTemplate(transactionManager);
      transactionTemplate.setReadOnly(true);
      transactionTemplate.execute(
          status -> {
            modelAndView.addObject(
                KEY_RESOURCE_FINGERPRINT_REGISTRY, resourceFingerprintRegistry);
            modelAndView.addObject(KEY_THEME_FINGERPRINT_REGISTRY, themeFingerprintRegistry);
            modelAndView.addObject(KEY_APP_SETTINGS, createAppSettings());
            modelAndView.addObject(
                KEY_AUTHENTICATION_OIDC_CLIENTS, runAsSystem(this::getOidcClients));
            modelAndView.addObject(
                KEY_AUTHENTICATION_SIGN_UP, authenticationSettings.getSignUp());
            modelAndView.addObject(KEY_ENVIRONMENT, getEnvironmentAttributes());
            modelAndView.addObject(
                KEY_I18N,
                new MessageSourceResourceBundle(messageSource, LocaleContextHolder.getLocale()));
            modelAndView.addObject(KEY_GSON, gson);
            modelAndView.addObject(KEY_LANGUAGE, LocaleContextHolder.getLocale().getLanguage());
            modelAndView.addObject(KEY_FALLBACK_LANGUAGE, appSettings.getLanguageCode());
            modelAndView.addObject(
                KEY_SUPER_USER, userAccountService.getCurrentUser().isSuperuser());
            return null;
          });
    }
  }
}
 
Example 8
@Override
public ResourceBundle getResourceBundle(Locale locale) {
	return new MessageSourceResourceBundle(this.messageSource, locale);
}
 
Example 9
@Override
public ResourceBundle getResourceBundle(Locale locale) {
	return new MessageSourceResourceBundle(this.messageSource, locale);
}
 
Example 10
@Override
public ResourceBundle getResourceBundle(Locale locale) {
	return new MessageSourceResourceBundle(this.messageSource, locale);
}
 
Example 11
@Override
public ResourceBundle getResourceBundle(Locale locale) {
	return new MessageSourceResourceBundle(this.messageSource, locale);
}
 
Example 12
Source Project: tutorials   Source File: ClientWebConfigJava.java    License: MIT License 4 votes vote down vote up
@Bean
public ResourceBundle getBeanResourceBundle() {

    final Locale locale = Locale.getDefault();
    return new MessageSourceResourceBundle(messageSource(), locale);
}
 
Example 13
/**
 * Creates a localization ResourceBundle for current locale.
 *
 * @return MessageSourceResourceBundle
 */
@Deprecated
public static MessageSourceResourceBundle getBundle() {
  return new MessageSourceResourceBundle(getMessageSource(), getLocale());
}