17 December 2009

Content mangement and the semantic web

I came across the term 'semantic web' a couple of years ago, when one of the original creators of Apache Cocoon went of to work on the SIMILE Project at MIT. I didn't pay much attention to the concept of 'semantic web' back then, because I just started learning Apache Cocoon and still had a lot to learn.
But over the last couple of months I've been doing some research on the currently available standards for providing semantic data on the web with a strong focus on RDFa.

Content management

Working at Hippo, a CMS vendor based in the Netherlands & USA, makes me think in content and publishing strategies. Publishing information to the web is one of our core businesses, but I've learned over the last couple of month we can enrich our publishing platform even more by providing semantic data. I started my journey by looking around if other CMS vendors are paying attention to semantic web standards. I noticed that only a few of the enormous amount of  content management vendors actually put effort in providing semantic web functionalities for their end-users. I think that's a shame, because enrich your pages a lot.
This post should give you an insight on how you could create a website with embedded meta data (with Hippo), but let's first start with some basics.


What's the idea behind the semantic web?

The current web is very well suited for being read by people like you and me. Computers however can only analyze the words on a page, but can not see the semantics of a piece of information on that specific page, that we as people do see.
If you would allow the information on you page to be machine-readable, the computer would be able to analyze your page and extract much more information from it then just being a piece of text. That's where semantic web standards can help out.
Standards for providing semantic data on the web are not new and some of them have already been available for quite some time. Probably the two most well known are: RDF and Microformats. However recently RDFa has been getting a lot of attention by Google, Yahoo and now also the UK government.


What is RDFa?


RDFa is short for “Resource Description Framework in attributes”. This sounds a bit descriptive, but it means that RDFa provides a set of XHTML attributes, which in their turn provide a way of translating visual data on a page into machine-readable hints. So let's take a look at an example of how a simple web page is currently structured.



<html>
  <body>
    <h1>Content management and the semantic web</h1>
    <h2>Jeroen Reijn</h2>
    <p>some information</p>
  </body>
</html> 

As you can see in the above XHTML fragment, we have a page with a title, a subtitle and a small snippet of text inside the body of the page. By rendering this HTML fragment in the browser the visitor of this page will recognize this piece of text as being the title and author of the current article on the page. A machine however would need a bit more information to be sure the content can be identified as a title and author. That's where RDFa can help out. By using vocabularies, you can give meaning to specific pieces of content on a page.
Let's see what the above XHTML fragment would look like if we would use RDFa.


<html>
  <body xmlns:dc="http://purl.org/dc/elements/1.1/"> 
    <h1 property="dc:title">Content management and the semantic web</h1>
    <h2 property="dc:creator">Jeroen Reijn</h2>
    <p>some information</p>
  </body>
</html>

As shown in the example, the Dublin Core vocabulary is added to the page first. This is important to be able to use the properties inside the vocabulary later on. Once the vocabulary is in place, we can give meaning to fragments on the page. In the HTML fragment above the h1 is marked as the Dublin Core title attribute and the h2 as the Dublin Core creator attribute. With these properties in place a machine, like a search engine crawler, can now also store this as additional meta data of the page.
One of the main advantages of RDFa is that your content can processed in a more efficient way, which in turn can make your page rank higher then it might have been before.
Big search engines like Google and Yahoo already scan your website for RDFa embedded information, so why not use it?

How to use RDFa in your (hippo) website?

Hippo CMS is a content (centered) management system and it differs from other CMS's in such a way that the information inside the Hippo CMS content repository is not stored or identified as pages, but rather as content. In most cases even reusable content. To be more precise: information stored inside the content repository is stored as JCR nodes and/or properties.
Since the data is just content and not bound to any front-end technology, you can either publish it as XML, (X)HTML with some help from the Hippo Site Toolkit (HST) or any other format you might like.
Now let's take the above HTML fragment as an example and let's see what this would look like on a content level. One of the most important things to mention here is that a JCR repository has the concept of nodetype definitions in which you can configure what your data model looks like. You could compare it with for instance a XML Schema or DTD for a piece of XML, but then for the nodes and properties available in a JCR repository.


Let's first start with our content definition or in content management terms the document type. We will need three fields:

  • Title
  • Author
  • Body (rich-text field)
If you would create a document type with the Hippo CMS template editor, the resulting nodetype definition will end up looking like this:


