@@ -18,7 +18,6 @@ package org.codehaus.groovy.grails.plugins.web.filters
1818import java.util.regex.Pattern
1919import javax.servlet.http.HttpServletRequest
2020import javax.servlet.http.HttpServletResponse
21- import org.apache.commons.logging.LogFactory
2221import org.codehaus.groovy.grails.web.servlet.GrailsApplicationAttributes
2322import org.codehaus.groovy.grails.web.util.WebUtils
2423import org.springframework.web.servlet.HandlerInterceptor
@@ -28,6 +27,7 @@ import org.springframework.util.AntPathMatcher
2827import org.codehaus.groovy.grails.web.servlet.view.NullView
2928
3029/**
30+ * Adapter between a FilterConfig object and a Spring HandlerInterceptor.
3131 * @author mike
3232 * @author Graeme Rocher
3333 */
@@ -40,12 +40,16 @@ class FilterToHandlerAdapter implements HandlerInterceptor {
4040 def uriPattern;
4141 def urlPathHelper = new UrlPathHelper ()
4242
43- private static final LOG = LogFactory . getLog(FilterToHandlerAdapter )
44-
43+ /**
44+ * Returns the name of the controller targeted by the given request.
45+ */
4546 String controllerName (request ) {
4647 return request. getAttribute(GrailsApplicationAttributes . CONTROLLER_NAME_ATTRIBUTE ). toString()
4748 }
4849
50+ /**
51+ * Returns the name of the action targeted by the given request.
52+ */
4953 String actionName (request ) {
5054 return request. getAttribute(GrailsApplicationAttributes . ACTION_NAME_ATTRIBUTE ). toString()
5155 }
@@ -66,13 +70,10 @@ class FilterToHandlerAdapter implements HandlerInterceptor {
6670 if (! accept(controllerName, actionName, uri)) return true ;
6771
6872 def callable = filterConfig. before. clone()
69- FilterActionDelegate delegate = new FilterActionDelegate ()
70- callable. delegate = delegate
71- callable. resolveStrategy = Closure . DELEGATE_FIRST
7273 def result = callable. call();
7374 if (result instanceof Boolean ) {
74- if (! result && delegate . modelAndView) {
75- renderModelAndView(delegate , request, response, controllerName)
75+ if (! result && filterConfig . modelAndView) {
76+ renderModelAndView(filterConfig , request, response, controllerName)
7677 }
7778 return result
7879 }
@@ -91,26 +92,22 @@ class FilterToHandlerAdapter implements HandlerInterceptor {
9192 if (! accept(controllerName, actionName, uri)) return ;
9293
9394 def callable = filterConfig. after. clone()
94- FilterActionDelegate delegate = new FilterActionDelegate ()
95- callable. delegate = delegate
96- callable. resolveStrategy = Closure . DELEGATE_FIRST
97-
98- def result = callable. call(modelAndView?. getModel());
95+ def result = callable. call(modelAndView?. model);
9996 if (result instanceof Boolean ) {
10097 // if false is returned don't render a view
10198 if (! result) {
10299 modelAndView. viewName = null
103100 modelAndView. view = new NullView (response. contentType)
104101 }
105102 }
106- else if (delegate . modelAndView && modelAndView) {
107- if (delegate . modelAndView. viewName) {
108- modelAndView. viewName = delegate . modelAndView. viewName
103+ else if (filterConfig . modelAndView && modelAndView) {
104+ if (filterConfig . modelAndView. viewName) {
105+ modelAndView. viewName = filterConfig . modelAndView. viewName
109106 }
110- modelAndView. getModel() . putAll(delegate . modelAndView. getModel() )
107+ modelAndView. model . putAll(filterConfig . modelAndView. model )
111108 }
112- else if (delegate . modelAndView?. viewName) {
113- renderModelAndView(delegate , request, response, controllerName)
109+ else if (filterConfig . modelAndView?. viewName) {
110+ renderModelAndView(filterConfig , request, response, controllerName)
114111 }
115112
116113 }
@@ -124,7 +121,7 @@ class FilterToHandlerAdapter implements HandlerInterceptor {
124121 view = WebUtils . resolveView(request, modelAndView. viewName, controllerName, viewResolver)
125122 else if (modelAndView. view)
126123 view = modelAndView. view
127- view?. render(modelAndView. getModel() , request, response)
124+ view?. render(modelAndView. model , request, response)
128125 }
129126
130127 void afterCompletion (HttpServletRequest request , HttpServletResponse response , Object o , Exception e ) throws java.lang.Exception {
@@ -136,9 +133,6 @@ class FilterToHandlerAdapter implements HandlerInterceptor {
136133
137134 if (! accept(controllerName, actionName, uri)) return ;
138135 def callable = filterConfig. afterView. clone()
139- callable. delegate = new FilterActionDelegate ()
140- callable. resolveStrategy = Closure . DELEGATE_FIRST
141-
142136 callable. call(e);
143137 }
144138 }
0 commit comments