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 YearDV 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, "gYear"}); 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 int start = 0; 66 if (str.charAt(0)=='-') { 67 start = 1; 68 } 69 int sign = findUTCSign(str, start, len); 70 if (sign == -1) { 71 date.year=parseIntYear(str, len); 72 } 73 else { 74 date.year=parseIntYear(str, sign); 75 getTimeZone (str, date, sign, len); 76 } 77 78 date.month=MONTH; 80 date.day=1; 81 82 validateDateTime(date); 84 85 saveUnnormalized(date); 87 88 if ( date.utc!=0 && date.utc!='Z' ) { 89 normalize(date); 90 } 91 date.position = 0; 92 return date; 93 } 94 95 101 protected String dateToString(DateTimeData date) { 102 StringBuffer message = new StringBuffer (5); 103 append(message, date.year, 4); 104 append(message, (char)date.utc, 0); 105 return message.toString(); 106 } 107 108 protected XMLGregorianCalendar getXMLGregorianCalendar(DateTimeData date) { 109 return factory.newXMLGregorianCalendar(date.unNormYear, DatatypeConstants.FIELD_UNDEFINED, DatatypeConstants.FIELD_UNDEFINED 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 |