1 28 29 package com.caucho.jstl.rt; 30 31 import com.caucho.jsp.PageContextImpl; 32 import com.caucho.util.L10N; 33 34 import javax.servlet.jsp.JspException ; 35 import javax.servlet.jsp.jstl.sql.SQLExecutionTag; 36 import javax.servlet.jsp.tagext.BodyTagSupport ; 37 import javax.servlet.jsp.tagext.Tag ; 38 39 42 public class SqlParamTag extends BodyTagSupport { 43 private static L10N L = new L10N(SqlParamTag.class); 44 45 private Object _value; 46 private boolean _hasValueSet; 47 48 53 public void setValue(Object value) 54 { 55 _value = value; 56 _hasValueSet = true; 57 } 58 59 62 public int doStartTag() 63 throws JspException 64 { 65 if (! _hasValueSet) 66 return EVAL_BODY_BUFFERED; 67 68 PageContextImpl pageContext = (PageContextImpl) this.pageContext; 69 70 Object value = _value; 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 (_hasValueSet) 95 return EVAL_PAGE; 96 97 String value; 98 99 if (bodyContent != null) 100 value = bodyContent.getString().trim(); 101 else 102 value = ""; 103 104 Tag parent = getParent(); 105 for (; 106 parent != null && ! (parent instanceof SQLExecutionTag); 107 parent = parent.getParent()) { 108 } 109 110 if (parent == null) 111 throw new JspException (L.l("sql:param requires sql:query parent.")); 112 113 SQLExecutionTag tag = (SQLExecutionTag) parent; 114 115 tag.addSQLParameter(value); 116 117 return EVAL_PAGE; 118 } 119 } 120 | Popular Tags |