Start page
Start page

Start page / Template development / Template syntax / Expressions / Method invocations

Method invocations

In general the algorithms assigned to a class of objects are called methods. The term “Method” is frequently used as a synonym for “Function”. However, in the template syntax of FirstSpirit the two terms stand for different actions.

  • Methods are directly invoked on a context object. These include, for example, access to attributes of a complex data type (picture.width) or even certain string operations (element.toString()).
  • Functions on the other hand are not invoked on an object and are only executed once on generation of a page (so-called header functions).

Method invocation syntax

EXPRESSION := VARIABLE | POINT_EXPRESSION '.' [ IDENTIFIER | METHODINVOCATION ]
METHODINVOCATION  := IDENTIFIER '(' PARAMETER_LIST ')'
PARAMETER_LIST := EXPRESSION [',' EXPRESSION]*

In FirstSpirit, method invocations can be given both in Java and in Bean syntax notation.

With the Bean syntax notation, the get and () of the method name can be omitted. In addition, the first letter after the get in the method name is written in lower case, e.g. getLanguage() => language, getMultiPageParams() => multiPageParams, etc.

For the method invocation $CMS_VALUE(#global.getEncoding())$ for example, $CMS_VALUE(#global.encoding)$ can also be used.

Important The Bean syntax notation should not be used in the method invocations of the system object #row as this can cause overlapping with the column names of the table.

Method invocations without return value

Methods can return a value as the result of a calculation or can execute code only without returning a return value.

If a method does not return a value, the unspecified data type void is given instead of the return parameter.

Method example:

void doSomething()

Method invocations with return value

If a method returns the result of a calculation as a value the data type of the return parameter is given before the method identifier.

Method example:

 java.lang.String toString()

  • Return parameter of data type java.lang.String.
  • Method identifier: toString
  • Parameter list: “empty”

Method invocation example:

$CMS_SET(myVar, 42.toString())$
Return value: $CMS_VALUE(myVar)$
Class: $CMS_VALUE (myVar.class())$

The method invocation toString converts the numerical value “42” into a character string and returns the character string '"42"' of String data type as the result. The return value is stored in the variable “myVar”:

Output:

Return value: 42
Class: java.lang.String

Method invocations without parameter transfer

Methods can pass (transfer) parameters which can be accessed within the method execution. If a method does not require a transfer parameter empty brackets () are appended.

Method example:

java.lang.Class getClass()

  • Return parameter of data type java.lang.Class.
  • Method identifier: getClass
  • Parameter list: “empty”

Method invocation example:

$CMS_SET(myVar, 42)$
Return value: $CMS_VALUE (myVar.getClass())$

The method invocation getClass returns the data type of variable “myVar” as the result.

Output:

Return value: java.math.BigInteger

Method invocations with parameter transfer

In method invocations with parameter transfer, parameters are transferred (passed) within the brackets ( ). Several parameters are passed as a comma-separated list.

Method example:

java.lang.String replaceAll (java.lang String, java.lang.String)

  • Return parameter of data type java.lang.String.
  • Method identifier: replaceAll
  • Parameter list: java.lang String, java.lang.String

Method invocation example:

$CMS_SET(myText, "That is a short character string.")$
Return value: $CMS_VALUE (myText.replaceAll("short", "great"))$

The method invocation replaceAll replaces a sub-character string (Parameter 1) with a second transferred character string (Parameter 2) and returns the original character string with the replacements as the result.

Output:

Return value: That is a great character string.

APIdoc method

The apiDoc method can be used to output all available methods in the context of existing objects. I.e. the return values of the method can be used to determine which attributes or methods are available on an object.

Method invocation example:

apiDoc(global)

Parameter: This is either:

  • an object (in this case global) which must be available within the context (e.g. global, global.page, ...), or
  • a class which was determined using .class.

Return value: The method returns a list of objects of type ApiMethodWrapper as a result. The following invocation can be used to determine which methods are made available by ApiMethodWrapper:

$CMS_FOR(m, apiDoc(class("de.espirit.firstspirit.parser.impl.ApiDocMethod$ApiMethodWrapper")))$
$CMS_VALUE(m)$
$CMS_END_FOR$

Output: all documented, available methods of the class ApiMethodWrapper:

java.lang.String getComment()
Boolean getDeprecated()
java.lang.String getMethodName()
java.lang.Class getReturnType()
java.lang.Class[] getSignature()
java.lang.String getSince()
java.util.List getVersions()

© 2005 - 2015 e-Spirit AG | All rights reserved. | Last change: 2011-12-06