01: /*
02: * Copyright 2005-2006 The Kuali Foundation.
03: *
04: *
05: * Licensed under the Educational Community License, Version 1.0 (the "License");
06: * you may not use this file except in compliance with the License.
07: * You may obtain a copy of the License at
08: *
09: * http://www.opensource.org/licenses/ecl1.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 edu.iu.uis.eden.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:
30: import edu.iu.uis.eden.EdenConstants;
31: import edu.iu.uis.eden.web.session.UserSession;
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 bmcgough
39: * @author rkirkend
40: * @author ahamid
41: */
42: public class StrutsRequestProcessor extends RequestProcessor {
43:
44: private static final String REFRESH_MAPPING_PREFIX = "/Refresh";
45: private static final String METHOD_PARAM = "methodToCall";
46: private static final String DOC_FORM_KEY_ATTRIBUTE = "docFormKey";
47:
48: @Override
49: public void process(HttpServletRequest request,
50: HttpServletResponse response) throws IOException,
51: ServletException {
52: ModuleContext.setKew(true);
53: try {
54: if (isConvertNullWorkaroundNeeded()) {
55: ConverterUtils.registerContextSensitiveConverters();
56: }
57: super .process(request, response);
58: } finally {
59: ModuleContext.setKew(false);
60: }
61: }
62:
63: /**
64: * In KEW we set the convertNull property to "true" on the Struts ActionServlet. However, if an application which is running
65: * KEW as an embedded Struts Module has it set to false or is using some customizations to BeanUtils this will
66: * cause problems. We need to detect when this case occurs, then register context sensitive converters which will convert
67: * properly inside of the KEW web application.
68: */
69: protected boolean isConvertNullWorkaroundNeeded() {
70: return ConvertUtils.convert("", Long.class) != null;
71: }
72:
73: protected ActionForm processActionForm(HttpServletRequest request,
74: HttpServletResponse response, ActionMapping mapping) {
75: UserSession userSession = (UserSession) request.getSession()
76: .getAttribute(EdenConstants.USER_SESSION_KEY);
77: if ((request.getParameter(DOC_FORM_KEY_ATTRIBUTE) != null && request
78: .getParameter(DOC_FORM_KEY_ATTRIBUTE).length() > 0)
79: && (mapping.getPath()
80: .startsWith(REFRESH_MAPPING_PREFIX) || "refresh"
81: .equalsIgnoreCase(request
82: .getParameter(METHOD_PARAM)))) {
83: if (userSession.retrieveObject(request
84: .getParameter(DOC_FORM_KEY_ATTRIBUTE)) != null) {
85: ActionForm form = (ActionForm) userSession
86: .retrieveObject(request
87: .getParameter(DOC_FORM_KEY_ATTRIBUTE));
88: request.setAttribute(mapping.getName(), form);
89: return form;
90: } else {
91: return null;
92: }
93: } else {
94: return super.processActionForm(request, response, mapping);
95: }
96: }
97:
98: }
|