Example usage for org.springframework.web.servlet.i18n CookieLocaleResolver CookieLocaleResolver

List of usage examples for org.springframework.web.servlet.i18n CookieLocaleResolver CookieLocaleResolver

Introduction

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

Prototype

public CookieLocaleResolver() 

Source Link

Document

Create a new instance of the CookieLocaleResolver class using the #DEFAULT_COOKIE_NAME default cookie name .

Usage

From source file:org.oruko.dictionary.DictionaryApplication.java

@Bean
public LocaleResolver localeResolver() {
    CookieLocaleResolver cookieLocaleResolver = new CookieLocaleResolver();
    cookieLocaleResolver.setDefaultLocale(Locale.ENGLISH);
    return cookieLocaleResolver;
}

From source file:br.com.semanticwot.cd.conf.AppWebConfiguration.java

@Bean // Esse  o bean que resolve o locate
public LocaleResolver localeResolver() {
    return new CookieLocaleResolver();
}

From source file:com.aspose.showcase.qrcodegen.web.config.WebAppConfig.java

@Bean
public LocaleResolver localeResolver() {

    CookieLocaleResolver cookieLocaleResolver = new CookieLocaleResolver();
    cookieLocaleResolver.setDefaultLocale(StringUtils.parseLocaleString("en"));
    return cookieLocaleResolver;
}

From source file:org.openlmis.fulfillment.Application.java

/**
 * Creates new LocaleResolver./*from   w  w w  . j a  v a2  s  .c om*/
 *
 * @return Created LocalResolver.
 */
@Bean
public LocaleResolver localeResolver() {
    CookieLocaleResolver lr = new CookieLocaleResolver();
    lr.setCookieName("lang");
    lr.setDefaultLocale(locale);
    return lr;
}

From source file:de.whs.poodle.Poodle.java

@Bean(name = "localeResolver")
public LocaleResolver cookieLocaleResolver() {
    return new CookieLocaleResolver();
}

From source file:com.isalnikov.config.web.WebConfig.java

@Bean
public LocaleResolver localeResolver() {
    CookieLocaleResolver localeResolver = new CookieLocaleResolver();
    localeResolver.setDefaultLocale(new Locale("ru")); // change this Locale.ENGLISH)
    localeResolver.setCookieName("terminal_cookie");
    localeResolver.setCookieMaxAge(60 * 30);
    return localeResolver;
}

From source file:it.f2informatica.webapp.WebApplicationConfig.java

@Bean
public CookieLocaleResolver localeResolver() {
    CookieLocaleResolver cookieLocaleResolver = new CookieLocaleResolver();
    cookieLocaleResolver.setCookieName(CURRENT_LOCALE_COOKIE);
    return cookieLocaleResolver;
}

From source file:com.autentia.wuija.web.LocaleContextFilter.java

public void init(FilterConfig config) throws ServletException {
    final WebApplicationContext wac = WebApplicationContextUtils
            .getRequiredWebApplicationContext(config.getServletContext());
    try {/*ww w .  j  a  v  a  2 s  . co  m*/
        localeResolver = (LocaleResolver) wac.getBean("localeResolver", LocaleResolver.class);
        log.info("LocaleResolver defined: " + localeResolver.getClass().getSimpleName());

    } catch (NoSuchBeanDefinitionException e) {
        log.info("No LocaleResolver defined. Using " + CookieLocaleResolver.class.getSimpleName()
                + " by default");
        localeResolver = new CookieLocaleResolver();
    }
}

From source file:com.castlemock.war.config.MvcConfig.java

/**
 * Creates a locale resolver. This is used to identify which language is currently configured to be used
 * for a user/*from w  w w  . j a  v a  2  s . c  om*/
 * @return A new cookie locale resolver
 */
@Bean
public LocaleResolver localeResolver() {
    final CookieLocaleResolver ret = new CookieLocaleResolver();
    ret.setDefaultLocale(new Locale("en"));
    return ret;
}

From source file:org.openmrs.module.mirebalais.page.controller.LoginPageController.java

public String post(@RequestParam(value = "username", required = false) String username,
        @RequestParam(value = "password", required = false) String password,
        @RequestParam(value = "sessionLocation", required = false) Integer sessionLocationId,
        @SpringBean ContextDAO contextDao, @SpringBean("locationService") LocationService locationService,
        UiUtils ui, EmrContext context, PageRequest request) {

    HttpSession httpSession = request.getRequest().getSession();
    Location sessionLocation = null;
    try {//  w ww.j  a  va2 s.  c o m
        // TODO as above, grant this privilege to Anonymous instead of using a proxy privilege
        Context.addProxyPrivilege(PrivilegeConstants.VIEW_LOCATIONS);

        if (sessionLocationId != null) {
            sessionLocation = locationService.getLocation(sessionLocationId);
            if (!sessionLocation.hasTag(EmrConstants.LOCATION_TAG_SUPPORTS_LOGIN)) {
                // the UI shouldn't allow this, but protect against it just in case
                httpSession.setAttribute(EmrConstants.SESSION_ATTRIBUTE_ERROR_MESSAGE,
                        ui.message("mirebalais.login.error.invalidLocation"));
                return "redirect:" + ui.pageLink("mirebalais", "login");
            }
        }
        if (sessionLocation == null) {
            httpSession.setAttribute(EmrConstants.SESSION_ATTRIBUTE_ERROR_MESSAGE,
                    ui.message("mirebalais.login.error.locationRequired"));
            return "redirect:" + ui.pageLink("mirebalais", "login");
        }
        // Set a cookie, so next time someone logs in on this machine, we can default to that same location
        request.setCookieValue(EmrConstants.COOKIE_NAME_LAST_SESSION_LOCATION, sessionLocationId.toString());
    } finally {
        Context.removeProxyPrivilege(PrivilegeConstants.VIEW_LOCATIONS);
    }

    try {
        context.getUserContext().authenticate(username, password, contextDao);
        context.setSessionLocation(sessionLocation);

        // set the locale based on the user's default locale
        Locale userLocale = GeneralUtils.getDefaultLocale(context.getUserContext().getAuthenticatedUser());
        if (userLocale != null) {
            context.getUserContext().setLocale(userLocale);

            // these have been taken from the core login servlet, not sure if they are necessary
            request.getResponse().setLocale(userLocale);
            new CookieLocaleResolver().setDefaultLocale(userLocale);
        }

        return "redirect:" + ui.pageLink("mirebalais", "home");
    } catch (ContextAuthenticationException ex) {
        httpSession.setAttribute(EmrConstants.SESSION_ATTRIBUTE_ERROR_MESSAGE,
                ui.message("mirebalais.login.error.authentication"));
        return "redirect:" + ui.pageLink("mirebalais", "login");
    }
}