1 28 29 package net.sf.jasperreports.engine.util; 30 31 import java.text.ParseException ; 32 import java.text.SimpleDateFormat ; 33 import java.util.Locale ; 34 import java.util.TimeZone ; 35 36 import org.apache.commons.beanutils.locale.converters.DateLocaleConverter; 37 import org.apache.commons.logging.Log; 38 import org.apache.commons.logging.LogFactory; 39 40 53 54 public class JRDateLocaleConverter extends DateLocaleConverter 55 { 56 57 private static Log log = LogFactory.getLog(DateLocaleConverter.class); 58 59 private TimeZone timeZone = null; 61 62 64 67 public JRDateLocaleConverter(TimeZone timeZone) { 68 super(); 69 70 this.timeZone = timeZone; 71 } 72 73 157 158 protected Object parse(Object value, String pattern) throws ParseException { 159 SimpleDateFormat formatter = getFormatter(pattern, locale); 160 if (locPattern) { 161 formatter.applyLocalizedPattern(pattern); 162 } 163 else { 164 formatter.applyPattern(pattern); 165 } 166 return formatter.parse((String ) value); 167 } 168 169 private SimpleDateFormat getFormatter(String pattern, Locale locale) { 170 171 if(pattern == null) { 172 pattern = locPattern ? 173 new SimpleDateFormat ().toLocalizedPattern() : new SimpleDateFormat ().toPattern(); 174 log.warn("Null pattern was provided, defaulting to: " + pattern); 175 } 176 SimpleDateFormat format = new SimpleDateFormat (pattern, locale); 177 if(timeZone != null) 178 format.setTimeZone(timeZone); 179 format.setLenient(isLenient()); 180 return format; 181 } 182 183 197 198 } 199 | Popular Tags |