1 57 58 package com.sun.org.apache.xerces.internal.impl.dv.xs; 59 60 import com.sun.org.apache.xerces.internal.impl.dv.InvalidDatatypeValueException; 61 import com.sun.org.apache.xerces.internal.impl.dv.ValidationContext; 62 63 71 72 public class YearDV extends AbstractDateTimeDV { 73 74 80 public Object getActualValue(String content, ValidationContext context) throws InvalidDatatypeValueException{ 81 try{ 82 return new DateTimeData(parse(content), this); 83 } catch(Exception ex){ 84 throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.1", new Object []{content, "gYear"}); 85 } 86 } 87 88 97 protected int[] parse(String str) throws SchemaDateTimeException{ 98 int len = str.length(); 99 int[] date = new int[TOTAL_SIZE]; 100 int[] timeZone = new int[2]; 101 102 int start = 0; 104 if (str.charAt(0)=='-') { 105 start = 1; 106 } 107 int sign = findUTCSign(str, start, len); 108 if (sign == -1) { 109 date[CY]=parseIntYear(str, len); 110 } 111 else { 112 date[CY]=parseIntYear(str, sign); 113 getTimeZone (str, date, sign, len, timeZone); 114 } 115 116 date[M]=MONTH; 118 date[D]=1; 119 120 validateDateTime(date, timeZone); 122 123 if ( date[utc]!=0 && date[utc]!='Z' ) { 124 normalize(date, timeZone); 125 } 126 return date; 127 } 128 129 135 protected String dateToString(int[] date) { 136 StringBuffer message = new StringBuffer (5); 137 append(message, date[CY], 4); 138 append(message, (char)date[utc], 0); 139 return message.toString(); 140 } 141 142 } 143 144 145 | Popular Tags |