Skip to content

Home

Development

IDEs

API Explorer

Releases

Release notes

Martini Runtime

Martini Desktop

Martini Online

Feature requests

Bug reports

GroovyMethods

The GroovyMethods class contains a bunch of one-liner methods for:

Below are the methods that make up the GroovyMethods class.

getApplicationProperty

Use any of these two methods to get an application property from the list of configured Martini application properties:

  • GroovyMethods.getApplicationProperty(String)
  • GroovyMethods.getApplicationProperty(String, String)

Parameters

Name Index Type Description
key 0 java.lang.String The name of the application property to get
defaultValue 1 java.lang.String The return value if the application property does not exist

Return value

Name Type Description
output java.lang.String The value of the application property; defaultValue if not found

Usage

Sample `getApplicationProperty` usage

1
2
3
4
5
6
// Gets value of the 'http.port' property of the Martini instance
def port = 'http.port'.getApplicationProperty()

// Gets the value of the 'default.format' property of the Martini instance
// If the 'default.format' property could not be found, return the value 'json' instead
def format = 'default.format'.getApplicationProperty('json')

getPackageProperty

Use any of these two methods to get the value of a package property belonging to the Martini package in the current thread context:

  • GroovyMethods.getPackageProperty(String)
  • GroovyMethods.getPackageProperty(String, String)

Parameters

Name Index Type Description
key 0 java.lang.String The name of the package property to get
defaultValue 1 java.lang.String The return value if the package property does not exist

Return value

Name Type Description
output java.lang.String The value of the package property; defaultValue if not found

Usage

Sample `getPackageProperty` usage

1
2
3
4
5
6
// Gets the value of the 'email' package property
def email = 'email'.getPackageProperty()

// Gets the value of the 'email' package property
// If the 'email' property could not be found, return the value 'default@email.com' instead
def email = 'email'.getPackageProperty('default@email.com')

getPackagePropertyArray

Use any of these two methods to get the array value of a package property belonging to the Martini package in the current thread context:

  • GroovyMethods.getPackagePropertyArray(String)
  • GroovyMethods.getPackagePropertyArray(String, String)

Parameters

Name Index Type Description
key 0 java.lang.String The name of the package property to get
defaultValue 1 java.lang.String[] The return value if the package property does not exist

Return value

Name Type Description
output java.lang.String[] The array value of the package property; defaultValue if not found

Usage

Sample `getPackagePropertyArray` usage

1
2
3
4
5
6
// Gets the value of the 'email.addresses' property as an array
def email = 'email.addresses'.getPackagePropertyArray()

// Gets the value of the 'formats' property as an array
// If 'formats' could not be found, return the array ['json', 'xml'] instead.
def formats = 'formats'.getPackagePropertyArray('json,xml')

getPackagePropertyComment

Use the method GroovyMethods.getPackagePropertyComment(String) to get the comment of an existing package property. The property must belong to the Martini package in the current thread context.

Parameters

Name Index Type Description
key 0 java.lang.String The name of the package property whose comment must be fetched

Return value

Name Type Description
output java.lang.String The package property's comment

Usage

Sample `getPackagePropertyComment` usage

1
2
// Gets the 'name' package property's comment
def name = 'name'.getPackagePropertyComment()

removePackageProperty

Use this method to remove a package property from the list of configured package properties owned by the current thread context's Martini package.

Parameters

Name Index Type Description
key 0 java.lang.String The name of the package property which will be removed

Return value

Name Type Description
output java.lang.String The package property's value before it got removed

Usage

Sample `removePackageProperty` usage

1
2
3
// Remove the 'name' property from the list of package properties
// And return its last cofigured value
def name = 'name'.removePackageProperty()

savePackageProperty

Use this method to add a new package property or edit the value of an existing package property. The affected Martini package will be the Martini package of the current thread context.

Parameters

Name Index Type Description
key 0 java.lang.String The name of the property to add or edit
value 1 java.lang.String The new value of the package property

Return value

Name Type Description
output java.lang.String The added or edited package property's new value

Usage

Sample `savePackageProperty` usage

1
2
3
// Set the 'name' package property's value to 'Bob'
// And return its newly configured value
def name = 'name'.savePackageProperty('Bob')

savePackagePropertyComment

Adds a comment to an existing package property or edits its previously configured comment. Only the Martini package of the current thread context will be affected.

Parameters

Name Index Type Description
key 0 java.lang.String The name of the package property where comment will be added to
comment 1 java.lang.String The comment to be added

Usage

Sample `savePackagePropertyComment` usage

1
2
// Sets the 'name' package property's comment to 'The name of the recipient'
'name'.savePackagePropertyComment('The name of the recipient')

  1. Or in simpler terms, the Martini package the script running the code belongs to.