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