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 public class YearMonthDV extends AbstractDateTimeDV{ 36 37 43 public Object getActualValue(String content, ValidationContext context) throws InvalidDatatypeValueException{ 44 try{ 45 return parse(content); 46 } catch(Exception ex){ 47 throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.1", new Object []{content, "gYearMonth"}); 48 } 49 } 50 51 59 protected DateTimeData parse(String str) throws SchemaDateTimeException{ 60 DateTimeData date = new DateTimeData(str, this); 61 int len = str.length(); 62 63 int end = getYearMonth(str, 0, len, date); 65 date.day = DAY; 66 parseTimeZone (str, end, len, date); 67 68 70 validateDateTime(date); 71 72 saveUnnormalized(date); 74 75 if ( date.utc!=0 && date.utc!='Z' ) { 76 normalize(date); 77 } 78 date.position = 0; 79 return date; 80 } 81 82 protected String dateToString(DateTimeData date) { 83 StringBuffer message = new StringBuffer (25); 84 append(message, date.year, 4); 85 message.append('-'); 86 append(message, date.month, 2); 87 append(message, (char)date.utc, 0); 88 return message.toString(); 89 } 90 91 protected XMLGregorianCalendar getXMLGregorianCalendar(DateTimeData date) { 92 return factory.newXMLGregorianCalendar(date.unNormYear, date.unNormMonth, DatatypeConstants.FIELD_UNDEFINED 93 , DatatypeConstants.FIELD_UNDEFINED, DatatypeConstants.FIELD_UNDEFINED, DatatypeConstants.FIELD_UNDEFINED, DatatypeConstants.FIELD_UNDEFINED, date.timezoneHr * 60 + date.timezoneMin); 94 } 95 } 96 97 98 | Popular Tags |