1 15 package org.apache.tapestry.web; 16 17 import java.net.MalformedURLException ; 18 import java.net.URL ; 19 import java.util.List ; 20 21 import javax.servlet.ServletContext ; 22 23 import org.apache.commons.logging.Log; 24 import org.apache.commons.logging.LogFactory; 25 import org.apache.hivemind.util.Defense; 26 import org.apache.tapestry.describe.DescriptionReceiver; 27 28 34 public class ServletWebContext implements WebContext 35 { 36 private static final Log LOG = LogFactory.getLog(ServletWebContext.class); 37 38 private final ServletContext _servletContext; 39 40 public void describeTo(DescriptionReceiver receiver) 41 { 42 receiver.describeAlternate(_servletContext); 43 } 44 45 public ServletWebContext(ServletContext context) 46 { 47 Defense.notNull(context, "context"); 48 49 _servletContext = context; 50 } 51 52 public List getAttributeNames() 53 { 54 return WebUtils.toSortedList(_servletContext.getAttributeNames()); 55 } 56 57 public Object getAttribute(String name) 58 { 59 return _servletContext.getAttribute(name); 60 } 61 62 public void setAttribute(String name, Object attribute) 63 { 64 if (attribute == null) 65 _servletContext.removeAttribute(name); 66 else 67 _servletContext.setAttribute(name, attribute); 68 69 } 70 71 public URL getResource(String path) 72 { 73 try 74 { 75 return _servletContext.getResource(path); 76 } 77 catch (MalformedURLException ex) 78 { 79 LOG.error(WebMessages.errorGettingResource(path, ex), ex); 80 81 return null; 82 } 83 } 84 85 public String getInitParameterValue(String name) 86 { 87 return _servletContext.getInitParameter(name); 88 } 89 90 public List getInitParameterNames() 91 { 92 return WebUtils.toSortedList(_servletContext.getInitParameterNames()); 93 } 94 95 public String getMimeType(String resourcePath) 96 { 97 return _servletContext.getMimeType(resourcePath); 98 } 99 } | Popular Tags |