1 package com.tonbeller.wcf.param; 2 3 import java.io.IOException ; 4 5 import javax.servlet.jsp.JspException ; 6 import javax.servlet.jsp.JspWriter ; 7 import javax.servlet.jsp.tagext.TagSupport ; 8 9 import org.apache.log4j.Logger; 10 11 import com.tonbeller.wcf.expr.ExprUtils; 12 13 19 public class ParamSqlTag extends TagSupport { 20 String paramName; 21 String qname; 22 SqlGenerator sg; 23 private static Logger logger = Logger.getLogger(ParamSqlTag.class); 24 25 public int doStartTag() throws JspException { 26 sg = createSqlGenerator(); 27 if (qname != null) 28 sg.getColumnMap().put(SqlGenerator.DEFAULT_COLUMN_ID, qname); 29 return EVAL_BODY_INCLUDE; 30 } 31 32 public void setMapping(String columnId, String qname) { 33 sg.getColumnMap().put(columnId, qname); 34 } 35 36 public int doEndTag() throws JspException { 37 if (ExprUtils.isExpression(paramName)) { 38 Object obj = ExprUtils.getModelReference(pageContext, paramName); 39 paramName = String.valueOf(obj); 40 } 41 42 SessionParam param = SessionParamPool.instance(pageContext).getParam(paramName); 43 if (param == null) 44 throw new JspException ("SessionParam " + paramName + " not found"); 45 SqlExpr ex = param.getSqlExpr(); 46 JspWriter out = pageContext.getOut(); 47 try { 48 out.print(sg.generate(ex)); 49 } catch (IOException e) { 50 logger.error(null, e); 51 } 52 return EVAL_PAGE; 53 } 54 55 58 protected SqlGenerator createSqlGenerator() { 59 return new SqlGenerator(); 60 } 61 public void setQname(String qname) { 62 this.qname = qname; 63 } 64 public void setParam(String paramName) { 65 this.paramName = paramName; 66 } 67 } 68 | Popular Tags |