1 13 package com.tonbeller.wcf.controller; 14 15 import java.util.Locale ; 16 import java.util.Map ; 17 18 import javax.servlet.ServletContext ; 19 import javax.servlet.http.HttpServletRequest ; 20 import javax.servlet.http.HttpServletResponse ; 21 import javax.servlet.http.HttpSession ; 22 23 import com.tonbeller.tbutils.res.Resources; 24 import com.tonbeller.wcf.convert.Converter; 25 import com.tonbeller.wcf.expr.ExprContext; 26 import com.tonbeller.wcf.format.Formatter; 27 28 33 public abstract class RequestContext implements ExprContext { 34 public abstract HttpServletRequest getRequest(); 35 public abstract HttpServletResponse getResponse(); 36 public abstract ServletContext getServletContext(); 37 public abstract HttpSession getSession(); 38 39 public abstract Converter getConverter(); 40 public abstract Formatter getFormatter(); 41 42 private static ThreadLocalStack instanceStack = new ThreadLocalStack(); 43 44 private static final String RESPONSE_COMPLETE_KEY = RequestContext.class.getName() + ".responseComplete"; 45 46 public abstract Map getFileParameters(); 47 48 protected RequestContext() { 49 } 50 51 56 public static RequestContext instance() throws EmptyThreadLocalStackException { 57 return (RequestContext) instanceStack.peek(true); 58 } 59 60 65 public static RequestContext instance(boolean failIfEmpty) throws EmptyThreadLocalStackException { 66 return (RequestContext) instanceStack.peek(failIfEmpty); 67 } 68 69 73 public static void setInstance(RequestContext context) { 74 instanceStack.push(context); 75 } 76 77 83 public void invalidate() { 84 instanceStack.pop(); 85 } 86 87 91 public abstract Map getParameters(); 92 public abstract String [] getParameters(String name); 93 public abstract String getParameter(String name); 94 95 98 public abstract Locale getLocale(); 99 100 104 public abstract void setLocale(Locale locale); 105 106 public abstract Resources getResources(); 107 public abstract Resources getResources(String bundleName); 108 public abstract Resources getResources(Class clasz); 109 110 113 public abstract Object getModelReference(String expr); 114 public abstract void setModelReference(String expr, Object value); 115 116 117 139 public abstract boolean isUserInRole(String roleExpr); 140 141 149 public abstract String getRemoteUser(); 150 public abstract String getRemoteDomain(); 151 152 157 public abstract boolean isAdmin(); 158 159 164 public void setResponseComplete(boolean complete) { 165 getRequest().setAttribute(RESPONSE_COMPLETE_KEY, Boolean.toString(complete)); 166 } 167 public boolean isResponseComplete() { 168 return "true".equals(getRequest().getAttribute(RESPONSE_COMPLETE_KEY)); 169 } 170 } 171 | Popular Tags |