@RequestMapping(value = "/", method = RequestMethod.GET)
 public String getTasksForPerformer(
     ModelMap model,
     @RequestParam(value = "tag", required = false) String tag,
     @RequestParam(value = "lang", required = false) String lang,
     HttpServletRequest request) {
   if (SecurityContextHolder.getContext().getAuthentication().getPrincipal()
       instanceof UserDetailsImpl) {
     model.put("ordersActive", true);
     model.put("tag", tag != null ? "#" + tag : "");
     return "announcmentsForPerformer";
   } else {
     if (lang != null) {
       return "redirect:/";
     }
     List<LandingSlideModel> allSlidesPeople =
         landingSlideService.findAllSlidesPeopleModel(
             localeResolver.resolveLocale(request).getLanguage());
     List<LandingSlideModel> allSlidesBusiness =
         landingSlideService.findAllSlidesBusinessModel(
             localeResolver.resolveLocale(request).getLanguage());
     List<LandingSlideModel> allSlidesBenefits =
         landingSlideService.findAllSlidesIconsModel(
             localeResolver.resolveLocale(request).getLanguage());
     Hibernate.initialize(allSlidesPeople);
     Hibernate.initialize(allSlidesBusiness);
     Hibernate.initialize(allSlidesBenefits);
     model.put("allSlidesPeople", allSlidesPeople);
     model.put("allSlidesBusiness", allSlidesBusiness);
     model.put("allSlidesBenefits", allSlidesBenefits);
     return "landing";
   }
 }
 protected void service(HttpServletRequest request, HttpServletResponse response)
     throws ServletException, IOException {
   final Locale locale = localeResolver.resolveLocale(request);
   LocaleContextHolder.setLocale(locale);
   ServletRequestAttributes requestAttributes = new ServletRequestAttributes(request);
   RequestContextHolder.setRequestAttributes(requestAttributes);
   try {
     super.service(
         new HttpServletRequestWrapper(request) {
           @Override
           public Locale getLocale() {
             return locale;
           }
         },
         response);
   } finally {
     if (!locale.equals(LocaleContextHolder.getLocale())) {
       if (logger.isDebugEnabled()) {
         logger.debug("locale changed, updating locale resolver");
       }
       localeResolver.setLocale(request, response, LocaleContextHolder.getLocale());
     }
     LocaleContextHolder.resetLocaleContext();
     RequestContextHolder.resetRequestAttributes();
   }
 }
