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 70 public class DayDV extends AbstractDateTimeDV { 71 72 private final static int DAY_SIZE=5; 74 75 public Object getActualValue(String content, ValidationContext context) throws InvalidDatatypeValueException { 76 try{ 77 return new DateTimeData(parse(content), this); 78 } catch(Exception ex){ 79 throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.1", new Object []{content, "gDay"}); 80 } 81 } 82 83 93 protected int[] parse(String str) throws SchemaDateTimeException { 94 int len = str.length(); 95 int[] date=new int[TOTAL_SIZE]; 96 int[] timeZone = new int[2]; 97 98 if (str.charAt(0)!='-' || str.charAt(1)!='-' || str.charAt(2)!='-') { 99 throw new SchemaDateTimeException ("Error in day parsing"); 100 } 101 102 date[CY]=YEAR; 104 date[M]=MONTH; 105 106 date[D]=parseInt(str, 3,5); 107 108 if ( DAY_SIZE<len ) { 109 int sign = findUTCSign(str, DAY_SIZE, len); 110 if ( sign<0 ) { 111 throw new SchemaDateTimeException ("Error in day parsing"); 112 } 113 else { 114 getTimeZone(str, date, sign, len, timeZone); 115 } 116 } 117 118 validateDateTime(date, timeZone); 120 121 if ( date[utc]!=0 && date[utc]!='Z' ) { 122 normalize(date, timeZone); 123 } 124 return date; 125 } 126 127 133 protected String dateToString(int[] date) { 134 StringBuffer message = new StringBuffer (6); 135 message.append('-'); 136 message.append('-'); 137 message.append('-'); 138 append(message, date[D], 2); 139 append(message, (char)date[utc], 0); 140 return message.toString(); 141 } 142 143 } 144 145 | Popular Tags |