001package org.kuali.ole.sys.batch;
002
003/**
004 * Concrete extension of AbstractFlatFilePrefixSpecificationBase which can handle the parsing of lines where substrings
005 * are parsed by knowing the beginning and ending position of the substring
006 */
007public class FixedWidthFlatFileSpecification extends AbstractFlatFilePrefixSpecificationBase {
008    /**
009     * Parses a line by pulling out substrings given by the FlatFilePropertySpecification configuration objects passed in
010     * @see org.kuali.ole.sys.batch.FlatFileSpecification#parseLineIntoObject(FlatFilePrefixObjectSpecification, String, Object)
011     */
012    public void parseLineIntoObject(FlatFileObjectSpecification parseSpecification, String lineToParse, Object parseIntoObject, int lineNumber) {
013        // loop through the properties to format and set the property values
014        // from the input line
015        for (FlatFilePropertySpecification propertySpecification : parseSpecification.getParseProperties()) {
016            int start = ((FixedWidthFlatFilePropertySpecification) propertySpecification).getStart();
017            int end = ((FixedWidthFlatFilePropertySpecification) propertySpecification).getEnd();
018            // if end is not specified, read to the end of line
019            if (end == 0) {
020                end = lineToParse.length();
021            }
022            String subString = lineToParse.substring(start, end);
023            propertySpecification.setProperty(subString, parseIntoObject, lineNumber);
024        }
025    }
026}