Posted by Federico Paparoni SEP 28, 2010
Posted in graph and sling Add comment
Yesterday I was looking an interesting javascript library, JIT (JavaScript InfoVis Toolkit), that is really useful to create some cool representation of your data with graphs, trees, charts and so on.
This toolkit creates different data representation using JSON as input, so I thought it could be funny to integrate with Apache Sling to have a new representation of my repository.
Unfortunately JSON translation in Apache Sling is a bit different from the one used in JIT, because it needs children node represented as an array (not in every demo contained in JIT but in the one I want so integrate with Sling).
So I modified org.apache.sling.commons.json.jcr.JsonItemWriter, to encapsulate the nodes in a JSON array
Iterator children = resource.listChildren();
if (children.hasNext()) {
w.key("children");
w.array();
while (children.hasNext()){
Resource n = children.next();
log.info("Giro "+n.getName());
dump(n);
}
w.endArray();
}
Now I have to load some data on my instance of Apache Sling, so I create a simple JSON.
{
"id": "node01",
"name": "0.2",
"data":"",
"jcr:primaryType":"sling:Folder",
"node11": {
"id": "node13",
"name": "1.3",
"data": "",
"jcr:primaryType":"sling:Folder",
"node111":{
...
...
Finally I have to load this data into JIT, so I modified an example to load JSON data from an external source
So I got a very cool representation of my data stored with JCR


