1 16 17 package org.apache.taglibs.standard.lang.jpath.expression; 18 19 import javax.servlet.jsp.PageContext ; 20 21 import org.apache.taglibs.standard.lang.jpath.adapter.ConversionException; 22 import org.apache.taglibs.standard.lang.jpath.adapter.Convert; 23 import org.apache.taglibs.standard.lang.jpath.adapter.GregorianCalendarAdapter; 24 import org.apache.taglibs.standard.lang.jpath.adapter.IterationContext; 25 import org.apache.taglibs.standard.lang.jpath.adapter.JSPDate; 26 27 34 public class DateFunction extends SimpleNode { 35 36 43 public DateFunction(int id) { 44 super(id); 45 } 46 47 55 public DateFunction(Parser p, int id) { 56 super(p, id); 57 } 58 59 69 public String toNormalizedString() { 70 71 boolean first = true; 72 String normalized; 73 74 normalized = "date("; 75 76 if (children != null) { 77 for (int i = 0; i < children.length; ++i) { 78 if (!first) { 79 normalized = normalized + ","; 80 } 81 82 first = false; 83 84 SimpleNode n = (SimpleNode) children[i]; 85 86 if (n != null) { 87 normalized = normalized + n.toNormalizedString(); 88 } 89 } 90 } 91 92 normalized = normalized + ")"; 93 94 return normalized; 95 } 96 97 114 public Object evaluate(PageContext pageContext, IterationContext icontext) 115 throws EvaluationException { 116 117 JSPDate d; 118 119 try { 120 if (jjtGetNumChildren() == 3) { 121 int year = 122 Convert.toDouble(jjtGetChild(0).evaluate(pageContext, 123 icontext)).intValue(); 124 int month = 125 Convert.toDouble(jjtGetChild(1) 126 .evaluate(pageContext, icontext)).intValue() - 1; 127 int date = 128 Convert.toDouble(jjtGetChild(2).evaluate(pageContext, 129 icontext)).intValue(); 130 131 d = new GregorianCalendarAdapter(year, month, date); 132 } else if (jjtGetNumChildren() == 5) { 133 int year = 134 Convert.toDouble(jjtGetChild(0).evaluate(pageContext, 135 icontext)).intValue(); 136 int month = 137 Convert.toDouble(jjtGetChild(1) 138 .evaluate(pageContext, icontext)).intValue() - 1; 139 int date = 140 Convert.toDouble(jjtGetChild(2).evaluate(pageContext, 141 icontext)).intValue(); 142 int hour = 143 Convert.toDouble(jjtGetChild(3).evaluate(pageContext, 144 icontext)).intValue(); 145 int minute = 146 Convert.toDouble(jjtGetChild(4).evaluate(pageContext, 147 icontext)).intValue(); 148 149 d = new GregorianCalendarAdapter(year, month, date, hour, 150 minute); 151 } else if (jjtGetNumChildren() == 6) { 152 int year = 153 Convert.toDouble(jjtGetChild(0).evaluate(pageContext, 154 icontext)).intValue(); 155 int month = 156 Convert.toDouble(jjtGetChild(1) 157 .evaluate(pageContext, icontext)).intValue() - 1; 158 int date = 159 Convert.toDouble(jjtGetChild(2).evaluate(pageContext, 160 icontext)).intValue(); 161 int hour = 162 Convert.toDouble(jjtGetChild(3).evaluate(pageContext, 163 icontext)).intValue(); 164 int minute = 165 Convert.toDouble(jjtGetChild(4).evaluate(pageContext, 166 icontext)).intValue(); 167 int second = 168 Convert.toDouble(jjtGetChild(5).evaluate(pageContext, 169 icontext)).intValue(); 170 171 d = new GregorianCalendarAdapter(year, month, date, hour, 172 minute, second); 173 } else { 174 throw new EvaluationException(this, 175 "date does not have the proper" 176 + "number of arguments"); 177 } 178 } catch (ConversionException ce) { 179 throw new EvaluationException(this, ce.getMessage()); 180 } 181 182 return d; 183 } 184 } 185 | Popular Tags |