1 16 package org.apache.taglibs.standard.tag.common.sql; 17 18 import javax.servlet.jsp.JspException ; 19 import javax.servlet.jsp.JspTagException ; 20 import javax.servlet.jsp.jstl.sql.SQLExecutionTag; 21 import javax.servlet.jsp.tagext.TagSupport ; 22 23 import org.apache.taglibs.standard.resources.Resources; 24 25 26 32 33 public abstract class DateParamTagSupport extends TagSupport { 34 35 38 private static final String TIMESTAMP_TYPE = "timestamp"; 39 private static final String TIME_TYPE = "time"; 40 private static final String DATE_TYPE = "date"; 41 42 43 46 protected String type; 47 protected java.util.Date value; 48 49 50 53 public DateParamTagSupport() { 54 super(); 55 init(); 56 } 57 58 private void init() { 59 value = null; 60 type = null; 61 } 62 63 64 67 public int doEndTag() throws JspException { 68 SQLExecutionTag parent = (SQLExecutionTag) 69 findAncestorWithClass(this, SQLExecutionTag.class); 70 if (parent == null) { 71 throw new JspTagException ( 72 Resources.getMessage("SQL_PARAM_OUTSIDE_PARENT")); 73 } 74 75 if (value != null) { 76 convertValue(); 77 } 78 79 parent.addSQLParameter(value); 80 return EVAL_PAGE; 81 } 82 83 84 87 private void convertValue() throws JspException { 88 89 if ((type == null) || (type.equalsIgnoreCase(TIMESTAMP_TYPE))) { 90 if (!(value instanceof java.sql.Timestamp )) { 91 value = new java.sql.Timestamp (value.getTime()); 92 } 93 } else if (type.equalsIgnoreCase(TIME_TYPE)) { 94 if (!(value instanceof java.sql.Time )) { 95 value = new java.sql.Time (value.getTime()); 96 } 97 } else if (type.equalsIgnoreCase(DATE_TYPE)) { 98 if (!(value instanceof java.sql.Date )) { 99 value = new java.sql.Date (value.getTime()); 100 } 101 } else { 102 throw new JspException ( 103 Resources.getMessage("SQL_DATE_PARAM_INVALID_TYPE", type)); 104 } 105 } 106 } 107 | Popular Tags |