package net.sourceforge.rtf.util;

import java.util.Locale;

import javax.servlet.http.HttpServletRequest;

import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.servlet.support.RequestContextUtils;

public class WebApplicationContextUtil {

	private WebApplicationContext webApplicationContext;
	private Locale locale;

	public WebApplicationContextUtil(HttpServletRequest request) {
		super();
		this.webApplicationContext = RequestContextUtils.findWebApplicationContext(request);
		this.locale = RequestContextUtils.getLocale(request);
	}
	
	public String getMessage(String code) {
		return getMessage(code, locale);
	}
	
	public String getMessage(String code, String defaultMessage) {
		return getMessage(code, locale, defaultMessage, null);
	}
	
	public String getMessage(String code, Locale locale, String...args) {
		return webApplicationContext.getMessage(code, args, locale);
	}
	
	public String getMessage(String code, Locale locale, String defaultMessage, String...args) {
		return webApplicationContext.getMessage(code, args, defaultMessage, locale);
	}
	
}
