Search in sources :

Example 1 with NameTest

use of org.exist.xquery.NameTest in project exist by eXist-db.

the class DocumentImpl method getElementsByTagName.

private NodeList getElementsByTagName(final QName qname) {
    try (final DBBroker broker = pool.getBroker()) {
        final MutableDocumentSet docs = new DefaultDocumentSet();
        docs.add(this);
        final NewArrayNodeSet contextSet = new NewArrayNodeSet();
        final ElementImpl root = ((ElementImpl) getDocumentElement());
        contextSet.add(new NodeProxy(this, root.getNodeId(), root.getInternalAddress()));
        return broker.getStructuralIndex().scanByType(ElementValue.ELEMENT, Constants.DESCENDANT_SELF_AXIS, new NameTest(Type.ELEMENT, qname), false, docs, contextSet, Expression.NO_CONTEXT_ID);
    } catch (final Exception e) {
        LOG.error("Exception while finding elements: {}", e.getMessage(), e);
    // TODO : throw exception ?
    }
    return NodeSet.EMPTY_SET;
}
Also used : NameTest(org.exist.xquery.NameTest) EXistException(org.exist.EXistException) IllegalQNameException(org.exist.dom.QName.IllegalQNameException) IOException(java.io.IOException)

Example 2 with NameTest

use of org.exist.xquery.NameTest in project exist by eXist-db.

the class BasicNodeSetTest method descendantOrSelfSelector.

@Test
public void descendantOrSelfSelector() throws XPathException, EXistException {
    NodeSelector selector = new DescendantOrSelfSelector(seqSpeech.toNodeSet(), -1);
    NameTest test = new NameTest(Type.ELEMENT, new QName("SPEECH", ""));
    try (final DBBroker broker = existEmbeddedServer.getBrokerPool().get(Optional.of(existEmbeddedServer.getBrokerPool().getSecurityManager().getSystemSubject()))) {
        NodeSet set = broker.getStructuralIndex().findElementsByTagName(ElementValue.ELEMENT, seqSpeech.getDocumentSet(), test.getName(), selector);
        assertEquals(2628, set.getLength());
    }
}
Also used : NameTest(org.exist.xquery.NameTest) DBBroker(org.exist.storage.DBBroker) QName(org.exist.dom.QName) NodeSelector(org.exist.xquery.NodeSelector) DescendantOrSelfSelector(org.exist.xquery.DescendantOrSelfSelector) Test(org.junit.Test) NameTest(org.exist.xquery.NameTest)

Example 3 with NameTest

use of org.exist.xquery.NameTest in project exist by eXist-db.

the class BasicNodeSetTest method selectFollowingSiblings.

@Test
public void selectFollowingSiblings() throws XPathException, SAXException, PermissionDeniedException, EXistException {
    try (final DBBroker broker = existEmbeddedServer.getBrokerPool().get(Optional.of(existEmbeddedServer.getBrokerPool().getSecurityManager().getSystemSubject()))) {
        Sequence largeSet = executeQuery(broker, "//SPEECH/LINE[fn:contains(., 'love')]/ancestor::SPEECH/SPEAKER", 187, null);
        NameTest test = new NameTest(Type.ELEMENT, new QName("LINE", ""));
        NodeSet lines = broker.getStructuralIndex().findElementsByTagName(ElementValue.ELEMENT, docs, test.getName(), null);
        NodeSet result = ((AbstractNodeSet) lines).selectFollowingSiblings(largeSet.toNodeSet(), -1);
        assertEquals(1689, result.getLength());
    }
}
Also used : DBBroker(org.exist.storage.DBBroker) NameTest(org.exist.xquery.NameTest) QName(org.exist.dom.QName) Sequence(org.exist.xquery.value.Sequence) Test(org.junit.Test) NameTest(org.exist.xquery.NameTest)

Example 4 with NameTest

use of org.exist.xquery.NameTest in project exist by eXist-db.

the class BasicNodeSetTest method ancestorSelector_self.

@Test
public void ancestorSelector_self() throws XPathException, EXistException {
    NodeSet ns = seqSpeech.toNodeSet();
    NodeSelector selector = new AncestorSelector(ns, -1, true, true);
    NameTest test = new NameTest(Type.ELEMENT, new QName("SPEECH", ""));
    try (final DBBroker broker = existEmbeddedServer.getBrokerPool().get(Optional.of(existEmbeddedServer.getBrokerPool().getSecurityManager().getSystemSubject()))) {
        NodeSet set = broker.getStructuralIndex().findElementsByTagName(ElementValue.ELEMENT, seqSpeech.getDocumentSet(), test.getName(), selector);
        assertEquals(2628, set.getLength());
    }
}
Also used : NameTest(org.exist.xquery.NameTest) DBBroker(org.exist.storage.DBBroker) AncestorSelector(org.exist.xquery.AncestorSelector) QName(org.exist.dom.QName) NodeSelector(org.exist.xquery.NodeSelector) Test(org.junit.Test) NameTest(org.exist.xquery.NameTest)

Example 5 with NameTest

use of org.exist.xquery.NameTest in project exist by eXist-db.

the class BasicNodeSetTest method childSelector.

@Test
public void childSelector() throws XPathException, EXistException {
    NodeSelector selector = new ChildSelector(seqSpeech.toNodeSet(), -1);
    NameTest test = new NameTest(Type.ELEMENT, new QName("LINE", ""));
    try (final DBBroker broker = existEmbeddedServer.getBrokerPool().get(Optional.of(existEmbeddedServer.getBrokerPool().getSecurityManager().getSystemSubject()))) {
        NodeSet set = broker.getStructuralIndex().findElementsByTagName(ElementValue.ELEMENT, seqSpeech.getDocumentSet(), test.getName(), selector);
        assertEquals(9492, set.getLength());
    }
}
Also used : ChildSelector(org.exist.xquery.ChildSelector) NameTest(org.exist.xquery.NameTest) DBBroker(org.exist.storage.DBBroker) QName(org.exist.dom.QName) NodeSelector(org.exist.xquery.NodeSelector) Test(org.junit.Test) NameTest(org.exist.xquery.NameTest)

Aggregations

NameTest (org.exist.xquery.NameTest)19 QName (org.exist.dom.QName)16 DBBroker (org.exist.storage.DBBroker)16 Test (org.junit.Test)16 Sequence (org.exist.xquery.value.Sequence)12 NodeSelector (org.exist.xquery.NodeSelector)5 IOException (java.io.IOException)2 EXistException (org.exist.EXistException)2 IllegalQNameException (org.exist.dom.QName.IllegalQNameException)2 AncestorSelector (org.exist.xquery.AncestorSelector)2 XMLStreamException (javax.xml.stream.XMLStreamException)1 ChildSelector (org.exist.xquery.ChildSelector)1 DescendantOrSelfSelector (org.exist.xquery.DescendantOrSelfSelector)1 DescendantSelector (org.exist.xquery.DescendantSelector)1 XPathException (org.exist.xquery.XPathException)1 Node (org.w3c.dom.Node)1 SAXException (org.xml.sax.SAXException)1