views:

71

answers:

1

Question

What generic and extensible solutions exist to convert a data file to fixed-width file?

The data file format can be CSV, XML, or plain text, as exported by JasperReports.

Background

The fields are listed as follows:

Field #  Field Name  Format   Type  Size  Required
1        Customer    RJ/ZF    N     1     Y
2        Account     RJ/SF    N     5     Y
3        Location    LJ/SF    AN    10    Y
4        Agreement   YN       A     1     Y
...
55       Election    CCYYMMDD N     8     N

Where: RJ is Right Justified, ZF is Zero Filled, SF is Space Filled, YN is Y or N, N is numeric-only, A is alphabetic, and AN is alpha-numeric.

Each field has a specific start and end position in the record and each record exists on a single line.

Ideas

1st solution:

  1. Export the data file in XML format.
  2. Codify the 55 fixed-width definitions in XML.
  3. Create an XSL template to transform the data file to the fixed-width file.

2nd solution:

  1. Use JRecord with JasperReports.

3rd solution:

  1. Codify each field using a Java expression inside the JRXML template.

Commentary

Of these solutions, I prefer the 1st.

Any other possibilities? Any software that can perform this task?