This Confluence has been LDAP enabled, if you are an ASF Committer, please use your LDAP Credentials to login. Any problems file an INFRA jira ticket please.

Child pages
  • GSoC 2010 mini-CMS project

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Table of Contents

Overview (from SLING-1438)

...

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.

Introduction

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.

...

Code Block
<h3>Entries</h3><h3>Entries</h3>
	<div>
        <%
        var uuids=tagNode.getProperty("UUIDs").getValues();
        for(var i =0; i<uuids.length; i++) {
        	var uuid=uuids[i];
                var nodeR=session.getNodeByUUID(uuid.getString());
        %>

        	<a href='<%=nodeR.getPath() %>.article'><%=nodeR.title%></a><br>

        <%
        }

        %>

You can see in this script as ESP language can be used to manage object related to JCR. Using the method getNodeByUUID of Session we have the node related to a particular UUID, so we can print it in the list.

Search for entries

Also the search is based on ESP script, /apps/david/search.esp . The user can make three different type of search: by title, by text and by tag. The search with title or text are executed using a XPATH query like this

Code Block

var query = queryManager.createQuery(
	"/jcr:root/content/david/*/*/*/element(*, nt:unstructured)[jcr:like(@title, '%"+request.getParameter("qtitle")+"%')] 
	order by @created descending", "xpath");

This query searches the entry with title LIKE (as in SQL) the parameter submitted.

The tag search is a bit different, because the structure of tags in David make it possible to search under the root node /content/tags, where we save the tags informations. So the query is like the following one

Code Block

var searchString =  
"/jcr:root/content/tags//element(*,nt:unstructured)[fn:name()= '"+request.getParameter("qtag")+"'] order by @created descending";

The initial form to perform the search is a simple HTML one, as you can see in the following image

Image Added

Create PDF renditions

Every node in David is an article and it's an easy task to render it as PDF file.

First of all there is a link on every articles and on the main list that links to

Code Block

http://localhost:8080/content/david/2010/08/14/myarticle.pdf

So it's a new extension called for the node. This extension, as we already have seen, can be managed by a Java class defined in our bundle and deployed on Sling. In David the PDF Extension is managed by sling.gsoc.david.servlet.PdfExtension. In this component there is the rendering of the node using iText library and the node, for which this component can be activated, can be a standard article or the root node. 

If this extension is used with a standard article, the following image is what we will give

Image Added

In the other case, we will have a PDF with the list of articles in David.

Image Added

Scheduler service

Every Sling application can use the opensource scheduler Quartz, provided by the Commons Scheduler bundle (this requires also another bundle, org.apache.sling.commons.threads).

Based on this scheduler there is a simple service, implemented by sling.gsoc.job.JobScheduler and sling.gsoc.job.SendTask. The first is the class that creates a SendTask and schedules it with Quartz. The second one is a simple class that send informations about David (the number of articles and tags available) with an email.