View Javadoc
1   package org.kuali.ole.sys.batch;
2   
3   import org.apache.commons.lang.StringUtils;
4   import org.apache.log4j.Logger;
5   
6   /**
7    * The specification for lines which are split by delimiters before being populated into objects
8    */
9   public class DelimitedFlatFileSpecification extends AbstractFlatFilePrefixSpecificationBase {
10      private static final Logger LOG = Logger.getLogger(DelimitedFlatFileSpecification.class);
11      private String delimiter;
12  
13      /**
14       * Splits the line based on the given delimiter and parses into properties
15       * @see org.kuali.ole.sys.batch.FlatFileSpecification#parseLineIntoObject(FlatFilePrefixObjectSpecification, String, Object)
16       */
17      public void parseLineIntoObject(FlatFileObjectSpecification parseSpecification, String lineToParse, Object parseIntoObject, int lineNumber) {
18          String[] lineSegments = StringUtils.splitPreserveAllTokens(lineToParse, delimiter);
19          for (FlatFilePropertySpecification propertySpecification : parseSpecification.getParseProperties()) {
20              try {
21                  propertySpecification.setProperty(lineSegments[((DelimitedFlatFilePropertySpecification) propertySpecification).getLineSegmentIndex()], parseIntoObject, lineNumber);
22              }
23              catch (ArrayIndexOutOfBoundsException e) {
24                  LOG.debug("Unable to set property " + propertySpecification.getPropertyName() + " since lineSegmentIndex does not exist for line");
25              }
26          }
27      }
28  
29      /**
30       * Sets the delimiter to split on
31       * @param delimiter the delimiter to split the substring on
32       */
33      public void setDelimiter(String delimiter) {
34          this.delimiter = delimiter;
35      }
36  }