Example usage for org.springframework.web.servlet.i18n SessionLocaleResolver setLocale

List of usage examples for org.springframework.web.servlet.i18n SessionLocaleResolver setLocale

Introduction

In this page you can find the example usage for org.springframework.web.servlet.i18n SessionLocaleResolver setLocale.

Prototype

@Override
    public void setLocale(HttpServletRequest request, @Nullable HttpServletResponse response,
            @Nullable Locale locale) 

Source Link

Usage

From source file:no.abmu.common.locale.LocaleUtil.java

/**
 * Setting session start locale. //from  w ww  .  jav  a2  s.com
 * 
 * Currently support the following languages: bokml and nynorsk.
 * StartLocale are used when starting application to enschure starting with 
 * bokml or nynorsk. siteLocale is used by inspectors to enable user to switch
 * locale. These to variables must have different names. 
 * 
 * @param request current HTTP request
 * @param response current HTTP response
 * @param startLocaleHttpParameterName Parameter name for start locale 
 *         http parameter, default is "startLocale".
 */
public void settingSessionStartLocale(HttpServletRequest request, HttpServletResponse response,
        String startLocaleHttpParameterName) {

    Locale newLocale = null;
    String parameterName;
    SessionLocaleResolver sessionLocaleResolver;

    if (logger.isDebugEnabled()) {
        logger.debug("Before settingSessionStartLocale");
        logLocale(request);
    }

    if (null == startLocaleHttpParameterName) {
        parameterName = "startLocale";
    } else {
        parameterName = startLocaleHttpParameterName;
    }

    String startLocaleValue = request.getParameter(parameterName);
    if (null != startLocaleValue) {
        if (startLocaleValue.equals("no_NO")) {
            newLocale = LocaleTypeNameConst.BOKMAAL;
        } else if (startLocaleValue.equals("no_NO_NY")) {
            newLocale = LocaleTypeNameConst.NYNORSK;
        } else if (startLocaleValue.equals("en_GB")) {
            newLocale = LocaleTypeNameConst.ENGLISH;
        }

        if (null != newLocale) {
            sessionLocaleResolver = new SessionLocaleResolver();
            sessionLocaleResolver.setLocale(request, response, newLocale);
        }
    }
    if (logger.isDebugEnabled()) {
        logger.debug("After settingSessionStartLocale");
        logLocale(request);
    }
}