Functions

As covered in the Configuration section, Calyxo supports the use of EL expressions in attributes of configuration elements. Static methods of a class may be registered as EL functions with the <functions> element.

Standard Functions

The de.odysseus.calyxo.base.misc.StandardFunctions class provides the JSTL standard functions as defined in the JSTL 1.1 specification.

The class has to be registered using the <functions> element as follows:

<base:functions
  prefix="fn"
  class="de.odysseus.calyxo.base.misc.StandardFunctions"/>

Example

The expression ${fn:split('foo/bar','/')} evaluates to string array ["foo","bar"].

Module Functions

The de.odysseus.calyxo.base.misc.ModuleFunctions class provides module-related functions.

The class has to be registered using the <functions> element as follows:

<base:functions
  prefix="module"
  class="de.odysseus.calyxo.base.misc.ModuleFunctions"/>

Having this, the following functions are available in dynamic attribute expressions:

  • attribute(ModuleContext module, String name) – Answer the value of the specified module scope attribute
  • initParameter(ModuleContext module, String name) – Answer the value of the specified module init parameter
  • path(ModuleContext module, String action) – Answer the context-related path for the specified action

Example

The expression ${module:attribute(moduleContext,'foo')} evaluates to the module attribute at key "foo".

Type Functions

The de.odysseus.calyxo.base.misc.TypeFunctions class provides functions to convert between several Java types.

The class has to be registered using the <functions> element as follows:

<base:functions
  prefix="type"
  class="de.odysseus.calyxo.base.misc.TypeFunctions"/>

Having this, the following functions are available in dynamic attribute expressions:

  • toByte(Object) – convert to java.lang.Byte (accepts numbers and strings)
  • toShort(Object) – convert to java.lang.Short (accepts numbers and strings)
  • toInteger(Object) – convert to java.lang.Integer (accepts numbers and strings)
  • toLong(Object) – convert to java.lang.Long (accepts numbers and strings)
  • toFloat(Object) – convert to java.lang.Float (accepts numbers and strings)
  • toDouble(Object) – convert to java.lang.Double (accepts numbers and strings)
  • toBigDecimal(Object) – convert to java.math.BigDecimal (accepts numbers and strings)
  • toCharacter(Object) – convert to java.lang.Character (accepts strings of length 1)
  • toString(Object) – convert to java.lang.String (accepts any object)
  • toDate(Object) – convert to java.util.Date (accepts strings)

Example

The expressions ${type:toInteger(123)} and ${type:toInteger('123')} both evaluate to a java.lang.Integer with value 123.