View Javadoc
1   package org.kuali.ole.sys.batch;
2   
3   /**
4    * Concrete extension of AbstractFlatFilePrefixSpecificationBase which can handle the parsing of lines where substrings
5    * are parsed by knowing the beginning and ending position of the substring
6    */
7   public class FixedWidthFlatFileSpecification extends AbstractFlatFilePrefixSpecificationBase {
8       /**
9        * Parses a line by pulling out substrings given by the FlatFilePropertySpecification configuration objects passed in
10       * @see org.kuali.ole.sys.batch.FlatFileSpecification#parseLineIntoObject(FlatFilePrefixObjectSpecification, String, Object)
11       */
12      public void parseLineIntoObject(FlatFileObjectSpecification parseSpecification, String lineToParse, Object parseIntoObject, int lineNumber) {
13          // loop through the properties to format and set the property values
14          // from the input line
15          for (FlatFilePropertySpecification propertySpecification : parseSpecification.getParseProperties()) {
16              int start = ((FixedWidthFlatFilePropertySpecification) propertySpecification).getStart();
17              int end = ((FixedWidthFlatFilePropertySpecification) propertySpecification).getEnd();
18              // if end is not specified, read to the end of line
19              if (end == 0) {
20                  end = lineToParse.length();
21              }
22              String subString = lineToParse.substring(start, end);
23              propertySpecification.setProperty(subString, parseIntoObject, lineNumber);
24          }
25      }
26  }