View Javadoc
1   /**
2    * Copyright 2005-2014 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.krad.web.controller;
17  
18  import org.kuali.rice.krad.web.bind.UifServletRequestDataBinderFactory;
19  import org.springframework.web.method.annotation.ErrorsMethodArgumentResolver;
20  import org.springframework.web.method.annotation.ExpressionValueMethodArgumentResolver;
21  import org.springframework.web.method.annotation.MapMethodProcessor;
22  import org.springframework.web.method.annotation.ModelMethodProcessor;
23  import org.springframework.web.method.annotation.RequestHeaderMapMethodArgumentResolver;
24  import org.springframework.web.method.annotation.RequestHeaderMethodArgumentResolver;
25  import org.springframework.web.method.annotation.RequestParamMapMethodArgumentResolver;
26  import org.springframework.web.method.annotation.RequestParamMethodArgumentResolver;
27  import org.springframework.web.method.annotation.SessionStatusMethodArgumentResolver;
28  import org.springframework.web.method.support.HandlerMethodArgumentResolver;
29  import org.springframework.web.method.support.InvocableHandlerMethod;
30  import org.springframework.web.servlet.mvc.method.annotation.HttpEntityMethodProcessor;
31  import org.springframework.web.servlet.mvc.method.annotation.MatrixVariableMapMethodArgumentResolver;
32  import org.springframework.web.servlet.mvc.method.annotation.MatrixVariableMethodArgumentResolver;
33  import org.springframework.web.servlet.mvc.method.annotation.PathVariableMapMethodArgumentResolver;
34  import org.springframework.web.servlet.mvc.method.annotation.PathVariableMethodArgumentResolver;
35  import org.springframework.web.servlet.mvc.method.annotation.RedirectAttributesMethodArgumentResolver;
36  import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter;
37  import org.springframework.web.servlet.mvc.method.annotation.RequestPartMethodArgumentResolver;
38  import org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor;
39  import org.springframework.web.servlet.mvc.method.annotation.ServletCookieValueMethodArgumentResolver;
40  import org.springframework.web.servlet.mvc.method.annotation.ServletModelAttributeMethodProcessor;
41  import org.springframework.web.servlet.mvc.method.annotation.ServletRequestDataBinderFactory;
42  import org.springframework.web.servlet.mvc.method.annotation.ServletRequestMethodArgumentResolver;
43  import org.springframework.web.servlet.mvc.method.annotation.ServletResponseMethodArgumentResolver;
44  import org.springframework.web.servlet.mvc.method.annotation.UriComponentsBuilderMethodArgumentResolver;
45  
46  import java.util.ArrayList;
47  import java.util.List;
48  
49  /**
50   * Override of request mapping handler apapter to create a custom binder factory.
51   *
52   * @author Kuali Rice Team (rice.collab@kuali.org)
53   */
54  public class UifRequestMappingHandlerAdapter extends RequestMappingHandlerAdapter {
55  
56      /**
57       * {@inheritDoc}
58       */
59      @Override
60      protected ServletRequestDataBinderFactory createDataBinderFactory(
61              List<InvocableHandlerMethod> binderMethods) throws Exception {
62          return new UifServletRequestDataBinderFactory(binderMethods, getWebBindingInitializer());
63      }
64  
65      /**
66       * Override to set Uif form argument resolver as first in the list of resolvers.
67       *
68       * {@inheritDoc}
69       */
70      @Override
71      public void afterPropertiesSet() {
72          List<HandlerMethodArgumentResolver> resolvers = getUifArgumentResolvers();
73          setArgumentResolvers(resolvers);
74  
75          super.afterPropertiesSet();
76      }
77  
78      /**
79       * Return the list of argument resolvers to use including built-in resolvers
80       * and custom resolvers provided via {@link #setCustomArgumentResolvers}.
81       */
82      protected List<HandlerMethodArgumentResolver> getUifArgumentResolvers() {
83          List<HandlerMethodArgumentResolver> resolvers = new ArrayList<HandlerMethodArgumentResolver>();
84  
85          resolvers.add(new UifDefaultFormMethodArgumentResolver());
86  
87          // Annotation-based argument resolution
88          resolvers.add(new RequestParamMethodArgumentResolver(getBeanFactory(), false));
89          resolvers.add(new RequestParamMapMethodArgumentResolver());
90          resolvers.add(new PathVariableMethodArgumentResolver());
91          resolvers.add(new PathVariableMapMethodArgumentResolver());
92          resolvers.add(new MatrixVariableMethodArgumentResolver());
93          resolvers.add(new MatrixVariableMapMethodArgumentResolver());
94          resolvers.add(new ServletModelAttributeMethodProcessor(false));
95          resolvers.add(new RequestResponseBodyMethodProcessor(getMessageConverters()));
96          resolvers.add(new RequestPartMethodArgumentResolver(getMessageConverters()));
97          resolvers.add(new RequestHeaderMethodArgumentResolver(getBeanFactory()));
98          resolvers.add(new RequestHeaderMapMethodArgumentResolver());
99          resolvers.add(new ServletCookieValueMethodArgumentResolver(getBeanFactory()));
100         resolvers.add(new ExpressionValueMethodArgumentResolver(getBeanFactory()));
101 
102         // Type-based argument resolution
103         resolvers.add(new ServletRequestMethodArgumentResolver());
104         resolvers.add(new ServletResponseMethodArgumentResolver());
105         resolvers.add(new HttpEntityMethodProcessor(getMessageConverters()));
106         resolvers.add(new RedirectAttributesMethodArgumentResolver());
107         resolvers.add(new ModelMethodProcessor());
108         resolvers.add(new MapMethodProcessor());
109         resolvers.add(new ErrorsMethodArgumentResolver());
110         resolvers.add(new SessionStatusMethodArgumentResolver());
111         resolvers.add(new UriComponentsBuilderMethodArgumentResolver());
112 
113         // Custom arguments
114         if (getCustomArgumentResolvers() != null) {
115             resolvers.addAll(getCustomArgumentResolvers());
116         }
117 
118         // Catch-all
119         resolvers.add(new RequestParamMethodArgumentResolver(getBeanFactory(), true));
120         resolvers.add(new ServletModelAttributeMethodProcessor(true));
121 
122         return resolvers;
123     }
124 }