1 /*
2 * Copyright 2011 The Kuali Foundation.
3 *
4 * Licensed under the Educational Community License, Version 1.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.opensource.org/licenses/ecl1.php
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package org.kuali.ole.sys.batch;
17
18 /**
19 * A flat file specification which matches lines via regular expressions and parses them via flat files
20 */
21 public class FixedWidthFlatFileRegexSpecification extends AbstractRegexSpecificationBase {
22
23 /**
24 * Parses the given line into the given object to parse into
25 * @param parseSpecification the specification of the parsing
26 * @param lineToParse the line to parse into the object
27 * @param parseIntoObject the object to parse into
28 */
29 public void parseLineIntoObject(FlatFileObjectSpecification parseSpecification, String lineToParse, Object parseIntoObject, int lineNumber) {
30 // loop through the properties to format and set the property values
31 // from the input line
32 for (FlatFilePropertySpecification propertySpecification : parseSpecification.getParseProperties()) {
33 int start = ((FixedWidthFlatFilePropertySpecification) propertySpecification).getStart();
34 int end = ((FixedWidthFlatFilePropertySpecification) propertySpecification).getEnd();
35 // if end is not specified, read to the end of line
36 if (end == 0) {
37 end = lineToParse.length();
38 }
39 String subString = lineToParse.substring(start, end);
40 propertySpecification.setProperty(subString, parseIntoObject, lineNumber);
41 }
42 }
43
44 }