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 34 public class DayDV extends AbstractDateTimeDV { 35 36 private final static int DAY_SIZE=5; 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, "gDay"}); 44 } 45 } 46 47 56 protected DateTimeData parse(String str) throws SchemaDateTimeException { 57 DateTimeData date = new DateTimeData(str, this); 58 int len = str.length(); 59 60 if (str.charAt(0)!='-' || str.charAt(1)!='-' || str.charAt(2)!='-') { 61 throw new SchemaDateTimeException ("Error in day parsing"); 62 } 63 64 date.year=YEAR; 66 date.month=MONTH; 67 68 date.day=parseInt(str, 3,5); 69 70 if ( DAY_SIZE<len ) { 71 if (!isNextCharUTCSign(str, DAY_SIZE, len)) { 72 throw new SchemaDateTimeException ("Error in day parsing"); 73 } 74 else { 75 getTimeZone(str, date, DAY_SIZE, len); 76 } 77 } 78 79 validateDateTime(date); 81 82 saveUnnormalized(date); 84 85 if ( date.utc!=0 && date.utc!='Z' ) { 86 normalize(date); 87 } 88 date.position = 2; 89 return date; 90 } 91 92 98 protected String dateToString(DateTimeData date) { 99 StringBuffer message = new StringBuffer (6); 100 message.append('-'); 101 message.append('-'); 102 message.append('-'); 103 append(message, date.day, 2); 104 append(message, (char)date.utc, 0); 105 return message.toString(); 106 } 107 108 protected XMLGregorianCalendar getXMLGregorianCalendar(DateTimeData date) { 109 return factory.newXMLGregorianCalendar(DatatypeConstants.FIELD_UNDEFINED, DatatypeConstants.FIELD_UNDEFINED, date.unNormDay 110 , DatatypeConstants.FIELD_UNDEFINED, DatatypeConstants.FIELD_UNDEFINED, DatatypeConstants.FIELD_UNDEFINED, DatatypeConstants.FIELD_UNDEFINED, date.timezoneHr * 60 + date.timezoneMin); 111 } 112 113 } 114 115 | Popular Tags |