001package org.kuali.ole.sys.batch; 002 003import org.apache.commons.lang.StringUtils; 004import org.apache.log4j.Logger; 005 006/** 007 * The specification for lines which are split by delimiters before being populated into objects 008 */ 009public class DelimitedFlatFileSpecification extends AbstractFlatFilePrefixSpecificationBase { 010 private static final Logger LOG = Logger.getLogger(DelimitedFlatFileSpecification.class); 011 private String delimiter; 012 013 /** 014 * Splits the line based on the given delimiter and parses into properties 015 * @see org.kuali.ole.sys.batch.FlatFileSpecification#parseLineIntoObject(FlatFilePrefixObjectSpecification, String, Object) 016 */ 017 public void parseLineIntoObject(FlatFileObjectSpecification parseSpecification, String lineToParse, Object parseIntoObject, int lineNumber) { 018 String[] lineSegments = StringUtils.splitPreserveAllTokens(lineToParse, delimiter); 019 for (FlatFilePropertySpecification propertySpecification : parseSpecification.getParseProperties()) { 020 try { 021 propertySpecification.setProperty(lineSegments[((DelimitedFlatFilePropertySpecification) propertySpecification).getLineSegmentIndex()], parseIntoObject, lineNumber); 022 } 023 catch (ArrayIndexOutOfBoundsException e) { 024 LOG.debug("Unable to set property " + propertySpecification.getPropertyName() + " since lineSegmentIndex does not exist for line"); 025 } 026 } 027 } 028 029 /** 030 * Sets the delimiter to split on 031 * @param delimiter the delimiter to split the substring on 032 */ 033 public void setDelimiter(String delimiter) { 034 this.delimiter = delimiter; 035 } 036}