1 16 17 package org.apache.xerces.impl.dv.xs; 18 19 import java.math.BigDecimal ; 20 import java.math.BigInteger ; 21 22 import javax.xml.datatype.XMLGregorianCalendar ; 23 24 import org.apache.xerces.impl.dv.InvalidDatatypeValueException; 25 import org.apache.xerces.impl.dv.ValidationContext; 26 27 37 public class DateTimeDV extends AbstractDateTimeDV { 38 39 public Object getActualValue(String content, ValidationContext context) throws InvalidDatatypeValueException { 40 try{ 41 return parse(content); 42 } catch(Exception ex){ 43 throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.1", new Object []{content, "dateTime"}); 44 } 45 } 46 47 55 protected DateTimeData parse(String str) throws SchemaDateTimeException { 56 DateTimeData date = new DateTimeData(str, this); 57 int len = str.length(); 58 59 int end = indexOf (str, 0, len, 'T'); 60 61 int dateEnd = getDate(str, 0, end, date); 63 getTime(str, end+1, len, date); 64 65 if (dateEnd != end) { 67 throw new RuntimeException (str 68 + " is an invalid dateTime dataype value. " 69 + "Invalid character(s) seprating date and time values."); 70 } 71 72 74 validateDateTime(date); 76 77 saveUnnormalized(date); 79 80 if (date.utc!=0 && date.utc!='Z') { 81 normalize(date); 82 } 83 return date; 84 } 85 86 protected XMLGregorianCalendar getXMLGregorianCalendar(DateTimeData date) { 87 return factory.newXMLGregorianCalendar(BigInteger.valueOf(date.unNormYear), date.unNormMonth, date.unNormDay 88 , date.unNormHour, date.unNormMinute, (int)date.unNormSecond, date.unNormSecond != 0?new BigDecimal (date.unNormSecond - ((int)date.unNormSecond)):null, date.timezoneHr * 60 + date.timezoneMin); 89 } 90 } 91 | Popular Tags |