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 MonthDV extends AbstractDateTimeDV { 37 38 44 public Object getActualValue(String content, ValidationContext context) throws InvalidDatatypeValueException{ 45 try{ 46 return parse(content); 47 } catch(Exception ex){ 48 throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.1", new Object []{content, "gMonth"}); 49 } 50 } 51 52 60 protected DateTimeData parse(String str) throws SchemaDateTimeException{ 61 DateTimeData date = new DateTimeData(str, this); 62 int len = str.length(); 63 64 date.year=YEAR; 66 date.day=DAY; 67 if (str.charAt(0)!='-' || str.charAt(1)!='-') { 68 throw new SchemaDateTimeException("Invalid format for gMonth: "+str); 69 } 70 int stop = 4; 71 date.month=parseInt(str,2,stop); 72 73 if (str.length() >= stop+2 && 77 str.charAt(stop) == '-' && str.charAt(stop+1) == '-') { 78 stop += 2; 79 } 80 if (stop < len) { 81 if (!isNextCharUTCSign(str, stop, len)) { 82 throw new SchemaDateTimeException ("Error in month parsing: "+str); 83 } 84 else { 85 getTimeZone(str, date, stop, len); 86 } 87 } 88 validateDateTime(date); 90 91 saveUnnormalized(date); 93 94 if ( date.utc!=0 && date.utc!='Z' ) { 95 normalize(date); 96 } 97 date.position = 1; 98 return date; 99 } 100 101 113 142 143 149 protected String dateToString(DateTimeData date) { 150 StringBuffer message = new StringBuffer (5); 151 message.append('-'); 152 message.append('-'); 153 append(message, date.month, 2); 154 append(message, (char)date.utc, 0); 155 return message.toString(); 156 } 157 158 protected XMLGregorianCalendar getXMLGregorianCalendar(DateTimeData date) { 159 return factory.newXMLGregorianCalendar(DatatypeConstants.FIELD_UNDEFINED, date.unNormMonth, DatatypeConstants.FIELD_UNDEFINED 160 , DatatypeConstants.FIELD_UNDEFINED, DatatypeConstants.FIELD_UNDEFINED, DatatypeConstants.FIELD_UNDEFINED, DatatypeConstants.FIELD_UNDEFINED, date.timezoneHr * 60 + date.timezoneMin); 161 } 162 } 163 | Popular Tags |