1 package org.tigris.scarab.util.xmlissues; 2 3 48 49 import java.util.Date ; 50 import java.text.ParseException ; 51 import java.text.SimpleDateFormat ; 52 53 import org.apache.commons.lang.StringUtils; 54 55 62 public class BaseDate implements java.io.Serializable 63 { 64 68 private static final String DEFAULT_FORMAT = "yyyy-MM-dd HH:mm:ss z"; 69 70 private String format = null; 71 private String timestamp = null; 72 73 public void setFormat(String format) 74 { 75 this.format = format; 76 } 77 78 public String getFormat() 79 { 80 return this.format; 81 } 82 83 public void setTimestamp(String timestamp) 84 { 85 this.timestamp = timestamp; 86 } 87 88 public String getTimestamp() 89 { 90 return this.timestamp; 91 } 92 93 100 public Date getDate() 101 throws ParseException 102 { 103 Date date = null; 104 String ts = getTimestamp(); 105 if (StringUtils.isNotEmpty(ts)) 106 { 107 String format = getFormat(); 108 boolean haveFormat = StringUtils.isNotEmpty(format); 109 try 110 { 111 SimpleDateFormat sdf = 112 new SimpleDateFormat (haveFormat ? format : DEFAULT_FORMAT); 113 sdf.setLenient(false); 114 date = sdf.parse(getTimestamp()); 115 } 116 catch (ParseException e) 117 { 118 if (haveFormat) 119 { 120 throw e; 123 } 124 } 125 } 126 return date; 127 } 128 129 public String toString() 130 { 131 return "format=" + format + "; timestamp=" + timestamp; 132 } 133 } 134 | Popular Tags |