1 package org.apache.slide.projector; 2 3 import java.io.IOException ; 4 5 import javax.servlet.http.HttpServletRequest ; 6 import javax.servlet.http.HttpServletResponse ; 7 8 import org.apache.commons.httpclient.Credentials; 9 import org.apache.slide.projector.store.Cache; 10 import org.apache.slide.projector.store.CookieStore; 11 import org.apache.slide.projector.store.FormStore; 12 import org.apache.slide.projector.store.RequestAttributeStore; 13 import org.apache.slide.projector.store.RequestHeaderStore; 14 import org.apache.slide.projector.store.RequestParameterStore; 15 import org.apache.slide.projector.store.SessionStore; 16 import org.apache.slide.projector.value.StreamableValue; 17 18 public class HttpContext extends SystemContext { 19 private final static String CREDENTIALS = "credentials"; 20 21 private StreamableValue resource; 22 private SessionStore sessionStore; 23 private RequestAttributeStore requestAttributeStore; 24 private RequestParameterStore requestParameterStore; 25 private RequestHeaderStore requestHeaderStore; 26 private CookieStore cookieStore; 27 private FormStore formStore; 28 private String contextPath; 29 30 public HttpContext(HttpServletRequest request, HttpServletResponse response) { 31 this.contextPath = request.getContextPath()+request.getServletPath(); 32 sessionStore = new SessionStore(request); 33 formStore = new FormStore(this, sessionStore); 34 requestAttributeStore = new RequestAttributeStore(request); 35 requestParameterStore = new RequestParameterStore(request); 36 requestHeaderStore = new RequestHeaderStore(request); 37 cookieStore = new CookieStore(request, response); 38 } 39 40 public void setCredentials(Credentials credentials) { 41 sessionStore.put(CREDENTIALS, credentials); 42 } 43 44 public Credentials getCredentials() { 45 Credentials credentials = (Credentials)sessionStore.get(CREDENTIALS); 46 if ( credentials == null ) { 47 credentials = Projector.getCredentials(); 48 } 49 return credentials; 50 } 51 52 public Store getStore(int store) { 53 switch ( store ) { 54 case Store.SESSION : { 55 return sessionStore; 56 } 57 case Store.REQUEST_PARAMETER : { 58 return requestParameterStore; 59 } 60 case Store.REQUEST_ATTRIBUTE : { 61 return requestAttributeStore; 62 } 63 case Store.REQUEST_HEADER : { 64 return requestHeaderStore; 65 } 66 case Store.COOKIE : { 67 return cookieStore; 68 } 69 case Store.CACHE : { 70 return Cache.getInstance(); 71 } 72 case Store.FORM : { 73 return formStore; 74 } 75 } 76 return super.getStore(store); 77 } 78 79 public String getContextPath() { 80 return contextPath; 81 } 82 83 public void setPresentableResource(StreamableValue resource) { 84 this.resource = resource; 85 } 86 87 public StreamableValue getPresentableResource() { 88 return resource; 89 } 90 91 public void setBookmark(URI processor) throws IOException { 92 sessionStore.put(BOOKMARK, processor); 93 } 94 95 public URI getBookmark() throws IOException { 96 return (URI)sessionStore.get(BOOKMARK); 97 } 98 } | Popular Tags |