1 28 29 package com.caucho.jstl.el; 30 31 import com.caucho.el.Expr; 32 import com.caucho.jsp.PageContextImpl; 33 import com.caucho.jstl.ParamContainerTag; 34 import com.caucho.util.L10N; 35 36 import javax.servlet.jsp.JspException ; 37 import javax.servlet.jsp.jstl.sql.SQLExecutionTag; 38 import javax.servlet.jsp.tagext.BodyTagSupport ; 39 import javax.servlet.jsp.tagext.Tag ; 40 41 44 public class SqlParamTag extends BodyTagSupport { 45 private static L10N L = new L10N(SqlParamTag.class); 46 47 private Expr _valueExpr; 48 49 54 public void setValue(Expr value) 55 { 56 _valueExpr = value; 57 } 58 59 62 public int doStartTag() 63 throws JspException 64 { 65 if (_valueExpr == null) 66 return EVAL_BODY_BUFFERED; 67 68 PageContextImpl pageContext = (PageContextImpl) this.pageContext; 69 70 Object value = _valueExpr.evalObject(pageContext.getELContext()); 71 72 Tag parent = getParent(); 73 for (; 74 parent != null && ! (parent instanceof SQLExecutionTag); 75 parent = parent.getParent()) { 76 } 77 78 if (parent == null) 79 throw new JspException (L.l("sql:param requires sql:query parent.")); 80 81 SQLExecutionTag tag = (SQLExecutionTag) parent; 82 83 tag.addSQLParameter(value); 84 85 return SKIP_BODY; 86 } 87 88 91 public int doEndTag() 92 throws JspException 93 { 94 if (_valueExpr != null) 95 return EVAL_PAGE; 96 97 String value; 98 99 if (bodyContent != null) 100 value = bodyContent.getString().trim(); 101 else 102 value = ""; 103 104 Object parent = getParent(); 105 if (! (parent instanceof ParamContainerTag)) 106 throw new JspException (L.l("sql:param requires sql:query parent.")); 107 108 ParamContainerTag tag = (ParamContainerTag) parent; 109 110 tag.addParam(value); 111 112 return EVAL_PAGE; 113 } 114 } 115 | Popular Tags |