/*******************************************************************************
 * Copyright 2Fi Business Solutions Ltd.
 *
 * This code is copyrighted. Under no circumstances should any party, people,
 * or organization should redistribute any portions of this code in any form,
 * either verbatim or through electronic media, to any third parties, unless
 * under explicit written permission by 2Fi Business Solutions Ltd.
 ******************************************************************************/
package com.ffii.core.utils;

import java.util.Locale;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.util.StringUtils;
import org.springframework.web.servlet.LocaleResolver;
import org.springframework.web.servlet.i18n.SessionLocaleResolver;

/**
 * Utility class for performing translation between Locale and String representations.
 */
public abstract class LocaleUtils {

	private static final LocaleResolver localeResolver = new SessionLocaleResolver();

	public static final String toString(Locale locale) {
		return locale.toString();
	}

	public static final Locale toLocale(String localeString) {
		return StringUtils.parseLocaleString(localeString);
	}

	public static final Locale resolveLocale(HttpServletRequest request) {
		return localeResolver.resolveLocale(request);
	}

	public static final String resolveLocaleString(HttpServletRequest request) {
		return resolveLocale(request).toString();
	}

	public static final void setLocale(HttpServletRequest request, HttpServletResponse response, Locale locale) {
		localeResolver.setLocale(request, response, locale);
	}

}