1 16 17 package org.springframework.web.context.support; 18 19 import javax.servlet.ServletContext ; 20 21 import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; 22 import org.springframework.beans.factory.support.DefaultListableBeanFactory; 23 import org.springframework.context.support.GenericApplicationContext; 24 import org.springframework.core.io.Resource; 25 import org.springframework.core.io.support.ResourcePatternResolver; 26 import org.springframework.ui.context.Theme; 27 import org.springframework.ui.context.ThemeSource; 28 import org.springframework.ui.context.support.UiApplicationContextUtils; 29 import org.springframework.web.context.ServletContextAware; 30 import org.springframework.web.context.WebApplicationContext; 31 import org.springframework.web.context.request.RequestScope; 32 import org.springframework.web.context.request.SessionScope; 33 34 56 public class GenericWebApplicationContext extends GenericApplicationContext 57 implements WebApplicationContext, ThemeSource { 58 59 private ServletContext servletContext; 60 61 private ThemeSource themeSource; 62 63 64 70 public GenericWebApplicationContext() { 71 super(); 72 } 73 74 81 public GenericWebApplicationContext(DefaultListableBeanFactory beanFactory) { 82 super(beanFactory); 83 } 84 85 86 89 public void setServletContext(ServletContext servletContext) { 90 this.servletContext = servletContext; 91 } 92 93 public ServletContext getServletContext() { 94 return servletContext; 95 } 96 97 98 102 protected void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) { 103 beanFactory.registerScope(SCOPE_REQUEST, new RequestScope()); 104 beanFactory.registerScope(SCOPE_SESSION, new SessionScope(false)); 105 beanFactory.registerScope(SCOPE_GLOBAL_SESSION, new SessionScope(true)); 106 107 beanFactory.addBeanPostProcessor(new ServletContextAwareProcessor(this.servletContext)); 108 beanFactory.ignoreDependencyInterface(ServletContextAware.class); 109 } 110 111 115 protected Resource getResourceByPath(String path) { 116 return new ServletContextResource(this.servletContext, path); 117 } 118 119 123 protected ResourcePatternResolver getResourcePatternResolver() { 124 return new ServletContextResourcePatternResolver(this); 125 } 126 127 130 protected void onRefresh() { 131 this.themeSource = UiApplicationContextUtils.initThemeSource(this); 132 } 133 134 public Theme getTheme(String themeName) { 135 return this.themeSource.getTheme(themeName); 136 } 137 138 } 139 | Popular Tags |