1 /*
2 * The Kuali Financial System, a comprehensive financial management system for higher education.
3 *
4 * Copyright 2005-2014 The Kuali Foundation
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as
8 * published by the Free Software Foundation, either version 3 of the
9 * License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
15 *
16 * You should have received a copy of the GNU Affero General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19 package org.kuali.kfs.sys.batch;
20
21 /**
22 * Concrete extension of AbstractFlatFilePrefixSpecificationBase which can handle the parsing of lines where substrings
23 * are parsed by knowing the beginning and ending position of the substring
24 */
25 public class FixedWidthFlatFileSpecification extends AbstractFlatFilePrefixSpecificationBase {
26 /**
27 * Parses a line by pulling out substrings given by the FlatFilePropertySpecification configuration objects passed in
28 * @see org.kuali.kfs.sys.batch.FlatFileSpecification#parseLineIntoObject(FlatFilePrefixObjectSpecification, String, Object)
29 */
30 @Override
31 public void parseLineIntoObject(FlatFileObjectSpecification parseSpecification, String lineToParse, Object parseIntoObject, int lineNumber) {
32 // loop through the properties to format and set the property values
33 // from the input line
34 for (FlatFilePropertySpecification propertySpecification : parseSpecification.getParseProperties()) {
35 int start = ((FixedWidthFlatFilePropertySpecification) propertySpecification).getStart();
36 int end = ((FixedWidthFlatFilePropertySpecification) propertySpecification).getEnd();
37 // if end is not specified, read to the end of line
38 if (end == 0) {
39 end = lineToParse.length();
40 }
41 String subString = lineToParse.substring(start, end);
42 propertySpecification.setProperty(subString, parseIntoObject, lineNumber);
43 }
44 }
45 }