<< April 2009 | Home | June 2009 >>

Adding an OSGi command (Equinox)

Extending the OSGi runtime

Adding OSGi commands using spring-osgi:

<osgi:reference id="utilities" interface="net.sourceforge.pebble.util.Utilities" />

<osgi:service interface="org.eclipse.osgi.framework.console.CommandProvider">
<bean class="net.sourceforge.pebble.commands.PebbleCommandProvider" autowire="constructor" />
</osgi:service>
The OSGi console command is implemented by the PebbleCommandProvider. Configuration is reduced to a bare minimum using Spring DI (constructor autowire).
public class PebbleCommandProvider implements CommandProvider {

private final Utilities utilities;
private final BlogManager blogManager;

public Object _reindex(CommandInterpreter commandInterpreter) {
String blogName = commandInterpreter.nextArgument();
if (blogName == null) {
blogName = "default";
}
utilities.buildIndexes(blogManager.getBlog(blogName));
return null;
}

public String getHelp() {
StringBuffer buffer = new StringBuffer();
buffer.append("---pebble commands---\n\t");
buffer.append("reindex [blogName] - reindex a blog\n");
return buffer.toString();
}
}

code

A sample OSGi session:

osgi> help
---pebble commands---
reindex [blogName] - reindex a blog
---Eclipse Runtime commands---
...

The tale of a sitemesh experiment

using sitemesh in an OSGi environment

Two sitemesh resources

Paul Codding's blog entry: 'Spring, Hibernate, and Sitemesh'
SiteMesh - Building SiteMesh Decorators

Weaving sitemesh into pebble

Add the sitemesh PageFilter into WEB-INF/web.xml:
<filter>
<filter-name>sitemesh</filter-name>
<filter-class>
com.opensymphony.module.sitemesh.filter.PageFilter
</filter-class>
</filter>

<filter-mapping>
<filter-name>sitemesh</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
Prepare the pebble template.jsp is as easy as replacing the built-in template mechanism
<%-- the main area into which content gets rendered --%>
<div id="content">
<template:content/>
</div>
with the sitemesh pendant:

<%@ taglib uri="http://www.opensymphony.com/sitemesh/decorator" prefix="decorator" %>
...
<div class="docBody">
<decorator:body />
</div>
And register the template.jsp as main decorator in WEB-INF/decorators.xml:
<decorators defaultdir="/themes/default">
<decorator name="main" page="template.jsp">
<pattern>/*</pattern>
</decorator>
</decorators>

The OSGi configuration in MANIFEST.MF

com.springsource.com.opensymphony.sitemesh;bundle-version="2.3.0"