Wednesday, December 28, 2011

CMIS support for Magnolia CMS

This autumn I've had the opportunity to work on implementing CMIS support in Magnolia CMS. CMIS stands for Content Management Interoperability Services and is a specification administered by OASIS. The goal is to improve interoperability between content management systems and it achieves this by defining a model representing the content in a repository and a set of services for accessing it. The services come in two flavors, SOAP Web Services and REST-style services using ATOM-format.

The first version of Magnolia to have CMIS support will be 4.5. The scope of the first release is to expose the DMS in Magnolia over CMIS. This means that you will be able to download, manipulate and store content in Magnolia and access Magnolia content in other CMIS enabled systems.

The implementation is based on OpenCMIS. An open source framework for implementing both server and client -side implementations. It's one of the libraries developed by Apache Chemistry. Of special interest to us is the server binding to JCR. OpenCMIS implements the services which delegates to a binding. We have extended the JCR binding to match the repository layout we use in Magnolia and integrated the OpenCMIS authentication mechanism to use our security model.

In the process we encountered a few things we wanted to improve to make OpenCMIS adaptable to our repository layout. We developed this and contributed patches that were accepted by the active and focused team working on OpenCMIS. As a result our implementation is quite minimal and mainly consists of mapping the CMIS model onto our JCR layout. The value of OpenCMIS is impressive, an entire stack with both SOAP and REST that only needs to know how to interact with the specifics of a JCR layout.

The source code for the Magnolia CMIS Module is publicly available as always.

Tuesday, November 22, 2011

Blossom 1.2.3 & Blossom Data Extension 1.0 Released

Today I have released version 1.2.3 of Blossom and Blossom Data Extension 1.0, an extension for using Blossom style dialogs with the Magnolia Data Module. It introduces a new annotation @DataTypeDialogFactory which is used for creating dialogs for data module types. It has the same feature set as @DialogFactory and is used in the same way.

In this release the feature set TabBuilder is expanded adding support for the multi select control, the include control and for adding any control by type. It's now also possible to get the dialog and the DialogCreationContext from the TabBuilder.

This is an example of how a dialog used for the type 'category':
public class CategoryDialog {

