Start page
Start page

Start page / Template development / Template syntax / Data types / Map

Map data typeAvailable from FirstSpirit Version 4.0

Value range of the Map data type

Elements of the template development can be grouped in:

FirstSpirit provides the Map data type for the processing/editing of values which represent a set of key value pairs. This data type enables grouping of elements represented by a set of unique key values (keys) to which specific contents (values) are assigned. Any number of key value pairs can be created within a map object. The values are always accessed via the key.

The data type Link can also be looked up in the Sun API documentation:

java.util.Map

Definition

Maps can be generated via { } (curly brackets). The following syntax must be fulfilled:

MAP := '{' EXPRESSION ':' EXPRESSION [',' EXPRESSION ':' EXPRESSION ]* ] '}'

The following code example generates an empty map and assigns the variable "map" to it:

  $CMS_SET(map, { })$

If a filled map is to be generated, i.e. a map which already contains key value pairs, these are passed as a comma-separated list within the curly brackets. The key and value are separated by a ':'. The following code example generates a new, file map "map" with the key "name" and the value "mustermann":

 $CMS_SET(map, {"name":"Mustermann", "firstname":"Heinz"})$

Access to map values

The map values are accessed solely via assigned key values whereby each of the following expressions is valid and returns the given output:

$CMS_VALUE(map.get("name"))$
$CMS_VALUE(map.name)$
$CMS_VALUE(map["name"])$
Output:
Mustermann

The following code example iterates across all elements of the map and outputs all available key value pairs:

$CMS_FOR(mapWrapper,map)$
$CMS_VALUE(mapWrapper)$
$CMS_END_FOR$
Output:
mapWrapper:name=Mustermann
mapWrapper:firstname=Heinz

Methods on map objects

The table below lists all methods which can be invoked on objects of data type "Map":

The object is generated by the following form objects:
FS_BUTTON
Method name Return type Brief description Available since
clear void
compareTo(Comparable) int
containsKey(Object) boolean
containsValue(Object) boolean
entrySet Set
equals(Object) boolean
get(Set) Set
get(Collection) List
get(String) Object Value of a key
get(Object) Object
getClass Class Class of the invoking object
hashCode int
isCase(Object) boolean 4.2.14
isEmpty boolean Checks whether an expression is empty
isNull boolean Checks whether an expression is null (zero)
keySet Set
print void
put(Object, Object) Object
putAll(Map) void
remove(Object) Object
set(String, Object) Object
set(Object, Object) Map
size int Number of the key/value pair
toJson String Convert to JSON string representtion (only handles Maps, Collections, Arrays, Numbers, and Strings) 4.2.14
toString String
type String
values Collection

clear

Method name Return type Available since
clear void

compareTo(Comparable)

Method name Return type Available since
compareTo(Comparable) int

containsKey(Object)

Method name Return type Available since
containsKey(Object) boolean

containsValue(Object)

Method name Return type Available since
containsValue(Object) boolean

entrySet

Method name Return type Available since
entrySet Set

equals(Object)

Method name Return type Available since
equals(Object) boolean

get(Set)

Method name Return type Available since
get(Set) Set

get(Collection)

Method name Return type Available since
get(Collection) List

get(String)

A map contains key/value pairs. The .get(String) method can be used to determine the value of the transferred key.

If a map contains the following key/value pairs:

1st pair: key="Max", value="Mustermann"
2nd pair: key="Franz", value="Meier"
3rd pair: key="Peter", value="Müller"

results in the invocation

MAP.get("Franz")

for return of a character string (cf. java.lang.String ) with the content

Meier
Method name Return type Available since
get(String) Object

get(Object)

Method name Return type Available since
get(Object) Object

getClass

The .getClass() (in Bean syntax: .class) method returns the class of the invoking object (cf. java.lang.Class).

Invocation:

$CMS_VALUE(myString.class)$
$CMS_VALUE(myString.getClass())$

Output:

java.lang.String
Method name Return type Available since
getClass Class

hashCode

Method name Return type Available since
hashCode int

isCase(Object)

Method name Return type Available since
isCase(Object) boolean 4.2.14

isEmpty

The .isEmpty() (in Bean syntax: .isEmpty) method checks whether an expression or object is empty, e.g. storeElement.isEmpty(). The result of the semantic check depends on the expression or object, e.g. a character string is empty if it does not contain any characters. In the case of objects with complex values or objects the object decides when it is empty. The data type DomElement for example always contains an empty document, thus it is never null. For this reason, checking an empty DOM editor input component by using the method .isNull() returns the value false, whereas checking the component with .isEmpty() would return the value true.

The method returns a Boolean value as the check result. true is the check result if the expression or object is empty and false if not.

Method name Return type Available since
isEmpty boolean

isNull

The .isNull() (in Bean syntax: .isNull) method checks whether an expression or object is null , e.g. storeElement.isNull(). In the case of objects with complex values or objects, the object decides when it is null. The data type DomElement for example always contains an empty document, thus it is never null. For this reason, checking an empty DOM editor input component by using the method .isNull() returns the value false, whereas checking the component with .isEmpty() would return the value true.

The method .isNull() returns a Boolean value as the check result. true is the check result if the expression or object is null and false if not.

Method name Return type Available since
isNull boolean

keySet

Method name Return type Available since
keySet Set

print

Method name Return type Available since
print void

put(Object, Object)

Method name Return type Available since
put(Object, Object) Object

putAll(Map)

Method name Return type Available since
putAll(Map) void

remove(Object)

Method name Return type Available since
remove(Object) Object

set(String, Object)

Method name Return type Available since
set(String, Object) Object

set(Object, Object)

Method name Return type Available since
set(Object, Object) Map

size

The .size() (in Bean syntax: .size) method returns the number of the key/value pair in a map.

The returned object is an integer (see java.lang.Integer).

Method name Return type Available since
size int

toJson

Convert to JSON string representtion (only handles Maps, Collections, Arrays, Numbers, and Strings)
Method name Return type Available since
toJson String 4.2.14

toString

Method name Return type Available since
toString String

type

Method name Return type Available since
type String

values

Method name Return type Available since
values Collection

© 2005 - 2015 e-Spirit AG | All rights reserved. | Last change: 2013-11-13