<'myproject'='http://www.myproject.org/nt/myproject/1.0'>
<'hippostd'='http://www.onehippo.org/jcr/hippostd/nt/2.0'>
<'hippo'='http://www.onehippo.org/jcr/hippo/nt/2.0'>

[myproject:text] > hippostd:publishable, hippostd:publishableSummary, hippo:document
- myproject:title (string)
- myproject:author (string)
+ myproject:body (hippostd:html)

As you can see all three fields are available and can be used later on by any client that can read from the Java content repository. To be able to render this type of information as XHTML, we will be using the Hippo Site Toolkit. The Hippo Site Toolkit uses the concept of mapping  JCR nodes to simple Java beans, to be able to have an easier development cycle without having to learn the entire JCR API.

A Java bean representation of the JCR 'myproject:text' nodetype will look like this:

import org.hippoecm.hst.content.beans.Node; 

import org.hippoecm.hst.content.beans.standard.HippoDocument;
import org.hippoecm.hst.content.beans.standard.HippoHtml;


@Node(jcrType="myproject:text")
public class TextBean extends HippoDocument{

    public String getTitle() {
        return getProperty("myproject:title");
    }
    
    public String getAuthor() {
        return getProperty("myproject:author");
    }

    public HippoHtml getBody(){
        return getHippoHtml("myproject:body");
    }

}

As you can see the Java bean is quite straight forward and easy to read.
Now if we want to render the information on a webpage, we can use for instance JSP's with expression language to get the information from the Java bean. The JSP needed for outputting the RDFa enabled webpage can be as simple as this:

<%@ page language="java" %>
<%@ taglib uri="http://www.hippoecm.org/jsp/hst/core" prefix='hst'%>
<html>
  <body xmlns:dc="http://purl.org/dc/elements/1.1/"> 
    <h1 property="dc:title">${document.title}</h1>
    <h2 property="dc:creator">${document.author}</h2>
    <hst:html hippohtml="${document.body}"/>
  </body>
</html>
As you can see it's that easy to use RDFa inside your website if you have a template independent CMS like Hippo.

It gets even better

Using RDFa for simple text can already be a great improvement for you website, but support for other RDFa vocabularies is added on a regular basis. Google recently announced support for RDFa enabled pages with videos (or media) on them. You can provide extra information for your media files to the Google crawler, like the url to the thumbnail that belongs to your video, which can be presented when your video is found as one of the results in a search performed at Google. The possibilities are enormous, so I can see a lot of good things coming from using RDFa in the near future.

I think the role that content management systems can have for RDFa should not be underestimated, since most website these days are backed by some sort of content management system.

For more information on RDFa see:

15 September 2009

Apache Cocoon and Javascript minification

A couple of days ago somebody on the Apache Cocoon user list send a message to the mailing-list about on the fly minification of for instance Javascript files. This topic has been quite popular over the past years, since web application have become richer and Javascript files have become larger.

The ideal situation would be to compres your static files (CSS or Javascript) at build time, so this will not cost you any processing power, when your application is already running. I myself quite often use the Maven 2 YUI compressor plugin while building my projects, but in case you can't use this plugin you could think about a different solution. Since I've been using Cocoon for over more then 5 years, I thought I gave it another try and write a nice Cocoon reader that does this minification for you.

There are multiple minification and obfuscation frameworks out there. One has a greater compression ratio then the other, but for me the most well know ones are probably:
  1. Dojo Shrinksafe - Rhino based compressor from the Dojo Toolkit
  2. YUI Compressor - Rhino based compressor by Yahoo
  3. JSMin - a whitespace compressor by Douglas Crockford
Since Apache Cocoon comes with a version of Rhino and both #1 and #2 have their own version of Rhino included, this could end up having nasty conflicts because of two different versions of the library on the same classpath. Therefore I chose to write a reader based on JSMin, which does a lot of whitespace compression for you.

The implementation of this reader was quite simple and if you're interested, you can get the source here. Do keep in mind that you will have to have the JSMin.java file also on the classpath, otherwise it wil not work.

07 August 2009

Japanese and Java resource bundles

At Hippo we have a project, which is build with Java Server Faces, for which I occasionally do some maintenance. A while ago I had an issue in our JIRA bug tracker that reported an error for the Japanese version of the website. The error came from a component that reads information from a resource bundle properties file, which is stored on the local filesystem. In this case from the Japanese version of the resource bundle (ApplicationResource_jp.properties), which is used by the web application to display some Japanese labels.

