class TilesDecorationFilter implements Filter {

    public void doFilter(javax.servlet.ServletRequest req, ServletResponse res, FilterChain filterChain)
            throws IOException, ServletException {
        // If the request contains the prevent token, we must not reapply the definition.
        // This is used to ensure that filters mapped to wild cards do not infinately
        // loop.
        if (!isPreventTokenPresent(req)) {
            ApplicationContext applicationContext = org.apache.tiles.request.servlet.ServletUtil
                    .getApplicationContext(servletContext);
            Request request = new ServletRequest(applicationContext,
                    (HttpServletRequest) req, (HttpServletResponse) res);
            TilesContainer container = TilesAccess.getContainer(applicationContext,
                    containerKey);
            mutator.mutate(container.getAttributeContext(request), req);
            if (preventDecorationToken != null) {
                req.setAttribute(preventDecorationToken, Boolean.TRUE);
            }
            String definitionName = getDefinitionForRequest(req);
            container.render(definitionName, request);
        }
        filterChain.doFilter(req, res);
    }

}