//TODO change responseAsString with something like
//return EncodingUtil.getString(rawdata, m.getResponseCharSet());
if (!isSuccessStatus(responseStatus))
return failureResultForStatusCode(responseStatus);
ResourceProxy resource = new ResourceProxy(path);
JSONObject json = new JSONObject(get.getResponseBodyAsString());
String primaryType = json.optString(Repository.JCR_PRIMARY_TYPE);
if (primaryType != null) { // TODO - needed?
resource.addProperty(Repository.JCR_PRIMARY_TYPE, primaryType);
}
// TODO - populate all properties
for (Iterator<?> keyIterator = json.keys(); keyIterator.hasNext();) {
String key = (String) keyIterator.next();
JSONObject value = json.optJSONObject(key);
if (value != null) {
ResourceProxy child = new ResourceProxy(PathUtil.join(path, key));
child.addProperty(Repository.JCR_PRIMARY_TYPE, value.optString(Repository.JCR_PRIMARY_TYPE));
resource.addChild(child);
}
}
return AbstractResult.success(resource);