| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| UifControllerHandlerInterceptor |
|
| 1.4;1.4 |
| 1 | /* | |
| 2 | * Copyright 2007 The Kuali Foundation | |
| 3 | * | |
| 4 | * Licensed under the Educational Community License, Version 1.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/ecl1.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.apache.log4j.Logger; | |
| 19 | import org.kuali.rice.krad.UserSession; | |
| 20 | import org.kuali.rice.krad.service.KRADServiceLocatorWeb; | |
| 21 | import org.kuali.rice.krad.service.SessionDocumentService; | |
| 22 | import org.kuali.rice.krad.uif.service.ViewService; | |
| 23 | import org.kuali.rice.krad.uif.util.UifWebUtils; | |
| 24 | import org.kuali.rice.krad.util.GlobalVariables; | |
| 25 | import org.kuali.rice.krad.util.KRADUtils; | |
| 26 | import org.springframework.web.servlet.HandlerInterceptor; | |
| 27 | import org.springframework.web.servlet.ModelAndView; | |
| 28 | ||
| 29 | import javax.servlet.http.HttpServletRequest; | |
| 30 | import javax.servlet.http.HttpServletResponse; | |
| 31 | ||
| 32 | /** | |
| 33 | * Spring controller intercepter for KRAD controllers | |
| 34 | * | |
| 35 | * <p> | |
| 36 | * Provides infrastructure for preparing the form and view before and after the | |
| 37 | * controller is invoked. Included in this is form session management and | |
| 38 | * preparation of the view for rendering | |
| 39 | * </p> | |
| 40 | * | |
| 41 | * @author Kuali Rice Team (rice.collab@kuali.org) | |
| 42 | */ | |
| 43 | 0 | public class UifControllerHandlerInterceptor implements HandlerInterceptor { |
| 44 | 0 | private static final Logger LOG = Logger.getLogger(UifControllerHandlerInterceptor.class); |
| 45 | ||
| 46 | @Override | |
| 47 | public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) | |
| 48 | throws Exception { | |
| 49 | // do nothing | |
| 50 | 0 | } |
| 51 | ||
| 52 | /** | |
| 53 | * After the controller logic is executed, the form is placed into session | |
| 54 | * and the corresponding view is prepared for rendering | |
| 55 | * | |
| 56 | * @see org.springframework.web.servlet.HandlerInterceptor#postHandle(javax.servlet.http.HttpServletRequest, | |
| 57 | * javax.servlet.http.HttpServletResponse, java.lang.Object, | |
| 58 | * org.springframework.web.servlet.ModelAndView) | |
| 59 | */ | |
| 60 | @Override | |
| 61 | public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, | |
| 62 | ModelAndView modelAndView) throws Exception { | |
| 63 | 0 | UifWebUtils.postControllerHandle(request, response, handler, modelAndView); |
| 64 | 0 | } |
| 65 | ||
| 66 | /** | |
| 67 | * Before the controller executes the user session is set on GlobalVariables | |
| 68 | * and messages are cleared | |
| 69 | * | |
| 70 | * TODO: do we need to clear the messages before this so that formatting and | |
| 71 | * validation errors done during the binding are not cleared out? | |
| 72 | * | |
| 73 | * @see org.springframework.web.servlet.HandlerInterceptor#preHandle(javax.servlet.http.HttpServletRequest, | |
| 74 | * javax.servlet.http.HttpServletResponse, java.lang.Object) | |
| 75 | */ | |
| 76 | @Override | |
| 77 | public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { | |
| 78 | 0 | final UserSession session = KRADUtils.getUserSessionFromRequest(request); |
| 79 | ||
| 80 | 0 | if (session == null) { |
| 81 | 0 | throw new IllegalStateException("the user session has not been established"); |
| 82 | } | |
| 83 | ||
| 84 | 0 | GlobalVariables.setUserSession(session); |
| 85 | 0 | GlobalVariables.clear(); |
| 86 | ||
| 87 | 0 | return true; |
| 88 | } | |
| 89 | ||
| 90 | ||
| 91 | public SessionDocumentService getSessionDocumentService() { | |
| 92 | 0 | return KRADServiceLocatorWeb.getSessionDocumentService(); |
| 93 | } | |
| 94 | ||
| 95 | protected ViewService getViewService() { | |
| 96 | 0 | return KRADServiceLocatorWeb.getViewService(); |
| 97 | } | |
| 98 | ||
| 99 | } |