use of org.springframework.integration.file.filters.SimplePatternFileListFilter in project tutorials by eugenp.
the class FileCopyConfig method fileReadingMessageSource.
@Bean
@InboundChannelAdapter(value = "fileChannel", poller = @Poller(fixedDelay = "10000"))
public MessageSource<File> fileReadingMessageSource() {
FileReadingMessageSource sourceReader = new FileReadingMessageSource();
sourceReader.setDirectory(new File(INPUT_DIR));
sourceReader.setFilter(new SimplePatternFileListFilter(FILE_PATTERN));
return sourceReader;
}
use of org.springframework.integration.file.filters.SimplePatternFileListFilter 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.SimplePatternFileListFilter in project spring-integration by spring-projects.
the class FileInboundChannelAdapterWithPatternParserTests method patternFilter.
@Test
@SuppressWarnings("unchecked")
public void patternFilter() {
DirectFieldAccessor scannerAccessor = new DirectFieldAccessor(accessor.getPropertyValue("scanner"));
Set<FileListFilter<?>> filters = (Set<FileListFilter<?>>) new DirectFieldAccessor(scannerAccessor.getPropertyValue("filter")).getPropertyValue("fileFilters");
String pattern = null;
for (FileListFilter<?> filter : filters) {
if (filter instanceof SimplePatternFileListFilter) {
pattern = (String) new DirectFieldAccessor(filter).getPropertyValue("path");
}
}
assertNotNull("expected SimplePatternFileListFilterTest", pattern);
assertEquals("*.txt", pattern.toString());
}
Aggregations