renamed EntryNamer to EntryNameExtractor since it gets the name but does not create it
This commit is contained in:
@@ -22,7 +22,7 @@ package org.springframework.integration.file.entries;
|
||||
* @author Josh Long
|
||||
* @param <T> the type of entry (there's an implementation for FTP, SFTP, and plain-old java.io.Files)
|
||||
*/
|
||||
public interface EntryNamer<T> {
|
||||
public interface EntryNameExtractor<T> {
|
||||
|
||||
/**
|
||||
* This is the one place I couldn't spackle over the interface differences between an FTPFile (FTP adapter), File (File adapter), and LsEntry (SFTP adapter)
|
||||
@@ -31,6 +31,6 @@ public interface EntryNamer<T> {
|
||||
* @param entry the entry in a file system listing
|
||||
* @return the String name that might be used to reference that entry or to do regular expression checks against
|
||||
*/
|
||||
String nameOf(T entry);
|
||||
String getName(T entry);
|
||||
|
||||
}
|
||||
@@ -19,14 +19,14 @@ package org.springframework.integration.file.entries;
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* {@link java.io.File}-based implementation of the {@link EntryNamer} strategy.
|
||||
* {@link java.io.File}-based implementation of the {@link EntryNameExtractor} strategy.
|
||||
*
|
||||
* @author Josh Long
|
||||
* @since 2.0
|
||||
*/
|
||||
public class FileEntryNamer implements EntryNamer<File> {
|
||||
public class FileEntryNameExtractor implements EntryNameExtractor<File> {
|
||||
|
||||
public String nameOf(File entry) {
|
||||
public String getName(File entry) {
|
||||
return (entry != null) ? entry.getName() : null;
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ import org.springframework.util.StringUtils;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* Filters a listing of entries (T) by qualifying their 'name' (as determined by {@link org.springframework.integration.file.entries.EntryNamer})
|
||||
* Filters a listing of entries (T) by qualifying their 'name' (as determined by {@link org.springframework.integration.file.entries.EntryNameExtractor})
|
||||
* against a regular expression (an instance of {@link java.util.regex.Pattern})
|
||||
*
|
||||
* @author Iwein Fuld
|
||||
@@ -33,26 +33,26 @@ import java.util.regex.Pattern;
|
||||
*/
|
||||
public class PatternMatchingEntryListFilter<T> extends AbstractEntryListFilter<T> implements InitializingBean {
|
||||
|
||||
private volatile EntryNamer<T> entryNamer;
|
||||
private volatile EntryNameExtractor<T> entryNameExtractor;
|
||||
|
||||
private volatile Pattern pattern;
|
||||
|
||||
private volatile String patternExpression;
|
||||
|
||||
|
||||
public PatternMatchingEntryListFilter(EntryNamer<T> en, String p) {
|
||||
this.entryNamer = en;
|
||||
this.patternExpression = p;
|
||||
public PatternMatchingEntryListFilter(EntryNameExtractor<T> entryNameExtractor, String pattern) {
|
||||
this.entryNameExtractor = entryNameExtractor;
|
||||
this.patternExpression = pattern;
|
||||
}
|
||||
|
||||
public PatternMatchingEntryListFilter(EntryNamer<T> en, Pattern p) {
|
||||
this.entryNamer = en;
|
||||
this.pattern = p;
|
||||
public PatternMatchingEntryListFilter(EntryNameExtractor<T> entryNameExtractor, Pattern pattern) {
|
||||
this.entryNameExtractor = entryNameExtractor;
|
||||
this.pattern = pattern;
|
||||
}
|
||||
|
||||
|
||||
public void setEntryNamer(EntryNamer<T> entryNamer) {
|
||||
this.entryNamer = entryNamer;
|
||||
public void setEntryNameExtractor(EntryNameExtractor<T> entryNameExtractor) {
|
||||
this.entryNameExtractor = entryNameExtractor;
|
||||
}
|
||||
|
||||
public void setPattern(Pattern pattern) {
|
||||
@@ -67,13 +67,13 @@ public class PatternMatchingEntryListFilter<T> extends AbstractEntryListFilter<T
|
||||
if (StringUtils.hasText(this.patternExpression) && (pattern == null)) {
|
||||
this.pattern = Pattern.compile(this.patternExpression);
|
||||
}
|
||||
Assert.notNull(this.entryNamer, "'entryNamer' must not be null!");
|
||||
Assert.notNull(this.entryNameExtractor, "'entryNameExtractor' must not be null!");
|
||||
Assert.notNull(this.pattern, "'pattern' must not be null!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean accept(T entry) {
|
||||
return (entry != null) && this.pattern.matcher(this.entryNamer.nameOf(entry)).matches();
|
||||
return (entry != null) && this.pattern.matcher(this.entryNameExtractor.getName(entry)).matches();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
package org.springframework.integration.file.filters;
|
||||
|
||||
import org.springframework.integration.file.entries.FileEntryNamer;
|
||||
import org.springframework.integration.file.entries.FileEntryNameExtractor;
|
||||
import org.springframework.integration.file.entries.PatternMatchingEntryListFilter;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
@@ -38,11 +38,11 @@ public class PatternMatchingFileListFilter extends PatternMatchingEntryListFilte
|
||||
* Create a file filter for the given pattern.
|
||||
*/
|
||||
public PatternMatchingFileListFilter(Pattern pattern) {
|
||||
super(new FileEntryNamer(), pattern);
|
||||
super(new FileEntryNameExtractor(), pattern);
|
||||
}
|
||||
|
||||
public PatternMatchingFileListFilter(String pattern) {
|
||||
super(new FileEntryNamer(), pattern);
|
||||
super(new FileEntryNameExtractor(), pattern);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -30,7 +30,7 @@ import org.springframework.integration.file.FileReadingMessageSource;
|
||||
import org.springframework.integration.file.entries.AcceptOnceEntryFileListFilter;
|
||||
import org.springframework.integration.file.entries.CompositeEntryListFilter;
|
||||
import org.springframework.integration.file.entries.EntryListFilter;
|
||||
import org.springframework.integration.file.entries.FileEntryNamer;
|
||||
import org.springframework.integration.file.entries.FileEntryNameExtractor;
|
||||
import org.springframework.integration.file.entries.PatternMatchingEntryListFilter;
|
||||
|
||||
/**
|
||||
@@ -155,11 +155,11 @@ public abstract class AbstractInboundRemoteFileSystemSynchronizingMessageSource<
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private EntryListFilter<File> buildFilter() {
|
||||
FileEntryNamer fileEntryNamer = new FileEntryNamer();
|
||||
FileEntryNameExtractor fileEntryNameExtractor = new FileEntryNameExtractor();
|
||||
Pattern completePattern = Pattern.compile("^.*(?<!" + INCOMPLETE_EXTENSION + ")$");
|
||||
return new CompositeEntryListFilter<File>(Arrays.asList(
|
||||
new AcceptOnceEntryFileListFilter<File>(),
|
||||
new PatternMatchingEntryListFilter<File>(fileEntryNamer, completePattern)));
|
||||
new PatternMatchingEntryListFilter<File>(fileEntryNameExtractor, completePattern)));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
p:directory="file:${java.io.tmpdir}/FileReadingMessageSourceIntegrationTests"
|
||||
p:filter-ref="compositeFilter"/>
|
||||
|
||||
<bean class="org.springframework.integration.file.entries.FileEntryNamer" id="entryNamer"/>
|
||||
<bean id="entryNameExtractor" class="org.springframework.integration.file.entries.FileEntryNameExtractor"/>
|
||||
|
||||
<!-- customized filter -->
|
||||
<bean id="legacyCompositeFilter" class="org.springframework.integration.file.entries.CompositeEntryListFilter">
|
||||
@@ -19,7 +19,7 @@
|
||||
<bean class="org.springframework.integration.file.entries.AcceptOnceEntryFileListFilter"/>
|
||||
<bean class="org.springframework.integration.file.TestFileListFilter"/>
|
||||
<bean class="org.springframework.integration.file.entries.PatternMatchingEntryListFilter">
|
||||
<constructor-arg ref="entryNamer"/>
|
||||
<constructor-arg ref="entryNameExtractor"/>
|
||||
<constructor-arg value="test*"/>
|
||||
</bean>
|
||||
</list>
|
||||
@@ -29,17 +29,12 @@
|
||||
<!-- is equivalent to previous filter -->
|
||||
<bean class="org.springframework.integration.file.config.FileListFilterFactoryBean" id="compositeFilter">
|
||||
<property name="filterReferences">
|
||||
|
||||
<util:list>
|
||||
|
||||
<bean class="org.springframework.integration.file.config.FileListFilterFactoryBean" p:preventDuplicates="true"/>
|
||||
<bean class="org.springframework.integration.file.config.FileListFilterFactoryBean" p:preventDuplicates="false"/>
|
||||
<bean class="org.springframework.integration.file.config.FileListFilterFactoryBean" p:filenamePattern="test*"/>
|
||||
|
||||
</util:list>
|
||||
|
||||
</property>
|
||||
|
||||
</bean>
|
||||
|
||||
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"/>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -20,7 +20,7 @@ import org.junit.Test;
|
||||
import org.springframework.beans.factory.BeanCreationException;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.integration.file.entries.EntryListFilter;
|
||||
import org.springframework.integration.file.entries.FileEntryNamer;
|
||||
import org.springframework.integration.file.entries.FileEntryNameExtractor;
|
||||
import org.springframework.integration.file.entries.PatternMatchingEntryListFilter;
|
||||
|
||||
import java.io.File;
|
||||
@@ -35,13 +35,13 @@ import static org.junit.Assert.assertTrue;
|
||||
*/
|
||||
public class PatternMatchingFileListFilterTests {
|
||||
|
||||
private FileEntryNamer fileEntryNamer = new FileEntryNamer();
|
||||
private FileEntryNameExtractor fileEntryNameExtractor = new FileEntryNameExtractor();
|
||||
|
||||
@Test
|
||||
public void matchSingleFile() {
|
||||
File[] files = new File[]{new File("/some/path/test.txt")};
|
||||
Pattern pattern = Pattern.compile("[a-z]+\\.txt");
|
||||
PatternMatchingEntryListFilter<File> filter = new PatternMatchingEntryListFilter<File>(fileEntryNamer, pattern);
|
||||
PatternMatchingEntryListFilter<File> filter = new PatternMatchingEntryListFilter<File>(fileEntryNameExtractor, pattern);
|
||||
List<File> accepted = filter.filterEntries(files);
|
||||
assertEquals(1, accepted.size());
|
||||
}
|
||||
@@ -50,7 +50,7 @@ public class PatternMatchingFileListFilterTests {
|
||||
public void noMatchWithSingleFile() {
|
||||
File[] files = new File[]{new File("/some/path/Test.txt")};
|
||||
Pattern pattern = Pattern.compile("[a-z]+\\.txt");
|
||||
PatternMatchingEntryListFilter<File> filter = new PatternMatchingEntryListFilter<File>(fileEntryNamer, pattern);
|
||||
PatternMatchingEntryListFilter<File> filter = new PatternMatchingEntryListFilter<File>(fileEntryNameExtractor, pattern);
|
||||
List<File> accepted = filter.filterEntries(files);
|
||||
assertEquals(0, accepted.size());
|
||||
}
|
||||
@@ -64,7 +64,7 @@ public class PatternMatchingFileListFilterTests {
|
||||
new File("/some/path/bar.not")
|
||||
};
|
||||
Pattern pattern = Pattern.compile("[a-z]+\\.txt");
|
||||
PatternMatchingEntryListFilter<File> filter = new PatternMatchingEntryListFilter<File>(this.fileEntryNamer, pattern);
|
||||
PatternMatchingEntryListFilter<File> filter = new PatternMatchingEntryListFilter<File>(this.fileEntryNameExtractor, pattern);
|
||||
List<File> accepted = filter.filterEntries(files);
|
||||
assertEquals(2, accepted.size());
|
||||
assertTrue(accepted.contains(new File("/some/path/foo.txt")));
|
||||
@@ -72,7 +72,8 @@ public class PatternMatchingFileListFilterTests {
|
||||
}
|
||||
|
||||
|
||||
@Test @SuppressWarnings("unchecked")
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void patternEditorInContext() {
|
||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"patternMatchingFileListFilterTests.xml", this.getClass());
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
-->
|
||||
<bean id="filter" class="org.springframework.integration.file.entries.PatternMatchingEntryListFilter">
|
||||
<constructor-arg>
|
||||
<bean class="org.springframework.integration.file.entries.FileEntryNamer"/>
|
||||
<bean class="org.springframework.integration.file.entries.FileEntryNameExtractor"/>
|
||||
</constructor-arg>
|
||||
<constructor-arg value="fo+\.[tx]{3}"/>
|
||||
</bean>
|
||||
|
||||
@@ -17,16 +17,16 @@
|
||||
package org.springframework.integration.ftp;
|
||||
|
||||
import org.apache.commons.net.ftp.FTPFile;
|
||||
import org.springframework.integration.file.entries.EntryNamer;
|
||||
import org.springframework.integration.file.entries.EntryNameExtractor;
|
||||
|
||||
/**
|
||||
* A {@link org.springframework.integration.file.entries.EntryNamer} for {@link org.apache.commons.net.ftp.FTPFile} objects
|
||||
* A {@link org.springframework.integration.file.entries.EntryNameExtractor} for {@link org.apache.commons.net.ftp.FTPFile} objects
|
||||
*
|
||||
* @author Josh Long
|
||||
*/
|
||||
public class FtpFileEntryNamer implements EntryNamer<FTPFile> {
|
||||
public class FtpFileEntryNameExtractor implements EntryNameExtractor<FTPFile> {
|
||||
|
||||
public String nameOf(FTPFile entry) {
|
||||
public String getName(FTPFile entry) {
|
||||
return entry.getName();
|
||||
}
|
||||
|
||||
@@ -154,11 +154,11 @@ public class FtpRemoteFileSystemSynchronizingMessageSourceFactoryBean
|
||||
this.localWorkingDirectory = "file://" + tmp.getAbsolutePath();
|
||||
}
|
||||
this.localDirectoryResource = this.fromText(this.localWorkingDirectory);
|
||||
FtpFileEntryNamer ftpFileEntryNamer = new FtpFileEntryNamer();
|
||||
FtpFileEntryNameExtractor fileEntryNameExtractor = new FtpFileEntryNameExtractor();
|
||||
CompositeEntryListFilter<FTPFile> compositeFtpFileListFilter = new CompositeEntryListFilter<FTPFile>();
|
||||
if (StringUtils.hasText(this.filenamePattern)) {
|
||||
PatternMatchingEntryListFilter<FTPFile> ftpFilePatternMatchingEntryListFilter =
|
||||
new PatternMatchingEntryListFilter<FTPFile>(ftpFileEntryNamer, filenamePattern);
|
||||
new PatternMatchingEntryListFilter<FTPFile>(fileEntryNameExtractor, filenamePattern);
|
||||
compositeFtpFileListFilter.addFilter(ftpFilePatternMatchingEntryListFilter);
|
||||
}
|
||||
if (this.filter != null) {
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
package org.springframework.integration.sftp;
|
||||
|
||||
import org.springframework.integration.file.entries.EntryNamer;
|
||||
import org.springframework.integration.file.entries.EntryNameExtractor;
|
||||
|
||||
import com.jcraft.jsch.ChannelSftp;
|
||||
|
||||
@@ -25,9 +25,9 @@ import com.jcraft.jsch.ChannelSftp;
|
||||
*
|
||||
* @author Josh Long
|
||||
*/
|
||||
public class SftpEntryNamer implements EntryNamer<ChannelSftp.LsEntry> {
|
||||
public class SftpEntryNameExtractor implements EntryNameExtractor<ChannelSftp.LsEntry> {
|
||||
|
||||
public String nameOf(ChannelSftp.LsEntry entry) {
|
||||
public String getName(ChannelSftp.LsEntry entry) {
|
||||
return entry.getFilename();
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ import org.springframework.integration.file.entries.CompositeEntryListFilter;
|
||||
import org.springframework.integration.file.entries.EntryListFilter;
|
||||
import org.springframework.integration.file.entries.PatternMatchingEntryListFilter;
|
||||
import org.springframework.integration.sftp.QueuedSftpSessionPool;
|
||||
import org.springframework.integration.sftp.SftpEntryNamer;
|
||||
import org.springframework.integration.sftp.SftpEntryNameExtractor;
|
||||
import org.springframework.integration.sftp.SftpSessionFactory;
|
||||
import org.springframework.integration.sftp.impl.SftpInboundRemoteFileSystemSynchronizer;
|
||||
import org.springframework.integration.sftp.impl.SftpInboundRemoteFileSystemSynchronizingMessageSource;
|
||||
@@ -169,10 +169,11 @@ public class SftpRemoteFileSystemSynchronizingMessageSourceFactoryBean
|
||||
this.localDirectoryResource = this.resourceFromString(localDirectoryPath);
|
||||
|
||||
// remote predicates
|
||||
SftpEntryNamer sftpEntryNamer = new SftpEntryNamer();
|
||||
SftpEntryNameExtractor sftpEntryNameExtractor = new SftpEntryNameExtractor();
|
||||
CompositeEntryListFilter<ChannelSftp.LsEntry> compositeFtpFileListFilter = new CompositeEntryListFilter<ChannelSftp.LsEntry>();
|
||||
if (StringUtils.hasText(this.filenamePattern)) {
|
||||
PatternMatchingEntryListFilter<ChannelSftp.LsEntry> ftpFilePatternMatchingEntryListFilter = new PatternMatchingEntryListFilter<ChannelSftp.LsEntry>(sftpEntryNamer, filenamePattern);
|
||||
PatternMatchingEntryListFilter<ChannelSftp.LsEntry> ftpFilePatternMatchingEntryListFilter =
|
||||
new PatternMatchingEntryListFilter<ChannelSftp.LsEntry>(sftpEntryNameExtractor, filenamePattern);
|
||||
compositeFtpFileListFilter.addFilter(ftpFilePatternMatchingEntryListFilter);
|
||||
}
|
||||
if (this.filter != null) {
|
||||
|
||||
Reference in New Issue
Block a user