Your browser does not support JavaScript and this site utilizes JavaScript to build content and provide links to additional information. You should either enable JavaScript in your browser settings or use a browser that supports JavaScript in order to take full advantage of this site.
1 19 20 package org.efs.openreports.providers; 21 22 import java.text.SimpleDateFormat ; 23 import java.util.Date ; 24 25 import com.opensymphony.xwork.ActionContext; 26 import com.opensymphony.xwork.interceptor.component.ComponentManager; 27 28 import org.apache.log4j.Logger; 29 import org.efs.openreports.objects.ORProperty; 30 31 public class DateProvider implements PropertiesProviderAware 32 { 33 protected static Logger log = 34 Logger.getLogger(DateProvider.class.getName()); 35 36 protected SimpleDateFormat dateFormat = new SimpleDateFormat ("MM/dd/yyyy"); 37 38 private PropertiesProvider propertiesProvider; 39 40 public DateProvider(PropertiesProvider propertiesProvider) throws ProviderException 42 { 43 this.propertiesProvider = propertiesProvider; 44 init(); 45 } 46 47 public DateProvider() throws ProviderException 49 { 50 ComponentManager container = 51 (ComponentManager) ActionContext.getContext().get( 52 "com.opensymphony.xwork.interceptor.component.ComponentManager"); 53 54 container.initializeObject(this); 55 56 init(); 57 } 58 59 protected void init() throws ProviderException 60 { 61 String dateFormat = "MM/dd/yyyy"; 62 63 ORProperty property = propertiesProvider.getProperty(ORProperty.DATE_FORMAT); 64 if (property != null && property.getValue() != null 65 && property.getValue().trim().length() > 0) 66 { 67 dateFormat = property.getValue(); 68 } 69 70 setDateFormat(dateFormat); 71 72 log.info("DateFormat: " + dateFormat); 73 log.info("Created"); 74 } 75 76 public SimpleDateFormat getDateFormat() 77 { 78 return dateFormat; 79 } 80 81 public void setDateFormat(String format) 82 { 83 dateFormat = new SimpleDateFormat (format); 84 } 85 86 public Date parseDate(String date) throws ProviderException 87 { 88 try 89 { 90 return dateFormat.parse(date); 91 } 92 catch (Exception e) 93 { 94 throw new ProviderException("Use " + dateFormat.toPattern()); 95 } 96 } 97 98 public String formatDate(Date date) 99 { 100 return dateFormat.format(date); 101 } 102 103 public void setPropertiesProvider(PropertiesProvider propertiesProvider) 104 { 105 this.propertiesProvider = propertiesProvider; 106 } 107 108 }
| Popular Tags
|