1 package org.apache.turbine.services.pull.util; 2 3 18 19 import java.text.SimpleDateFormat ; 20 import java.util.Date ; 21 22 import org.apache.commons.lang.StringUtils; 23 import org.apache.turbine.Turbine; 24 import org.apache.turbine.services.pull.ApplicationTool; 25 26 32 public class DateFormatter 33 implements ApplicationTool 34 { 35 36 private SimpleDateFormat sdf = new SimpleDateFormat (); 37 38 39 private static final String DATE_FORMAT_DEFAULT = "MM/dd/yyyy"; 40 41 45 private static final String DATE_FORMAT_KEY = "tool.dateTool.format"; 46 47 private String dateFormat = null; 48 49 59 public void init(Object data) 60 { 61 dateFormat = Turbine.getConfiguration() 62 .getString(DATE_FORMAT_KEY, DATE_FORMAT_DEFAULT); 63 } 64 65 72 public void refresh() 73 { 74 } 75 76 83 public String format(Date theDate) 84 { 85 return format(theDate, dateFormat); 86 } 87 88 96 public String format(Date theDate, String dateFormatString) 97 { 98 String result = null; 99 100 if (StringUtils.isEmpty(dateFormatString) || theDate == null) 101 { 102 result = ""; 103 } 104 else 105 { 106 this.sdf.applyPattern(dateFormatString); 107 result = this.sdf.format(theDate); 108 } 109 return result; 110 } 111 112 } 113 | Popular Tags |