Custom page tokens

Livesite has silently introduced a new feature that could be very helpfull: custom page tokens. Documentation for it is non-existing (and this seems to be a trend at Autonomy. In the Interwoven area documentation was never its strongest point but since Autonomy has taken over the situation has gone worse.)

Page tokens are a well known and documented feature of Livesite. They are used to insert text into the resulting HTML, like livesite-links (URL_PREFIX) or xpath-values (MODEL). This feature is now extended so that you can write your own custom page tokens. Here is how to:

First, add a section like to to TeamSite\local\config\lib\content_center\livesite_customer_src\etc\conf\livesite_customer\resources\customer-resource-config.xml::

<entry key="SAMPLE_TOKEN">
<value>com.interwoven.livesite.external.runtime.example.PageTokenVariableSample</value>
</entry>

in which the key is the name of the token (without the $-prefix!) and the value is your (custom) class that implements the token.

Second, create the class:

public class PageTokenVariableSample extends PageTokenVariable
{
/**
* {@inheritDoc}
*/
public void init(BaseRequestContext context)
{
super.init(context);
// Do additional initialization here or remove this method if there if none
}

/**
* {@inheritDoc}
*/
public void preRender(BaseRequestContext context)
{
super.preRender(context);

// Do additional pre-rendering here or remove this method if there if none
}

/**
* {@inheritDoc}
*/

public void render(PrintWriter writer, BaseRequestContext context) throws Exception
{
// Do some work here
writer.print("$"+mTokenName+" has been replaced with this text");
}
}

Note that the result of the init-method is cached by livesite. Any parameters can be found in the inherited String ‘mParameter’.

Run build.bat and you are ready to go.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s