KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jivesoftware > util > LocaleFilter


1 /*
2  * $RCSfile: LocaleFilter.java,v $
3  * $Revision: 1.2 $
4  * $Date: 2005/04/11 21:05:19 $
5  *
6  * Copyright (C) 2004-2005 Jive Software. All rights reserved.
7  *
8  * This software is published under the terms of the GNU Public License (GPL),
9  * a copy of which is included in this distribution.
10  */

11
12 package org.jivesoftware.util;
13
14 import javax.servlet.*;
15 import javax.servlet.jsp.jstl.core.Config;
16 import java.io.IOException JavaDoc;
17
18 /**
19  * Sets the locale context-wide.
20  */

21 public class LocaleFilter implements Filter {
22
23     private ServletContext context;
24
25     public void init(FilterConfig config) throws ServletException {
26         this.context = config.getServletContext();
27     }
28
29     /**
30      * Ssets the locale context-wide based on a call to {@link JiveGlobals#getLocale()}.
31      */

32     public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
33             throws IOException JavaDoc, ServletException
34     {
35         // Note, putting the locale in the application at this point is a little overkill
36
// (ie, every user who hits this filter will do this). Eventually, it might make
37
// sense to just set the locale in the user's session and if that's done we might
38
// want to honor a preference to get the user's locale based on request headers.
39
// For now, this is just a convenient place to set the locale globally.
40
Config.set(context, Config.FMT_LOCALE, JiveGlobals.getLocale());
41
42         // Move along:
43
chain.doFilter(request, response);
44     }
45
46     /** Does nothing */
47     public void destroy() {
48     }
49 }
50
Popular Tags