}
resp.setContentType(req.getResponseContentType());
resp.setCharacterEncoding("UTF-8");
final JSONWriter w = new JSONWriter(resp.getWriter());
w.setTidy(isTidy(req));
w.array();
long count = -1;
if (req.getParameter(ROWS) != null) {
count = Long.parseLong(req.getParameter(ROWS));
}
List<String> properties = new ArrayList<String>();
if (req.getParameterValues(PROPERTY) != null) {
for (String property : req.getParameterValues(PROPERTY)) {
properties.add(property);
}
}
String exerptPath = "";
if (req.getParameter(EXCERPT_PATH) != null) {
exerptPath = req.getParameter(EXCERPT_PATH);
}
// iterate through the result set and build the "json result"
while (result.hasNext() && count != 0) {
Map<String, Object> row = result.next();
w.object();
String path = row.get("jcr:path").toString();
w.key("name");
w.value(ResourceUtil.getName(path));
// dump columns
for (String colName : row.keySet()) {
w.key(colName);
String strValue = "";
if (colName.equals(REP_EXCERPT)) {
Object ev = row.get("rep:excerpt(" + exerptPath + ")");
strValue = (ev == null) ? "" : ev.toString();
w.value(strValue);
} else {
//strValue = formatValue(row.get(colName));
itemWriter.dumpValue(w, row.get(colName));
}
//w.value(strValue);
}
// load properties and add it to the result set
if (!properties.isEmpty()) {
Resource nodeRes = resolver.getResource(path);
dumpProperties(w, nodeRes, properties);
}
w.endObject();
count--;
}
w.endArray();
} catch (JSONException je) {
throw wrapException(je);
}
}