Java Code Examples for com.sun.org.apache.xerces.internal.util.XMLChar#isValidNCName()

The following examples show how to use com.sun.org.apache.xerces.internal.util.XMLChar#isValidNCName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IDDatatypeValidator.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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 (!XMLChar.isValidNCName(content)) {
            throw new InvalidDatatypeValueException("IDInvalidWithNamespaces", new Object[]{content});
        }
    }
    else {
        if (!XMLChar.isValidName(content)) {
            throw new InvalidDatatypeValueException("IDInvalid", new Object[]{content});
        }
    }

    if (context.isIdDeclared(content)) {
        throw new InvalidDatatypeValueException("IDNotUnique", new Object[]{content});
    }

    context.addId(content);
}
 
Example 2
Source File: IDDatatypeValidator.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
/**
 * 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 (!XMLChar.isValidNCName(content)) {
            throw new InvalidDatatypeValueException("IDInvalidWithNamespaces", new Object[]{content});
        }
    }
    else {
        if (!XMLChar.isValidName(content)) {
            throw new InvalidDatatypeValueException("IDInvalid", new Object[]{content});
        }
    }

    if (context.isIdDeclared(content)) {
        throw new InvalidDatatypeValueException("IDNotUnique", new Object[]{content});
    }

    context.addId(content);
}
 
Example 3
Source File: IDREFDatatypeValidator.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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 (!XMLChar.isValidNCName(content)) {
            throw new InvalidDatatypeValueException("IDREFInvalidWithNamespaces", new Object[]{content});
        }
    }
    else {
        if (!XMLChar.isValidName(content)) {
            throw new InvalidDatatypeValueException("IDREFInvalid", new Object[]{content});
        }
    }

    context.addIdRef(content);

}
 
Example 4
Source File: IDREFDatatypeValidator.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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 (!XMLChar.isValidNCName(content)) {
            throw new InvalidDatatypeValueException("IDREFInvalidWithNamespaces", new Object[]{content});
        }
    }
    else {
        if (!XMLChar.isValidName(content)) {
            throw new InvalidDatatypeValueException("IDREFInvalid", new Object[]{content});
        }
    }

    context.addIdRef(content);

}
 
Example 5
Source File: CoreDocumentImpl.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example 6
Source File: IDREFDatatypeValidator.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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 (!XMLChar.isValidNCName(content)) {
            throw new InvalidDatatypeValueException("IDREFInvalidWithNamespaces", new Object[]{content});
        }
    }
    else {
        if (!XMLChar.isValidName(content)) {
            throw new InvalidDatatypeValueException("IDREFInvalid", new Object[]{content});
        }
    }

    context.addIdRef(content);

}
 
Example 7
Source File: IDDatatypeValidator.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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 (!XMLChar.isValidNCName(content)) {
            throw new InvalidDatatypeValueException("IDInvalidWithNamespaces", new Object[]{content});
        }
    }
    else {
        if (!XMLChar.isValidName(content)) {
            throw new InvalidDatatypeValueException("IDInvalid", new Object[]{content});
        }
    }

    if (context.isIdDeclared(content)) {
        throw new InvalidDatatypeValueException("IDNotUnique", new Object[]{content});
    }

    context.addId(content);
}
 
Example 8
Source File: IDDatatypeValidator.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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 (!XMLChar.isValidNCName(content)) {
            throw new InvalidDatatypeValueException("IDInvalidWithNamespaces", new Object[]{content});
        }
    }
    else {
        if (!XMLChar.isValidName(content)) {
            throw new InvalidDatatypeValueException("IDInvalid", new Object[]{content});
        }
    }

    if (context.isIdDeclared(content)) {
        throw new InvalidDatatypeValueException("IDNotUnique", new Object[]{content});
    }

    context.addId(content);
}
 
Example 9
Source File: CoreDocumentImpl.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
/**
 * 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
 */
