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;
}
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());
}
}
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());
}
}
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());
}
}
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());
}
}
Aggregations