@Override
  public Locale resolveLocale(HttpServletRequest request) {

    Object locale = Config.get(request, Config.FMT_LOCALE);
    if (locale == null) {
      HttpSession session = request.getSession(false);
      if (session != null) {
        locale = Config.get(session, Config.FMT_LOCALE);
      }
    }

    return (locale instanceof Locale ? (Locale) locale : null);
  }
Пример #2
0
 public static Locale getJstlLocale(HttpServletRequest request, ServletContext servletContext) {
   Object localeObject = Config.get(request, Config.FMT_LOCALE);
   if (localeObject == null) {
     HttpSession session = request.getSession(false);
     if (session != null) {
       localeObject = Config.get(session, Config.FMT_LOCALE);
     }
     if (localeObject == null && servletContext != null) {
       localeObject = Config.get(servletContext, Config.FMT_LOCALE);
     }
   }
   return (localeObject instanceof Locale ? (Locale) localeObject : null);
 }
Пример #3
0
 public static TimeZone getJstlTimeZone(
     HttpServletRequest request, ServletContext servletContext) {
   Object timeZoneObject = Config.get(request, Config.FMT_TIME_ZONE);
   if (timeZoneObject == null) {
     HttpSession session = request.getSession(false);
     if (session != null) {
       timeZoneObject = Config.get(session, Config.FMT_TIME_ZONE);
     }
     if (timeZoneObject == null && servletContext != null) {
       timeZoneObject = Config.get(servletContext, Config.FMT_TIME_ZONE);
     }
   }
   return (timeZoneObject instanceof TimeZone ? (TimeZone) timeZoneObject : null);
 }
Пример #4
0
  /**
   * Get the Locale for a session according to the user's language selection or language
   * preferences. Order of selection - language selected via UI - language as set by application -
   * language browser default
   *
   * @param request the request Object
   * @return supportedLocale Locale supported by this DSpace Instance for this request
   */
  public static Locale getSessionLocale(HttpServletRequest request) {

    String paramLocale = request.getParameter("locale");
    Locale sessionLocale = null;
    Locale supportedLocale = null;

    if (!StringUtils.isEmpty(paramLocale)) {
      /* get session locale according to user selection */
      sessionLocale = new Locale(paramLocale);
    }

    if (sessionLocale == null) {
      /* get session locale set by application */
      HttpSession session = request.getSession();
      sessionLocale = (Locale) Config.get(session, Config.FMT_LOCALE);
    }

    /*
     * if session not set by selection or application then default browser
     * locale
     */
    if (sessionLocale == null) {
      sessionLocale = request.getLocale();
    }

    if (sessionLocale == null) {
      sessionLocale = I18nUtil.DEFAULTLOCALE;
    }
    supportedLocale = I18nUtil.getSupportedLocale(sessionLocale);

    return supportedLocale;
  }
Пример #5
0
  public void testJstlLocaleIsSet() throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.addParameter("locale", "es");

    MockHttpServletResponse response = new MockHttpServletResponse();
    request.setSession(new MockHttpSession(null));

    filter.doFilter(request, response, new MockFilterChain());

    assertNotNull(Config.get(request.getSession(), Config.FMT_LOCALE));
  }