org.pentaho.reporting.engine.classic.core.filter
Class MessageFormatSupport

java.lang.Object
  extended by org.pentaho.reporting.engine.classic.core.filter.MessageFormatSupport
All Implemented Interfaces:
Serializable, Cloneable

public class MessageFormatSupport
extends Object
implements Serializable, Cloneable

The message format support class helps to translate named references to fields in a message format string into numeric index positions. With the help of this mapping, we can use a standard Java MessageFormat object to reference fields by their name instead of an arbitrary index position.

A field is referenced by the pattern "$(fieldname)". For additional formatting, all MessageFormat format options are available using the format "$(fieldname, <message option>)". To format a date field with the default short date format, one would use the pattern $(datefield,date,short).

Author:
Thomas Morgner
See Also:
Serialized Form

Constructor Summary
MessageFormatSupport()
          Default Constructor.
 
Method Summary
 Object clone()
          Creates a copy of this message format support object.
 String getCompiledFormat()
          Returns the compiled message format string.
 String[] getFields()
           
 String getFormatString()
          Returns the original format string that is used to format the fields.
 Locale getLocale()
          Returns the locale that is used to format the messages.
 String getNullString()
          Returns the replacement text that is used if one of the referenced message parameters is null.
 String performFormat(DataRow dataRow)
          Formats the message using the fields from the given data-row as values for the parameters.
 void setFormatString(String formatString)
          Updates the named format string and compiles a new field list and message-format string.
 void setLocale(Locale locale)
          Updates the locale that is used to format the messages.
 void setNullString(String nullString)
          Defines the replacement text that is used if one of the referenced message parameters is null.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MessageFormatSupport

public MessageFormatSupport()
Default Constructor.

Method Detail

getFormatString

public String getFormatString()
Returns the original format string that is used to format the fields. This format string contains named references.

Returns:
the format string.

setFormatString

public void setFormatString(String formatString)
Updates the named format string and compiles a new field list and message-format string.

Parameters:
formatString - the format string.

performFormat

public String performFormat(DataRow dataRow)
Formats the message using the fields from the given data-row as values for the parameters.

Parameters:
dataRow - the data row.
Returns:
the formated message.

getCompiledFormat

public String getCompiledFormat()
Returns the compiled message format string.

Returns:
the compiled message format string.

getLocale

public Locale getLocale()
Returns the locale that is used to format the messages.

Returns:
the locale in the message format.

setLocale

public void setLocale(Locale locale)
Updates the locale that is used to format the messages.

Parameters:
locale - the locale in the message format.

getNullString

public String getNullString()
Returns the replacement text that is used if one of the referenced message parameters is null.

Returns:
the replacement text for null-values.

setNullString

public void setNullString(String nullString)
Defines the replacement text that is used if one of the referenced message parameters is null.

Parameters:
nullString - the replacement text for null-values.

getFields

public String[] getFields()

clone

public Object clone()
             throws CloneNotSupportedException
Creates a copy of this message format support object.

Overrides:
clone in class Object
Returns:
the copy.
Throws:
CloneNotSupportedException - if an error occured.