Clover coverage report - angkor - 0.4
Coverage timestamp: ti okt 15 2002 22:32:48 CEST
file stats: LOC: 86   Methods: 3
NCLOC: 53   Classes: 1
Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover.
 
 Source file Conditionals Statements Methods TOTAL
ApplicationFilter.java 66,7% 90% 100% 86,2%
 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  2
     public void init(FilterConfig config) throws ServletException
 42   
     {
 43  2
         String applicationClassName = config.getInitParameter(APPLICATION_CLASS_PARAM);
 44  2
         if (applicationClassName == null)
 45   
         {
 46  1
             throw new ServletException("Configuration error. Application-class must be specified in 'application'-property.");
 47   
         }
 48  1
         try
 49   
         {
 50  1
             applicationClass = Class.forName(applicationClassName);
 51   
         }
 52   
         catch (ClassNotFoundException e)
 53   
         {
 54  0
             throw new ServletException(e.getMessage());
 55   
         }
 56   
     }
 57   
 
 58  1
     public void doFilter(ServletRequest sRequest, ServletResponse sResponse, FilterChain chain) throws IOException, ServletException
 59   
     {
 60  0
         if (applicationClass == null) init(filterConfig);
 61  1
         HttpServletRequest request = (HttpServletRequest) sRequest;
 62  1
         HttpServletResponse response = (HttpServletResponse) sResponse;
 63   
 
 64  1
         RenderContext context = new RenderContext(request, response);
 65  1
         ApplicationFactory applicationFactory = new ApplicationFactory(request.getSession());
 66  1
         applicationFactory.ensureApplicationInit(applicationClass);
 67  1
         Application application = applicationFactory.getApplication();
 68   
 
 69  1
         request.getSession().setMaxInactiveInterval(5 * 60); // expire after five minutes
 70   
 
 71  1
         context.ensureApplicationInit(applicationClass);
 72   
 
 73  1
         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  1
         if (!response.isCommitted()) chain.doFilter(sRequest, sResponse);
 78   
 
 79  1
         context.afterRequest();
 80   
     }
 81   
 
 82  1
     public void destroy()
 83   
     {
 84   
     }
 85   
 }
 86