Search in sources :

Example 1 with SimplePatternFileListFilter

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;
}
Also used : File(java.io.File) FileReadingMessageSource(org.springframework.integration.file.FileReadingMessageSource) SimplePatternFileListFilter(org.springframework.integration.file.filters.SimplePatternFileListFilter) InboundChannelAdapter(org.springframework.integration.annotation.InboundChannelAdapter) Bean(org.springframework.context.annotation.Bean)

Example 2 with SimplePatternFileListFilter

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;
}
Also used : AcceptAllFileListFilter(org.springframework.integration.file.filters.AcceptAllFileListFilter) IgnoreHiddenFileListFilter(org.springframework.integration.file.filters.IgnoreHiddenFileListFilter) AcceptOnceFileListFilter(org.springframework.integration.file.filters.AcceptOnceFileListFilter) FileListFilter(org.springframework.integration.file.filters.FileListFilter) SimplePatternFileListFilter(org.springframework.integration.file.filters.SimplePatternFileListFilter) RegexPatternFileListFilter(org.springframework.integration.file.filters.RegexPatternFileListFilter) CompositeFileListFilter(org.springframework.integration.file.filters.CompositeFileListFilter) ArrayList(java.util.ArrayList) RegexPatternFileListFilter(org.springframework.integration.file.filters.RegexPatternFileListFilter) IgnoreHiddenFileListFilter(org.springframework.integration.file.filters.IgnoreHiddenFileListFilter) AcceptOnceFileListFilter(org.springframework.integration.file.filters.AcceptOnceFileListFilter) SimplePatternFileListFilter(org.springframework.integration.file.filters.SimplePatternFileListFilter) File(java.io.File)

Example 3 with SimplePatternFileListFilter

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());
}
Also used : Set(java.util.Set) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) AcceptOnceFileListFilter(org.springframework.integration.file.filters.AcceptOnceFileListFilter) FileListFilter(org.springframework.integration.file.filters.FileListFilter) SimplePatternFileListFilter(org.springframework.integration.file.filters.SimplePatternFileListFilter) CompositeFileListFilter(org.springframework.integration.file.filters.CompositeFileListFilter) SimplePatternFileListFilter(org.springframework.integration.file.filters.SimplePatternFileListFilter) Test(org.junit.Test)

Aggregations

SimplePatternFileListFilter (org.springframework.integration.file.filters.SimplePatternFileListFilter)3 File (java.io.File)2 AcceptOnceFileListFilter (org.springframework.integration.file.filters.AcceptOnceFileListFilter)2 CompositeFileListFilter (org.springframework.integration.file.filters.CompositeFileListFilter)2 FileListFilter (org.springframework.integration.file.filters.FileListFilter)2 ArrayList (java.util.ArrayList)1 Set (java.util.Set)1 Test (org.junit.Test)1 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)1 Bean (org.springframework.context.annotation.Bean)1 InboundChannelAdapter (org.springframework.integration.annotation.InboundChannelAdapter)1 FileReadingMessageSource (org.springframework.integration.file.FileReadingMessageSource)1 AcceptAllFileListFilter (org.springframework.integration.file.filters.AcceptAllFileListFilter)1 IgnoreHiddenFileListFilter (org.springframework.integration.file.filters.IgnoreHiddenFileListFilter)1 RegexPatternFileListFilter (org.springframework.integration.file.filters.RegexPatternFileListFilter)1