try {
broker = pool.get(session.getUser());
final QueryResult queryResult = session.getQueryResult();
if (queryResult == null)
{throw new RemoteException("result set unknown or timed out");}
final Sequence seq = (Sequence) queryResult.result;
if (start < 1 || start > seq.getItemCount())
{throw new RuntimeException(
"index " + start + " out of bounds (" + seq.getItemCount() + ")");}
if (start + howmany > seq.getItemCount() || howmany == 0)
{howmany = seq.getItemCount() - start + 1;}
final String xml[] = new String[howmany];
final Serializer serializer = broker.getSerializer();
serializer.reset();
serializer.setProperty(OutputKeys.INDENT, indent ? "yes" : "no");
serializer.setProperty(EXistOutputKeys.EXPAND_XINCLUDES, xinclude ? "yes" : "no");
serializer.setProperty(EXistOutputKeys.HIGHLIGHT_MATCHES, highlight);
Item item;
int j = 0;
for (int i = --start; i < start + howmany; i++, j++) {
item = seq.itemAt(i);
if (item == null)
{continue;}
if (item.getType() == Type.ELEMENT) {
final NodeValue node = (NodeValue) item;
xml[j] = serializer.serialize(node);