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 import com.sun.org.apache.xerces.internal.impl.dv.util.Base64; 63 64 72 public class Base64BinaryDV extends TypeValidator { 73 74 public short getAllowedFacets(){ 75 return (XSSimpleTypeDecl.FACET_LENGTH | XSSimpleTypeDecl.FACET_MINLENGTH | XSSimpleTypeDecl.FACET_MAXLENGTH | XSSimpleTypeDecl.FACET_PATTERN | XSSimpleTypeDecl.FACET_ENUMERATION | XSSimpleTypeDecl.FACET_WHITESPACE ); 76 } 77 78 public Object getActualValue(String content, ValidationContext context) throws InvalidDatatypeValueException { 79 byte[] decoded = Base64.decode(content); 80 if (decoded == null) 81 throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.1", new Object []{content, "base64Binary"}); 82 83 return new XBase64(decoded); 84 } 85 86 public int getDataLength(Object value) { 88 return ((XBase64)value).length(); 89 } 90 91 94 private static final class XBase64 { 95 final byte[] data; 97 private String canonical; 99 public XBase64(byte[] data) { 100 this.data = data; 101 } 102 public synchronized String toString() { 103 if (canonical == null) { 104 canonical = Base64.encode(data); 105 } 106 return canonical; 107 } 108 public int length() { 109 return data.length; 110 } 111 public boolean equals(Object obj) { 112 if (!(obj instanceof XBase64)) 113 return false; 114 byte[] odata = ((XBase64)obj).data; 115 int len = data.length; 116 if (len != odata.length) 117 return false; 118 for (int i = 0; i < len; i++) { 119 if (data[i] != odata[i]) 120 return false; 121 } 122 return true; 123 } 124 } 125 } | Popular Tags |