Coverage Report - org.kuali.rice.kew.web.StrutsRequestProcessor
 
Classes in this File Line Coverage Branch Coverage Complexity
StrutsRequestProcessor
0%
0/18
0%
0/14
3.667
 
 1  
 /*
 2  
  * Copyright 2005-2007 The Kuali Foundation
 3  
  *
 4  
  *
 5  
  * Licensed under the Educational Community License, Version 2.0 (the "License");
 6  
  * you may not use this file except in compliance with the License.
 7  
  * You may obtain a copy of the License at
 8  
  *
 9  
  * http://www.opensource.org/licenses/ecl2.php
 10  
  *
 11  
  * Unless required by applicable law or agreed to in writing, software
 12  
  * distributed under the License is distributed on an "AS IS" BASIS,
 13  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  
  * See the License for the specific language governing permissions and
 15  
  * limitations under the License.
 16  
  */
 17  
 package org.kuali.rice.kew.web;
 18  
 
 19  
 import java.io.IOException;
 20  
 
 21  
 import javax.servlet.ServletException;
 22  
 import javax.servlet.http.HttpServletRequest;
 23  
 import javax.servlet.http.HttpServletResponse;
 24  
 
 25  
 import org.apache.commons.beanutils.ConvertUtils;
 26  
 import org.apache.struts.action.ActionForm;
 27  
 import org.apache.struts.action.ActionMapping;
 28  
 import org.apache.struts.action.RequestProcessor;
 29  
 import org.kuali.rice.kew.util.KEWConstants;
 30  
 import org.kuali.rice.kew.web.session.UserSession;
 31  
 
 32  
 
 33  
 /**
 34  
  * A RequestProcessor implementation for Struts which handles saving and retrieving
 35  
  * {@link ActionForm}s when leaving one context in the web GUI for another and then
 36  
  * returning.  This uses the {@link #DOC_FORM_KEY_ATTRIBUTE} to store the saved forms.
 37  
  *
 38  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 39  
  */
 40  0
 public class StrutsRequestProcessor extends RequestProcessor {
 41  
 
 42  
     private static final String REFRESH_MAPPING_PREFIX = "/Refresh";
 43  
     private static final String METHOD_PARAM = "methodToCall";
 44  
     private static final String DOC_FORM_KEY_ATTRIBUTE = "docFormKey";
 45  
     
 46  
     @Override
 47  
         public void process(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
 48  0
             ModuleContext.setKew(true);
 49  
             try {
 50  0
                     if (isConvertNullWorkaroundNeeded()) {
 51  0
                             ConverterUtils.registerContextSensitiveConverters();
 52  
                     }
 53  0
                     super.process(request, response);
 54  0
             } finally {
 55  0
                     ModuleContext.setKew(false);
 56  0
             }
 57  0
         }
 58  
 
 59  
     /**
 60  
          * In KEW we set the convertNull property to "true" on the Struts ActionServlet.  However, if an application which is running
 61  
          * KEW as an embedded Struts Module has it set to false or is using some customizations to BeanUtils this will
 62  
          * cause problems.  We need to detect when this case occurs, then register context sensitive converters which will convert
 63  
          * properly inside of the KEW web application.
 64  
          */
 65  
     protected boolean isConvertNullWorkaroundNeeded() {
 66  0
             return ConvertUtils.convert("", Long.class) != null;
 67  
     }
 68  
 
 69  
         protected ActionForm processActionForm(HttpServletRequest request, HttpServletResponse response, ActionMapping mapping) {
 70  0
             UserSession userSession = (UserSession) request.getSession().getAttribute(KEWConstants.USER_SESSION_KEY);
 71  0
         if ((request.getParameter(DOC_FORM_KEY_ATTRIBUTE) != null && request.getParameter(DOC_FORM_KEY_ATTRIBUTE).length() > 0) && (mapping.getPath().startsWith(REFRESH_MAPPING_PREFIX) || "refresh".equalsIgnoreCase(request.getParameter(METHOD_PARAM)))) {
 72  0
             if (userSession.retrieveObject(request.getParameter(DOC_FORM_KEY_ATTRIBUTE)) != null) {
 73  0
                 ActionForm form = (ActionForm) userSession.retrieveObject(request.getParameter(DOC_FORM_KEY_ATTRIBUTE));
 74  0
                 request.setAttribute(mapping.getName(), form);
 75  0
                 return form;
 76  
             } else {
 77  0
                 return null;
 78  
             }
 79  
         } else {
 80  0
             return super.processActionForm(request, response, mapping);
 81  
         }
 82  
     }
 83  
 
 84  
 }