net.sf.anupam.csv.formatters package
Provides a framework and default implementations for formatting CSV fields during
the CSV to POJO parsing. The framework is configurable and can be extended if
the default formatters are not sufficient.
In most usage situations, no formatting is required on the CSV fields during parsing,
and data formatting can be performed on the source CSV data itself.
However, minor formatting is necessary in certain circumstances, e.g.,
when only part of a CSV field value needs to be mapped to a POJO attribute. Common
examples include extracting the first name from a full name, or changing the
case of the input string value. This functionality is enabled by this package.
Default Formatters
The following formatters are present in the default system. The declarative formatter
name is in brackets. Details on each formatter is present in the respective
class' documentation.
- {@link net.sf.anupam.csv.formatters.DoNothingFormatter DoNothingFormatter} (none)
- {@link net.sf.anupam.csv.formatters.DoNothingFormatter firstWordFormatter} (firstWord)
- {@link net.sf.anupam.csv.formatters.DoNothingFormatter lastWordFormatter} (lastWord)
- {@link net.sf.anupam.csv.formatters.DoNothingFormatter AllUpperCaseFormatter} (AllUpperCase)
Configuration of Formatters
The formatters are registered into the CSV parser framework via the
csv-formatter-config.xml XML file. The file defines the
logical formatter name, and the formatter implementation class name.
Custom Formatters
Customer formatters can be created by implementing the
{@link net.sf.anupam.csv.formatters.CSVFieldFormatter CSVFieldFormatter}
interface, and its sole method: String format(String) . This method
acts as the transformation/formatting implementation. It is recommended that
the custom formatters be stateless and provide re-entrant implementations.
Once the custom formatters are defined, they can be registered in the
Framework by updating the csv-formatter-config.xml configuration file.
A custom Xdoclet template/tagset is provided for ease of
generating the configuration XML file.
|