$fn

Object providing a set of utility functions


Since : 2.0.3

Attributes and methods
.argumentsList(List fields) : String

Returns a string containing a list of field names separated by a comma

Parameters :
   fields : list of fields to be added in the arguments list

Example :
   $fn.argumentsList( $entity.attributes )
   Returns : 'id, firstName, lastName, age'

Since : 2.0.5

.argumentsListWithGetter(String object, List fields) : String

Returns a string containing a list of fields getters separated by a comma

Parameters :
   object : name of the object providing the getters
   fields : list of fields to be added in the arguments list

Example :
   $fn.argumentsListWithGetter( 'person', $entity.attributes )
   Returns : 'person.getId(), person.getFirstName(), person.getLastName(), person.getAge()'

Since : 2.0.5

.argumentsListWithType(List fields) : String

Returns a string containing a list of fields (type and name) separated by a comma

Parameters :
   fields : list of fields to be added in the arguments list

Example :
   $fn.argumentsListWithType( $entity.attributes )
   Returns : 'int id, String firstName, String lastName, int age'

Since : 2.0.5

.argumentsListWithWrapperType(List fields) : String

Returns a string containing a list of fields (wrapper type and name) separated by a comma

Parameters :
   fields : list of fields to be added in the arguments list

Example :
   $fn.argumentsListWithWrapperType( $entity.attributes )
   Returns : 'Integer id, String firstName, String lastName, Integer age'

Since : 3.0.0

.backslash(String s, String c) : String

Protects each occurrence of the given char with a backslash in the given string

Parameters :
   s : the string to be processed
   c : the character to be protected with a backslash

.buildIntValues(Collection collection) : List

Builds a list of N integer consecutive values starting with 1

Parameters :
   collection : the collection determining the number of values (collection size)

Example :
   #set ( $values = $fn.buildIntValues($entity.attributes) )
   Values size = $values.size()
   #foreach( $v in $values )
    . value = $v
   #end
   #set($last = ( $values.size() - 1) )
   #foreach ( $i in [0..$last] )
    . value($i) = $values.get($i)
   #end

Since : 3.0.0

.buildIntValues(Collection collection, int int) : List

Builds a list of N integer consecutive values starting with the given value

Parameters :
   collection : the collection determining the number of values (collection size)
   int : the first value of the list

Example :
   #set ( $values = $fn.buildIntValues($entity.attributes, 0) )
   Values size = $values.size()
   #foreach( $v in $values )
    . value = $v
   #end
   #set($last = ( $values.size() - 1) )
   #foreach ( $i in [0..$last] )
    . value($i) = $values.get($i)
   #end

Since : 3.0.0

.buildIntValues(int int) : List

Builds a list of N integer consecutive values starting with 1

Parameters :
   int : the number of values to be created

Example :
   #set ( $values = $fn.buildIntValues(5) ) ## 5 values from 1 to 5
   Values size = $values.size()
   #foreach( $v in $values )
    . value = $v
   #end
   #set($last = ( $values.size() - 1) )
   #foreach ( $i in [0..$last] )
    . value($i) = $values.get($i)
   #end

Since : 3.0.0

.buildIntValues(int int, int int) : List

Builds a list of N integer consecutive values starting with the given value

Parameters :
   int : the number of values to be created
   int : the first value of the list

Example :
   #set ( $values = $fn.buildIntValues(10,0) ) ## 10 values from 0 to 9
   Values size = $values.size()
   #foreach( $v in $values )
    . value = $v
   #end
   #set($last = ( $values.size() - 1) )
   #foreach ( $i in [0..$last] )
    . value($i) = $values.get($i)
   #end

Since : 3.0.0

.buildValues(List attributes, int step) : ValuesInContext

Builds a list of literal values.
Returns a list with one literal value for each attribute according with the attribute type.
e.g. : 12 for an integer, true for a boolean, 230L for a long, 'ABC' for a string, etc
Each value can be retrieved by its attribute's name, e.g. $values.getValue($attribute.name)
A list of all values separated by a comma is returned by $values.allValues
Those values are typically used to populate attributes in test cases

