View Javadoc
1   package org.kuali.ole.sys.batch;
2   
3   import java.util.List;
4   
5   import org.springframework.util.StringUtils;
6   
7   /**
8    * The abstract base class of the configuration element which specifies how to parse flat files
9    */
10  public abstract class AbstractFlatFilePrefixSpecificationBase extends AbstractFlatFileSpecificationBase {
11      protected List<String> insignificantPrefixes;
12      protected int prefixStartingPosition = 0;
13  
14      /**
15       * This method determine the class of the given line. It checks the prefix list to see if the line started with what ever the
16       * prefix of the line and returns the class; if not , it returns the default class.
17       * @param line the line to determine the class of
18       * @see org.kuali.ole.sys.batch.FlatFileSpecification#determineClassForLine(String)
19       */
20      public Class<?> determineClassForLine(String line) {
21          if (line != null) {
22              if (objectSpecifications != null && !objectSpecifications.isEmpty()) {
23                  for (FlatFileObjectSpecification objectSpecification : objectSpecifications) {
24                      final FlatFilePrefixObjectSpecification prefixObjectSpecification = (FlatFilePrefixObjectSpecification)objectSpecification;
25                      String prefix = prefixObjectSpecification.getLinePrefix();
26                      if ((prefix != null) && (line.length() >= (prefixStartingPosition + prefix.length())) && 
27                              (line.substring(prefixStartingPosition, prefixStartingPosition + prefix.length()).equals(prefix))) {
28                          return objectSpecification.getBusinessObjectClass();
29                      }
30                  }
31              }
32              if (insignificantPrefixes != null && !insignificantPrefixes.isEmpty()) {
33                  for (String insignificantPrefix : insignificantPrefixes) {
34                      if ((line.length() >= (prefixStartingPosition + insignificantPrefix.length())) && 
35                              line.substring(prefixStartingPosition, prefixStartingPosition + insignificantPrefix.length()).
36                              equals(insignificantPrefix)) {
37                          return null; // don't return any class for an insignificant prefix
38                      }
39                  }
40              }
41              return defaultBusinessObjectClass;
42          }
43  
44          return null;
45      }
46  
47      /**
48       * Sets the list of prefixes which mean that the line is not to be parsed
49       * @param insignificantPrefixes
50       */
51      public void setInsignificantPrefixes(List<String> insignificantPrefixes) {
52          this.insignificantPrefixes = insignificantPrefixes;
53      }
54  
55      /**
56       * Determines where the starting position in the String to look for the prefix substring is; if not set, defaults to 0, the beginning of the String
57       * @param prefixStartingPosition the starting position in the String of the prefix substring
58       */
59      public void setPrefixStartingPosition(int prefixStartingPosition) {
60          this.prefixStartingPosition = prefixStartingPosition;
61      }
62  }