Putting JCR into action – Sling and µJAX

**Putting JCR into action – Sling and µJAX **

During last couple of years the enterprise content management community has been noticing a steady rise in the popularity of JCR aka JSR170. A lot of CMS vendors and application server vendors have pledged support to this initiative. For those who are not familiar with JCR, it is the Content Repository API for Java Technology - a Java standard advocated by Day software. JCR provides a “JDBC” equivalent access to content so that the application code does not have to know the details of the underlying vendor implementation. JCR aims at providing an elegant solution to some of the content management challenges faced by organizations dealing with a profusion of content repositories and CMS products. JCR promises “best of both worlds” by providing a single API to access and modify content stored in a DB or in a file system.

I have been tracking the evolution of products based on JCR implementation for a while and was quite disappointed initially to see that other than Day (the proponent of JCR) none of the major ECM vendors provided any real support to JCR based repositories. However recently the situation is getting much better with Alfresco offering a JCR-170 compliant repository and Day supporting the Apache Sling initiative that exposes the JCR APIs via REST.

Exposing the JCR API via a set of RESTful services is a wonderful idea and Sling is one of the first RESTful open source web application frameworks built on top of JCR. Sling uses Apache JackRabbit as the JCR repository. JCR is a tree structured or hierarchical content store. So naturally it makes sense to map tree-structured URLs directly to the tree structure of JCR so that the nodes can be accessed just like a file system with static files.

Before looking at Sling, I tried to build a blogging tool using the evaluation of copy of CRX (Day’s Communiqué) and the µjax library that came with it. Unfortunately I didn’t make much progress with it because of lack of supporting documentation and missing files etc. Then I downloaded Sling Launchpad (a ready-to-run Sling configuration, with an embedded JCR content repository and web server with some Sling components). The maven build went fairly smooth, and I was up and running in less than 10 minutes or so. Initially I used the CURL to post content into the repository and later switched to an HTML form to post the content into the repository. Content in the repository can be rendered using ESP server side JavaScript module that comes with Launchpad.

The biggest plus I see with sling is that it handles the normal GET and PUT methods out of the box and translates them into corresponding JCR actions to retrieve and post content into the repository. The blogging tool is a very simple form of CMS, but it can be extended easily by writing servlet code. Although I used ESP to render the page, Sling supports other scripting languages supported by the Java Scripting framework (JSR-223).

I see a lot of potential for Sling. If we can build a good interface for posting and editing the content in the repository (I have been bugging Atul Kedar to post his custom JavaScript library for building advanced content entry forms into some open source repository) it could beat many of the CMS products out there in the areas of customizability and flexibility.