1 16 17 package org.apache.xerces.impl.dv.xs; 18 19 import java.math.BigDecimal ; 20 21 import javax.xml.datatype.DatatypeConstants ; 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 TimeDV extends AbstractDateTimeDV { 38 39 45 public Object getActualValue(String content, ValidationContext context) throws InvalidDatatypeValueException{ 46 try{ 47 return parse(content); 48 } catch(Exception ex){ 49 throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.1", new Object []{content, "time"}); 50 } 51 } 52 53 62 protected DateTimeData parse(String str) throws SchemaDateTimeException{ 63 DateTimeData date = new DateTimeData(str, this); 64 int len = str.length(); 65 66 date.year=YEAR; 69 date.month=MONTH; 70 date.day=15; 71 getTime(str, 0, len, date); 72 73 75 validateDateTime(date); 76 77 saveUnnormalized(date); 79 80 if ( date.utc!=0 && date.utc != 'Z') { 81 normalize(date); 82 } 83 date.position = 2; 84 return date; 85 } 86 87 93 protected String dateToString(DateTimeData date) { 94 StringBuffer message = new StringBuffer (16); 95 append(message, date.hour, 2); 96 message.append(':'); 97 append(message, date.minute, 2); 98 message.append(':'); 99 append(message, date.second); 100 101 append(message, (char)date.utc, 0); 102 return message.toString(); 103 } 104 105 protected XMLGregorianCalendar getXMLGregorianCalendar(DateTimeData date) { 106 return factory.newXMLGregorianCalendar(null 107 , DatatypeConstants.FIELD_UNDEFINED, DatatypeConstants.FIELD_UNDEFINED, date.unNormHour, date.unNormMinute, (int)date.unNormSecond, date.unNormSecond != 0?new BigDecimal (date.unNormSecond - ((int)date.unNormSecond)):null, date.timezoneHr * 60 + date.timezoneMin); 108 } 109 } 110 | Popular Tags |