String xml[] = null;
if (Type.subTypeOf(qr.getItemType(), Type.NODE)) {
// Fix typecast exception RMT
// NodeList resultSet = (NodeSet)qr;
final ExtArrayNodeSet hitsByDoc = new ExtArrayNodeSet();
NodeProxy p;
String ppath;
for (final SequenceIterator i = qr.iterate(); i.hasNext(); ) {
// for (Iterator i = ((NodeSet) resultSet).iterator(); i.hasNext();) {
p = (NodeProxy) i.nextItem();
///TODO : use dedicated function in XmldbURI
ppath = p.getDocument().getCollection().getURI().toString() + '/' + p.getDocument().getFileURI();
if (ppath.equals(path))
{hitsByDoc.add(p);}
}
--start;
if (start < 0 || start > hitsByDoc.getLength())
{throw new RemoteException(
"index " + start + "out of bounds (" + hitsByDoc.getLength() + ")");}
if (start + howmany >= hitsByDoc.getLength())
{howmany = hitsByDoc.getLength() - start;}
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);
xml = new String[howmany];
int j=0;
for (int i = start; i < start + howmany; i++) {
final NodeProxy proxy = ((NodeSet) hitsByDoc).get(i);
if (proxy == null)
{throw new RuntimeException("not found: " + start);}
xml[j] = serializer.serialize(proxy);
j++; // update count number of results
}