String parentUrl = isRoot ? RestHelper.urlFrom(baseUrl, ITEMS_METHOD_NAME, "..", "..") : RestHelper.urlFrom(baseUrl,
ITEMS_METHOD_NAME,
encodedPath(
node.getParent()
.getPath()));
RestNode restNode = new RestNode(nodeName(node), node.getIdentifier(), nodeUrl, parentUrl);
// add the properties
for (PropertyIterator propertyIterator = node.getProperties(); propertyIterator.hasNext();) {
Property property = propertyIterator.nextProperty();
restNode.addJcrProperty(createRestProperty(session, property, baseUrl));
}
// add the children
for (NodeIterator nodeIterator = node.getNodes(); nodeIterator.hasNext();) {
Node childNode = nodeIterator.nextNode();
RestNode restChild = null;
if (depth > 0) {
restChild = createRestNode(session, childNode, baseUrl, depth - 1);
} else if (depth < 0) {
restChild = createRestNode(session, childNode, baseUrl, -1);
} else {
String childUrl = RestHelper.urlFrom(baseUrl, ITEMS_METHOD_NAME, encodedPath(childNode.getPath()));
restChild = new RestNode(nodeName(childNode), childNode.getIdentifier(), childUrl, nodeUrl);
}
restNode.addChild(restChild);
}
return restNode;
}