protected final void checkQName(String prefix, String local) {
    if (!errorChecking) {
        return;
    }

    // check that both prefix and local part match NCName
    boolean validNCName = false;
    if (!xml11Version) {
        validNCName = (prefix == null || XMLChar.isValidNCName(prefix))
                && XMLChar.isValidNCName(local);
    }
    else {
        validNCName = (prefix == null || XML11Char.isXML11ValidNCName(prefix))
                && XML11Char.isXML11ValidNCName(local);
    }

    if (!validNCName) {
        // REVISIT: add qname parameter to the message
        String msg =
        DOMMessageFormatter.formatMessage(
                        DOMMessageFormatter.DOM_DOMAIN,
                        "INVALID_CHARACTER_ERR",
                        null);
        throw new DOMException(DOMException.INVALID_CHARACTER_ERR, msg);
    }
}
 
Example 10
Source File: CoreDocumentImpl.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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
 */
protected final void checkQName(String prefix, String local) {
    if (!errorChecking) {
        return;
    }

            // check that both prefix and local part match NCName
    boolean validNCName = false;
    if (!xml11Version) {
        validNCName = (prefix == null || XMLChar.isValidNCName(prefix))
            && XMLChar.isValidNCName(local);
    }
    else {
        validNCName = (prefix == null || XML11Char.isXML11ValidNCName(prefix))
            && XML11Char.isXML11ValidNCName(local);
    }

    if (!validNCName) {
        // REVISIT: add qname parameter to the message
        String msg =
        DOMMessageFormatter.formatMessage(
        DOMMessageFormatter.DOM_DOMAIN,
        "INVALID_CHARACTER_ERR",
        null);
        throw new DOMException(DOMException.INVALID_CHARACTER_ERR, msg);
    }
}
 
Example 11
Source File: QNameDV.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
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;
    }

    // both prefix (if any) a nd localpart must be valid NCName
    if (prefix.length() > 0 && !XMLChar.isValidNCName(prefix))
        throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.1", new Object[]{content, "QName"});

    if(!XMLChar.isValidNCName(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);

}
 
Example 12
Source File: EntityDV.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public Object getActualValue(String content, ValidationContext context) throws InvalidDatatypeValueException {
    if (!XMLChar.isValidNCName(content)) {
        throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.1", new Object[]{content, "NCName"});
    }

    return content;
}
 
Example 13
Source File: EntityDV.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public Object getActualValue(String content, ValidationContext context) throws InvalidDatatypeValueException {
    if (!XMLChar.isValidNCName(content)) {
        throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.1", new Object[]{content, "NCName"});
    }

    return content;
}
 
Example 14
Source File: QNameDV.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
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;
    }

    // both prefix (if any) a nd localpart must be valid NCName
    if (prefix.length() > 0 && !XMLChar.isValidNCName(prefix))
        throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.1", new Object[]{content, "QName"});

    if(!XMLChar.isValidNCName(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);

}
 
Example 15
Source File: EntityDV.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public Object getActualValue(String content, ValidationContext context) throws InvalidDatatypeValueException {
    if (!XMLChar.isValidNCName(content)) {
        throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.1", new Object[]{content, "NCName"});
    }

    return content;
}
 
Example 16
Source File: EntityDV.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public Object getActualValue(String content, ValidationContext context) throws InvalidDatatypeValueException {
    if (!XMLChar.isValidNCName(content)) {
        throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.1", new Object[]{content, "NCName"});
    }

    return content;
}
 
Example 17
Source File: IDDV.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
public Object getActualValue(String content, ValidationContext context) throws InvalidDatatypeValueException {
    if (!XMLChar.isValidNCName(content)) {
        throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.1", new Object[]{content, "NCName"});
    }
    return content;
}
 
Example 18
Source File: IDREFDV.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
public Object getActualValue(String content, ValidationContext context) throws InvalidDatatypeValueException {
    if (!XMLChar.isValidNCName(content)) {
        throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.1", new Object[]{content, "NCName"});
    }
    return content;
}
 
Example 19
Source File: IDDV.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
public Object getActualValue(String content, ValidationContext context) throws InvalidDatatypeValueException {
    if (!XMLChar.isValidNCName(content)) {
        throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.1", new Object[]{content, "NCName"});
    }
    return content;
}
 
Example 20
Source File: IDREFDV.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public Object getActualValue(String content, ValidationContext context) throws InvalidDatatypeValueException {
    if (!XMLChar.isValidNCName(content)) {
        throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.1", new Object[]{content, "NCName"});
    }
    return content;
}