View Javadoc
1 /* 2 * Angkor Web Framework 3 * 4 * Distributable under LGPL license. 5 * See terms of license at gnu.org. 6 */ 7 8 package com.tirsen.angkor; 9 10 import org.apache.commons.logging.Log; 11 import org.apache.commons.logging.LogFactory; 12 13 import javax.servlet.Filter; 14 import javax.servlet.FilterChain; 15 import javax.servlet.FilterConfig; 16 import javax.servlet.ServletException; 17 import javax.servlet.ServletRequest; 18 import javax.servlet.ServletResponse; 19 import javax.servlet.http.HttpServletRequest; 20 import javax.servlet.http.HttpServletResponse; 21 import java.io.IOException; 22 23 /*** 24 * A servlet filter acting as the main entry point to the Angkor engine, passes the request 25 * to RenderContext where the actual engine is implemented. 26 * 27 * <!-- $Id: ApplicationFilter.java,v 1.8 2002/10/13 13:37:26 tirsen Exp $ --> 28 * 29 * @author $Author: tirsen $ 30 * @version $Revision: 1.8 $ 31 */ 32 public class ApplicationFilter implements Filter 33 { 34 private static Log logger = LogFactory.getLog(ApplicationFilter.class); 35 36 private FilterConfig filterConfig; 37 38 private Class applicationClass; 39 public final static String APPLICATION_CLASS_PARAM = "application"; 40 41 public void init(FilterConfig config) throws ServletException 42 { 43 String applicationClassName = config.getInitParameter(APPLICATION_CLASS_PARAM); 44 if (applicationClassName == null) 45 { 46 throw new ServletException("Configuration error. Application-class must be specified in 'application'-property."); 47 } 48 try 49 { 50 applicationClass = Class.forName(applicationClassName); 51 } 52 catch (ClassNotFoundException e) 53 { 54 throw new ServletException(e.getMessage()); 55 } 56 } 57 58 public void doFilter(ServletRequest sRequest, ServletResponse sResponse, FilterChain chain) throws IOException, ServletException 59 { 60 if (applicationClass == null) init(filterConfig); 61 HttpServletRequest request = (HttpServletRequest) sRequest; 62 HttpServletResponse response = (HttpServletResponse) sResponse; 63 64 RenderContext context = new RenderContext(request, response); 65 ApplicationFactory applicationFactory = new ApplicationFactory(request.getSession()); 66 applicationFactory.ensureApplicationInit(applicationClass); 67 Application application = applicationFactory.getApplication(); 68 69 request.getSession().setMaxInactiveInterval(5 * 60); // expire after five minutes 70 71 context.ensureApplicationInit(applicationClass); 72 73 context.beforeRequest(); 74 75 // the processing could have redirected the request or sent an error or something else 76 // therefor make sure not to write on a commited response 77 if (!response.isCommitted()) chain.doFilter(sRequest, sResponse); 78 79 context.afterRequest(); 80 } 81 82 public void destroy() 83 { 84 } 85 }

This page was automatically generated by Maven