FileDocCategorySizeDatePackage
LocaleFilter.javaAPI DocExample2127Wed Sep 15 20:24:50 BST 2004com.oreilly.strutsckbk.ch12

LocaleFilter

public class LocaleFilter extends Object implements Filter

Fields Summary
private String
localeCode
private boolean
ignore
private FilterConfig
filterConfig
Constructors Summary
Methods Summary
public voiddestroy()

        // Nothing necessary
    
public voiddoFilter(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, javax.servlet.FilterChain chain)

        HttpServletRequest req = (HttpServletRequest) request;
        HttpServletResponse res = (HttpServletResponse) response;
        
        // create the session if needed
        HttpSession session = req.getSession();

        Locale currentLocale = (Locale) session.getAttribute(Globals.LOCALE_KEY);
        if (currentLocale == null || ignore) {
            // create the new locale
            Locale locale = new Locale(localeCode);

            // reset the Struts locale
            session.setAttribute(Globals.LOCALE_KEY, locale);
                
            // reset the JSTL locale
            Config.set(session, Config.FMT_LOCALE, locale);
        }
        chain.doFilter(request, response);
    
public voidinit(javax.servlet.FilterConfig filterConfig)


          
        this.filterConfig = filterConfig;
        localeCode = filterConfig.getInitParameter("locale");
        ignore = Boolean.valueOf(filterConfig.getInitParameter("ignore")).booleanValue();