View Javadoc
1 /*** 2 * DateFunction.java 3 * 4 * $Author: mballesteros $ 5 * $Date: 2003/11/28 19:18:04 $ 6 * $Revision: 1.1 $ 7 */ 8 package net.sf.jec.functions; 9 10 import java.text.SimpleDateFormat; 11 import java.util.Date; 12 13 import net.sf.jec.Function; 14 15 /*** Direct and inverse maps between Date/Timestamps to String objects. 16 * 17 * @author mballesteros 18 */ 19 public class DateFunction extends Function { 20 21 private SimpleDateFormat sdf; 22 23 /*** Creates a new instance of DateFunction 24 * @param dateFormat The date format to use. Example: "dd/MM/yyyy" 25 */ 26 public DateFunction(String dateFormat) { 27 sdf = new SimpleDateFormat(dateFormat); 28 } 29 30 /*** Inverse map: the inverse conversion 31 * @param object The source object 32 * @return The result object after applying the inverse map 33 */ 34 public Object inverseMap(Object[] objects) { 35 Object object = objects[0]; 36 if (object instanceof String) { 37 try { 38 return sdf.parse((String)object); 39 } catch (Exception ex) {} 40 } 41 return null; 42 } 43 44 /*** Direct map: the direct conversion 45 * @param object The source object 46 * @return The result object after applying the map 47 */ 48 public Object directMap(Object[] objects) { 49 Object object = objects[0]; 50 String out; 51 if (object instanceof Date) { 52 out = sdf.format( (Date)object ); 53 } else if (object instanceof java.sql.Timestamp) { 54 out = sdf.format( (java.sql.Timestamp)object ); 55 } else if (object == null) { 56 out = null; 57 } else { 58 out = "unknown("+object+")"; 59 } 60 return out; 61 } 62 }

This page was automatically generated by Maven