Search in sources :

Example 6 with IllegalQNameException

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

the class DocumentImpl method createElement.

/**
 * The method <code>createElement</code>
 *
 * @param tagName a <code>String</code> value
 * @return an <code>Element</code> value
 * @throws DOMException if an error occurs
 */
@Override
public Element createElement(final String tagName) throws DOMException {
    final QName qname;
    try {
        qname = new QName(tagName);
    } catch (final IllegalQNameException e) {
        throw new DOMException(DOMException.INVALID_CHARACTER_ERR, "name is invalid");
    }
    // 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");
    }
    final ElementImpl element = new ElementImpl(qname, getBrokerPool().getSymbols());
    element.setOwnerDocument(this);
    return element;
}
Also used : QName(org.exist.dom.QName) IllegalQNameException(org.exist.dom.QName.IllegalQNameException)

Example 7 with IllegalQNameException

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

the class DocumentImpl method createElementNS.

/**
 * The method <code>createElementNS</code>
 *
 * @param namespaceURI  a <code>String</code> value
 * @param qualifiedName a <code>String</code> value
 * @return an <code>Element</code> value
 * @throws DOMException if an error occurs
 */
@Override
public Element createElementNS(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 ElementImpl element = new ElementImpl(qname, getBrokerPool().getSymbols());
    element.setOwnerDocument(this);
    return element;
}
Also used : QName(org.exist.dom.QName) IllegalQNameException(org.exist.dom.QName.IllegalQNameException)

Example 8 with IllegalQNameException

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

the class DOMStreamer method endNode.

protected void endNode(final Node node) throws SAXException {
    if (node == null) {
        return;
    }
    if (node.getNodeType() == Node.ELEMENT_NODE) {
        final ElementInfo info = stack.pop();
        nsSupport.popContext();
        String localName = node.getLocalName();
        if (localName == null) {
            try {
                localName = QName.extractLocalName(node.getNodeName());
            } catch (final IllegalQNameException e) {
                throw new SAXException(e);
            }
        }
        String namespaceURI = node.getNamespaceURI();
        if (namespaceURI == null) {
            namespaceURI = XMLConstants.NULL_NS_URI;
        }
        contentHandler.endElement(namespaceURI, localName, node.getNodeName());
        if (info.prefixes != null) {
            for (int i = 0; i < info.prefixes.length; i++) {
                contentHandler.endPrefixMapping(info.prefixes[i]);
            }
        }
    }
}
Also used : IllegalQNameException(org.exist.dom.QName.IllegalQNameException) SAXException(org.xml.sax.SAXException)

Example 9 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 {
        qname = new QName(name);
    } catch (final IllegalQNameException e) {
        throw new DOMException(DOMException.INVALID_CHARACTER_ERR, "name is invalid");
    }
    // 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 10 with IllegalQNameException

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

the class DocumentImpl method createAttributeNS.

@Override
public Attr createAttributeNS(final String namespaceURI, final String qualifiedName) throws DOMException {
    final QName qname;
    try {
        if (getContext() != null) {
            qname = QName.parse(getContext(), 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");
    }
    // TODO(AR) implement this!
    throw unsupported();
}
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