1 16 package org.apache.cocoon.environment.http; 17 18 import java.io.InputStream ; 19 import java.net.MalformedURLException ; 20 import java.net.URL ; 21 import java.util.Enumeration ; 22 23 import javax.servlet.RequestDispatcher ; 24 import javax.servlet.ServletContext ; 25 26 import org.apache.avalon.framework.CascadingRuntimeException; 27 import org.apache.cocoon.environment.Context; 28 29 35 36 public final class HttpContext implements Context { 37 38 39 private final ServletContext servletContext; 40 41 44 public HttpContext (ServletContext servletContext) { 45 this.servletContext = servletContext; 46 } 47 48 public Object getAttribute(String name) { 49 return servletContext.getAttribute(name); 50 } 51 52 public void setAttribute(String name, Object value) { 53 servletContext.setAttribute(name, value); 54 } 55 56 public void removeAttribute(String name) { 57 servletContext.removeAttribute(name); 58 } 59 60 public Enumeration getAttributeNames() { 61 return servletContext.getAttributeNames(); 62 } 63 64 public URL getResource(String path) 65 throws MalformedURLException { 66 return servletContext.getResource(path); 67 } 68 69 public InputStream getResourceAsStream(String path) { 70 return servletContext.getResourceAsStream(path); 71 } 72 73 public String getRealPath(String path) { 74 if (path.equals("/")) { 75 String value = servletContext.getRealPath(path); 76 if (value == null) { 77 try { 79 value = this.servletContext.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 servletContext.getRealPath(path); 88 } 89 90 public String getMimeType(String file) { 91 return servletContext.getMimeType(file); 92 } 93 94 public String getInitParameter(String name) { 95 return servletContext.getInitParameter(name); 96 } 97 98 111 112 public ServletContext getContext(String uripath) { 113 return this.servletContext.getContext(uripath); 114 } 115 116 public Enumeration getInitParameterNames() { 117 return this.servletContext.getInitParameterNames(); 118 } 119 120 public int getMajorVersion() { 121 return this.servletContext.getMajorVersion(); 122 } 123 124 public int getMinorVersion() { 125 return this.servletContext.getMinorVersion(); 126 } 127 128 public RequestDispatcher getNamedDispatcher(String name) { 129 return this.servletContext.getNamedDispatcher(name); 130 } 131 132 public RequestDispatcher getRequestDispatcher(String path) { 133 return this.servletContext.getRequestDispatcher(path); 134 } 135 136 public String getServerInfo() { 137 return this.servletContext.getServerInfo(); 138 } 139 140 public void log(String msg) { 141 this.servletContext.log(msg); 142 } 143 144 public void log(String msg, Throwable throwable) { 145 this.servletContext.log(msg, throwable); 146 } 147 } 148 | Popular Tags |