The error wasn't very clear since it only gave the following exception:

java.util.MissingResourceException:
Can't find resource for bundle java.util.PropertyResourceBundle, key 'somekey'


Looking in my project, I could clearly see that the resource bundle was there and after a quick peek at the resource bundle file itself, I could see that the requested key was also present.

After trying some different options I came to the conclusion that my web application was unable to read the actual .properties file from the classpath. By searching some more, I found out that the Java compiler and other Java tools can only process files which contain Latin-1 and/or Unicode-encoded (\udddd notation) characters. Since I was seeing Japanese characters when opening the properties file, it was clearly the case that this file did not meet those requirements.

Solving this issue was quite simple in the end, since the Sun JDK comes with a utility to help you out with files that contain characters, which are not Latin1. The utility is called: 'native2ascii' and can be run from the command-line quite easily by typing:

$ native2ascii [inputfile] [outputfile]

Once I did that the application was working like a charm again!

10 June 2009

JCR: Sorting on child node properties

A JCR repository, like Apache Jackrabbit (basis for Hippo CMS 7's content repository), mainly consists of nodes and properties.
As described in the JCR specification, a Java Content Repository should support 2 different query syntaxes: XPath and SQL. Once you get the hang of the syntax, performing a search on a JCR repository is quite easy, but today I came into a situation where I was not able perform the query I wanted. In this post I'll try to describe what my problem was and how the same result can still be achieved.

The content model


Let's first start with my content model. The actual node definition for my project looks something like the below:


[myproject:metadata]
- myproject:creator (string)
- myproject:language (string)
- myproject:publicationDate (date)
- myproject:availableUntil (date)
- myproject:lastModified (date)
- myproject:keywords (string)
- myproject:contributor (string)

[myproject:news] > hippostd:publishable, hippostd:publishableSummary, hippo:document
- myproject:title (string)
+ myproject:introduction (hippostd:html)
+ myproject:body (hippostd:html)
+ myproject:metadata (myproject:metadata)


I came into a situation where I wanted to search for nodes of type 'myproject:news', but sorted on the 'myproject:publicationDate' property of the 'myproject:metadata' subnode. Writing an XPath for such a query is quite easy if you're familiar with the XPath syntax.

Let's start out with a very simple search and just search for nodes of the type 'myproject:news' , which in XPath looks like:


//element( *, myproject:news)


Now if we would want to order these node types based on for instance the myproject:title property the same XPath query looks like:


//element( *, myproject:news) order by @myproject:title descending


Now if we would want to sort on the 'myproject:publicationDate' property of the myproject:metadata subnode, I would expect the same XPath to be:


//element( *, myproject:news) order by myproject:metadata/@myproject:publicationDate descending


Unfortunately this query did not seem to actually sort the result on the publicatenDate property as I would have expected. I was searching for typos first, but it appeared that the syntax of my query was ok, but it appeared that support for child axis in order by clauses was not yet supported by Jackrabbit itself.

Then I found this JIRA issue[1] in the Jackrabbit bugtracker describing this problem and there appears to be a patch available. I'm still wondering how much of a performance impact this might have for large repositories, where you might want to sort on a property of a child node 'n'-levels deep underneath the actual node.

If you want to sort on properties of a specific nodetype, you will have to add the sortable properties to the actual nodetype, which you are searching for and can't put them on a subnode.
It seems that the patch, which should fix this problem, has already been comitted to the Jackrabbit trunk and should be available from Jackrabbit 1.6.0 as marked in the JackRabbit JIRA.

25 May 2009

Mozilla lightning in Ubuntu Jaunty

I just did a fresh install of Ubuntu Jaunty Jackalope(9.04). After reinstalling Thunderbird (my favorite mail client), I was unable to see my Google calendars with Thunderbirds Lightning extension.

The Lightning extension seemed to work, since I saw a calendar, but I was unable to actually add one of my existing calendars.

Google gave me a quick answer, which was located at the ubuntu forums.

To fix this a couple of simple steps needed to be taken:

First remove the Lightning extension from Thunderbird: Tools->Addons, select Lightning, and uninstall. Close Thunderbird.

Now install libstdc++5:

$ sudo apt-get install libstdc++5

Now open Thunderbird again, and go back to Tools->Addons. Click the 'Install' button, and browse to the extension file, lightning-0.9-tb-linux.xpi - and open it. At the Software Installation prompt, click 'Install Now' after the short countdown, restart Thunderbird.

Once Thunderbird has been restarting you should be able to add your calendars again.

30 April 2009

Eclipse plugins

I've been using Eclipse as my main IDE the past couple of years. Eclipse by itself is great for Java development, but you can do so much more with it then just that. One of the biggest advantages I think Eclipse has, is that there are so many plugins available for it.

I recently added a couple of new plugins to my default set of Eclipse plugins, which you might like.

Resource bundle editor


The ResourceBundle editor plugin for eclipse allows you to easily edit the resource bundles in your project. It can give you a very nice overview of all the available values for a key in your resource bundles.


JCR explorer


Recently Sandro Boehme was so kind to create a version of his JCR Browser plugin to be able to connect with Hippo Repository.


It's a nice Eclipse plugin, which allows you to browse the Hippo JCR repository based on Apache Jackrabbit. It's a view only plugin, but it can be very usefull just to have some insight on what kind of information is in your repository.


Hudson plugin


The Hudson Eclipse plugin ,created by Joakim Recht, allows you to monitor the build status of your projects from within Eclipse.
This plugin allows you to see the current build status and console output. You can also trigger your builds from within Eclipse, which makes it quite a handy little addition to your development environment.

30 March 2009

Apache Camel: open source integration framework

I'm currently working on a project where we are looking at creating an integration layer for external applications to connect to our back-end applications. In our case, one of the back-end applications is Hippo CMS 7's repository.

I've been reading up on ESB's like Apache ServiceMix and Synapse, but even though both projects look very interesting, they actually are a bit too much for what I want to do. There was one project though that seems to be exactly what I want: Apache Camel.

About Apache Camel

Apache Camel is an open source Java framework that focuses on making integration easier. One of the great things is that Camel comes with a lot of default components and connectors.
Even though I was quite new to the integration concept, I was able to get my first Camel project up and running within 30 minutes or so, which I think is quite fast. You only need is a bit of Java/Spring knowledge to get going.

The basic concepts

While using an integration framework like Camel, you will have to keep four key terms in mind:

  • Endpoint: where the message comes in or leaves the integration layer
  • Route: how a message goes from endpoint A to endpoint B
  • Filter: the chained components that are involved in the process of handling a message that comes from endpoint A and goes to endpoint B. It could be that the content of the message needs to be transformed from SOAP to for instance ATOM.
  • Pipe: the way the message travels from endpoint A through filters to endpoint B

One of the things I'm looking at Camel for is using it to convert RSS feed entries into JCR nodes. If I would create an endpoint diagram, which would describe my route, it would look something like the image below.


With Camel, the endpoints and routes can be configured in a few lines of Java code or with Spring XML configuration. I started out with the Spring XML configuration and it was actually quite easy to get going. Here is an example where I poll my own RSS feed and store the items into a mock 'feeds' object.
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://camel.apache.org/schema/spring
http://camel.apache.org/schema/spring/camel-spring.xsd">

  <camelContext xmlns="http://camel.apache.org/schema/spring">
    <route>
      <from uri="rss://http://blog.jeroenreijn.com/feeds/posts/default?alt=rss" />
      <to uri="mock:feeds"/>
    </route>
  </camelContext>

</beans>

As you can see that's just a couple of lines of code. It's really that simple to do things in Camel. Of course this configuration does not end up in a JCR repository, but as an example I think it's quite easy to grasp. For those of you, that want to play around with Camel as well, I'll try to explain all the step I took to get a working web application example from here on. As I'm using Maven2 for building my projects, you should be able to reproduce my setup quite easily.

Setting up your maven project

First off we'll start with adding the camel dependencies to our maven project descriptor( pom.xml).
<dependencies>
  <dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-core</artifactId>
    <version>${camel-version}</version>
  </dependency>
  <dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-spring</artifactId>
    <version>${camel-version}</version>
  </dependency>
  <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-core</artifactId>
    <version>${spring-version}</version>
  </dependency>
  <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-web</artifactId>
    <version>${spring-version}</version>
  </dependency>
  <dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-rss</artifactId>
    <version>${camel-version}</version>
  </dependency>
</dependencies>
As you can see I explicitly added the camel-rss component, so that my camel application knows how to handle rss feeds. Camel does not have it's own RSS parser, but is using Rome in the background for handling the RSS feeds. The Camel project is setup in such a way that you can include any component you want, by adding the needed component dependency to your pom.xml. If you're thinking about using Camel, make sure you checkout the components page, which shows you all of the currently available components.

Camel uses Spring, so we need to add the Spring ContextLoaderListener to the local web.xml in src/main/webapp/WEB-INF/.
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">

  <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>
</web-app>
The last step in our process is defining our endpoints. In my case I chose to use the Spring XML configuration for defining my endpoints.

Add a file called applicationContext.xml to your src/main/webapp/WEB-INF/ folder.
Once the file is created you should be able to define your routes like this:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://camel.apache.org/schema/spring
http://camel.apache.org/schema/spring/camel-spring.xsd">

  <camelContext xmlns="http://camel.apache.org/schema/spring">
   <route>
     <from uri="rss://http://blog.jeroenreijn.com/feeds/posts/default?alt=rss" />
     <to uri="mock:feeds"/>
  </route>
</camelContext>

</beans>
In this example I'm using my own RSS feed, but you can of course use any feed url you like.
For testing purposes you can add a log4j.properties file in src/main/resources/, so you can see the output of the Camel RSS component in your console. Here is the configuration I used writing this blogpost.


# The logging properties used for eclipse testing, We want to see debug output on the console.
log4j.rootLogger=INFO, out

log4j.logger.org.apache.camel=DEBUG

# uncomment the following line to turn on ActiveMQ debugging
# log4j.logger.org.springframework=INFO

# CONSOLE appender not used by default
log4j.appender.out=org.apache.log4j.ConsoleAppender
log4j.appender.out.layout=org.apache.log4j.PatternLayout
log4j.appender.out.layout.ConversionPattern=[%30.30t] %-30.30c{1} %-5p %m%n




Well that's it. Now the only thing you will need to do is fire up an application container, like Jetty and see what's going on in the console.

$ mvn jetty:run

If Jetty is running and everything is setup correctly you should be able to see some debug information come by that looks like:


SyndFeedImpl.author=noreply@blogger.com (Jeroen Reijn)
SyndFeedImpl.authors=[]
SyndFeedImpl.title=Jeroen Reijn
SyndFeedImpl.description=
SyndFeedImpl.feedType=rss_2.0
SyndFeedImpl.encoding=null
SyndFeedImpl.entries[0].contributors=[]


As you will see the RSS feed is parsed and converted into a SyndFeed object.
From there on you can make use of this object and perform any operation on it.

I must admit that while playing around with Camel and RSS feeds,
I noticed that the RSS (and Atom) component did not handle extra request parameters correctly, so I added a patch in the Camel JIRA, hoping it wil be included in the next release of Camel.
If you have issues with the RSS component and request parameters, you might want to try to build the Camel SVN trunk and apply my patch (CAMEL-1496).
This is only necessary if you want to parse a feed that has for instance a unique id as request parameter added to the feed URL.

We'll that's it! This post will get a follow-up, where I will show you have to use Camel to actually store the RSS feed entries into a JCR repository.

Here are a couple of good articles too read before starting with Camel:

This blogpost was inspired by an article over at Gridshore, where Jettro wrote a post on using Spring Integrations as integration framework. Since I'm pretty much Apache minded, I have been looking around for other open source integration frameworks within the ASF, which brought me to Apache Camel.

24 March 2009

Attended the Maven and Lucene Meetup

Since I'm not able to attend the actual ApacheCon conference days I decided to join some of the pre-conference meetups.

On monday evening I joined Jasha and some other fellow Hippos to the Maven meetup, were I was hoping to hear some new and interesting stuff. Maven has been one of my default development tools for over more then 3 years.This was the first time I actually met other users and developers from the Maven community. I think there were around 40 people at the meetup and some interesting topics came along.

Carlos Sanchez talked about the effort they're putting in the "Eclipse IAM" project over at the Eclipse foundation. I just recently started using the m2eclipse plugin in my Eclipse IDE, which seems to suite my needs, but the Eclipse IAM plugin looked really interesting. Towards the end of the Maven meetup Jasha and I left for a chat with Grzegorz Kossakowski. It was good seeing you again Grzegorz!

Tuesday evening was an evening packed with interesting meetups, but unfortunately they were all at the same time. In the end I went to the Lucene Meetup, where I stayed until 21.30. It was good to see so many people (60+) at the meetup and after an introduction round it was nice to found out that other open source content management vendors were also present at the meetup.

I was especially interested in the talks about Solr. Most of the attendees were Solr users as far as I could see. After some presentations the attendees started asking questions and talking about the number of documents in their Lucene/Solr indexes and I was a bit blown away by the amount of documents some of them had in their lucene index. It ranged from 300.000 to tens of millions, which is really a lot. For me, from a content management perspective, I really wondered what kind of content it was and I would love to see that amount of content in our CMS.

Well that was my ApacheCon for this year. I'm curious too see where the ApacheCon Europe will be held next year. Hope to see you all next year...

22 March 2009

This week: ApacheCon Europe 2009

This week is ApacheCon Europe week. I'm afraid I won't be able to attend any sessions during the actual conference, but I am going to attend some of the meetup sessions on Monday and Tuesday evening.
For those of you that are attending the conference, I can say that the program looks really promising and has a lot to offer.

If you're attending the ApacheCon on Thursday, be sure to check out Niels's talk on "Documentation: get it right!"

Using Daemon modules with Hippo CMS 7

Recently I was working on a new Hippo CMS 7 based project, where I was in need of a repository component that could run in the background and perform some scheduled tasks.

While talking to some colleagues about what I had to do, they pointed me to a build-in solution for adding repository components, which are initiated at startup.

It was actually very simple to implement this feature, so I'll try to describe how you can achieve the same solution in some very small steps.

The first thing you will need to do is create a Java class that implements the DaemonModule interface. As an example I've created the BackgroundModule as shown below.

package com.example.repository;

import javax.jcr.RepositoryException;
import javax.jcr.Session;

import org.hippoecm.repository.ext.DaemonModule;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class BackgroundModule implements DaemonModule{

  static final Logger log = LoggerFactory.getLogger(BackgroundModule.class);
  static Session session = null;

  public void initialize(Session session) throws RepositoryException {
    this.session = session; 
    log.info("BackgroundModule started"); 
  }

  public void shutdown() {
    session.logout();
  }

}



You might wonder how the repository knows about these daemon modules? Well the trick is that the repository goes through all 'MANIFEST.MF' files, which it can find on the classpath. If the MANIFEST.MF file contains an entry for the property 'Hippo-Modules', it will be added to the list of available modules. Once finished finding all modules it will start to initialize each of them and pass on an authorized JCR session, so you will be able to work with all information inside the repository.

I'm always using Maven 2 while working with CMS 7. Maven 2 has some usefull utilities and it can help you you out with adding the correct manifest entry. In my pom.xml I added some configuration for the maven-jar-plugin that adds my module to the manifest.

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-jar-plugin</artifactId>
  <configuration>
    <archive>
      <manifest>
        <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
      </manifest>
      <manifestEntries>
        <Hippo-Modules>com.example.repository.BackgroundModule</Hippo-Modules>
      </manifestEntries>
    </archive>
  </configuration>
</plugin>


If you need to add more then one module, you can do so by adding a space in between modules.

For the project I was doing, I also made use of Quartz triggers, so my module would execute once in a while instead of just after initialization of the repository.

The concept of these modules is quite powerful, so I hope this can help you to get started with writing your own Daemon modules.

Update

The above article describes the situation back in 2009. With the recent release of Hippo CMS 7.8 there is a slightly different way of creating these modules. For more information see the repository managed components page in the hippo documentation.

21 March 2009

Welcome to my new Blog

Well all my content has been migrated to Blogger and the default skin is gone. Goal for tomorrow is writing a new blog post on Daemon modules for Hippo Repository.

16 February 2009

Using Apache Commons FileUpload

I'm currently working on a project that required me to upload some files from a JSP driven web application. A quick Google search brought me to Apache Commons FileUpload. It's a very useful library, that if used correctly makes you're life a lot easier.

Once adding the dependency to my Maven 2 pom.xml and looking at the user guide, I expected it to work straight away, but unfortunately it didn't and I was not really sure why. My piece of code seemed to halt when trying to execute the following method:

List items = upload.parseRequest(request);


My friend Google was unable to provide me with the correct answer (that's why I'm writing it down now), but after a while I figured out what the problem was. The problem was: me not reading the documentation. On that same user guide page it states:


FileUpload depends on Commons IO, so make sure you have the version mentioned on the dependencies page in your classpath before continuing.


So in the end it was just another dependency. Not sure why it did not throw an error though, but after adding it to my pom.xml it worked like a charm.