How to create an SSP Template

Requirements

 Be sure that you have the following software installed:

Objective

In this tutorial you will learn how to create a template and add your own style information to the cms (e.g. css, image icons etc.).

Setting up a CMS project

 To setup your project we have created an archetype for a standard cms module (in OSGi it is called bundle). Therefore do the following steps:

  1. hg clone http://scm.trialox.org/main/org.clerezza.cms.archetype org.clerezza.cms.archetype 
  2. open a shell/terminal and go into the created folder "org.clerezza.cms.archetype" (you could also open the archetype in your IDE)
  3. run mvn clean install, which installs the archetype into your maven repository
  4. go to a folder where you want to create your new project
  5. run mvn archetype:generate -DarchetypeCatalog=local
  6. choose the archetype "org.clerezza.cms.archetype-archetype"
  7. and follow the steps on the screen

A new project should be created. For this tutorial we have created a project with the following information:

  • groupId = org.clerezza
  • artifactId = org.clerezza.example
  • version = 1.0-SNAPSHOT
  • package = org.clerezza.example

Add a new template

If you have successfully finished the steps above you just have created a cms bundle. This bundle could be used to implement a own business logic and web services. In the next sections we explain now how to add a template to your bundle.

  1. go to your preferred IDE (we are using NetBeans)
  2. open the created project in the IDE
  3. open the Java class JaxRsResource.java

First we have a look at the activate method. This method will be executed while the bundle is starting.

setupStaticWeb(componentContext);

ResourceFinder resourceFinder = new ResourceFinder(componentContext, getClass());


URL templateURL = resourceFinder.find("example-page.ssp");
renderletManager.registerRenderlet(ScalaServerPagesRenderlet.class.getName(),
	new UriRef(templateURL.toString()), SIOC.Forum,
	null, MediaType.APPLICATION_XHTML_XML_TYPE, true);

templateURL = resourceFinder.find("example-widget.ssp");
renderletManager.registerRenderlet(ScalaServerPagesRenderlet.class.getName(),
	new UriRef(templateURL.toString()), SIOC.Post,
	"naked", MediaType.APPLICATION_XHTML_XML_TYPE, true);

The setupStaticWeb method retrieves css, javascripts or images within the staticweb folder (is a sub folder of src/main/resources/[packagename]/) and exposes it via web under the class url (e.g. "/enter-your-url/foo/"). The ResourceFinder retrieves template urls from the bundle, which will be used for the registration of the templates: The templates are also registered in the "activate" method. An Alternative to register templates would be via the web application renderlets (/admin/renderlets).
registerRenderlet method has 6 arguments:

  1. the Renderlet  (normally we are using the ScalaServerPagesRenderlet).
  2. the UriRef of the template
  3. the RDF type of the template
  4. mode this allows to register an alternative template for a specific rdf type (e.g. a template from RDF type Page has an additional mode "edit", where the Page can be edited)
  5. MediaType of the template
  6. Built-In For the same RDF type, MediaType and mode at most one built-in and one non-built-in renderlet can be registered. An attempt to register a second renderlet results in the unregistration of the previously registered one

We are now creating a new SSP Template. Therefore we have to add a template into the folder "src/main/resources/[packagename]/" and register the template as explained above. We suggest to create a template for rendering information about a person. For this case we are using the foaf ontology (http://xmlns.com/foaf/spec/).

  1. create a new file in the folder "src/main/resources/org/clerezza/example/" called person-page.ssp
  2. register this template with RDF type Person (you have to import the foaf ontology, which is available in the org.apache.clerezza.rdf.ontologiesproject)
 templateURL = resourceFinder.find("person-page.ssp");
renderletManager.registerRenderlet(ScalaServerPagesRenderlet.class.getName(),
	new UriRef(templateURL.toString()), FOAF.Person,
	null, MediaType.APPLICATION_XHTML_XML_TYPE, true);

Now we add html and scala snippets (http://www.scala-lang.org/) to the template. Using scala in an xml (or xhtml) is allowed but must be within curly brackets. "res" is a so called GraphNode, which is in this case the person points to its properties like name.

def rdfs(s: Any) = new UriRef("http://www.w3.org/2000/01/rdf-schema#"+s)
def foaf(s: Any) = new UriRef("http://rdfs.org/sioc/ns#"+s)

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head><title></title></head>
<body>
<div>Hi { res/foaf("name")* }
</div>
</body>

Add demo data (TODO)

To test the template we have 2 alternatives:

  1. Upload demo data via upload form (/graph/upload-form) or
  2. add demo data via bundle

Labels

 
(None)