    public void settingsTab(TabBuilder tab) {
        tab.addEdit("name", "Name", "");
        tab.addEdit("maxResults", "Max results", "");

To use the Data Extension you need to add it to your pom.xml

Add this line to your blossom-servlet.xml or equivalent.

<bean class="" />

And if you're using classpath scanning you'll also want to add an include-filter for the new annotation.

<context:component-scan base-package="package-containing-dialogs" use-default-filters="false">
  <context:include-filter type="annotation" expression=""/>

For more details see the Blossom Data Extension wiki page.

Monday, November 7, 2011

Webinar - How US Navy used Blossom to integrate Spring Applications with Magnolia CMS

I have some exciting news to share!

As many Blossom users are already aware, Campbell Ewald used Magnolia CMS and Spring Framework for building On November 15th there will be a webinar on how they did it and how Blossom made their app integrations straightforward. It will be hosted by Campbell Ewald's Matt Dertinger, Magnolia's Sean McMains and myself.

The webinar is for Spring developers of all levels and you will learn how to develop content rich websites with Spring. It will take you through setting up your project and with examples show how Blossom solved real use cases for the navy. Matt will also show how they used it with RESTEasy and took advantage of Bean Validation (JSR-303).

Register now, I've been told it's starting to fill up already.

See you there!

The webinar recording is now online.

Sunday, May 8, 2011

Twitter and Spring Social in Magnolia

Tweets on 'summer' embedded in a page.
Integrations with social networks are everywhere. All the big social sites offer javascript widgets that you can easily drop into your pages and display things like recent tweets, facebook likes and so on. Though recently there's been some voices raised saying that these widgets sometimes don't blend nicely with the design of the rest of site. I've seen this especially on cms blogs reviewing high profile sites as they launch or relaunch with new designs.

So, last weekend I decided to find out how much work it would take to display a Twitter search using Spring Social with Blossom, the Spring integration for Magnolia CMS. Magnolia calls reusable components that you can snap into a page paragraphs. I wanted a paragraph that an author could add to any page to show relevant tweets about its topic. The author supplies the search query and the maximum number of tweets to display.On the right is the end result.

Twitter provides a RESTful API that can return JSON or ATOM. There's a lot of functionality in there and most of it requires OAuth authentication. For this example we'll do a simple search which doesn't require authentication. Spring Social offers an OAuth implementation that is compatible with Twitter and seems to be minimal effort to use. A twitter search using the API is done with a request like Spring Social uses RestTemplate and parses the response using Jackson to return plain java objects representing the tweets.

Since Blossom is an extension of Spring Web MVC that lets Spring controllers be embedded into the content of a page the twitter search paragraph is implemented as a controller. The interface provided to the author to enable filling in the search query and the maximum number of tweets is provided by Magnolia using dialogs. By adding methods in our controller and annotating them Magnolia will call them when the dialog is to be displayed and for validation when its submitted. The view for displaying the tweets is a JSP.

In the source below you'll see that Spring Social makes things really easy since it will request the Twitter API and return the tweets with just one line of code.

public class TwitterParagraph {

  public String twitter(ModelMap model, Content content) {

    String query = content.getNodeData("query").getString();
    int maxResults = Integer.parseInt(content.getNodeData("maxResults").getString());

    TwitterTemplate twitterTemplate = new TwitterTemplate();
    SearchResults searchResults = twitterTemplate.searchOperations().search(query, 1, maxResults);

    List<Tweet> tweets = searchResults.getTweets();
    model.put("query", query);
    model.put("tweets", tweets.subList(0, Math.min(tweets.size(), maxResults)));

    return "twitter";

  public void settingsTab(TabBuilder tab) {
    tab.addEdit("query", "Query", "Search phrase on Twitter");
    tab.addEdit("maxResults", "Max results", "Number of tweets to display at most");

  public void validateSettings(DialogTab tab) {
    if (!StringUtils.hasText(tab.getSub("query").getValue()))
      AlertUtil.setMessage("Query must not be empty");
    if (!NumberUtil.isPositiveInteger(tab.getSub("maxResults").getValue()))
      AlertUtil.setMessage("Max results must be a positive number");

If you haven't used Magnolia or Blossom before this screenshot might be helpful to see what the dialog presented to the author looks like. The methods annotated with @TabFactory and @TabValidator are used to provide the user interface and validate the input.

And here's the source for the view.

<div>Recently about <a href="${query}">${query}</a></div>
<ul class="tweets">
<c:forEach items="${tweets}" var="tweet">
        <div class="signature">
            <img src="${tweet.profileImageUrl}"/>
            <a href="${tweet.fromUser}">${tweet.fromUser}</a>
            <div class="date"><fmt:formatDate value="${tweet.createdAt}" pattern="d MMM HH:mm"/></div>
            <div style="clear:both;"></div>

So how much work was it? I think I spent less than an hour setting it up and writing the java code, followed by a couple of hours on the view and css to get it decent enough to show in a blog post ;-)

To try it out you need to add their milestone repository since Spring Social has still to reach its 1.0 release. Here's the maven snippets you'll need.

  <name>Spring Maven Milestone Repository</name>


Monday, March 21, 2011

Spring Web MVC with Content

The idea that sparked me writing the Blossom Module for Magnolia CMS was to bring the CMS and especially the content into Spring Web MVC not the other way around. Controllers should be the building blocks when composing pages. The latest version 1.2.2 brings a small but significant piece to the puzzle. By adding a custom WebArgumentResolver you can add content objects to the argument list in annotated handler methods.

This is an example of a paragraph that displays a contact form where the author that created the page specified which office will be receiving the filled in form. The office is fetched from a database and passed to the view where details such as its address are displayed.

public String contactForm(ModelMap model, Content page, Content paragraph) {
    model.put("office", officeDao.getOfficeById(paragraph.getNodeData("office").getString()));
    return "contactForm";

To enable it you need to add the BlossomWebArgumentResolver to your AnnotationMethodHandlerAdapter.

<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
  <property name="customArgumentResolver">
    <bean class="info.magnolia.module.blossom.web.BlossomWebArgumentResolver" />

BlossomWebArgumentResolver provides support for a few more arguments that is handy to have handed directly to your handler method. They are: AggregationState, WebContext, Context, User and MgnlUser.