Search in sources :

Example 1 with AcceptAllFileListFilter

use of org.springframework.integration.file.filters.AcceptAllFileListFilter 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)

Aggregations

File (java.io.File)1 ArrayList (java.util.ArrayList)1 AcceptAllFileListFilter (org.springframework.integration.file.filters.AcceptAllFileListFilter)1 AcceptOnceFileListFilter (org.springframework.integration.file.filters.AcceptOnceFileListFilter)1 CompositeFileListFilter (org.springframework.integration.file.filters.CompositeFileListFilter)1 FileListFilter (org.springframework.integration.file.filters.FileListFilter)1 IgnoreHiddenFileListFilter (org.springframework.integration.file.filters.IgnoreHiddenFileListFilter)1 RegexPatternFileListFilter (org.springframework.integration.file.filters.RegexPatternFileListFilter)1 SimplePatternFileListFilter (org.springframework.integration.file.filters.SimplePatternFileListFilter)1