Search in sources :

Example 1 with IllegalQNameException

use of org.exist.dom.QName.IllegalQNameException in project exist by eXist-db.

the class ElementImpl method setAttributeNS.

@Override
public void setAttributeNS(final String namespaceURI, final String qualifiedName, final String value) throws DOMException {
    final QName qname;
    try {
        if (document.context != null) {
            qname = QName.parse(document.context, qualifiedName, namespaceURI);
        } else {
            qname = QName.parse(namespaceURI, qualifiedName);
        }
    } catch (final IllegalQNameException e) {
        final short errCode;
        if (e.getValidity() == ILLEGAL_FORMAT.val || (e.getValidity() & QName.Validity.INVALID_NAMESPACE.val) == QName.Validity.INVALID_NAMESPACE.val) {
            errCode = DOMException.NAMESPACE_ERR;
        } else {
            errCode = DOMException.INVALID_CHARACTER_ERR;
        }
        throw new DOMException(errCode, "qualified name is invalid");
    }
    // check the QName is valid for use
    final byte validity = qname.isValid(false);
    if ((validity & QName.Validity.INVALID_LOCAL_PART.val) == QName.Validity.INVALID_LOCAL_PART.val) {
        throw new DOMException(DOMException.INVALID_CHARACTER_ERR, "qualified name is invalid");
    } else if ((validity & QName.Validity.INVALID_NAMESPACE.val) == QName.Validity.INVALID_NAMESPACE.val) {
        throw new DOMException(DOMException.NAMESPACE_ERR, "qualified name is invalid");
    }
    setAttribute(qname, value, qn -> getAttributeNodeNS(qn.getNamespaceURI(), qn.getLocalPart()));
}
Also used : QName(org.exist.dom.QName) IllegalQNameException(org.exist.dom.QName.IllegalQNameException)

Example 2 with IllegalQNameException

use of org.exist.dom.QName.IllegalQNameException in project exist by eXist-db.

the class ElementImpl method setAttribute.

@Override
public void setAttribute(final String name, final String value) throws DOMException {
    final QName qname;
    try {
        if (document.context != null) {
            qname = QName.parse(document.context, name);
        } else {
            qname = new QName(name);
        }
    } catch (final IllegalQNameException e) {
        throw new DOMException(DOMException.INVALID_CHARACTER_ERR, e.getMessage());
    }
    // check the QName is valid for use
    if (qname.isValid(false) != QName.Validity.VALID.val) {
        throw new DOMException(DOMException.INVALID_CHARACTER_ERR, "name is invalid");
    }
    setAttribute(qname, value, qn -> getAttributeNode(qn.getLocalPart()));
}
Also used : QName(org.exist.dom.QName) IllegalQNameException(org.exist.dom.QName.IllegalQNameException)

Example 3 with IllegalQNameException

use of org.exist.dom.QName.IllegalQNameException in project exist by eXist-db.

the class ElementImpl method getElementsByTagNameNS.

@Override
public NodeList getElementsByTagNameNS(final String namespaceURI, final String localName) {
    final boolean wildcardNS = namespaceURI != null && namespaceURI.equals(QName.WILDCARD);
    final boolean wildcardLocalPart = localName != null && localName.equals(QName.WILDCARD);
    if (wildcardNS && wildcardLocalPart) {
        return getElementsByTagName(QName.WildcardQName.getInstance());
    } else if (wildcardNS) {
        return getElementsByTagName(new QName.WildcardNamespaceURIQName(localName));
    } else if (wildcardLocalPart) {
        return getElementsByTagName(new QName.WildcardLocalPartQName(namespaceURI));
    } else {
        final QName qname;
        if (document.getContext() != null) {
            try {
                qname = QName.parse(document.context, localName, namespaceURI);
            } catch (final IllegalQNameException e) {
                throw new DOMException(DOMException.INVALID_CHARACTER_ERR, e.getMessage());
            }
        } else {
            qname = new QName(localName, namespaceURI);
        }
        return getElementsByTagName(qname);
    }
}
Also used : QName(org.exist.dom.QName) IllegalQNameException(org.exist.dom.QName.IllegalQNameException)

