Java Code Examples for org.w3c.dom.DOMException#INVALID_CHARACTER_ERR

The following examples show how to use org.w3c.dom.DOMException#INVALID_CHARACTER_ERR . 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: IIOMetadataNode.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
public void setAttribute(String name, String value) {
    // Name must be valid unicode chars
    boolean valid = true;
    char[] chs = name.toCharArray();
    for (int i=0;i<chs.length;i++) {
        if (chs[i] >= 0xfffe) {
            valid = false;
            break;
        }
    }
    if (!valid) {
        throw new IIODOMException(DOMException.INVALID_CHARACTER_ERR,
                                  "Attribute name is illegal!");
    }
    removeAttribute(name, false);
    attributes.add(new IIOAttr(this, name, value));
}
 
Example 2
Source File: IIOMetadataNode.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public void setAttribute(String name, String value) {
    // Name must be valid unicode chars
    boolean valid = true;
    char[] chs = name.toCharArray();
    for (int i=0;i<chs.length;i++) {
        if (chs[i] >= 0xfffe) {
            valid = false;
            break;
        }
    }
    if (!valid) {
        throw new IIODOMException(DOMException.INVALID_CHARACTER_ERR,
                                  "Attribute name is illegal!");
    }
    removeAttribute(name, false);
    attributes.add(new IIOAttr(this, name, value));
}
 
Example 3
Source File: IIOMetadataNode.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
public void setAttribute(String name, String value) {
    // Name must be valid unicode chars
    boolean valid = true;
    char[] chs = name.toCharArray();
    for (int i=0;i<chs.length;i++) {
        if (chs[i] >= 0xfffe) {
            valid = false;
            break;
        }
    }
    if (!valid) {
        throw new IIODOMException(DOMException.INVALID_CHARACTER_ERR,
                                  "Attribute name is illegal!");
    }
    removeAttribute(name, false);
    attributes.add(new IIOAttr(this, name, value));
}
 
Example 4
Source File: CoreDocumentImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * NON-DOM Factory method; creates an Entity having this Document as its
 * OwnerDoc. (REC-DOM-Level-1-19981001 left the process of building DTD
 * information unspecified.)
 *
 * @param name The name of the Entity we wish to provide a value for.
 *
 * @throws DOMException(NOT_SUPPORTED_ERR) for HTML documents, where
 * nonstandard entities are not permitted. (HTML not yet implemented.)
 */
public Entity createEntity(String name)
        throws DOMException {

    if (errorChecking && !isXMLName(name, xml11Version)) {
        String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INVALID_CHARACTER_ERR", null);
        throw new DOMException(DOMException.INVALID_CHARACTER_ERR, msg);
    }
    return new EntityImpl(this, name);

}
 
Example 5
Source File: SVGDocument.java    From latexdraw with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Element createElement(final String tagName) {
	if(tagName == null) {
		throw new DOMException(DOMException.INVALID_CHARACTER_ERR, "Invalid tagName.");
	}

	final OtherNSElement elt = new OtherNSElement(this);
	elt.setNodeName(tagName);

	return elt;
}
 
Example 6
Source File: CoreDocumentImpl.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * NON-DOM Factory method: creates an element definition. Element
 * definitions hold default attribute values.
 */
public ElementDefinitionImpl createElementDefinition(String name)
throws DOMException {

    if (errorChecking && !isXMLName(name,xml11Version)) {
        String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INVALID_CHARACTER_ERR", null);
        throw new DOMException(DOMException.INVALID_CHARACTER_ERR, msg);
    }
    return new ElementDefinitionImpl(this, name);

}
 
Example 7
Source File: CoreDocumentImpl.java    From TencentKona-8 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 8
Source File: CoreDocumentImpl.java    From hottub 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 9
Source File: CoreDocumentImpl.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
/**
 * NON-DOM Factory method: creates an element definition. Element
 * definitions hold default attribute values.
 */
public ElementDefinitionImpl createElementDefinition(String name)
        throws DOMException {

    if (errorChecking && !isXMLName(name, xml11Version)) {
        String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INVALID_CHARACTER_ERR", null);
        throw new DOMException(DOMException.INVALID_CHARACTER_ERR, msg);
    }
    return new ElementDefinitionImpl(this, name);

}
 
Example 10
Source File: CoreDocumentImpl.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Factory method; creates an Attribute having this Document as its
 * OwnerDoc.
 *
 * @param name The name of the attribute. Note that the attribute's value is
 * _not_ established at the factory; remember to set it!
 *
 * @throws DOMException(INVALID_NAME_ERR)
 * if the attribute name is not acceptable.
 */
