KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > dlog4j > ContentTypeFilter


1 /*
2  * This program is free software; you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License as published by
4  * the Free Software Foundation; either version 2 of the License, or
5  * (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * 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 JavaDoc;
19
20 import javax.servlet.Filter JavaDoc;
21 import javax.servlet.FilterChain JavaDoc;
22 import javax.servlet.FilterConfig JavaDoc;
23 import javax.servlet.ServletException JavaDoc;
24 import javax.servlet.ServletRequest JavaDoc;
25 import javax.servlet.ServletResponse JavaDoc;
26 import javax.servlet.http.HttpServletResponse JavaDoc;
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 JavaDoc {
37     
38     protected String JavaDoc contentType = "text/html;charset=UTF-8";
39
40     public void init(FilterConfig JavaDoc config) throws ServletException JavaDoc {
41         String JavaDoc 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 JavaDoc req, ServletResponse JavaDoc res,
50             FilterChain JavaDoc chain) throws IOException JavaDoc, ServletException JavaDoc {
51         res.setContentType(contentType);
52         HttpServletResponse JavaDoc p_res = ResponseProxy.getProxy(res).getInstance();
53         chain.doFilter(req, p_res);
54     }
55
56     /* (non-Javadoc)
57      * @see javax.servlet.Filter#destroy()
58      */

59     public void destroy() {
60     }
61
62 }
63
Popular Tags