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 MonthDayDV extends AbstractDateTimeDV { 73 74 private final static int MONTHDAY_SIZE = 7; 76 77 83 public Object getActualValue(String content, ValidationContext context) throws InvalidDatatypeValueException { 84 try{ 85 return new DateTimeData(parse(content), this); 86 } catch(Exception ex){ 87 throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.1", new Object []{content, "gMonthDay"}); 88 } 89 } 90 91 100 protected int[] parse(String str) throws SchemaDateTimeException{ 101 int len = str.length(); 102 int[] date=new int[TOTAL_SIZE]; 103 int[] timeZone = new int[2]; 104 105 date[CY]=YEAR; 107 108 if (str.charAt(0)!='-' || str.charAt(1)!='-') { 109 throw new SchemaDateTimeException("Invalid format for gMonthDay: "+str); 110 } 111 date[M]=parseInt(str, 2, 4); 112 int start=4; 113 114 if (str.charAt(start++)!='-') { 115 throw new SchemaDateTimeException("Invalid format for gMonthDay: " + str); 116 } 117 118 date[D]=parseInt(str, start, start+2); 119 120 if ( MONTHDAY_SIZE<len ) { 121 int sign = findUTCSign(str, MONTHDAY_SIZE, len); 122 if ( sign<0 ) { 123 throw new SchemaDateTimeException ("Error in month parsing:" +str); 124 } 125 else { 126 getTimeZone(str, date, sign, len, timeZone); 127 } 128 } 129 131 validateDateTime(date, timeZone); 132 133 if ( date[utc]!=0 && date[utc]!='Z' ) { 134 normalize(date, timeZone); 135 } 136 return date; 137 } 138 139 145 protected String dateToString(int[] date) { 146 StringBuffer message = new StringBuffer (8); 147 message.append('-'); 148 message.append('-'); 149 append(message, date[M], 2); 150 message.append('-'); 151 append(message, date[D], 2); 152 append(message, (char)date[utc], 0); 153 return message.toString(); 154 } 155 156 } 157 158 | Popular Tags |