1 24 package org.riotfamily.riot.runtime; 25 26 import javax.servlet.ServletContext ; 27 28 import org.riotfamily.riot.RiotVersion; 29 import org.springframework.beans.factory.BeanFactoryUtils; 30 import org.springframework.context.ApplicationContext; 31 import org.springframework.util.Assert; 32 import org.springframework.web.context.ServletContextAware; 33 34 44 public class RiotRuntime implements ServletContextAware { 45 46 public static final String SERVLET_PREFIX_ATTRIBUTE = "riotServletPrefix"; 47 48 public static final String DEFAULT_SERVLET_PREFIX = "/riot"; 49 50 private String servletPrefix; 51 52 private String resourceMapping; 53 54 private String resourcePath; 55 56 public void setResourceMapping(String resourceMapping) { 57 this.resourceMapping = resourceMapping; 58 } 59 60 public void setServletContext(ServletContext context) { 61 Assert.notNull(resourceMapping, "A resourceMapping must be specified."); 62 servletPrefix = (String ) context.getInitParameter(SERVLET_PREFIX_ATTRIBUTE); 63 if (servletPrefix == null) { 64 servletPrefix = DEFAULT_SERVLET_PREFIX; 65 } 66 resourcePath = servletPrefix + resourceMapping + '/' + getVersionString() + '/'; 67 } 68 69 public String getServletPrefix() { 70 return servletPrefix; 71 } 72 73 public String getResourcePath() { 74 return resourcePath; 75 } 76 77 public String getVersionString() { 78 return RiotVersion.getVersionString(); 79 } 80 81 public static RiotRuntime getRuntime(ApplicationContext context) { 82 return (RiotRuntime) BeanFactoryUtils.beanOfTypeIncludingAncestors( 83 context, RiotRuntime.class); 84 } 85 } 86 | Popular Tags |