1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package org.archive.crawler.admin.ui;
24
25 import java.io.IOException;
26
27 import javax.servlet.Filter;
28 import javax.servlet.FilterChain;
29 import javax.servlet.FilterConfig;
30 import javax.servlet.ServletException;
31 import javax.servlet.ServletRequest;
32 import javax.servlet.ServletResponse;
33 import javax.servlet.http.HttpServletRequest;
34 import javax.servlet.http.HttpServletResponse;
35
36 /***
37 * Filter that redirects accesses to 'index.jsp'.
38 * @author stack
39 * @version $Date: 2005-08-29 21:52:36 +0000 (Mon, 29 Aug 2005) $, $Revision: 3771 $
40 */
41 public class RootFilter implements Filter {
42 private FilterConfig filterConfig = null;
43
44 public void init(FilterConfig config) {
45 this.filterConfig = config;
46 }
47
48 public void doFilter(ServletRequest req, ServletResponse res,
49 FilterChain chain)
50 throws IOException, ServletException {
51 if (this.filterConfig == null) {
52 return;
53 }
54 if (req instanceof HttpServletRequest) {
55 HttpServletRequest httpRequest = (HttpServletRequest)req;
56 String path = httpRequest.getRequestURI();
57 if (path == null || path.equals(httpRequest.getContextPath()) ||
58 (path.equals(httpRequest.getContextPath() + "/"))) {
59 String tgt = this.filterConfig.
60 getInitParameter("rootFilter.redirectTo");
61 ((HttpServletResponse)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 }