1 16 17 package org.springframework.web.struts; 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.struts.action.Action; 26 import org.apache.struts.action.ActionMapping; 27 import org.apache.struts.action.ActionServlet; 28 import org.apache.struts.config.ModuleConfig; 29 import org.apache.struts.tiles.TilesRequestProcessor; 30 31 import org.springframework.beans.BeansException; 32 import org.springframework.web.context.WebApplicationContext; 33 34 58 public class DelegatingTilesRequestProcessor extends TilesRequestProcessor { 59 60 private WebApplicationContext webApplicationContext; 61 62 63 public void init(ActionServlet actionServlet, ModuleConfig moduleConfig) throws ServletException { 64 super.init(actionServlet, moduleConfig); 65 if (actionServlet != null) { 66 this.webApplicationContext = initWebApplicationContext(actionServlet, moduleConfig); 67 } 68 } 69 70 81 protected WebApplicationContext initWebApplicationContext( 82 ActionServlet actionServlet, ModuleConfig moduleConfig) throws IllegalStateException { 83 84 return DelegatingActionUtils.findRequiredWebApplicationContext(actionServlet, moduleConfig); 85 } 86 87 90 protected final WebApplicationContext getWebApplicationContext() { 91 return webApplicationContext; 92 } 93 94 95 99 protected Action processActionCreate( 100 HttpServletRequest request, HttpServletResponse response, ActionMapping mapping) 101 throws IOException { 102 103 Action action = getDelegateAction(mapping); 104 if (action != null) { 105 return action; 106 } 107 return super.processActionCreate(request, response, mapping); 108 } 109 110 120 protected Action getDelegateAction(ActionMapping mapping) throws BeansException { 121 String beanName = determineActionBeanName(mapping); 122 if (!getWebApplicationContext().containsBean(beanName)) { 123 return null; 124 } 125 return (Action) getWebApplicationContext().getBean(beanName, Action.class); 126 } 127 128 139 protected String determineActionBeanName(ActionMapping mapping) { 140 return DelegatingActionUtils.determineActionBeanName(mapping); 141 } 142 143 } 144 | Popular Tags |