1 16 package org.apache.cocoon.environment.portlet; 17 18 import org.apache.cocoon.environment.Context; 19 20 import org.apache.avalon.framework.CascadingRuntimeException; 21 22 import java.io.InputStream ; 23 import java.net.MalformedURLException ; 24 import java.net.URL ; 25 import java.util.Enumeration ; 26 27 35 public final class PortletContext implements Context { 36 37 40 private final javax.portlet.PortletContext context; 41 42 45 public PortletContext(javax.portlet.PortletContext context) { 46 this.context = context; 47 } 48 49 public Object getAttribute(String name) { 50 return context.getAttribute(name); 51 } 52 53 public void setAttribute(String name, Object value) { 54 context.setAttribute(name, value); 55 } 56 57 public void removeAttribute(String name) { 58 context.removeAttribute(name); 59 } 60 61 public Enumeration getAttributeNames() { 62 return context.getAttributeNames(); 63 } 64 65 public URL getResource(String path) throws MalformedURLException { 66 return context.getResource(path); 67 } 68 69 public InputStream getResourceAsStream(String path) { 70 return context.getResourceAsStream(path); 71 } 72 73 public String getRealPath(String path) { 74 if (path.equals("/")) { 75 String value = context.getRealPath(path); 76 if (value == null) { 77 try { 79 value = this.context.getResource("/WEB-INF").toString(); 80 } catch (MalformedURLException mue) { 81 throw new CascadingRuntimeException("Cannot determine the base URL for " + path, mue); 82 } 83 value = value.substring(0, value.length() - "WEB-INF".length()); 84 } 85 return value; 86 } 87 return context.getRealPath(path); 88 } 89 90 public String getMimeType(String file) { 91 return context.getMimeType(file); 92 } 93 94 public String getInitParameter(String name) { 95 return context.getInitParameter(name); 96 } 97 98 99 101 public Enumeration getInitParameterNames() { 102 return context.getInitParameterNames(); 103 } 104 105 public int getMajorVersion() { 106 return context.getMajorVersion(); 107 } 108 109 public int getMinorVersion() { 110 return context.getMinorVersion(); 111 } 112 113 public String getPortletContextName() { 114 return context.getPortletContextName(); 115 } 116 117 public String getServerInfo() { 118 return context.getServerInfo(); 119 } 120 } 121 | Popular Tags |