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.Action; 24 import org.apache.struts.action.ActionServlet; 25 26 import org.springframework.context.support.MessageSourceAccessor; 27 import org.springframework.web.context.WebApplicationContext; 28 import org.springframework.web.util.WebUtils; 29 30 62 public abstract class ActionSupport extends Action { 63 64 private WebApplicationContext webApplicationContext; 65 66 private MessageSourceAccessor messageSourceAccessor; 67 68 69 75 public void setServlet(ActionServlet actionServlet) { 76 super.setServlet(actionServlet); 77 if (actionServlet != null) { 78 this.webApplicationContext = initWebApplicationContext(actionServlet); 79 this.messageSourceAccessor = new MessageSourceAccessor(this.webApplicationContext); 80 onInit(); 81 } 82 else { 83 onDestroy(); 84 } 85 } 86 87 95 protected WebApplicationContext initWebApplicationContext(ActionServlet actionServlet) 96 throws IllegalStateException { 97 98 return DelegatingActionUtils.findRequiredWebApplicationContext(actionServlet, null); 99 } 100 101 102 105 protected final WebApplicationContext getWebApplicationContext() { 106 return this.webApplicationContext; 107 } 108 109 113 protected final MessageSourceAccessor getMessageSourceAccessor() { 114 return this.messageSourceAccessor; 115 } 116 117 120 protected final ServletContext getServletContext() { 121 return this.webApplicationContext.getServletContext(); 122 } 123 124 129 protected final File getTempDir() { 130 return WebUtils.getTempDir(getServletContext()); 131 } 132 133 134 138 protected void onInit() { 139 } 140 141 145 protected void onDestroy() { 146 } 147 148 } 149 | Popular Tags |