Class DateFormatParser
- java.lang.Object
-
- org.pentaho.reporting.engine.classic.core.filter.FormatParser
-
- org.pentaho.reporting.engine.classic.core.filter.DateFormatParser
-
- All Implemented Interfaces:
Serializable
,Cloneable
,DataFilter
,DataSource
,DataTarget
- Direct Known Subclasses:
SimpleDateFormatParser
public class DateFormatParser extends FormatParser
Parses a String into a java.util.Date. The string is read from the given datasource and then parsed by the dateformat contained in this FormatParser.- Author:
- Thomas Morgner
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description DateFormatParser()
Creates a new 'date format parser'.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description DateFormat
getDateFormat()
Returns the format for this filter.Object
getValue(ExpressionRuntime runtime, ReportElement element)
Returns the parsed object.protected boolean
isValidOutput(Object o)
Checks whether the given value is already a valid result.void
setDateFormat(DateFormat format)
Sets the format for the filter.void
setFormatter(Format format)
Sets the format for the filter.void
setNullValue(Object nullvalue)
Sets the value that will be displayed if the data source supplies a null value.-
Methods inherited from class org.pentaho.reporting.engine.classic.core.filter.FormatParser
clone, getDataSource, getFormatter, getNullValue, setDataSource
-
-
-
-
Method Detail
-
getDateFormat
public DateFormat getDateFormat()
Returns the format for this filter. The format object is returned as DateFormat.- Returns:
- the formatter.
- Throws:
NullPointerException
- if the given format is null
-
setDateFormat
public void setDateFormat(DateFormat format)
Sets the format for the filter.- Parameters:
format
- The format.- Throws:
NullPointerException
- if the given format is null
-
setFormatter
public void setFormatter(Format format)
Sets the format for the filter. The formater is required to be of type DateFormat.- Overrides:
setFormatter
in classFormatParser
- Parameters:
format
- The format.- Throws:
NullPointerException
- if the given format is nullClassCastException
- if an invalid formater is set.
-
getValue
public Object getValue(ExpressionRuntime runtime, ReportElement element)
Description copied from class:FormatParser
Returns the parsed object. The value is read using the data source given and parsed using the formatter of this object. The parsing is guaranteed to completly form the target object or to return the defined NullValue. If the given datasource does not return a string, the returned object is transformed into a string using String.valueOf (Object) and then parsed. If format, datasource or object are null, the NullValue is returned.- Specified by:
getValue
in interfaceDataSource
- Overrides:
getValue
in classFormatParser
- Parameters:
runtime
- the expression runtime that is used to evaluate formulas and expressions when computing the value of this filter.element
- the element for which the data is computed.- Returns:
- The formatted value.
-
setNullValue
public void setNullValue(Object nullvalue)
Sets the value that will be displayed if the data source supplies a null value. The nullValue itself can be null to cover the case when no reasonable default value can be defined. The null value for date format parsers is required to be either null or a java.util.Date.- Overrides:
setNullValue
in classFormatParser
- Parameters:
nullvalue
- the nullvalue returned when parsing failed.- Throws:
ClassCastException
- if the value is no date or not null.
-
isValidOutput
protected boolean isValidOutput(Object o)
Checks whether the given value is already a valid result. IF the datasource already returned a valid value, and no parsing is required, a parser can skip the parsing process by returning true in this function.- Overrides:
isValidOutput
in classFormatParser
- Parameters:
o
- the value.- Returns:
- true, if the given value is already an instance of date.
-
-