1 9 package org.jboss.portal.portlet.impl; 10 11 import java.io.InputStream ; 12 import java.net.MalformedURLException ; 13 import java.net.URL ; 14 import java.util.Enumeration ; 15 import java.util.Set ; 16 17 import javax.portlet.PortletContext; 18 import javax.portlet.PortletRequestDispatcher; 19 import javax.servlet.RequestDispatcher ; 20 import javax.servlet.ServletContext ; 21 22 26 public class PortletContextImpl implements PortletContext 27 { 28 29 private ServletContext servletContext; 30 31 public PortletContextImpl(ServletContext servletContext) 32 { 33 this.servletContext = servletContext; 34 } 35 36 public String getServerInfo() 37 { 38 return "JBossPortal/1.0"; 39 } 40 41 public PortletRequestDispatcher getRequestDispatcher(String path) 42 { 43 if (path == null || !path.startsWith("/")) 44 { 45 return null; 46 } 47 RequestDispatcher rd = servletContext.getRequestDispatcher(path); 48 if (rd != null) 49 { 50 return new PortletRequestDispatcherImpl(rd, path); 51 } 52 else 53 { 54 return null; 55 } 56 } 57 58 public PortletRequestDispatcher getNamedDispatcher(String name) 59 { 60 if (name == null) 61 { 62 return null; 63 } 64 RequestDispatcher rd = servletContext.getNamedDispatcher(name); 65 if (rd != null) 66 { 67 return new PortletRequestDispatcherImpl(rd); 68 } 69 else 70 { 71 return null; 72 } 73 } 74 75 public InputStream getResourceAsStream(String s) 76 { 77 return servletContext.getResourceAsStream(s); 78 } 79 80 public int getMajorVersion() 81 { 82 return 1; 83 } 84 85 public int getMinorVersion() 86 { 87 return 0; 88 } 89 90 public String getMimeType(String s) 91 { 92 return servletContext.getMimeType(s); 93 } 94 95 public String getRealPath(String s) 96 { 97 return servletContext.getRealPath(s); 98 } 99 100 public Set getResourcePaths(String s) 101 { 102 return servletContext.getResourcePaths(s); 103 } 104 105 public URL getResource(String s) throws MalformedURLException 106 { 107 if (s == null || !s.startsWith("/")) 108 { 109 throw new MalformedURLException ("invalid resource"); 110 } 111 URL resource = servletContext.getResource(s); 112 return resource; 113 } 114 115 public Object getAttribute(String s) 116 { 117 if (s == null) 118 { 119 throw new IllegalArgumentException ("attribute name must not be null"); 120 } 121 return servletContext.getAttribute(s); 122 } 123 124 public Enumeration getAttributeNames() 125 { 126 return servletContext.getAttributeNames(); 127 } 128 129 public String getInitParameter(String s) 130 { 131 if (s == null) 132 { 133 throw new IllegalArgumentException ("init parameter name must not be null"); 134 } 135 return servletContext.getInitParameter(s); 136 } 137 138 public Enumeration getInitParameterNames() 139 { 140 return servletContext.getInitParameterNames(); 141 } 142 143 public void log(String s) 144 { 145 servletContext.log(s); 146 } 147 148 public void log(String s, Throwable throwable) 149 { 150 servletContext.log(s, throwable); 151 } 152 153 public void removeAttribute(String s) 154 { 155 if (s == null) 156 { 157 throw new IllegalArgumentException ("attribute name must not be null"); 158 } 159 servletContext.removeAttribute(s); 160 } 161 162 public void setAttribute(String s, Object o) 163 { 164 servletContext.setAttribute(s, o); 165 } 166 167 public String getPortletContextName() 168 { 169 return servletContext.getServletContextName(); 170 } 171 } 172 | Popular Tags |