1 10 package com.hp.hpl.jena.datatypes.xsd.impl; 11 12 import com.hp.hpl.jena.datatypes.*; 13 import com.hp.hpl.jena.datatypes.xsd.*; 14 15 28 public class XSDDurationType extends XSDAbstractDateTimeType { 29 30 33 public XSDDurationType() { 34 super("duration"); 35 javaClass = XSDDuration.class; 36 } 37 38 43 public Object parseValidated(String str) { 44 int len = str.length(); 45 int[] date=new int[TOTAL_SIZE]; 46 47 int start = 0; 48 char c=str.charAt(start++); 49 if ( c!='P' && c!='-' ) { 50 throw new DatatypeFormatException("Internal error: validated duration failed to parse(1)"); 51 } 52 else { 53 date[utc]=(c=='-')?'-':0; 54 if ( c=='-' && str.charAt(start++)!='P' ) { 55 throw new DatatypeFormatException("Internal error: validated duration failed to parse(2)"); 56 } 57 } 58 59 int negate = 1; 60 if ( date[utc]=='-' ) { 62 negate = -1; 63 64 } 65 66 int endDate = indexOf (str, start, len, 'T'); 67 if ( endDate == -1 ) { 68 endDate = len; 69 } 70 int end = indexOf (str, start, endDate, 'Y'); 72 if ( end!=-1 ) { 73 date[CY]=negate * parseInt(str,start,end); 75 start = end+1; 76 } 77 78 end = indexOf (str, start, endDate, 'M'); 79 if ( end!=-1 ) { 80 date[M]=negate * parseInt(str,start,end); 82 start = end+1; 83 } 84 85 end = indexOf (str, start, endDate, 'D'); 86 if ( end!=-1 ) { 87 date[D]=negate * parseInt(str,start,end); 89 start = end+1; 90 } 91 92 if ( len == endDate && start!=len ) { 93 throw new DatatypeFormatException("Internal error: validated duration failed to parse(3)"); 94 } 95 if ( len !=endDate ) { 96 97 end = indexOf (str, ++start, len, 'H'); 98 if ( end!=-1 ) { 99 date[h]=negate * parseInt(str,start,end); 101 start=end+1; 102 } 103 104 end = indexOf (str, start, len, 'M'); 105 if ( end!=-1 ) { 106 date[m]=negate * parseInt(str,start,end); 108 start=end+1; 109 } 110 111 end = indexOf (str, start, len, 'S'); 112 if ( end!=-1 ) { 113 int mlsec = indexOf (str, start, end, '.'); 115 if ( mlsec >0 ) { 116 date[s] = negate * parseInt (str, start, mlsec); 117 date[ms] = negate * parseInt (str, mlsec+1, end); 118 } 119 else { 120 date[s]=negate * parseInt(str, start,end); 121 } 122 start=end+1; 123 } 124 } 125 return new XSDDuration(date); 126 } 127 128 } 129 130 159 | Popular Tags |