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 36 public class MonthDayDV extends AbstractDateTimeDV { 37 38 private final static int MONTHDAY_SIZE = 7; 40 41 47 public Object getActualValue(String content, ValidationContext context) throws InvalidDatatypeValueException { 48 try{ 49 return parse(content); 50 } catch(Exception ex){ 51 throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.1", new Object []{content, "gMonthDay"}); 52 } 53 } 54 55 63 protected DateTimeData parse(String str) throws SchemaDateTimeException{ 64 DateTimeData date = new DateTimeData(str, this); 65 int len = str.length(); 66 67 date.year=YEAR; 69 70 if (str.charAt(0)!='-' || str.charAt(1)!='-') { 71 throw new SchemaDateTimeException("Invalid format for gMonthDay: "+str); 72 } 73 date.month=parseInt(str, 2, 4); 74 int start=4; 75 76 if (str.charAt(start++)!='-') { 77 throw new SchemaDateTimeException("Invalid format for gMonthDay: " + str); 78 } 79 80 date.day=parseInt(str, start, start+2); 81 82 if ( MONTHDAY_SIZE<len ) { 83 if (!isNextCharUTCSign(str, MONTHDAY_SIZE, len)) { 84 throw new SchemaDateTimeException ("Error in month parsing:" +str); 85 } 86 else { 87 getTimeZone(str, date, MONTHDAY_SIZE, len); 88 } 89 } 90 92 validateDateTime(date); 93 94 saveUnnormalized(date); 96 97 if ( date.utc!=0 && date.utc!='Z' ) { 98 normalize(date); 99 } 100 date.position = 1; 101 return date; 102 } 103 104 110 protected String dateToString(DateTimeData date) { 111 StringBuffer message = new StringBuffer (8); 112 message.append('-'); 113 message.append('-'); 114 append(message, date.month, 2); 115 message.append('-'); 116 append(message, date.day, 2); 117 append(message, (char)date.utc, 0); 118 return message.toString(); 119 } 120 121 protected XMLGregorianCalendar getXMLGregorianCalendar(DateTimeData date) { 122 return factory.newXMLGregorianCalendar(DatatypeConstants.FIELD_UNDEFINED, date.unNormMonth, date.unNormDay 123 , DatatypeConstants.FIELD_UNDEFINED, DatatypeConstants.FIELD_UNDEFINED, DatatypeConstants.FIELD_UNDEFINED, DatatypeConstants.FIELD_UNDEFINED, date.timezoneHr * 60 + date.timezoneMin); 124 } 125 } 126 127 | Popular Tags |