This is a Google Summer of Code 2010, Federico Paparoni has been accepted as a student to work on it, mentored by Bertrand Delacretaz
The goal is to create a mini-CMS with Sling, that demonstrates Sling best practices.
See http://tinyurl.com/asfgsoc for the full list of GSoC 2010 projects at the ASF, and http://community.apache.org/gsoc for general GSoC information.
Apache Sling is an opensource project with a lot of technologies and features. The goal of this project is to create a mini-CMS, that developers can use to understand how to develop a simple application with Sling.
So it is necessary to know a little about two main topics: OSGi and JCR. The following links are useful resources to read something about these technologies.
The repository for this project can be found at http://code.google.com/p/davidgsoc2010/.
This project shows some features of Apache Sling and can be used for educational purpose to move your first steps with this framework.
David uses the following opensource library/technologies:
The available features are
These aren't space age features, but are useful to understand how to create an application using Apache Sling
Firstly you must setup the environment for Sling, so you can follow the guide at http://sling.apache.org/site/getting-and-building-sling.html.
Now that you created your environment, you can setup some other tools that can be useful during the development:
It's time to make our "Hello world" in Apache Sling.
Open a console and simply launch the next command:
curl -F"sling:resourceType=foo/bar" -F"title=Hello world" http://admin:admin@localhost:8080/content/myfirstnode
This is a simple HTTP request, where you pass some parameters and values. Using it you have created a first resource under Sling.
The resource is a JCR node, as every resource in Sling, put under folder /content. This node has two parameters, title and sling:resourceType.
Node creation is a simple task, but you must understand how you can render the information stored in the nodes using Sling.
The first document you can read is the next one: http://dev.day.com/content/ddc/blog/2008/07/cheatsheet/_jcr_content/par/download/file.res/cheatsheet.pdf
It simply describes how content resolution works in Sling.
Another important information to better understand Sling, is that a resource is rendered by a script.
Script files are stored under the folders /apps or /libs and there is a wide choice of possible scripting engine:
To select a script, Sling uses the node's sling:resourceType property. So if we say that sling:resourceType is foo/bar, Sling will search under the /apps/foo/bar/ folder.
The following links describes how the scripts work and what type of variables we have during the script execution:
You can setup some initial contents that can be used in your application. It is a useful thing, because with a simple configuration you have some nodes already created when your application starts.
In David there are two different nodes created when you deploy your application: /content/david and /content/tags .
These nodes are defined in the application folders, using a JSON format. Every information stored in these JSON will be a property of the created nodes.
The most important property is the next one
This property defines "david" as resource type, so Sling knows that it will search under the folder /apps/david to find the scripts that will be called on this node.
These JSON files are loaded using the Maven Bundle Plugin , as you can see in the David core/pom.xml file
<!-- initial content to be loaded on bundle installation --> <Sling-Initial-Content> initial-content;overwrite:=true;uninstall:=true </Sling-Initial-Content>
JSON isn't the only way to load initial content. Further informations about content loading can be found in the Content Loading Bundle Documentation.
There is a script that provide this basic function, /apps/david/new.esp. As you can see in David I choose the ESP scripting language, but as we already said, you can choose among a lot of scripting engines with Sling. This script loads two other script files, used in every script of David: /apps/david/header.esp and /apps/david/menu.esp. These scripts, as the name suggests, contain header informations and the menu for David.
In the header there are jQuery functions and CSS definitions, useful for the whole CMS. In the menu script we can find the definition of a classic menu.
Turning back to the new.esp script, we can see in the following code as header and menu are loaded, using an ESP function.
... ... <title>David Mini CMS</title> <% load("header.esp"); %> </head> <body onload="checkAuth()"> <div id="lCenter"> <div id="desktop"> <% load("menu.esp"); %> <div id="contentPanel" class="centralPanel"> ... ...
So we loaded these two scripts in new.esp. In addition to this, in this script we defined a simple form, with some input text and a CKEditor panel.
Once the user fills the input, the page is like in the following image