* @throws RepositoryException if an error occurs.
*/
private MultiStatus queryResultToMultiStatus(Query query)
throws RepositoryException {
QueryResult qResult = query.execute();
MultiStatus ms = new MultiStatus();
List<String> columnNames = new ArrayList<String>();
columnNames.addAll(Arrays.asList(qResult.getColumnNames()));
StringBuffer responseDescription = new StringBuffer();
String delim = "";
for (String columnName : columnNames) {
responseDescription.append(delim);
responseDescription.append(ISO9075.encode(columnName));
delim = " ";
}
ms.setResponseDescription(responseDescription.toString());
ValueFactory vf = getRepositorySession().getValueFactory();
List<RowValue> descr = new ArrayList<RowValue>();
for (Iterator<String> it = columnNames.iterator(); it.hasNext(); ) {
String columnName = it.next();
if (!isPathOrScore(columnName)) {
descr.add(new PlainValue(columnName, null, vf));
} else {
it.remove();
}
}
// add path and score for each selector
List<String> sn = new ArrayList<String>();
collectSelectorNames(query, qResult, sn);
for (String selectorName : sn) {
descr.add(new PathValue(JcrConstants.JCR_PATH, selectorName, vf));
columnNames.add(JcrConstants.JCR_PATH);
descr.add(new ScoreValue(JcrConstants.JCR_SCORE, selectorName, vf));
columnNames.add(JcrConstants.JCR_SCORE);
}
String[] selectorNames = createSelectorNames(descr);
String[] colNames = columnNames.toArray(new String[columnNames.size()]);
RowIterator rowIter = qResult.getRows();
while (rowIter.hasNext()) {
Row row = rowIter.nextRow();
List<Value> values = new ArrayList<Value>();
for (RowValue rv : descr) {
values.add(rv.getValue(row));
}
// get the path for the first selector and build
// a webdav compliant resource path of it.
String itemPath = row.getPath();
// create a new ms-response for this row of the result set
DavResourceLocator loc = locator.getFactory().createResourceLocator(locator.getPrefix(), locator.getWorkspacePath(), itemPath, false);
String href = loc.getHref(true);
MultiStatusResponse resp = new MultiStatusResponse(href, null);
// build the s-r-property
SearchResultProperty srp = new SearchResultProperty(colNames,
selectorNames, values.toArray(new Value[values.size()]));
resp.add(srp);
ms.addResponse(resp);
}
return ms;
}