public Attr createAttribute(String name)
    throws DOMException {

    if (errorChecking && !isXMLName(name,xml11Version)) {
        String msg =
            DOMMessageFormatter.formatMessage(
                DOMMessageFormatter.DOM_DOMAIN,
                "INVALID_CHARACTER_ERR",
                null);
        throw new DOMException(DOMException.INVALID_CHARACTER_ERR, msg);
    }
    return new AttrImpl(this, name);

}
 
Example 11
Source File: CoreDocumentImpl.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Factory method; creates an EntityReference having this Document
 * as its OwnerDoc.
 *
 * @param name The name of the Entity we wish to refer to
 *
 * @throws DOMException(NOT_SUPPORTED_ERR) for HTML documents, where
 * nonstandard entities are not permitted. (HTML not yet
 * implemented.)
 */
public EntityReference createEntityReference(String name)
        throws DOMException {

    if (errorChecking && !isXMLName(name,xml11Version)) {
        String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INVALID_CHARACTER_ERR", null);
        throw new DOMException(DOMException.INVALID_CHARACTER_ERR, msg);
    }
    return new EntityReferenceImpl(this, name);

}
 
Example 12
Source File: CoreDocumentImpl.java    From openjdk-jdk8u-backup 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 13
Source File: CoreDocumentImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * NON-DOM Factory method: creates an element definition. Element
 * definitions hold default attribute values.
 */
public ElementDefinitionImpl createElementDefinition(String name)
        throws DOMException {

    if (errorChecking && !isXMLName(name, xml11Version)) {
        String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INVALID_CHARACTER_ERR", null);
        throw new DOMException(DOMException.INVALID_CHARACTER_ERR, msg);
    }
    return new ElementDefinitionImpl(this, name);

}
 
Example 14
Source File: NodeImpl.java    From j2objc with Apache License 2.0 4 votes vote down vote up
/**
 * Sets {@code node} to be namespace-aware and assigns its namespace URI
 * and qualified name.
 *
 * @param node an element or attribute node.
 * @param namespaceURI this node's namespace URI. May be null.
 * @param qualifiedName a possibly-prefixed name like "img" or "html:img".
 */
static void setNameNS(NodeImpl node, String namespaceURI, String qualifiedName) {
    if (qualifiedName == null) {
        throw new DOMException(DOMException.NAMESPACE_ERR, qualifiedName);
    }

    String prefix = null;
    int p = qualifiedName.lastIndexOf(":");
    if (p != -1) {
        prefix = validatePrefix(qualifiedName.substring(0, p), true, namespaceURI);
        qualifiedName = qualifiedName.substring(p + 1);
    }

    if (!DocumentImpl.isXMLIdentifier(qualifiedName)) {
        throw new DOMException(DOMException.INVALID_CHARACTER_ERR, qualifiedName);
    }

    switch (node.getNodeType()) {
    case ATTRIBUTE_NODE:
        if ("xmlns".equals(qualifiedName)
                && !"http://www.w3.org/2000/xmlns/".equals(namespaceURI)) {
            throw new DOMException(DOMException.NAMESPACE_ERR, qualifiedName);
        }

        AttrImpl attr = (AttrImpl) node;
        attr.namespaceAware = true;
        attr.namespaceURI = namespaceURI;
        attr.prefix = prefix;
        attr.localName = qualifiedName;
        break;

    case ELEMENT_NODE:
        ElementImpl element = (ElementImpl) node;
        element.namespaceAware = true;
        element.namespaceURI = namespaceURI;
        element.prefix = prefix;
        element.localName = qualifiedName;
        break;

    default:
        throw new DOMException(DOMException.NOT_SUPPORTED_ERR,
                "Cannot rename nodes of type " + node.getNodeType());
    }
}
 
Example 15
Source File: CoreDocumentImpl.java    From jdk8u60 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Factory method; creates an Element having this Document
 * as its OwnerDoc.
 *
 * @param tagName The name of the element type to instantiate. For
 * XML, this is case-sensitive. For HTML, the tagName parameter may
 * be provided in any case, but it must be mapped to the canonical
 * uppercase form by the DOM implementation.
 *
 * @throws DOMException(INVALID_NAME_ERR) if the tag name is not
 * acceptable.
 */
