StringBuilder sb = new StringBuilder();
sb.append("{\"collections\": [\n");
for (int i = 0; i < children.size(); i++) {
Node node = children.get(i);
if (node.isAsset()) {
JSSnippetAssetNode snippetNode = (JSSnippetAssetNode) node;
String unid = snippetNode.getUnid();
String gadgetUrl = UrlUtil.getBaseUrl(request) + "/gadget/sampleRunner.jsp?snippet="
+ URLEncoder.encode(unid);
sb.append("{\n");
sb.append("\"name\": \"").append(snippetNode.getName()).append("\",\n");
sb.append("\"Description\": \"").append(snippetNode.getName()).append(" from ")
.append(snippetNode.getCategory()).append("\",\n");
sb.append("\"apps\" : [\n");
sb.append("{\"name\": \"").append(snippetNode.getName()).append("\", \"url\": \"")
.append(gadgetUrl).append("\"}\n");
sb.append("]\n");
sb.append((i + 1 < children.size()) ? "},\n" : "}\n");
}
}