/*
Copyright (C) European Community 2008 - Licensed under the EUPL V.1.0 (http://ec.europa.eu/idabc/en/document/6523)
*/
package it.hotel.controller.locale;
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.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;
import org.springframework.web.servlet.support.RequestContextUtils;
/**
*
*
*/
public class SetLocaleController extends AbstractController {
protected LocaleContainer localeContainer;
public LocaleContainer getLocaleContainer() {
return localeContainer;
}
public void setLocaleContainer(LocaleContainer localeContainer) {
this.localeContainer = localeContainer;
}
/**
* @throws
* @return
*/
@Override
protected ModelAndView handleRequestInternal(HttpServletRequest req,
HttpServletResponse res) throws Exception {
String language = req.getParameter("language");
Locale locale = StringUtils.parseLocaleString(language);
LocaleResolver localeResolver = RequestContextUtils.getLocaleResolver(req);
localeResolver.setLocale(req, res, locale);
localeContainer.setLocale(locale.getLanguage());
return new ModelAndView("redirect:/");
}
}