} else {
return false;
}
}
};
FilterIterator segmentIter = new FilterIterator(messageIter, segmentsOnly);
String[] segments = split(string, segDelim);
char delim = '|';
for (int i = 0; i < segments.length; i++) {
//get rid of any leading whitespace characters ...
if (segments[i] != null && segments[i].length() > 0 && Character.isWhitespace(segments[i].charAt(0)))
segments[i] = stripLeadingWhitespace(segments[i]);
//sometimes people put extra segment delimiters at end of msg ...
if (segments[i] != null && segments[i].length() >= 3) {
final String name;
if (i == 0) {
name = segments[i].substring(0, 3);
delim = segments[i].charAt(3);
} else {
if (segments[i].indexOf(delim) >= 0 ) {
name = segments[i].substring(0, segments[i].indexOf(delim));
} else {
name = segments[i];
}
}
log.debug("Parsing segment {}", name);
messageIter.setDirection(name);
FilterIterator.Predicate byDirection = new FilterIterator.Predicate() {
public boolean evaluate(Object obj) {
Structure s = (Structure) obj;
log.debug("PipeParser iterating message in direction {} at {} ", name, s.getName());
return s.getName().matches(name + "\\d*");
}
};
FilterIterator dirIter = new FilterIterator(segmentIter, byDirection);
if (dirIter.hasNext()) {
parse((Segment) dirIter.next(), segments[i], getEncodingChars(string));
}
}
}
}