1 29 30 package com.caucho.jstl.el; 31 32 import com.caucho.el.Expr; 33 import com.caucho.util.L10N; 34 35 import javax.el.ELContext; 36 import javax.servlet.jsp.JspException ; 37 import javax.servlet.jsp.jstl.sql.SQLExecutionTag; 38 import javax.servlet.jsp.tagext.Tag ; 39 import javax.servlet.jsp.tagext.TagSupport ; 40 41 44 public class SqlDateParamTag extends TagSupport { 45 private static L10N L = new L10N(SqlDateParamTag.class); 46 47 private Expr _valueExpr; 48 private Expr _typeExpr; 49 50 55 public void setValue(Expr value) 56 { 57 _valueExpr = value; 58 } 59 60 65 public void setType(Expr type) 66 { 67 _typeExpr = type; 68 } 69 70 73 public int doStartTag() 74 throws JspException 75 { 76 ELContext env = pageContext.getELContext(); 77 78 Object value = _valueExpr.evalObject(env); 79 80 long time = 0; 81 82 Object result = null; 83 84 if (value == null) { 85 } 86 else if (value instanceof Number ) 87 time = ((Number ) value).longValue(); 88 else if (value instanceof java.util.Date ) 89 time = ((java.util.Date ) value).getTime(); 90 else if (value instanceof java.sql.Date ) 91 time = ((java.sql.Date ) value).getTime(); 92 else 93 throw new JspException (L.l("sql:dateParam requires at date at `{0}'", value)); 94 95 if (value == null) 96 result = null; 97 else if (_typeExpr == null) 98 result = new java.sql.Timestamp (time); 99 else { 100 String type = _typeExpr.evalString(env); 101 102 if (type.equals("time")) 103 result = new java.sql.Time (time); 104 else if (type.equals("date")) 105 result = new java.sql.Date (time); 106 else 107 result = new java.sql.Timestamp (time); 108 } 109 110 Tag parent = getParent(); 111 for (; 112 parent != null && ! (parent instanceof SQLExecutionTag); 113 parent = parent.getParent()) { 114 } 115 116 if (parent == null) 117 throw new JspException (L.l("sql:dateParam requires sql:query parent.")); 118 119 SQLExecutionTag tag = (SQLExecutionTag) parent; 120 121 tag.addSQLParameter(result); 122 123 return SKIP_BODY; 124 } 125 } 126 | Popular Tags |