use of org.springframework.integration.file.filters.CompositeFileListFilter in project spring-integration by spring-projects.
the class FileListFilterFactoryBean method initializeFileListFilter.
private void initializeFileListFilter() {
if (this.result != null) {
return;
}
FileListFilter<File> createdFilter = null;
if ((this.filter != null) && (this.filenamePattern != null || this.filenameRegex != null)) {
throw new IllegalArgumentException("The 'filter' reference is mutually exclusive with " + "either the 'filename-pattern' or 'filename-regex' attribute.");
}
if (this.filenamePattern != null && this.filenameRegex != null) {
throw new IllegalArgumentException("The 'filename-pattern' and 'filename-regex' attributes are mutually exclusive.");
}
final List<FileListFilter<File>> filtersNeeded = new ArrayList<FileListFilter<File>>();
if (!Boolean.FALSE.equals(this.ignoreHidden)) {
filtersNeeded.add(new IgnoreHiddenFileListFilter());
}
// 'filter' is set
if (this.filter != null) {
if (Boolean.TRUE.equals(this.preventDuplicates)) {
filtersNeeded.add(new AcceptOnceFileListFilter<File>());
filtersNeeded.add(this.filter);
} else {
// preventDuplicates is either FALSE or NULL
filtersNeeded.add(this.filter);
}
} else // 'file-pattern' or 'file-regex' is set
if (this.filenamePattern != null || this.filenameRegex != null) {
if (!Boolean.FALSE.equals(this.preventDuplicates)) {
// preventDuplicates is either null or true
filtersNeeded.add(new AcceptOnceFileListFilter<File>());
}
if (this.filenamePattern != null) {
SimplePatternFileListFilter patternFilter = new SimplePatternFileListFilter(this.filenamePattern);
if (this.alwaysAcceptDirectories != null) {
patternFilter.setAlwaysAcceptDirectories(this.alwaysAcceptDirectories);
}
filtersNeeded.add(patternFilter);
}
if (this.filenameRegex != null) {
RegexPatternFileListFilter regexFilter = new RegexPatternFileListFilter(this.filenameRegex);
if (this.alwaysAcceptDirectories != null) {
regexFilter.setAlwaysAcceptDirectories(this.alwaysAcceptDirectories);
}
filtersNeeded.add(regexFilter);
}
} else // no filters are provided
if (Boolean.FALSE.equals(this.preventDuplicates)) {
filtersNeeded.add(new AcceptAllFileListFilter<File>());
} else {
// preventDuplicates is either TRUE or NULL
filtersNeeded.add(new AcceptOnceFileListFilter<File>());
}
if (filtersNeeded.size() == 1) {
createdFilter = filtersNeeded.get(0);
} else {
createdFilter = new CompositeFileListFilter<File>(filtersNeeded);
}
this.result = createdFilter;
}
use of org.springframework.integration.file.filters.CompositeFileListFilter in project spring-integration by spring-projects.
the class FileInboundChannelAdapterWithPreventDuplicatesFlagTests method defaultAndTrue.
@Test
public void defaultAndTrue() throws Exception {
FileListFilter<File> filter = this.extractFilter("defaultAndTrue");
assertFalse(filter instanceof CompositeFileListFilter);
assertTrue(filter instanceof AcceptOnceFileListFilter);
File testFile = new File("test");
File[] files = new File[] { testFile, testFile, testFile };
List<File> result = filter.filterFiles(files);
assertEquals(1, result.size());
}
use of org.springframework.integration.file.filters.CompositeFileListFilter in project spring-integration by spring-projects.
the class FtpStreamingInboundChannelAdapterSpec method composeFilters.
@SuppressWarnings("unchecked")
private CompositeFileListFilter<FTPFile> composeFilters(FileListFilter<FTPFile> fileListFilter) {
CompositeFileListFilter<FTPFile> compositeFileListFilter = new CompositeFileListFilter<>();
compositeFileListFilter.addFilters(fileListFilter, new FtpPersistentAcceptOnceFileListFilter(new SimpleMetadataStore(), "ftpStreamingMessageSource"));
return compositeFileListFilter;
}
Aggregations