1 23 24 package org.apache.webdav.lib.properties; 25 26 import java.text.ParseException ; 27 import java.text.SimpleDateFormat ; 28 import java.util.Date ; 29 import java.util.Locale ; 30 31 import org.apache.webdav.lib.BaseProperty; 32 import org.apache.webdav.lib.ResponseEntity; 33 import org.apache.webdav.lib.util.DOMUtils; 34 import org.w3c.dom.Element ; 35 36 39 public abstract class DateProperty extends BaseProperty 40 { 41 42 private static final SimpleDateFormat FORMATS[] = { 43 new SimpleDateFormat ("EEE, d MMM yyyy kk:mm:ss z", Locale.US), 44 new SimpleDateFormat ("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US), 45 new SimpleDateFormat ("EEE MMM dd HH:mm:ss zzz yyyy", Locale.US), 46 new SimpleDateFormat ("EEEEEE, dd-MMM-yy HH:mm:ss zzz", Locale.US), 47 new SimpleDateFormat ("EEE MMMM d HH:mm:ss yyyy", Locale.US), 48 new SimpleDateFormat ("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.US), 49 new SimpleDateFormat ("yyyy-MM-dd'T'HH:mm:ss.sss'Z'", Locale.US) 50 }; 51 52 public DateProperty(ResponseEntity response, Element element) { 53 super(response, element); 54 } 55 56 59 public Date getDate() 60 { 61 String dateString = DOMUtils.getTextValue(element); 62 for(int i = 0; i < FORMATS.length; i++) { 63 try { 64 return FORMATS[i].parse(dateString); 65 } catch (ParseException e) { 66 } 68 } 69 return null; 70 } 71 } 72 | Popular Tags |