Class FormatFilter
- java.lang.Object
-
- org.pentaho.reporting.engine.classic.core.filter.FormatFilter
-
- All Implemented Interfaces:
Serializable
,Cloneable
,DataFilter
,DataSource
,DataTarget
,RawDataSource
- Direct Known Subclasses:
DateFormatFilter
,NumberFormatFilter
public class FormatFilter extends Object implements DataFilter, RawDataSource
The base class for filters that format data. Data is received from a DataSource and formatted. The data source might be a field in the TableModel or a report function, or even another format filter (since filters implement the DataSource interface). Formating is done by a java.text.Format object. This filter will always return a String object on getValue(). If the formater does not understand the object returned by the defined datasource, the defined null value is returned. The nullValue is set to "-" by default.- Author:
- Thomas Morgner
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description FormatFilter()
Default constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description FormatFilter
clone()
Clones the filter.DataSource
getDataSource()
Returns the data source for the filter.FormatSpecification
getFormatString(ExpressionRuntime runtime, ReportElement element, FormatSpecification formatSpecification)
Returns information about the formatstring that was used to transform a raw-value into a formatted text.Format
getFormatter()
Returns the format for the filter.String
getNullValue()
Returns the string representing a null value from the data source.Object
getRawValue(ExpressionRuntime runtime, ReportElement element)
Returns the unformated raw value.Object
getValue(ExpressionRuntime runtime, ReportElement element)
Returns the formatted string.protected void
invalidateCache()
Clears all cached values and forces a complete recomputation of all formattings.void
setDataSource(DataSource ds)
Sets the data source.void
setFormatter(Format format)
Sets the format for the filter.void
setNullValue(String nullvalue)
Sets the value that will be displayed if the data source supplies a null value.
-
-
-
Method Detail
-
invalidateCache
protected void invalidateCache()
Clears all cached values and forces a complete recomputation of all formattings.
-
setFormatter
public void setFormatter(Format format)
Sets the format for the filter.- Parameters:
format
- The format.- Throws:
NullPointerException
- if the given format is null
-
getFormatter
public Format getFormatter()
Returns the format for the filter.- Returns:
- The format.
-
getValue
public Object getValue(ExpressionRuntime runtime, ReportElement element)
Returns the formatted string. The value is read using the data source given and formated using the formatter of this object. The formating is guaranteed to completly form the object to an string or to return the defined NullValue. If format, datasource or object are null, the NullValue is returned.- Specified by:
getValue
in interfaceDataSource
- Parameters:
runtime
- the expression runtime that is used to evaluate formulas and expressions when computing the value of this filter.element
-- Returns:
- The formatted value.
-
setNullValue
public void setNullValue(String nullvalue)
Sets the value that will be displayed if the data source supplies a null value.- Parameters:
nullvalue
- The string.
-
getNullValue
public String getNullValue()
Returns the string representing a null value from the data source.- Returns:
- The string.
-
getDataSource
public DataSource getDataSource()
Returns the data source for the filter.- Specified by:
getDataSource
in interfaceDataTarget
- Returns:
- The data source.
-
setDataSource
public void setDataSource(DataSource ds)
Sets the data source.- Specified by:
setDataSource
in interfaceDataTarget
- Parameters:
ds
- The data source.
-
clone
public FormatFilter clone() throws CloneNotSupportedException
Clones the filter.- Specified by:
clone
in interfaceDataSource
- Specified by:
clone
in interfaceDataTarget
- Overrides:
clone
in classObject
- Returns:
- a clone.
- Throws:
CloneNotSupportedException
- this should never happen.
-
getRawValue
public Object getRawValue(ExpressionRuntime runtime, ReportElement element)
Description copied from interface:RawDataSource
Returns the unformated raw value. Whether that raw value is useable for the export is beyond the scope of this API definition, but providing access toNumber
orDate
objects is a good idea.- Specified by:
getRawValue
in interfaceRawDataSource
- Parameters:
runtime
- the expression runtime that is used to evaluate formulas and expressions when computing the value of this filter.- Returns:
- the raw data.
-
getFormatString
public FormatSpecification getFormatString(ExpressionRuntime runtime, ReportElement element, FormatSpecification formatSpecification)
Description copied from interface:RawDataSource
Returns information about the formatstring that was used to transform a raw-value into a formatted text. Not all elements will make use of a format-string. These elements will return.classic.core.filter.FormatSpecification#TYPE_UNDEFINED
in that case.- Specified by:
getFormatString
in interfaceRawDataSource
- Parameters:
runtime
- the Expression runtime used to possibly compute the raw-value.element
- the element to which this datasource is added.formatSpecification
- the format specification (can be null). @return a filled format specififcation. If theformatSpecification
parameter was not null, this given instance is reused.
-
-