log.debug("sendContent: " + encodedUrl);
JsonConfig cfg = new JsonConfig();
cfg.setIgnoreTransientFields(true);
cfg.setCycleDetectionStrategy(CycleDetectionStrategy.LENIENT);
JSON json;
Writer writer = new PrintWriter(out);
String[] arr;
if (propertyBuilder == null) {
if (wrappedResource instanceof CollectionResource) {
List<? extends Resource> children = ((CollectionResource) wrappedResource).getChildren();
json = JSONSerializer.toJSON(toSimpleList(children), cfg);
} else {
json = JSONSerializer.toJSON(toSimple(wrappedResource), cfg);
}
} else {
// use propfind handler
String sFields = params.get("fields");
Set<QName> fields = new HashSet<QName>();
Map<QName, String> aliases = new HashMap<QName, String>();
if (sFields != null && sFields.length() > 0) {
arr = sFields.split(",");
for (String s : arr) {
parseField(s, fields, aliases);
}
}
String sDepth = params.get("depth");
int depth = 1;
if (sDepth != null && sDepth.trim().length() > 0) {
depth = Integer.parseInt(sDepth);
}
String href = encodedUrl.replace("/_DAV/PROPFIND", "");
log.debug("prop builder: " + propertyBuilder.getClass());
ParseResult parseResult = new ParseResult(false, fields);
List<PropFindResponse> props = propertyBuilder.buildProperties(wrappedResource, depth, parseResult, href);
String where = params.get("where");
filterResults(props, where);
List<Map<String, Object>> list = helper.toMap(props, aliases);
json = JSONSerializer.toJSON(list, cfg);
}
json.write(writer);
writer.flush();
}