1 16 17 package org.springframework.web.struts; 18 19 import java.io.File ; 20 21 import javax.servlet.ServletContext ; 22 23 import org.apache.struts.action.ActionServlet; 24 import org.apache.struts.actions.LookupDispatchAction; 25 26 import org.springframework.context.support.MessageSourceAccessor; 27 import org.springframework.web.context.WebApplicationContext; 28 import org.springframework.web.util.WebUtils; 29 30 61 public abstract class LookupDispatchActionSupport extends LookupDispatchAction { 62 63 private WebApplicationContext webApplicationContext; 64 65 private MessageSourceAccessor messageSourceAccessor; 66 67 68 74 public void setServlet(ActionServlet actionServlet) { 75 super.setServlet(actionServlet); 76 if (actionServlet != null) { 77 this.webApplicationContext = initWebApplicationContext(actionServlet); 78 this.messageSourceAccessor = new MessageSourceAccessor(this.webApplicationContext); 79 onInit(); 80 } 81 else { 82 onDestroy(); 83 } 84 } 85 86 94 protected WebApplicationContext initWebApplicationContext(ActionServlet actionServlet) 95 throws IllegalStateException { 96 97 return DelegatingActionUtils.findRequiredWebApplicationContext(actionServlet, null); 98 } 99 100 101 104 protected final WebApplicationContext getWebApplicationContext() { 105 return this.webApplicationContext; 106 } 107 108 112 protected final MessageSourceAccessor getMessageSourceAccessor() { 113 return this.messageSourceAccessor; 114 } 115 116 119 protected final ServletContext getServletContext() { 120 return this.webApplicationContext.getServletContext(); 121 } 122 123 128 protected final File getTempDir() { 129 return WebUtils.getTempDir(getServletContext()); 130 } 131 132 133 137 protected void onInit() { 138 } 139 140 144 protected void onDestroy() { 145 } 146 147 } 148 | Popular Tags |