1 16 17 package org.apache.xerces.impl.dv.xs; 18 19 import javax.xml.datatype.DatatypeConstants ; 20 import javax.xml.datatype.XMLGregorianCalendar ; 21 22 import org.apache.xerces.impl.dv.InvalidDatatypeValueException; 23 import org.apache.xerces.impl.dv.ValidationContext; 24 25 35 public class DateDV extends DateTimeDV { 36 37 public Object getActualValue(String content, ValidationContext context) throws InvalidDatatypeValueException { 38 try{ 39 return parse(content); 40 } catch(Exception ex){ 41 throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.1", new Object []{content, "date"}); 42 } 43 } 44 45 53 protected DateTimeData parse(String str) throws SchemaDateTimeException { 54 DateTimeData date = new DateTimeData(str, this); 55 int len = str.length(); 56 57 int end = getDate(str, 0, len, date); 58 parseTimeZone (str, end, len, date); 59 60 validateDateTime(date); 63 64 saveUnnormalized(date); 66 67 if (date.utc!=0 && date.utc!='Z') { 68 normalize(date); 69 } 70 return date; 71 } 72 73 protected String dateToString(DateTimeData date) { 74 StringBuffer message = new StringBuffer (25); 75 append(message, date.year, 4); 76 message.append('-'); 77 append(message, date.month, 2); 78 message.append('-'); 79 append(message, date.day, 2); 80 append(message, (char)date.utc, 0); 81 return message.toString(); 82 } 83 84 protected XMLGregorianCalendar getXMLGregorianCalendar(DateTimeData date) { 85 return factory.newXMLGregorianCalendar(date.unNormYear, date.unNormMonth, date.unNormDay 86 , DatatypeConstants.FIELD_UNDEFINED, DatatypeConstants.FIELD_UNDEFINED, DatatypeConstants.FIELD_UNDEFINED, DatatypeConstants.FIELD_UNDEFINED, date.timezoneHr * 60 + date.timezoneMin); 87 } 88 89 } 90 | Popular Tags |