1 18 package org.apache.beehive.netui.script.el; 19 20 import javax.servlet.ServletRequest ; 21 import javax.servlet.ServletResponse ; 22 import javax.servlet.http.HttpServletRequest ; 23 import javax.servlet.jsp.el.VariableResolver ; 24 25 import org.apache.beehive.netui.script.IllegalExpressionException; 26 import org.apache.beehive.netui.script.common.ImplicitObjectUtil; 27 import org.apache.beehive.netui.script.el.util.RequestAttributeMap; 28 import org.apache.beehive.netui.script.el.util.SessionAttributeMap; 29 import org.apache.beehive.netui.util.logging.Logger; 30 import org.apache.beehive.netui.pageflow.SharedFlowController; 31 import org.apache.beehive.netui.pageflow.PageFlowController; 32 import org.apache.beehive.netui.pageflow.GlobalApp; 33 34 import java.util.Map ; 35 36 39 public class NetUIUpdateVariableResolver 40 extends NetUIVariableResolver { 41 42 private static final Logger LOGGER = Logger.getInstance(NetUIVariableResolver.class); 43 44 private boolean _requestParameter = true; 45 private Object _form = null; 46 private ServletRequest _request = null; 47 private ServletResponse _response = null; 48 49 public NetUIUpdateVariableResolver(Object form, ServletRequest request, ServletResponse response, boolean requestParameter) { 50 super(); 51 52 _requestParameter = requestParameter; 53 _form = form; 54 _request = request; 55 _response = response; 56 } 57 58 public Object resolveVariable(String name) { 59 if(name.equals("actionForm")) 60 return _form; 61 else if(name.equals("pageFlow")) 62 return getPageFlow(_request, _response); 63 else if(name.equals("globalApp")) 64 return getGlobalApp(_request, _response); 65 else if(name.equals("sharedFlow")) 66 return getSharedFlow(_request, _response); 67 else if(name.equals("requestScope")) { 68 if(_requestParameter == false) 69 return new RequestAttributeMap(_request); 70 else 71 throw new IllegalExpressionException("The request data binding context can not be updated from a request parameter."); 72 } else if(name.equals("sessionScope")) { 73 if(_requestParameter == false) 74 return new SessionAttributeMap(((HttpServletRequest )_request).getSession()); 75 else 76 throw new IllegalExpressionException("The session data binding context can not be updated from a request parameter."); 77 } 78 else if(name.equals("applicationScope")) { 80 if(_requestParameter == false) 81 return null; 82 else 83 throw new IllegalExpressionException("The application data binding context can not be updated from a request parameter."); 84 } else { 85 String msg = "Could not resolve variable named \"" + name + "\" for an expression update."; 86 if(LOGGER.isErrorEnabled()) 87 LOGGER.error(msg); 88 89 throw new IllegalExpressionException(msg); 90 } 91 } 92 93 public String [] getAvailableVariables() { 94 if(_requestParameter) 95 return new String []{"actionForm", "pageFlow", "globalApp"}; 96 else 97 return new String []{"actionForm", "pageFlow", "globalApp", "request", "session", "application"}; 98 } 99 100 private static final Map getSharedFlow(ServletRequest request, ServletResponse response) { 101 return ImplicitObjectUtil.getSharedFlow(request); 102 } 103 104 private static final PageFlowController getPageFlow(ServletRequest request, ServletResponse response) { 105 return ImplicitObjectUtil.getPageFlow(request, response); 106 } 107 108 private static final GlobalApp getGlobalApp(ServletRequest request, ServletResponse response) { 109 return ImplicitObjectUtil.getGlobalApp(request, response); 110 } 111 } 112 | Popular Tags |