01: /*
02: * This program is free software; you can redistribute it and/or modify
03: * it under the terms of the GNU General Public License as published by
04: * the Free Software Foundation; either version 2 of the License, or
05: * (at your option) any later version.
06: *
07: * This program is distributed in the hope that it will be useful,
08: * but WITHOUT ANY WARRANTY; without even the implied warranty of
09: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10: * GNU Library General Public License for more details.
11: *
12: * You should have received a copy of the GNU General Public License
13: * along with this program; if not, write to the Free Software
14: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
15: */
16: package dlog4j;
17:
18: import java.io.IOException;
19:
20: import javax.servlet.Filter;
21: import javax.servlet.FilterChain;
22: import javax.servlet.FilterConfig;
23: import javax.servlet.ServletException;
24: import javax.servlet.ServletRequest;
25: import javax.servlet.ServletResponse;
26: import javax.servlet.http.HttpServletResponse;
27:
28: import dlog4j.proxy.ResponseProxy;
29:
30: /**
31: * 用来设置contentType的过滤器
32: * 该过滤器目前用于/blog/下的几个页面 atom.jsp, rss1.jsp, rss2.jsp
33: * 主要是让<xml version="1.0"> 这行位于文件的第一行
34: * @author Winter Lau
35: */
36: public class ContentTypeFilter implements Filter {
37:
38: protected String contentType = "text/html;charset=UTF-8";
39:
40: public void init(FilterConfig config) throws ServletException {
41: String ct = config.getInitParameter("contentType");
42: if (ct != null && ct.trim().length() > 0)
43: contentType = ct;
44: }
45:
46: /* (non-Javadoc)
47: * @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain)
48: */
49: public void doFilter(ServletRequest req, ServletResponse res,
50: FilterChain chain) throws IOException, ServletException {
51: res.setContentType(contentType);
52: HttpServletResponse p_res = ResponseProxy.getProxy(res)
53: .getInstance();
54: chain.doFilter(req, p_res);
55: }
56:
57: /* (non-Javadoc)
58: * @see javax.servlet.Filter#destroy()
59: */
60: public void destroy() {
61: }
62:
63: }
|