/** * Checks if the given qualified name is legal with respect * to the version of XML to which this document must conform. * * @param prefix prefix of qualified name * @param local local part of qualified name */ public static final boolean isValidQName(String prefix, String local, boolean xml11Version) { // check that both prefix and local part match NCName if (local == null) return false; boolean validNCName = false; if (!xml11Version) { validNCName = (prefix == null || XMLChar.isValidNCName(prefix)) && XMLChar.isValidNCName(local); } else { validNCName = (prefix == null || XML11Char.isXML11ValidNCName(prefix)) && XML11Char.isXML11ValidNCName(local); } return validNCName; } //
public Object getActualValue(String content, ValidationContext context) throws InvalidDatatypeValueException { final boolean valid = (context.getDatatypeXMLVersion() == Constants.XML_VERSION_1_0) ? XMLChar.isValidNCName(content) : XML11Char.isXML11ValidNCName(content); if (!valid) { throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.1", new Object[]{content, "NCName"}); } return content; }
public Object getActualValue(String content, ValidationContext context) throws InvalidDatatypeValueException { final boolean valid = (context.getDatatypeXMLVersion() == Constants.XML_VERSION_1_0) ? XMLChar.isValidNCName(content) : XML11Char.isXML11ValidNCName(content); if (!valid) { throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.1", new Object[]{content, "NCName"}); } return content; }
public Object getActualValue(String content, ValidationContext context) throws InvalidDatatypeValueException { final boolean valid = (context.getDatatypeXMLVersion() == Constants.XML_VERSION_1_0) ? XMLChar.isValidNCName(content) : XML11Char.isXML11ValidNCName(content); if (!valid) { throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.1", new Object[]{content, "NCName"}); } return content; }
validNCName = (prefix == null || XML11Char.isXML11ValidNCName(prefix)) && XML11Char.isXML11ValidNCName(local);
public Object getActualValue(String content, ValidationContext context) throws InvalidDatatypeValueException { // "prefix:localpart" or "localpart" // get prefix and local part out of content String prefix, localpart; int colonptr = content.indexOf(":"); if (colonptr > 0) { prefix = context.getSymbol(content.substring(0,colonptr)); localpart = content.substring(colonptr+1); } else { prefix = EMPTY_STRING; localpart = content; } final boolean isXML10 = context.getDatatypeXMLVersion() == Constants.XML_VERSION_1_0; // both prefix (if any) and localpart must be valid NCName // if using XSD 1.1, use the XML 1.1 rules of validating the prefix and the local part, else use the XML 1.0 rules if (prefix.length() > 0 && ((isXML10) ? !XMLChar.isValidNCName(prefix) : !XML11Char.isXML11ValidNCName(prefix))) { throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.1", new Object[]{content, "QName"}); } if ((isXML10) ? !XMLChar.isValidNCName(localpart) : !XML11Char.isXML11ValidNCName(localpart)) { throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.1", new Object[]{content, "QName"}); } // resove prefix to a uri, report an error if failed String uri = context.getURI(prefix); if (prefix.length() > 0 && uri == null) throw new InvalidDatatypeValueException("UndeclaredPrefix", new Object[]{content, prefix}); return new XQName(prefix, context.getSymbol(localpart), context.getSymbol(content), uri); }
/** * Checks that "content" string is valid IDREF value. * If invalid a Datatype validation exception is thrown. * * @param content the string value that needs to be validated * @param context the validation context * @throws InvalidDatatypeException if the content is * invalid according to the rules for the validators * @see InvalidDatatypeValueException */ public void validate(String content, ValidationContext context) throws InvalidDatatypeValueException { //Check if is valid key-[81] EncName ::= [A-Za-z] ([A-Za-z0-9._] | '-')* if(context.useNamespaces()) { if (!XML11Char.isXML11ValidNCName(content)) { throw new InvalidDatatypeValueException("IDREFInvalidWithNamespaces", new Object[]{content}); } } else { if (!XML11Char.isXML11ValidName(content)) { throw new InvalidDatatypeValueException("IDREFInvalid", new Object[]{content}); } } context.addIdRef(content); }
seenErr = (isXML11) ? !XML11Char.isXML11ValidNCName(nvalue) : !XMLChar.isValidNCName(nvalue);
/** * Checks that "content" string is valid ID value. * If invalid a Datatype validation exception is thrown. * * @param content the string value that needs to be validated * @param context the validation context * @throws InvalidDatatypeException if the content is * invalid according to the rules for the validators * @see InvalidDatatypeValueException */ public void validate(String content, ValidationContext context) throws InvalidDatatypeValueException { //Check if is valid key-[81] EncName ::= [A-Za-z] ([A-Za-z0-9._] | '-')* if(context.useNamespaces()) { if (!XML11Char.isXML11ValidNCName(content)) { throw new InvalidDatatypeValueException("IDInvalidWithNamespaces", new Object[]{content}); } } else { if (!XML11Char.isXML11ValidName(content)) { throw new InvalidDatatypeValueException("IDInvalid", new Object[]{content}); } } if (context.isIdDeclared(content)) { throw new InvalidDatatypeValueException("IDNotUnique", new Object[]{content}); } context.addId(content); }