ServletContext servletContext = filterConfig.getServletContext();
SiteMeshWebAppContext webAppContext = new SiteMeshWebAppContext(request, response, servletContext);
ContentProcessor contentProcessor = initContentProcessor(webAppContext);
DecoratorSelector decoratorSelector = initDecoratorSelector(webAppContext);
if (filterAlreadyAppliedForRequest(request)) {
// Prior to Servlet 2.4 spec, it was unspecified whether the filter should be called again upon an include().
chain.doFilter(request, response);
return;
}
if (!contentProcessor.handles(webAppContext)) {
// Optimization: If the content doesn't need to be processed, bypass SiteMesh.
chain.doFilter(request, response);
return;
}
if (containerTweaks.shouldAutoCreateSession()) {
// Some containers (such as Tomcat 4) will not allow sessions to be created in the decorator.
// (i.e after the response has been committed).
request.getSession(true);
}
try {
Content content = obtainContent(contentProcessor, webAppContext, request, response, chain);
if (content == null) {
request.setAttribute(ALREADY_APPLIED_KEY, null);
return;
}
Decorator decorator = decoratorSelector.selectDecorator(content, webAppContext);
decorator.render(content, webAppContext);
} catch (IllegalStateException e) {
// Some containers (such as WebLogic) throw an IllegalStateException when an error page is served.
// It may be ok to ignore this. However, for safety it is propegated if possible.