Example 4 with IllegalQNameException

use of org.exist.dom.QName.IllegalQNameException in project exist by eXist-db.

the class ElementImpl method setAttributeNS.

@Override
public void setAttributeNS(final String namespaceURI, final String qualifiedName, final String value) throws DOMException {
    final QName qname;
    try {
        qname = QName.parse(namespaceURI, qualifiedName);
    } catch (final IllegalQNameException e) {
        final short errCode;
        if (e.getValidity() == ILLEGAL_FORMAT.val || (e.getValidity() & QName.Validity.INVALID_NAMESPACE.val) == QName.Validity.INVALID_NAMESPACE.val) {
            errCode = DOMException.NAMESPACE_ERR;
        } else {
            errCode = DOMException.INVALID_CHARACTER_ERR;
        }
        throw new DOMException(errCode, "qualified name is invalid");
    }
    // check the QName is valid for use
    final byte validity = qname.isValid(false);
    if ((validity & QName.Validity.INVALID_LOCAL_PART.val) == QName.Validity.INVALID_LOCAL_PART.val) {
        throw new DOMException(DOMException.INVALID_CHARACTER_ERR, "qualified name is invalid");
    } else if ((validity & QName.Validity.INVALID_NAMESPACE.val) == QName.Validity.INVALID_NAMESPACE.val) {
        throw new DOMException(DOMException.NAMESPACE_ERR, "qualified name is invalid");
    }
    setAttribute(qname, value, qn -> getAttributeNodeNS(qn.getNamespaceURI(), qn.getLocalPart()));
}
Also used : QName(org.exist.dom.QName) IllegalQNameException(org.exist.dom.QName.IllegalQNameException)

Example 5 with IllegalQNameException

use of org.exist.dom.QName.IllegalQNameException in project exist by eXist-db.

the class DocumentImpl method createAttributeNS.

/**
 * The method <code>createAttributeNS</code>
 *
 * @param namespaceURI  a <code>String</code> value
 * @param qualifiedName a <code>String</code> value
 * @return an <code>Attr</code> value
 * @throws DOMException if an error occurs
 */
@Override
public Attr createAttributeNS(final String namespaceURI, final String qualifiedName) throws DOMException {
    final QName qname;
    try {
        qname = QName.parse(namespaceURI, qualifiedName);
    } catch (final IllegalQNameException e) {
        final short errCode;
        if (e.getValidity() == ILLEGAL_FORMAT.val || (e.getValidity() & QName.Validity.INVALID_NAMESPACE.val) == QName.Validity.INVALID_NAMESPACE.val) {
            errCode = DOMException.NAMESPACE_ERR;
        } else {
            errCode = DOMException.INVALID_CHARACTER_ERR;
        }
        throw new DOMException(errCode, "qualified name is invalid");
    }
    // check the QName is valid for use
    final byte validity = qname.isValid(false);
    if ((validity & QName.Validity.INVALID_LOCAL_PART.val) == QName.Validity.INVALID_LOCAL_PART.val) {
        throw new DOMException(DOMException.INVALID_CHARACTER_ERR, "qualified name is invalid");
    } else if ((validity & QName.Validity.INVALID_NAMESPACE.val) == QName.Validity.INVALID_NAMESPACE.val) {
        throw new DOMException(DOMException.NAMESPACE_ERR, "qualified name is invalid");
    }
    final AttrImpl attr = new AttrImpl(qname, getBrokerPool().getSymbols());
    attr.setOwnerDocument(this);
    return attr;
}
Also used : QName(org.exist.dom.QName) IllegalQNameException(org.exist.dom.QName.IllegalQNameException)

Aggregations

IllegalQNameException (org.exist.dom.QName.IllegalQNameException)15 QName (org.exist.dom.QName)13 SAXException (org.xml.sax.SAXException)2 Attr (org.w3c.dom.Attr)1 NamedNodeMap (org.w3c.dom.NamedNodeMap)1 AttributesImpl (org.xml.sax.helpers.AttributesImpl)1