CSVObjects Framework

Package net.sf.anupam.csv.formatters

Provides a framework and default implementations for formatting CSV fields during the CSV to POJO parsing.

See:
          Description

Interface Summary
CSVFieldFormatter Main Interface for a CSV field formatter.
 

Class Summary
AllLowerCaseFormatter A Formatter which transforms the input into all lower-case and returns the lower-case version.
AllUpperCaseFormatter A Formatter which transforms the input into all upper case and returns the upper case version.
CSVFormatterConfigParser XML Parser (based on Commons Digester) to parse and return the CSV formatter configuration.
CSVFormatterFactory A singleton factory which creates and caches the csv field formatters.
DoNothingFormatter A No-Op formatter that acts as the default if no explicit formatter is configured for a CSV field.
FirstWordFormatter A formatter that returns the first word of the specified CSV value.
FormatterConfiguration FormatConfiguration.
LastWordFormatter A formatter that returns the last word of the specified CSV value.
TrimWordFormatter A formatter that returns the trimmed CSV value.
 

Package net.sf.anupam.csv.formatters Description

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.

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 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.


SourceForge.net Logo

© Anupam Sengupta 2005