Search in sources :

Example 16 with NameTest

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

the class BasicNodeSetTest method selectParentChild_2.

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

Example 17 with NameTest

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

the class BasicNodeSetTest method nodeProxy_getParents.

@Test
public void nodeProxy_getParents() throws XPathException, SAXException, PermissionDeniedException, EXistException {
    try (final DBBroker broker = existEmbeddedServer.getBrokerPool().get(Optional.of(existEmbeddedServer.getBrokerPool().getSecurityManager().getSystemSubject()))) {
        Sequence smallSet = executeQuery(broker, "//SPEECH/LINE[fn:contains(., 'perturbed spirit')]/ancestor::SPEECH", 1, null);
        NodeProxy proxy = (NodeProxy) smallSet.itemAt(0);
        NodeSet result = proxy.getParents(-1);
        assertEquals(1, result.getLength());
        NameTest test = new NameTest(Type.ELEMENT, new QName("SPEAKER", ""));
        NodeSet speakers = broker.getStructuralIndex().findElementsByTagName(ElementValue.ELEMENT, docs, test.getName(), null);
        result = speakers.selectParentChild(proxy, NodeSet.DESCENDANT, -1);
        assertEquals(1, 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 18 with NameTest

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

the class BasicNodeSetTest method selectPrecedingSiblings.

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

Example 19 with NameTest

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

the class BasicNodeSetTest method extArrayNodeSet_selectParentChild_4.

@Test
public void extArrayNodeSet_selectParentChild_4() throws XPathException, SAXException, PermissionDeniedException, EXistException {
    try (final DBBroker broker = existEmbeddedServer.getBrokerPool().get(Optional.of(existEmbeddedServer.getBrokerPool().getSecurityManager().getSystemSubject()))) {
        Sequence nestedSet = executeQuery(broker, "//para[@n = ('1.1.2.1')]", 1, null);
        NameTest test = new NameTest(Type.ELEMENT, new QName("section", ""));
        NodeSet sections = broker.getStructuralIndex().findElementsByTagName(ElementValue.ELEMENT, docs, test.getName(), null);
        NodeSet result = ((NodeSet) nestedSet).selectParentChild(sections.toNodeSet(), NodeSet.DESCENDANT);
        assertEquals(1, 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)

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