KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > archive > crawler > admin > ui > RootFilter


1 /* RootFilter
2  *
3  * Created on Oct 25, 2004
4  *
5  * Copyright (C) 2004 Internet Archive.
6  *
7  * This file is part of the Heritrix web crawler (crawler.archive.org).
8  *
9  * Heritrix is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU Lesser Public License as published by
11  * the Free Software Foundation; either version 2.1 of the License, or
12  * any later version.
13  *
14  * Heritrix is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU Lesser Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser Public License
20  * along with Heritrix; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22  */

23 package org.archive.crawler.admin.ui;
24
25 import java.io.IOException JavaDoc;
26
27 import javax.servlet.Filter JavaDoc;
28 import javax.servlet.FilterChain JavaDoc;
29 import javax.servlet.FilterConfig JavaDoc;
30 import javax.servlet.ServletException JavaDoc;
31 import javax.servlet.ServletRequest JavaDoc;
32 import javax.servlet.ServletResponse JavaDoc;
33 import javax.servlet.http.HttpServletRequest JavaDoc;
34 import javax.servlet.http.HttpServletResponse JavaDoc;
35
36 /**
37  * Filter that redirects accesses to 'index.jsp'.
38  * @author stack
39  * @version $Date: 2005/08/29 21:52:36 $, $Revision: 1.2 $
40  */

41 public class RootFilter implements Filter JavaDoc {
42     private FilterConfig JavaDoc filterConfig = null;
43     
44     public void init(FilterConfig JavaDoc config) {
45         this.filterConfig = config;
46     }
47     
48     public void doFilter(ServletRequest JavaDoc req, ServletResponse JavaDoc res,
49             FilterChain JavaDoc chain)
50     throws IOException JavaDoc, ServletException JavaDoc {
51         if (this.filterConfig == null) {
52             return;
53         }
54         if (req instanceof HttpServletRequest JavaDoc) {
55             HttpServletRequest JavaDoc httpRequest = (HttpServletRequest JavaDoc)req;
56             String JavaDoc path = httpRequest.getRequestURI();
57             if (path == null || path.equals(httpRequest.getContextPath()) ||
58                     (path.equals(httpRequest.getContextPath() + "/"))) {
59                 String JavaDoc tgt = this.filterConfig.
60                     getInitParameter("rootFilter.redirectTo");
61                 ((HttpServletResponse JavaDoc)res).sendRedirect((tgt == null)?
62                     httpRequest.getContextPath() + "/index.jsp":
63                     httpRequest.getContextPath() + tgt);
64                 return;
65             }
66         }
67         chain.doFilter(req, res);
68     }
69
70     public void destroy() {
71         this.filterConfig = null;
72     }
73 }
74
Popular Tags