Search in sources :

Example 11 with NameTest

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

the class BasicNodeSetTest method extArrayNodeSet_selectParentChild_1.

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

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

the class BasicNodeSetTest method ancestorSelector.

@Test
public void ancestorSelector() throws XPathException, EXistException {
    NodeSelector selector = new AncestorSelector(seqSpeech.toNodeSet(), -1, false, true);
    NameTest test = new NameTest(Type.ELEMENT, new QName("ACT", ""));
    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(15, 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 13 with NameTest

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

the class BasicNodeSetTest method descendantSelector.

@Test
public void descendantSelector() throws XPathException, SAXException, PermissionDeniedException, EXistException {
    try (final DBBroker broker = existEmbeddedServer.getBrokerPool().get(Optional.of(existEmbeddedServer.getBrokerPool().getSecurityManager().getSystemSubject()))) {
        Sequence seq = executeQuery(broker, "//SCENE", 72, null);
        NameTest test = new NameTest(Type.ELEMENT, new QName("SPEAKER", ""));
        NodeSelector selector = new DescendantSelector(seq.toNodeSet(), -1);
        NodeSet set = broker.getStructuralIndex().findElementsByTagName(ElementValue.ELEMENT, seq.getDocumentSet(), test.getName(), selector);
        assertEquals(2639, set.getLength());
    }
}
Also used : DBBroker(org.exist.storage.DBBroker) NameTest(org.exist.xquery.NameTest) QName(org.exist.dom.QName) Sequence(org.exist.xquery.value.Sequence) NodeSelector(org.exist.xquery.NodeSelector) DescendantSelector(org.exist.xquery.DescendantSelector) Test(org.junit.Test) NameTest(org.exist.xquery.NameTest)

Example 14 with NameTest

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

the class BasicNodeSetTest method selectAncestors.

@Test
public void selectAncestors() throws XPathException, SAXException, PermissionDeniedException, EXistException {
    NameTest test = new NameTest(Type.ELEMENT, new QName("SCENE", ""));
    try (final DBBroker broker = existEmbeddedServer.getBrokerPool().get(Optional.of(existEmbeddedServer.getBrokerPool().getSecurityManager().getSystemSubject()))) {
        NodeSet scenes = broker.getStructuralIndex().findElementsByTagName(ElementValue.ELEMENT, docs, test.getName(), null);
        Sequence largeSet = executeQuery(broker, "//SPEECH/LINE[fn:contains(., 'love')]/ancestor::SPEECH", 187, null);
        NodeSet result = ((AbstractNodeSet) scenes).selectAncestors(largeSet.toNodeSet(), false, -1);
        assertEquals(49, 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 15 with NameTest

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

the class BasicNodeSetTest method selectAncestorDescendant.

@Test
public void selectAncestorDescendant() 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 outerSet = executeQuery(broker, "//SCENE/TITLE[fn:contains(., 'closet')]/ancestor::SCENE", 1, null);
        NodeSet result = speakers.selectAncestorDescendant(outerSet.toNodeSet(), NodeSet.DESCENDANT, false, -1, true);
        assertEquals(56, 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)

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