Example usage for javax.servlet.jsp.jstl.core Config FMT_TIME_ZONE

List of usage examples for javax.servlet.jsp.jstl.core Config FMT_TIME_ZONE

Introduction

In this page you can find the example usage for javax.servlet.jsp.jstl.core Config FMT_TIME_ZONE.

Prototype

String FMT_TIME_ZONE

To view the source code for javax.servlet.jsp.jstl.core Config FMT_TIME_ZONE.

Click Source Link

Document

Name of localization setting for time zone

Usage

From source file:com.edgenius.core.webapp.filter.LocaleFilter.java

public void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain)
        throws IOException, ServletException {
    //       if(log.isDebugEnabled()){
    //          log.debug("Request URL: " + request.getRequestURI());
    //       }/*w w  w . ja  v  a 2  s .  c  o m*/

    //charset encoding
    if (!StringUtils.isEmpty(this.encoding))
        request.setCharacterEncoding(encoding);
    else
        request.setCharacterEncoding(Constants.UTF8);

    String direction = null;
    Locale preferredLocale = null;
    TimeZone timezone = null;
    HttpSession session = request.getSession(false);
    if (getUserService() != null) { //for Install mode, it will return null
        User user = getUserService().getUserByName(request.getRemoteUser());
        if (user != null && !user.isAnonymous()) {
            //locale
            UserSetting set = user.getSetting();
            String userLang = set.getLocaleLanguage();
            String userCountry = set.getLocaleCountry();
            if (userLang != null && userCountry != null) {
                preferredLocale = new Locale(userLang, userCountry);
            }
            //text direction in HTML 
            direction = set.getDirection();
            //timezone
            if (set.getTimeZone() != null)
                timezone = TimeZone.getTimeZone(set.getTimeZone());
        }
    }
    if (preferredLocale == null) {
        if (Global.DetectLocaleFromRequest) {
            Locale locale = request.getLocale();
            if (locale != null) {
                preferredLocale = locale;
            }
        }
        if (preferredLocale == null) {
            preferredLocale = Global.getDefaultLocale();
        }
    }

    if (direction == null) {
        direction = Global.DefaultDirection;
    }

    if (timezone == null) {
        if (session != null) {
            //try to get timezone from HttpSession, which will be intial set in SecurityControllerImpl.checkLogin() method
            timezone = (TimeZone) session.getAttribute(Constants.TIMEZONE);
        }
        if (timezone == null)
            timezone = TimeZone.getTimeZone(Global.DefaultTimeZone);
    }

    //set locale for STURTS and JSTL
    // set the time zone - must be set for dates to display the time zone
    if (session != null) {
        Config.set(session, Config.FMT_LOCALE, preferredLocale);
        session.setAttribute(Constants.DIRECTION, direction);
        Config.set(session, Config.FMT_TIME_ZONE, timezone);
    }

    //replace request by LocaleRequestWrapper
    if (!(request instanceof LocaleRequestWrapper)) {
        request = new LocaleRequestWrapper(request, preferredLocale);
        LocaleContextConfHolder.setLocale(preferredLocale);
    }

    if (chain != null) {
        request.setAttribute(PREFERRED_LOCALE, preferredLocale.toString());
        chain.doFilter(request, response);
    }
    // Reset thread-bound LocaleContext.
    LocaleContextConfHolder.setLocaleContext(null);
}