KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > jforum > util > legacy > clickstream > ClickstreamFilter


1 package net.jforum.util.legacy.clickstream;
2
3 import java.io.IOException JavaDoc;
4
5 import javax.servlet.Filter JavaDoc;
6 import javax.servlet.FilterChain JavaDoc;
7 import javax.servlet.FilterConfig JavaDoc;
8 import javax.servlet.ServletException JavaDoc;
9 import javax.servlet.ServletRequest JavaDoc;
10 import javax.servlet.ServletResponse JavaDoc;
11 import javax.servlet.http.HttpServletRequest JavaDoc;
12
13 import net.jforum.util.preferences.ConfigKeys;
14
15 import org.apache.log4j.Logger;
16
17 /**
18  * The filter that keeps track of a new entry in the clickstream for <b>every request</b>.
19  *
20  * @author <a HREF="plightbo@hotmail.com">Patrick Lightbody</a>
21  * @author Rafael Steil (little hacks for JForum)
22  * @version $Id: ClickstreamFilter.java,v 1.4 2005/07/26 03:05:03 rafaelsteil Exp $
23  */

24 public class ClickstreamFilter implements Filter JavaDoc
25 {
26     private static final Logger log = Logger.getLogger(ClickstreamFilter.class);
27
28     /**
29      * Attribute name indicating the filter has been applied to a given request.
30      */

31     private final static String JavaDoc FILTER_APPLIED = "_clickstream_filter_applied";
32
33     /**
34      * Processes the given request and/or response.
35      *
36      * @param request The request
37      * @param response The response
38      * @param chain The processing chain
39      * @throws IOException If an error occurs
40      * @throws ServletException If an error occurs
41      */

42     public void doFilter(ServletRequest JavaDoc request, ServletResponse JavaDoc response, FilterChain JavaDoc chain) throws IOException JavaDoc,
43             ServletException JavaDoc
44     {
45         // Ensure that filter is only applied once per request.
46
if (request.getAttribute(FILTER_APPLIED) == null) {
47             request.setAttribute(FILTER_APPLIED, Boolean.TRUE);
48             
49             String JavaDoc bot = BotChecker.isBot((HttpServletRequest JavaDoc)request);
50             
51             if (bot != null && log.isInfoEnabled()) {
52                 log.info("Found a bot: " + bot);
53             }
54             
55             request.setAttribute(ConfigKeys.IS_BOT, new Boolean JavaDoc(bot != null));
56         }
57         
58         // Pass the request on
59
chain.doFilter(request, response);
60     }
61
62     /**
63      * Initializes this filter.
64      *
65      * @param filterConfig The filter configuration
66      * @throws ServletException If an error occurs
67      */

68     public void init(FilterConfig JavaDoc filterConfig) throws ServletException JavaDoc {}
69
70     /**
71      * Destroys this filter.
72      */

73     public void destroy() {}
74 }
Popular Tags