Search in sources :

Example 6 with QName

use of org.exist.dom.QName 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 7 with QName

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

the class ElementImpl method getAttributeNS.

@Override
public String getAttributeNS(final String namespaceURI, final String localName) {
    int attr = document.alpha[nodeNumber];
    if (-1 < attr) {
        while (attr < document.nextAttr && document.attrParent[attr] == nodeNumber) {
            final QName name = document.attrName[attr];
            if (name.getLocalPart().equals(localName) && name.getNamespaceURI().equals(namespaceURI)) {
                return document.attrValue[attr];
            }
            ++attr;
        }
    }
    if (Namespaces.XMLNS_NS.equals(namespaceURI)) {
        int ns = document.alphaLen[nodeNumber];
        if (-1 < ns) {
            while (ns < document.nextNamespace && document.namespaceParent[ns] == nodeNumber) {
                final QName nsQName = document.namespaceCode[ns];
                if (nsQName.getLocalPart().equals(localName)) {
                    return nsQName.getNamespaceURI();
                }
                ++ns;
            }
        }
    }
    return null;
}
Also used : QName(org.exist.dom.QName)

Example 8 with QName

use of org.exist.dom.QName 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 9 with QName

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

the class ElementImpl method getPrefixes.

/**
 * The method <code>getPrefixes.</code>
 *
 * @return a <code>Set</code> value
 */
public Set<String> getPrefixes() {
    final Set<String> set = new HashSet<>();
    int ns = document.alphaLen[nodeNumber];
    if (-1 < ns) {
        while (ns < document.nextNamespace && document.namespaceParent[ns] == nodeNumber) {
            final QName nsQName = document.namespaceCode[ns];
            set.add(nsQName.getStringValue());
            ++ns;
        }
    }
    return set;
}
Also used : QName(org.exist.dom.QName) HashSet(java.util.HashSet)

Example 10 with QName

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

the class ElementImpl method getAttributeNode.

@Override
public Attr getAttributeNode(final String name) {
    int attr = document.alpha[nodeNumber];
    if (-1 < attr) {
        while (attr < document.nextAttr && document.attrParent[attr] == nodeNumber) {
            final QName attrQName = document.attrName[attr];
            if (attrQName.getStringValue().equals(name)) {
                return new AttrImpl(document, attr);
            }
            ++attr;
        }
    }
    if (name.startsWith(XMLConstants.XMLNS_ATTRIBUTE + ":")) {
        int ns = document.alphaLen[nodeNumber];
        if (-1 < ns) {
            while (ns < document.nextNamespace && document.namespaceParent[ns] == nodeNumber) {
                final QName nsQName = document.namespaceCode[ns];
                if (nsQName.getStringValue().equals(name)) {
                    return new NamespaceNode(document, ns);
                }
                ++ns;
            }
        }
    }
    return null;
}
Also used : QName(org.exist.dom.QName)

Aggregations

QName (org.exist.dom.QName)260 Test (org.junit.Test)54 Sequence (org.exist.xquery.value.Sequence)39 DBBroker (org.exist.storage.DBBroker)31 MemTreeBuilder (org.exist.dom.memtree.MemTreeBuilder)28 IOException (java.io.IOException)23 Document (org.w3c.dom.Document)23 DocumentSet (org.exist.dom.persistent.DocumentSet)20 Text (org.w3c.dom.Text)20 NameTest (org.exist.xquery.NameTest)17 XPathException (org.exist.xquery.XPathException)17 BrokerPool (org.exist.storage.BrokerPool)15 IllegalQNameException (org.exist.dom.QName.IllegalQNameException)13 Node (org.w3c.dom.Node)12 ReentrantLock (java.util.concurrent.locks.ReentrantLock)11 NodeSet (org.exist.dom.persistent.NodeSet)11 SAXException (org.xml.sax.SAXException)11 DefaultDocumentSet (org.exist.dom.persistent.DefaultDocumentSet)10 MutableDocumentSet (org.exist.dom.persistent.MutableDocumentSet)10 PermissionDeniedException (org.exist.security.PermissionDeniedException)10