Creating A Decorator
An Escenic content item decorator is a Java class that:
-
Extends
neo.xredsys.presentation.PresentationArticleDecorator
-
Contains a
get
method for each content item property it is to modify
The following example shows a content item decorator that
converts a content item's title
property to upper
case:
package com.mycompany.decorators; import neo.xredsys.presentation.*; public class TitleToUpperCase extends PresentationArticleDecorator { public TitleToUpperCase(PresentationArticle pa) { super(pa); } public String getTitle() { String title = super.getTitle().toUpperCase(); return title; } }
The PresentationArticleDecorator
class
implements the PresentationArticle
interface. Since
the TitleToUpperCase
class extends
PresentationArticleDecorator
, it can be used to
override methods in the standard implementation of
PresentationArticle
. In this case, the
getTitle()
method will override the standard
PresentationArticle.getTitle()
method.
The TitleToUpperCase
constructor accepts a
PresentationArticle
bean as input parameter and
stores it in the property super
(i.e, superclass).
When a bean for a content type that is configured to use the
TitleToUpperCase
decorator is created, the
Content Engine:
-
Creates a standard
PresentationArticle
bean -
Creates a
TitleToUpperCase
bean, passing in thePresentationArticle
bean as its constructor parameter
When the article's getTitle()
method is
called, TitleToUpperCase.getTitle()
:
-
Calls
super
'sgetTitle()
method to get thetitle
property -
Calls
String.toUpperCase()
to convert the title to upper case -
Returns the result
Note the following points:
-
A decorator changes the behavior of the content item bean itself. It does not matter whether you access the
title
property via a JSP tag or in-line java - it will always be returned in upper case. -
Only the specified property is affected. If you access the title field directly via the
article:field
tag or the JavagetFieldElement()
method, then it will not be converted to upper case.
Before a decorator can be used it must be:
-
Compiled
-
Added to the web application's classpath
To compile a decorator you need the following Escenic JAR files in your classpath:
-
engine-core-5.4.7.169266.jar
-
engine-presentation-5.4.7.169266.jar
-
common-util-
n.n.n.n.jar
(replace n.n.n.n with the version number of thecommon-util
library included with the current version of the Content Engine).