Extensions Wiki » Extensions » Velocity Module

Velocity Module

Last modified by Eduard Moraru on 2014/08/12 16:19
cogAdds support for Velocity scripting
TypeJAR
Developed by

XWiki Development Team

LicenseGNU Lesser General Public License 2.1
Bundled With

XWiki Enterprise, XWiki Enterprise Manager

Compatibility

XWiki 3.0M3+

Description

You can also check the XWiki Platform Developer's Guide for information about Velocity scripting in the XWiki Platform

This module offers APIs to evaluate content with Velocity.

The following concepts are exposed:

  • VelocityEngine: This is the object on which you call evaluate()
  • VelocityConfiguration: Default Velocity configuration. Sets default configuration parameters and default tools (see below)
  • VelocityContextFactory: Allows to create Velocity Context. Context are used when evaluating in order to expose some variable to the script content
  • VelocityFactory: Allows to create several VelocityEngine based on a key you defined. For example XWiki Platform uses this to have one VelocityEngine per Skin. This allows each Skin to provide its own set of Velocimacros.
  • VelocityContextInitializer: Allows to callback components that implements this Role when VelocityFactory is called to create a new Velocity Context. This allows your code to automatically bind new variables in the Velocity Context.

To see more of the API read the Velocity Module Javadoc

Velocity Tools

For security reasons we're not exposing some APIs to Velocity scripting (such as Reflection or Threading APIs). In addition Velocity is a template language and doesn't have the full support a complete development language has (for example you cannot instantiate new classes or you cannot handle exceptions just to name 2). Thus we need to offer some Tools (i.e. API) that are meant to be used from Velocity to make it easy to create powerful scripts in Velocity code.

The following Velocity tools are made available:

See more available variables at XWiki Scripting Reference Documentation

Velocity Uberspectors

The introspection behaviour in Velocity can be customized by implementing an uberspector. Velocity supports by default only one uberspector. To overcome this limitation we have implemented an uberspector that forwards all calls to a chain of uberspectors.

Method Arguments Uberspector

A chainable uberspector that tries to convert method arguments to formal parameter types when the passed arguments don't match the method signature. In other words, it looks for a method matching the passed arguments and if none is found then it tries the convert the arguments to match the available method signatures (the available methods with the same name and the same number of parameters but with different parameter types). E.g.:

$obj.someMethod('VALUE')
// will forward to
obj.someMethod(SomeEnum.VALUE)
// if obj has a method with signature someMethod(SomeEnum) and not someMethod(String)

But this is not limited to enums. The conversion is done using the Properties Module which means you can create and register custom converters for data types specific to your application domain.

Tags:
Created by Marius Dumitru Florea on 2012/04/04 17:20

Download XWiki

Get Connected