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.util.XMLChar; 22 import org.apache.xerces.xni.QName; 23 import org.apache.xerces.xs.datatypes.XSQName; 24 25 35 public class QNameDV extends TypeValidator { 36 37 private static final String EMPTY_STRING = "".intern(); 38 39 public short getAllowedFacets() { 40 return (XSSimpleTypeDecl.FACET_LENGTH | XSSimpleTypeDecl.FACET_MINLENGTH | XSSimpleTypeDecl.FACET_MAXLENGTH | XSSimpleTypeDecl.FACET_PATTERN | XSSimpleTypeDecl.FACET_ENUMERATION | XSSimpleTypeDecl.FACET_WHITESPACE); 41 } 42 43 public Object getActualValue(String content, ValidationContext context) 44 throws InvalidDatatypeValueException { 45 46 String prefix, localpart; 49 int colonptr = content.indexOf(":"); 50 if (colonptr > 0) { 51 prefix = context.getSymbol(content.substring(0,colonptr)); 52 localpart = content.substring(colonptr+1); 53 } else { 54 prefix = EMPTY_STRING; 55 localpart = content; 56 } 57 58 if (prefix.length() > 0 && !XMLChar.isValidNCName(prefix)) 60 throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.1", new Object []{content, "QName"}); 61 62 if(!XMLChar.isValidNCName(localpart)) 63 throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.1", new Object []{content, "QName"}); 64 65 String uri = context.getURI(prefix); 67 if (prefix.length() > 0 && uri == null) 68 throw new InvalidDatatypeValueException("UndeclaredPrefix", new Object []{content, prefix}); 69 70 return new XQName(prefix, context.getSymbol(localpart), context.getSymbol(content), uri); 71 72 } 73 74 public int getDataLength(Object value) { 77 return ((XQName)value).rawname.length(); 78 } 79 80 83 private static final class XQName extends QName implements XSQName { 84 85 public XQName(String prefix, String localpart, String rawname, String uri) { 86 setValues(prefix, localpart, rawname, uri); 87 } 89 90 public boolean equals(Object object) { 91 if (object instanceof QName) { 92 QName qname = (QName)object; 93 return uri == qname.uri && localpart == qname.localpart; 94 } 95 return false; 96 } 98 public synchronized String toString() { 99 return rawname; 100 } 101 public javax.xml.namespace.QName getJAXPQName() { 102 return new javax.xml.namespace.QName (uri, localpart, prefix); 103 } 104 public QName getXNIQName() { 105 return this; 106 } 107 } 108 } | Popular Tags |