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 MonthDV 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, "gMonth"}); 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 date[CY]=YEAR; 104 date[D]=DAY; 105 if (str.charAt(0)!='-' || str.charAt(1)!='-') { 106 throw new SchemaDateTimeException("Invalid format for gMonth: "+str); 107 } 108 int stop = 4; 109 date[M]=parseInt(str,2,stop); 110 111 if (str.length() >= stop+2 && 115 str.charAt(stop) == '-' && str.charAt(stop+1) == '-') { 116 stop += 2; 117 } 118 if (stop < len) { 119 int sign = findUTCSign(str, stop, len); 120 if ( sign<0 ) { 121 throw new SchemaDateTimeException ("Error in month parsing: "+str); 122 } 123 else { 124 getTimeZone(str, date, sign, len, timeZone); 125 } 126 } 127 validateDateTime(date, timeZone); 129 130 if ( date[utc]!=0 && date[utc]!='Z' ) { 131 normalize(date, timeZone); 132 } 133 return date; 134 } 135 136 148 protected short compareDates(int[] date1, int[] date2) { 149 150 if ( date1[utc]==date2[utc] ) { 151 return (short)((date1[M]>=date2[M])?(date1[M]>date2[M])?1:0:-1); 152 } 153 154 if ( date1[utc]=='Z' || date2[utc]=='Z' ) { 155 156 if ( date1[M]==date2[M] ) { 157 return INDETERMINATE; 159 } 160 if ( (date1[M]+1 == date2[M] || date1[M]-1 == date2[M]) ) { 161 return INDETERMINATE; 166 } 167 } 168 169 if ( date1[M]<date2[M] ) { 170 return -1; 171 } 172 else { 173 return 1; 174 } 175 176 } 177 178 184 protected String dateToString(int[] date) { 185 StringBuffer message = new StringBuffer (5); 186 message.append('-'); 187 message.append('-'); 188 append(message, date[M], 2); 189 append(message, (char)date[utc], 0); 190 return message.toString(); 191 } 192 193 } 194 | Popular Tags |