OpenTranqueraFramework SourceForge.net Logo
Home
Features
Skin definition
Examples
Processor
Xkins Forms
Velocity
Struts
JSF
Downloads

Template processor architecture

XkinProcessor is the façade to Xkins framework. XkinsProcessor process templates content using a class that implements TemplateProcessor interface. Xkins framework comes with a built-in template processor that implements this interface, and you can also write your own TemplateProcessor.

Implementing your own TemplateProcessor

You can implement your own template processor. All you need is to implement TemplateProcessor interface and declare it to be used in processor tag in xkin-definition file.
Xkins bundle comes with an implementation of Velocity templates, so you can use Velocity's templates in xkin-definition file and use xkins capabilities for extend skins and organize paths and resources.
You are free to implement all template processors as you want in any output format (not only HTML), for example, PDF processors, XLS or Microsoft DOC processors, or a template for generating images on the fly.

This diagram shows TemplateProcessor hierarchy:

A template processor can also implement a event notification interface (XkinsEventListener) in order to receive Xkins event if needed.

Velocity template processor:

This is the recomended processor for an enterprise scale application. This processor process templates written in VTL language (see Velocity home page for more information).
All you need to know is that templates parameters are passed to this template and Skin's resources are passed as variables too, but with "res_" prefix.
Alse you can use req, res, app and session objects and Xkins variable bodyContent.
For example, you can refer to a Skin resource from a Velocity Template like this: $res_spacer, assuming that resource name is spacer.
This processor implements a TemplateLoader and create and caches Velocity templates in a lazy fashion. Some metrics shows that VelocityTemplateProcessor is 100% faster than Xkins own Template processor. Of course, this performance can still be improved and contributions are welcomed.
It also implements XkinsEventListener to clear template's cache when xkins are reloaded.

Xkins own template processor:

The default processor transforms template content replacing parameters and resources properly in runtime. You can use this processor if tou don't want to use Velocity Template processor for whatever reason you have.
When writing template content, you can include parameters and resources. Parameters and resources are defined in the following way:

Properties:
${pro:propertyName}
where propertyName is the property to be replaced at runtime by its value.

Resources:
${res:resourceName}
where resourceName is the resource to be replaced at runtime. Resouces can be Constants or Elements. A resource has a getData method that is used by the TemplateProcessor to render the value. When a resource is a Constant, constant value is rendered. If Element is the resource, a string generated by "skin url + path url + element url" is rendered.

Built-in commands:
${jsp:parameter}
jsp command allows template creator access to context page in runtime, without the need to explicitly pass this values as parameters. The parameter can be:

  • bodyContent, gets taglib body content.
  • request(attrName), gets attrName attribute from request.
  • session(attrName), gets attrName attribute from session.
  • application(attrName), gets attrName attribute from servlet context

This TemplateProcessor uses a cache schema that stores processed content if template has only static and fixed resources. You can add more commands to this processor by implementing Command interface and declaring it to be used by processor. For example, you could create an i18n command that takes a key and write the ResourceBundle result according to user's locale.



Print version | Download | Powered by SourceForge.net