Beispiel #3
0
 protected String getMessage(String code, Object[] args) {
   HttpServletRequest request =
       ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
   LocaleResolver localeResolver = RequestContextUtils.getLocaleResolver(request);
   Locale locale = localeResolver.resolveLocale(request);
   return getRes().getMessage(code, args, locale);
 }
  /**
   * Initialize this context with the given request, using the given model attributes for Errors
   * retrieval.
   *
   * <p>Delegates to {@code getFallbackLocale} and {@code getFallbackTheme} for determining the
   * fallback locale and theme, respectively, if no LocaleResolver and/or ThemeResolver can be found
   * in the request.
   *
   * @param request current HTTP request
   * @param servletContext the servlet context of the web application (can be {@code null};
   *     necessary for fallback to root WebApplicationContext)
   * @param model the model attributes for the current view (can be {@code null}, using the request
   *     attributes for Errors retrieval)
   * @see #getFallbackLocale
   * @see #getFallbackTheme
   * @see org.springframework.web.servlet.DispatcherServlet#LOCALE_RESOLVER_ATTRIBUTE
   * @see org.springframework.web.servlet.DispatcherServlet#THEME_RESOLVER_ATTRIBUTE
   */
  protected void initContext(
      HttpServletRequest request,
      HttpServletResponse response,
      ServletContext servletContext,
      Map<String, Object> model) {

    this.request = request;
    this.response = response;
    this.model = model;

    // Fetch WebApplicationContext, either from DispatcherServlet or the root context.
    // ServletContext needs to be specified to be able to fall back to the root context!
    this.webApplicationContext =
        (WebApplicationContext) request.getAttribute(WEB_APPLICATION_CONTEXT_ATTRIBUTE);
    if (this.webApplicationContext == null) {
      this.webApplicationContext =
          RequestContextUtils.getWebApplicationContext(request, servletContext);
    }

    // Determine locale to use for this RequestContext.
    LocaleResolver localeResolver = RequestContextUtils.getLocaleResolver(request);
    if (localeResolver instanceof LocaleContextResolver) {
      LocaleContext localeContext =
          ((LocaleContextResolver) localeResolver).resolveLocaleContext(request);
      this.locale = localeContext.getLocale();
      if (localeContext instanceof TimeZoneAwareLocaleContext) {
        this.timeZone = ((TimeZoneAwareLocaleContext) localeContext).getTimeZone();
      }
    } else if (localeResolver != null) {
      // Try LocaleResolver (we're within a DispatcherServlet request).
      this.locale = localeResolver.resolveLocale(request);
    }

    // Try JSTL fallbacks if necessary.
    if (this.locale == null) {
      this.locale = getFallbackLocale();
    }
    if (this.timeZone == null) {
      this.timeZone = getFallbackTimeZone();
    }

    // Determine default HTML escape setting from the "defaultHtmlEscape"
    // context-param in web.xml, if any.
    this.defaultHtmlEscape =
        WebUtils.getDefaultHtmlEscape(this.webApplicationContext.getServletContext());

    // Determine response-encoded HTML escape setting from the "responseEncodedHtmlEscape"
    // context-param in web.xml, if any.
    this.responseEncodedHtmlEscape =
        WebUtils.getResponseEncodedHtmlEscape(this.webApplicationContext.getServletContext());

    this.urlPathHelper = new UrlPathHelper();

    if (this.webApplicationContext.containsBean(REQUEST_DATA_VALUE_PROCESSOR_BEAN_NAME)) {
      this.requestDataValueProcessor =
          this.webApplicationContext.getBean(
              REQUEST_DATA_VALUE_PROCESSOR_BEAN_NAME, RequestDataValueProcessor.class);
    }
  }
Beispiel #5
0
 /** 获得i18n字符串 */
 public static String getMessage(String code, Object[] args) {
   LocaleResolver localLocaleResolver =
       (LocaleResolver) SpringContextHolder.getBean(LocaleResolver.class);
   HttpServletRequest request =
       ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
   Locale localLocale = localLocaleResolver.resolveLocale(request);
   return SpringContextHolder.getApplicationContext().getMessage(code, args, localLocale);
 }
Beispiel #6
0
 @RequestMapping(value = "/canviaIdioma", method = RequestMethod.GET)
 public String canviaIdioma(
     @RequestParam String idioma,
     HttpServletRequest request,
     HttpSession session,
     HttpServletResponse response) {
   LocaleResolver localeResolver = RequestContextUtils.getLocaleResolver(request);
   localeResolver.setLocale(request, response, new Locale(idioma));
   session.setAttribute("data", obtenirData(localeResolver.resolveLocale(request)));
   return "redirect:/";
 }
Beispiel #7
0
 public void doTag() throws JspException, IOException {
   Locale localLocale = _$3.resolveLocale(request());
   if (this._$1.size() == 0) {
     String localObject = ResourceBundleHelper.getString(localLocale, this._$2);
     write((String) localObject);
   } else {
     String[] localObject = new String[this._$1.size()];
     for (int i = 0; i < this._$1.size(); ++i) {
       String str2 = (String) this._$1.get(i);
       if ((str2 != null) && (str2.startsWith("message:")))
         localObject[i] =
             ResourceBundleHelper.getString(localLocale, str2.substring("message:".length()));
       else localObject[i] = str2;
     }
     String str1 = ResourceBundleHelper.getString(localLocale, this._$2, localObject);
     write(str1);
   }
 }
Beispiel #8
0
/*
 private Locale getLocale(final HttpServletRequest request) {
   final Locale locale = localeResolver.resolveLocale(request);
   if (locale == null) return Locale.ENGLISH;
   if (!Constants.SUPPORTED_LOCALES.contains(locale.getLanguage())) return Locale.ENGLISH;
   return new Locale(locale.getLanguage());
 }