use of org.exist.xquery.value.SequenceIterator in project exist by eXist-db.
the class IndexerTest2 method executeQuery.
private String executeQuery() throws EXistException, PermissionDeniedException, SAXException, XPathException, IOException {
final BrokerPool pool = existEmbeddedServer.getBrokerPool();
try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()));
final StringWriter out = new StringWriter()) {
final XQuery xquery = broker.getBrokerPool().getXQueryService();
final Sequence result = xquery.execute(broker, XQUERY, null);
final Properties props = new Properties();
props.setProperty(OutputKeys.INDENT, "yes");
final SAXSerializer serializer = new SAXSerializer(out, props);
serializer.startDocument();
for (final SequenceIterator i = result.iterate(); i.hasNext(); ) {
final Item next = i.nextItem();
next.toSAX(broker, serializer, props);
}
serializer.endDocument();
return out.toString();
}
}
use of org.exist.xquery.value.SequenceIterator in project exist by eXist-db.
the class IndexerTest method store_and_retrieve_ws_mixed_content_value.
private String store_and_retrieve_ws_mixed_content_value(final boolean preserve, final String typeXml, final String typeXquery) throws EXistException, IOException, LockException, AuthenticationException, PermissionDeniedException, SAXException, XPathException {
store_preserve_ws_mixed_content_value(preserve, typeXml);
final BrokerPool pool = existEmbeddedServer.getBrokerPool();
try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()))) {
final XQuery xquery = pool.getXQueryService();
final Sequence result = xquery.execute(broker, typeXquery, null);
try (final StringWriter out = new StringWriter()) {
final Properties props = new Properties();
props.setProperty(OutputKeys.INDENT, "yes");
final SAXSerializer serializer = new SAXSerializer(out, props);
serializer.startDocument();
for (final SequenceIterator i = result.iterate(); i.hasNext(); ) {
final Item next = i.nextItem();
next.toSAX(broker, serializer, props);
}
serializer.endDocument();
return out.toString();
}
}
}
use of org.exist.xquery.value.SequenceIterator in project exist by eXist-db.
the class IndexerTest3 method store_and_retrieve_suppress_type.
private String store_and_retrieve_suppress_type(final String type, final String typeXml, final String typeXquery) throws EXistException, IOException, LockException, AuthenticationException, PermissionDeniedException, SAXException, XPathException {
store_suppress_type(type, typeXml);
final BrokerPool pool = existEmbeddedServer.getBrokerPool();
try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()));
final StringWriter out = new StringWriter()) {
final XQuery xquery = pool.getXQueryService();
final Sequence result = xquery.execute(broker, typeXquery, null);
final Properties props = new Properties();
props.setProperty(OutputKeys.INDENT, "no");
final SAXSerializer serializer = new SAXSerializer(out, props);
serializer.startDocument();
for (final SequenceIterator i = result.iterate(); i.hasNext(); ) {
final Item next = i.nextItem();
next.toSAX(broker, serializer, props);
}
serializer.endDocument();
return out.toString();
}
}
use of org.exist.xquery.value.SequenceIterator in project exist by eXist-db.
the class RangeSequenceTest method iterate_skip_loop.
@Test
public void iterate_skip_loop() {
final SequenceIterator it = rangeSequence.iterate();
assertEquals(99, it.skippable());
assertEquals(10, it.skip(10));
assertEquals(89, it.skippable());
int count = 0;
while (it.hasNext()) {
it.nextItem();
count++;
}
assertEquals(89, count);
}
use of org.exist.xquery.value.SequenceIterator in project exist by eXist-db.
the class RangeSequenceTest method iterateInReverse_loop.
@Test
public void iterateInReverse_loop() {
final SequenceIterator it = rangeSequence.iterateInReverse();
int count = 0;
while (it.hasNext()) {
it.nextItem();
count++;
}
assertEquals(99, count);
}
Aggregations