Adapt Text

The Imixs WorkflowService provides the method ‘adaptText(text, document)’ which can be called when a text fragment should be adapted to a custom format or custom values.

 String result=workflowService.adaptText(text, workitem);

The Imixs WorkflowService provides the following adapter classes:

  • TextItemValueAdapter
  • TextForEachAdapter
  • TextPropertyAdapter

The adapter classes are called by the CDI observer pattern which allows to implement custom text adapters as well. See the section ‘Custom Text Adapters’ below for more details.

Adapting Item Values

The TextItemValueAdapter adapts a text fragment containing the XML tag <itemvalue> with the item value of a item. This adapter is useful if a string constant need to be updated with values from the current workitem.

For example, a BPMN mail message text can be adapted with information from the current workitem.

The invoice was generated by <itemvalue>namcreator</itemvalue> 
at <itemvalue format="EEE, MMM d, yyyy">$created</itemvalue>

This message text-block will be automatically adapted with the workitem properties ‘namcreator’ and ‘$created’ into:

The invoice was generated by Ralph 
at Wed, Jul 4, 2010

To format a number you can also use the Java standard number formating:

<itemvalue format="#,###,##0.00" locale="de_DE">price</itemvalue>

Format multi-value Items

If a item contains a multi-value list, all the values can be separated by a character sequence defined by the tag ‘separator’. For example the following message text based on an item ‘_parts’ with the values {“pants”, “shirt”, “jacket”} and a separator ', ':

The following item has been ordered: <itemvalue separator=", ">_parts</itemvalue>

will be replaced with:

The following item has been ordered: pants, shirt, jacket

Note: If no separator is defined, only the first value will be returned.

To get the last value of a multi-value list the tag ‘position’ can be set to ‘last’

The last order item was: <itemvalue position="last">_parts</itemvalue>

This example extract the last value of the mulit-value item ‘_parts’.

Format date/number values by locale

To format a date or number value into a language specific format the tags ‘format’ and ‘locale’ can be used. The following example shows how to format a date value into the German date format:

 The Date in german format is: <itemvalue format="EEEE, d. MMMM yyyy" locale="de_DE">datdate</itemvalue>.

The For-Each Adapter

The TextForEachAdapter can be used to format text fragments with the ‘for-each’ tag. The adapter will iterate over the value list of a specified item.

 <for-each item="_partid">
  Order-No: <itemvalue>_orderid</itemvalue> - Part ID: <itemvalue>_partid</itemvalue><br />
 </for-each>  

In this example, the for-each block will be executed for each single value of the item ‘_partid’. Within the for-each block it is possible to access the current value of the iteration as also any other values of the current document. The result may look like in the following example:

 Order-No: 111222 - Part ID: A123
 Order-No: 111222 - Part ID: B456

In case the item contains an embedded list of child ItemCollections the content of the for-each block will be processed in the context for each embedded ItemCollection:

 <for-each item="_orderitems">
    <itemvalue>_orderid</itemvalue>: <itemvalue>_price</itemvalue>
  </for-each>  

The result may look like in the following example:

 Order ID: A123: 50.55
 Order ID: B456: 150.10

Adapting Property Values

The TextPropertyAdapter adapts a text fragment adapts text blocks with values stored in the imixs.property file. A static message text will be automatically replaced with the values ​​from the imixs.property file if the tag “propertyvalue” is used.

Please use the following Link to open the Application: 
<propertyvalue>dbRootURL</propertyvalue>

The values from the imixs.prperties file are accessed by the PropertyService.

Custom Text Adapters

A application can extend the AdaptText method by implementing a service with the CDI Observer pattern. The CDI Event TextEvent is send to registered observers. See the following example:

@Stateless
public class CustomTextAdapter {
	// Observer method for CDI TextEvetns
	public void onEvent(@Observes TextEvent event) {
		String text = event.getText();
		text+=" Hello World";
		event.setText(text);
	}
}

Adapt a TextList

A custom adapter can also adapt a text into a text list. For example a Custom Adapter can compute a list of values based on a text pattern. The custom adapter can set the result test list with the method ‘setTextList()’. This feature is for example used from the AccessPlugin method mergeRoles. The method expects that the adapter provide a list with roles.