1 16 17 package org.apache.xerces.impl.dv.xs; 18 19 import org.apache.xerces.impl.dv.InvalidDatatypeValueException; 20 import org.apache.xerces.impl.dv.ValidationContext; 21 import org.apache.xerces.impl.dv.util.Base64; 22 import org.apache.xerces.impl.dv.util.ByteListImpl; 23 24 34 public class Base64BinaryDV extends TypeValidator { 35 36 public short getAllowedFacets(){ 37 return (XSSimpleTypeDecl.FACET_LENGTH | XSSimpleTypeDecl.FACET_MINLENGTH | XSSimpleTypeDecl.FACET_MAXLENGTH | XSSimpleTypeDecl.FACET_PATTERN | XSSimpleTypeDecl.FACET_ENUMERATION | XSSimpleTypeDecl.FACET_WHITESPACE ); 38 } 39 40 public Object getActualValue(String content, ValidationContext context) throws InvalidDatatypeValueException { 41 byte[] decoded = Base64.decode(content); 42 if (decoded == null) 43 throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.1", new Object []{content, "base64Binary"}); 44 45 return new XBase64(decoded); 46 } 47 48 public int getDataLength(Object value) { 50 return ((XBase64)value).getLength(); 51 } 52 53 56 private static final class XBase64 extends ByteListImpl { 57 58 public XBase64(byte[] data) { 59 super(data); 60 } 61 public synchronized String toString() { 62 if (canonical == null) { 63 canonical = Base64.encode(data); 64 } 65 return canonical; 66 } 67 68 public boolean equals(Object obj) { 69 if (!(obj instanceof XBase64)) 70 return false; 71 byte[] odata = ((XBase64)obj).data; 72 int len = data.length; 73 if (len != odata.length) 74 return false; 75 for (int i = 0; i < len; i++) { 76 if (data[i] != odata[i]) 77 return false; 78 } 79 return true; 80 } 81 } 82 } | Popular Tags |