public Element createElement(String tagName)
throws DOMException {

    if (errorChecking && !isXMLName(tagName,xml11Version)) {
        String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INVALID_CHARACTER_ERR", null);
        throw new DOMException(DOMException.INVALID_CHARACTER_ERR, msg);
    }
    return new ElementImpl(this, tagName);

}
 
Example 16
Source File: CoreDocumentImpl.java    From jdk8u60 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * NON-DOM
 * Factory method; creates a Notation having this Document
 * as its OwnerDoc. (REC-DOM-Level-1-19981001 left the process of building
 * DTD information unspecified.)
 *
 * @param name The name of the Notation we wish to describe
 *
 * @throws DOMException(NOT_SUPPORTED_ERR) for HTML documents, where
 * notations are not permitted. (HTML not yet
 * implemented.)
 */
public Notation createNotation(String name)
throws DOMException {

    if (errorChecking && !isXMLName(name,xml11Version)) {
        String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INVALID_CHARACTER_ERR", null);
        throw new DOMException(DOMException.INVALID_CHARACTER_ERR, msg);
    }
    return new NotationImpl(this, name);

}
 
Example 17
Source File: CoreDocumentImpl.java    From TencentKona-8 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Factory method; creates a ProcessingInstruction having this Document
 * as its OwnerDoc.
 *
 * @param target The target "processor channel"
 * @param data Parameter string to be passed to the target.
 *
 * @throws DOMException(INVALID_NAME_ERR) if the target name is not
 * acceptable.
 *
 * @throws DOMException(NOT_SUPPORTED_ERR) for HTML documents. (HTML
 * not yet implemented.)
 */
public ProcessingInstruction createProcessingInstruction(String target,
        String data)
        throws DOMException {

    if (errorChecking && !isXMLName(target,xml11Version)) {
        String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INVALID_CHARACTER_ERR", null);
        throw new DOMException(DOMException.INVALID_CHARACTER_ERR, msg);
    }
    return new ProcessingInstructionImpl(this, target, data);

}
 
Example 18
Source File: CoreDocumentImpl.java    From openjdk-8-source with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Factory method; creates a ProcessingInstruction having this Document
 * as its OwnerDoc.
 *
 * @param target The target "processor channel"
 * @param data Parameter string to be passed to the target.
 *
 * @throws DOMException(INVALID_NAME_ERR) if the target name is not
 * acceptable.
 *
 * @throws DOMException(NOT_SUPPORTED_ERR) for HTML documents. (HTML
 * not yet implemented.)
 */
public ProcessingInstruction createProcessingInstruction(String target,
String data)
throws DOMException {

    if (errorChecking && !isXMLName(target,xml11Version)) {
        String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INVALID_CHARACTER_ERR", null);
        throw new DOMException(DOMException.INVALID_CHARACTER_ERR, msg);
    }
    return new ProcessingInstructionImpl(this, target, data);

}
 
Example 19
Source File: CoreDocumentImpl.java    From openjdk-8 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * NON-DOM
 * Factory method; creates an Entity having this Document
 * as its OwnerDoc. (REC-DOM-Level-1-19981001 left the process of building
 * DTD information unspecified.)
 *
 * @param name The name of the Entity we wish to provide a value for.
 *
 * @throws DOMException(NOT_SUPPORTED_ERR) for HTML documents, where
 * nonstandard entities are not permitted. (HTML not yet
 * implemented.)
 */
public Entity createEntity(String name)
throws DOMException {


    if (errorChecking && !isXMLName(name,xml11Version)) {
        String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INVALID_CHARACTER_ERR", null);
        throw new DOMException(DOMException.INVALID_CHARACTER_ERR, msg);
    }
    return new EntityImpl(this, name);

}
 
Example 20
Source File: CoreDocumentImpl.java    From openjdk-8 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Factory method; creates a ProcessingInstruction having this Document
 * as its OwnerDoc.
 *
 * @param target The target "processor channel"
 * @param data Parameter string to be passed to the target.
 *
 * @throws DOMException(INVALID_NAME_ERR) if the target name is not
 * acceptable.
 *
 * @throws DOMException(NOT_SUPPORTED_ERR) for HTML documents. (HTML
 * not yet implemented.)
 */
public ProcessingInstruction createProcessingInstruction(String target,
String data)
throws DOMException {

    if (errorChecking && !isXMLName(target,xml11Version)) {
        String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INVALID_CHARACTER_ERR", null);
        throw new DOMException(DOMException.INVALID_CHARACTER_ERR, msg);
    }
    return new ProcessingInstructionImpl(this, target, data);

}