1 52 53 package freemarker.ext.beans; 54 55 import java.util.Date ; 56 57 import freemarker.ext.util.ModelFactory; 58 import freemarker.template.ObjectWrapper; 59 import freemarker.template.TemplateDateModel; 60 import freemarker.template.TemplateModel; 61 62 67 public class DateModel 68 extends 69 BeanModel 70 implements 71 TemplateDateModel 72 { 73 static final ModelFactory FACTORY = 74 new ModelFactory() 75 { 76 public TemplateModel create(Object object, ObjectWrapper wrapper) 77 { 78 return new DateModel((Date )object, (BeansWrapper)wrapper); 79 } 80 }; 81 82 private final int type; 83 84 92 public DateModel(Date date, BeansWrapper wrapper) 93 { 94 super(date, wrapper); 95 if(date instanceof java.sql.Date ) { 96 type = DATE; 97 } 98 else if(date instanceof java.sql.Time ) { 99 type = TIME; 100 } 101 else if(date instanceof java.sql.Timestamp ) { 102 type = DATETIME; 103 } 104 else { 105 type = wrapper.getDefaultDateType(); 106 } 107 } 108 109 public Date getAsDate() { 110 return (Date )object; 111 } 112 113 public int getDateType() { 114 return type; 115 } 116 } 117 | Popular Tags |