1 13 package com.tonbeller.jpivot.param; 14 15 import javax.servlet.jsp.JspException ; 16 import javax.servlet.jsp.tagext.TagSupport ; 17 18 import com.tonbeller.jpivot.olap.model.Expression; 19 import com.tonbeller.jpivot.olap.model.OlapModel; 20 import com.tonbeller.jpivot.olap.navi.ExpressionParser; 21 import com.tonbeller.jpivot.olap.navi.SetParameter; 22 import com.tonbeller.jpivot.olap.navi.ExpressionParser.InvalidSyntaxException; 23 import com.tonbeller.wcf.expr.ExprUtils; 24 import com.tonbeller.wcf.param.SessionParam; 25 import com.tonbeller.wcf.param.SessionParamPool; 26 27 34 public class SetParameterTag extends TagSupport { 35 String httpParam; 36 String mdxParam; 37 String sessionParam; 38 String query; 39 40 public int doStartTag() throws JspException { 41 if ((httpParam == null) == (sessionParam == null)) 42 throw new JspException ("either httpParam or sessionParam required"); 43 44 if (httpParam != null) 45 return doStartTagHttp(); 46 return doStartTagSession(); 47 } 48 49 public int doStartTagSession() throws JspException { 50 return SKIP_BODY; 51 } 52 53 public int doStartTagHttp() throws JspException { 54 String value = pageContext.getRequest().getParameter(httpParam); 55 if (value != null) 56 return EVAL_BODY_INCLUDE; 57 return SKIP_BODY; 58 } 59 60 public int doEndTag() throws JspException { 61 if (httpParam != null) 62 return doEndTagHttp(); 63 return doEndTagSession(); 64 } 65 66 public int doEndTagSession() throws JspException { 67 SessionParamPool pool = SessionParamPool.instance(pageContext.getSession()); 68 SessionParam p = pool.getParam(sessionParam); 69 if (p != null) 70 setQueryParam(p.getMdxValue()); 71 return super.doEndTag(); 72 } 73 74 public int doEndTagHttp() throws JspException { 75 String value = pageContext.getRequest().getParameter(httpParam); 76 if (value != null) 77 setQueryParam(value); 78 return super.doEndTag(); 79 } 80 81 private void setQueryParam(String value) throws JspException { 82 OlapModel model = (OlapModel) ExprUtils.getModelReference(pageContext, query); 84 if (model == null) 85 throw new JspException ("OlapModel/Query " + query + " not found"); 86 SetParameter setter = (SetParameter) model.getExtension(SetParameter.ID); 87 if (setter == null) 88 throw new JspException ("SetParameter not supported"); 89 ExpressionParser parser = (ExpressionParser) model.getExtension(ExpressionParser.ID); 90 if (parser == null) 91 throw new JspException ("ExpressionParser not supported"); 92 try { 93 Expression expr = parser.parse(value); 94 setter.setParameter(mdxParam, expr); 95 } catch (InvalidSyntaxException e) { 96 throw new JspException (e); 97 } 98 } 99 100 public void setHttpParam(String string) { 101 httpParam = string; 102 } 103 104 public void setMdxParam(String string) { 105 mdxParam = string; 106 } 107 108 public void setQuery(String string) { 109 query = string; 110 } 111 112 public void setSessionParam(String sessionParam) { 113 this.sessionParam = sessionParam; 114 } 115 } | Popular Tags |