KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > thaiopensource > datatype > xsd > TokenDatatype


1 package com.thaiopensource.datatype.xsd;
2
3 import org.relaxng.datatype.ValidationContext;
4 import com.thaiopensource.util.Utf16;
5
6 class TokenDatatype extends DatatypeBase implements Measure {
7
8   TokenDatatype() { }
9   TokenDatatype(int whiteSpace) {
10     super(whiteSpace);
11   }
12
13   public boolean lexicallyAllows(String JavaDoc str) {
14     return true;
15   }
16
17   public boolean alwaysValid() {
18     return true;
19   }
20
21   Object JavaDoc getValue(String JavaDoc str, ValidationContext vc) {
22     return str;
23   }
24
25   Measure getMeasure() {
26     return this;
27   }
28
29   public int getLength(Object JavaDoc obj) {
30     String JavaDoc str = (String JavaDoc)obj;
31     int len = str.length();
32     int nSurrogatePairs = 0;
33     for (int i = 0; i < len; i++)
34       if (Utf16.isSurrogate1(str.charAt(i)))
35     nSurrogatePairs++;
36     return len - nSurrogatePairs;
37   }
38 }
39
Popular Tags