KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > myfaces > webapp > filter > JavaScriptDetectorFilter


1 /*
2  * Copyright 2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.myfaces.webapp.filter;
17
18 import org.apache.myfaces.context.servlet.ServletExternalContextImpl;
19 import org.apache.myfaces.renderkit.html.util.JavascriptUtils;
20
21 import org.apache.commons.logging.Log;
22 import org.apache.commons.logging.LogFactory;
23
24 import javax.faces.context.ExternalContext;
25 import javax.servlet.*;
26 import javax.servlet.http.HttpServletRequest JavaDoc;
27 import javax.servlet.http.HttpServletResponse JavaDoc;
28 import java.io.IOException JavaDoc;
29
30
31 /**
32  *
33  * Filter to handle javascript detection redirect. This is an EXPERIMENTAL feature.
34  *
35  * @author Oliver Rossmueller (latest modification by $Author: matze $)
36  *
37  * $Log: JavaScriptDetectorFilter.java,v $
38  * Revision 1.4 2004/10/13 11:51:01 matze
39  * renamed packages to org.apache
40  *
41  * Revision 1.3 2004/09/08 09:31:25 manolito
42  * moved isJavascriptDetected from MyFacesConfig to JavascriptUtils class
43  *
44  * Revision 1.2 2004/09/01 18:32:57 mwessendorf
45  * Organize Imports
46  *
47  * Revision 1.1 2004/08/05 22:10:44 o_rossmueller
48  * EXPERIMENTAL: JavaScript detection
49  *
50  */

51 public class JavaScriptDetectorFilter implements Filter
52 {
53     private static final Log log = LogFactory.getLog(JavaScriptDetectorFilter.class);
54
55     private ServletContext _servletContext;
56
57     public void init(FilterConfig filterConfig) throws ServletException
58     {
59         _servletContext = filterConfig.getServletContext();
60     }
61
62
63     public void doFilter(ServletRequest JavaDoc servletRequest, ServletResponse JavaDoc servletResponse, FilterChain filterChain) throws IOException JavaDoc, ServletException
64     {
65         HttpServletRequest JavaDoc request = (HttpServletRequest JavaDoc) servletRequest;
66         HttpServletResponse JavaDoc response = (HttpServletResponse JavaDoc) servletResponse;
67
68         ExternalContext externalContext = new ServletExternalContextImpl(_servletContext,
69                                                                          servletRequest,
70                                                                          servletResponse);
71         JavascriptUtils.setJavascriptDetected(externalContext, true); // mark the session to use javascript
72

73         log.info("Enabled JavaScript for session - redirect to" + request.getParameter("goto"));
74         response.sendRedirect(request.getParameter("goto"));
75     }
76
77
78     public void destroy()
79     {
80
81     }
82 }
83
Popular Tags