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.util.XMLChar; 62 import com.sun.org.apache.xerces.internal.xni.QName; 63 import com.sun.org.apache.xerces.internal.impl.dv.ValidationContext; 64 65 73 public class QNameDV extends TypeValidator { 74 75 private static final String EMPTY_STRING = "".intern(); 76 77 public short getAllowedFacets() { 78 return (XSSimpleTypeDecl.FACET_LENGTH | XSSimpleTypeDecl.FACET_MINLENGTH | XSSimpleTypeDecl.FACET_MAXLENGTH | XSSimpleTypeDecl.FACET_PATTERN | XSSimpleTypeDecl.FACET_ENUMERATION | XSSimpleTypeDecl.FACET_WHITESPACE); 79 } 80 81 public Object getActualValue(String content, ValidationContext context) 82 throws InvalidDatatypeValueException { 83 84 String prefix, localpart; 87 int colonptr = content.indexOf(":"); 88 if (colonptr > 0) { 89 prefix = context.getSymbol(content.substring(0,colonptr)); 90 localpart = content.substring(colonptr+1); 91 } else { 92 prefix = EMPTY_STRING; 93 localpart = content; 94 } 95 96 if (prefix.length() > 0 && !XMLChar.isValidNCName(prefix)) 98 throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.1", new Object []{content, "QName"}); 99 100 if(!XMLChar.isValidNCName(localpart)) 101 throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.1", new Object []{content, "QName"}); 102 103 String uri = context.getURI(prefix); 105 if (prefix.length() > 0 && uri == null) 106 throw new InvalidDatatypeValueException("UndeclaredPrefix", new Object []{content, prefix}); 107 108 return new XQName(prefix, context.getSymbol(localpart), context.getSymbol(content), uri); 109 110 } 111 112 public int getDataLength(Object value) { 115 return ((XQName)value).rawname.length(); 116 } 117 118 121 private static final class XQName extends QName { 122 123 public XQName(String prefix, String localpart, String rawname, String uri) { 124 setValues(prefix, localpart, rawname, uri); 125 } 127 128 public boolean equals(Object object) { 129 if (object instanceof QName) { 130 QName qname = (QName)object; 131 return uri == qname.uri && localpart == qname.localpart; 132 } 133 return false; 134 } 136 public synchronized String toString() { 137 return rawname; 138 } 139 } 140 } | Popular Tags |