Parameters :
   attributes : list of attributes requiring a literal value
   step : a step (from 1 to N) used to change the values builded

Example :
   #set( $values = $fn.buildValues($entity.attributes, 1) )
   #foreach( $attribute in $entity.attributes )
    Literal value for $attribute.name : $values.getValue($attribute.name)
   #end
    All values : $values.allValues

Since : 2.1.1

.capitalize(String string) : String

Capitalizes the given string
changing the first letter to upper case

Parameters :
   string : the string to be capitalized

Example :
   $fn.capitalize($var)

Since : 2.1.0

.concatLists(List list1, List list2) : List

Concatenates 2 lists ( add all the elements of the second list at the end of the first one )
The 2 given lists remain unchanged. The result is stored in a new list.

Parameters :
   list1 : List of objects
   list2 : List of objects to be added at the end of list1

Example :
   #set ( $list3 = $fn.concatLists( $list1, $list2 )

Since : 2.0.7

.escapeXml(String s) : String

Returns the XML string for the given string
Replaces special characters (&, <, >, etc) by their corresponding XML notation

Parameters :
   s : the string to be escaped

.firstCharToUpperCase(String s) : String

Converts the first character to upper case

Parameters :
   s : the string to be converted

Since : 2.0.7

.get(String objectName, Object defaultValue) : Any kind of object

Returns the object stored with the given name in the Velocity Context
If there's no object for the given name the default value is returned

Parameters :
   objectName : the name (or key) in the Velocity Context
   defaultValue : the value to be returned if the object is not defined

Example :
   $fn.get('groupId','defaultValue')

Since : 2.1.0

.isBlank(String s) : boolean

Returns true if the given string is 'blank'
(true if the string is null or void or only composed of blanks)

Parameters :
   s : the string to be tested

Since : 2.0.3

.isDefined(String objectName) : boolean

Returns TRUE if the given object name is defined in the Velocity Context

Parameters :
   objectName : the name (or key) in the Velocity Context

Example :
   #if ( $fn.isDefined('myvar') )

Since : 2.1.0

.isNotBlank(String s) : boolean

Returns true if the given string is not 'blank'
(true if the string is not null, not void and not only composed of blanks)

Parameters :
   s : the string to be tested

.isNotVoid(Object collection) : boolean

Returns TRUE if the given List/Array is NOT VOID

Parameters :
   collection : List or Array

Example :
   #if ( $fn.isNotVoid( $entity.attributes ) )

Since : 2.0.7

.isVoid(Object collection) : boolean

Returns TRUE if the given List/Array is VOID

Parameters :
   collection : List or Array

Example :
   #if ( $fn.isVoid( $entity.attributes ) )

Since : 2.0.7

.quote(String s) : String

Adds a double quote character at the beginning and at the end of the given string

Parameters :
   s : the string to be quoted

.size(Object collection) : int

Returns the SIZE of the given List or Array

Parameters :
   collection : List or Array

Example :
   Number of attribute = $fn.size( $entity.attributes )

Since : 2.0.7

.tab : String

Returns a single tabulation character

.tab(int n) : String

Returns N tabulation characters

Parameters :
   n : the number of tabulations to be returned

.toLowerCase(String s) : String

Converts all of the characters in the given string to lower case

Parameters :
   s : the string to be converted

Since : 2.0.7

.toUpperCase(String s) : String

Converts all of the characters in the given string to upper case

Parameters :
   s : the string to be converted

Since : 2.0.7

.uncapitalize(String string) : String

Uncapitalizes the given string
changing the first letter to lower case

Parameters :
   string : the string to be uncapitalized

Example :
   $fn.uncapitalize($var)

Since : 2.1.0

.unquote(String s) : String

Removes the double quote character at the beginning and at the end of the given string (if any)
If the string is not quoted it is returned as is
If there's a quote character only at the beginning or at the end the string is returned as is


Parameters :
   s : the string to be unquoted