Package org.springframework.web.servlet

Examples of org.springframework.web.servlet.LocaleResolver


  @Override
  public void postHandle(HttpServletRequest request,
      HttpServletResponse response, Object handler,
      ModelAndView modelAndView) throws Exception {
    LocaleResolver localeResolver = RequestContextUtils
        .getLocaleResolver(request);
    if (localeResolver == null) {
      throw new IllegalStateException(
          "No LocaleResolver found: not in a DispatcherServlet request?");
    }
    if (modelAndView != null) {
      modelAndView.getModelMap().addAttribute(LOCALE,
          localeResolver.resolveLocale(request).toString());
    }
  }
View Full Code Here


  @Override
  public boolean preHandle(HttpServletRequest request,
      HttpServletResponse response, Object handler)
      throws ServletException {
    LocaleResolver localeResolver = RequestContextUtils
        .getLocaleResolver(request);
    if (localeResolver == null) {
      throw new IllegalStateException(
          "No LocaleResolver found: not in a DispatcherServlet request?");
    }
    CmsSite site = CmsUtils.getSite(request);
    String newLocale = site.getLocaleAdmin();
    LocaleEditor localeEditor = new LocaleEditor();
    localeEditor.setAsText(newLocale);
    localeResolver.setLocale(request, response, (Locale) localeEditor
        .getValue());
    // Proceed in any case.
    return true;
  }
View Full Code Here

  @Override
  public void postHandle(HttpServletRequest request,
      HttpServletResponse response, Object handler,
      ModelAndView modelAndView) throws Exception {
    LocaleResolver localeResolver = RequestContextUtils
        .getLocaleResolver(request);
    if (localeResolver == null) {
      throw new IllegalStateException(
          "No LocaleResolver found: not in a DispatcherServlet request?");
    }
    if (modelAndView != null) {
      modelAndView.getModelMap().addAttribute(LOCALE,
          localeResolver.resolveLocale(request).toString());
    }
  }
View Full Code Here

   */
  public WebErrors(HttpServletRequest request) {
    WebApplicationContext webApplicationContext = RequestContextUtils
        .getWebApplicationContext(request);
    if (webApplicationContext != null) {
      LocaleResolver localeResolver = RequestContextUtils
          .getLocaleResolver(request);
      Locale locale;
      if (localeResolver != null) {
        locale = localeResolver.resolveLocale(request);
        this.messageSource = webApplicationContext;
        this.locale = locale;
      }
    }
  }
View Full Code Here

    WebApplicationContext messageSource = RequestContextUtils
        .getWebApplicationContext(request);
    if (messageSource == null) {
      throw new IllegalStateException("WebApplicationContext not found!");
    }
    LocaleResolver localeResolver = RequestContextUtils
        .getLocaleResolver(request);
    Locale locale;
    if (localeResolver != null) {
      locale = localeResolver.resolveLocale(request);
    } else {
      locale = request.getLocale();
    }
    return messageSource.getMessage(code, args, locale);
  }
View Full Code Here

        JCUser user = (JCUser) authentication.getPrincipal();
        userService.updateLastLoginTime(user);
        logger.info("JCUser logged in: " + user.getUsername());
        //apply language settings assuming CookieLocaleResolver usage
        String languageCode = user.getLanguage().getLanguageCode();
        LocaleResolver localeResolver = new CookieLocaleResolver();
        localeResolver.setLocale(request, response, user.getLanguage().getLocale());
        Cookie cookie = new Cookie(CookieLocaleResolver.DEFAULT_COOKIE_NAME, languageCode);
        cookie.setPath("/");
        response.addCookie(cookie);
        super.onAuthenticationSuccess(request, response, authentication);
    }
View Full Code Here

        JCUser jcuser = userService.getCurrentUser();
        Language languageFromRequest = Language.byLocale(new Locale(lang));
        if (!jcuser.isAnonymous()) {
            changeLanguageWithLockHandling(jcuser, languageFromRequest);
        }
        LocaleResolver localeResolver = RequestContextUtils.getLocaleResolver(request);
        localeResolver.setLocale(request, response, languageFromRequest.getLocale());
        return "redirect:" + request.getHeader("Referer");
    }
View Full Code Here

     * Change the pattern here to affect all the dates formatting on pages.
     */
    private void setDateFormattingOptions() {
        try {
            HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
            LocaleResolver localeResolver = RequestContextUtils.getLocaleResolver(request);
            this.setLocale(localeResolver.resolveLocale(request));
        } catch (JspTagException e) {
            throw new IllegalStateException("Error while rendering the date", e);
        }
    }
View Full Code Here

    @BeforeMethod
    public void setUp() {
        request = mock(HttpServletRequest.class);
        context = new MockPageContext(new MockServletContext(), request);
        LocaleResolver resolver = new FixedLocaleResolver(locale);
        when(request.getAttribute(DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE)).thenReturn(resolver);
        tag = new FormattedDate();
    }
View Full Code Here

        assertModelAttributeAvailable(mav, "postsPage");
    }

    @Test
    public void testSaveUserLanguage() throws ServletException {
        LocaleResolver localeResolver = mock(LocaleResolver.class);
        JCUser user = getUser();
        MockHttpServletRequest reuqest = new MockHttpServletRequest();
        MockHttpServletResponse response = new MockHttpServletResponse();
       
        reuqest.setAttribute(LOCALE_RESOLVER_ATTRIBUTE, localeResolver);
View Full Code Here

TOP

Related Classes of org.springframework.web.servlet.LocaleResolver

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.