polishing

This commit is contained in:
Mark Fisher
2011-10-19 15:46:15 -04:00
parent 5059ecc318
commit b28ec17885
5 changed files with 49 additions and 45 deletions

View File

@@ -127,11 +127,11 @@ xsi:schemaLocation="http://www.springframework.org/schema/integration/ftp
</para>
<para>
By default the transferred file will carry the same name as the original file. If you want to override this behavior you
can set <code>local-filename-generator-expression</code> attribute which allows you to provide SpEL Expression to generate
can set the <code>local-filename-generator-expression</code> attribute which allows you to provide a SpEL Expression to generate
the name of the local file. Unlike outbound gateways and adapters where the root object of the SpEL Evaluation Context
is <classname>Message</classname>, Inbound adapter generates <classname>Message</classname> based on the transferred file
which means that <classname>Message</classname> does not exist yet at the time of Expression evaluation. So the root object
of the SpEL Evaluation Context is the original name of the remote file (String)
is a <classname>Message</classname>, this inbound adapter does not yet have the Message at the time of evaluation since
that's what it ultimately generates with the transferred file as its payload. So, the root object of the SpEL Evaluation Context
is the original name of the remote file (String).
</para>
<para>

View File

@@ -93,11 +93,11 @@ xsi:schemaLocation="http://www.springframework.org/schema/integration/sftp
</para>
<para>
By default the transferred file will carry the same name as the original file. If you want to override this behavior you
can set <code>local-filename-generator-expression</code> attribute which allows you to provide SpEL Expression to generate
can set the <code>local-filename-generator-expression</code> attribute which allows you to provide a SpEL Expression to generate
the name of the local file. Unlike outbound gateways and adapters where the root object of the SpEL Evaluation Context
is <classname>Message</classname>, Inbound adapter generates <classname>Message</classname> based on the transferred file
which means that <classname>Message</classname> does not exist yet at the time of Expression evaluation. So the root object
of the SpEL Evaluation Context is the original name of the remote file (String)
is a <classname>Message</classname>, this inbound adapter does not yet have the Message at the time of evaluation since
that's what it ultimately generates with the transferred file as its payload. So, the root object of the SpEL Evaluation Context
is the original name of the remote file (String).
</para>
<para>
Some times file filtering based on the simple pattern specified via <code>filename-pattern</code> attribute might not be

View File

@@ -26,6 +26,7 @@ import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.expression.Expression;
import org.springframework.expression.spel.support.StandardEvaluationContext;
@@ -50,17 +51,18 @@ import org.springframework.util.ObjectUtils;
* @since 2.0
*/
public abstract class AbstractInboundFileSynchronizer<F> implements InboundFileSynchronizer, InitializingBean {
private static final StandardEvaluationContext context = new StandardEvaluationContext();
private String remoteFileSeparator = "/";
protected final Log logger = LogFactory.getLog(this.getClass());
private final StandardEvaluationContext evaluationContext = new StandardEvaluationContext();
private volatile String remoteFileSeparator = "/";
/**
* Extension used when downloading files. We change it right after we know it's downloaded.
*/
private volatile String temporaryFileSuffix =".writing";
protected final Log logger = LogFactory.getLog(this.getClass());
private volatile Expression localFilenameGeneratorExpression;
/**
@@ -82,14 +84,9 @@ public abstract class AbstractInboundFileSynchronizer<F> implements InboundFileS
* Should we <emphasis>delete</emphasis> the remote <b>source</b> files
* after copying to the local directory? By default this is false.
*/
private boolean deleteRemoteFiles;
private volatile boolean deleteRemoteFiles;
public void setLocalFilenameGeneratorExpression(Expression localFilenameGeneratorExpression) {
Assert.notNull(localFilenameGeneratorExpression, "'localFilenameGeneratorExpression' must not be null");
this.localFilenameGeneratorExpression = localFilenameGeneratorExpression;
}
/**
* Create a synchronizer with the {@link SessionFactory} used to acquire {@link Session} instances.
*/
@@ -103,7 +100,12 @@ public abstract class AbstractInboundFileSynchronizer<F> implements InboundFileS
Assert.notNull(remoteFileSeparator, "'remoteFileSeparator' must not be null");
this.remoteFileSeparator = remoteFileSeparator;
}
public void setLocalFilenameGeneratorExpression(Expression localFilenameGeneratorExpression) {
Assert.notNull(localFilenameGeneratorExpression, "'localFilenameGeneratorExpression' must not be null");
this.localFilenameGeneratorExpression = localFilenameGeneratorExpression;
}
public void setTemporaryFileSuffix(String temporaryFileSuffix) {
this.temporaryFileSuffix = temporaryFileSuffix;
}
@@ -223,7 +225,7 @@ public abstract class AbstractInboundFileSynchronizer<F> implements InboundFileS
private String generateLocalFileName(String remoteFileName){
if (this.localFilenameGeneratorExpression != null){
return this.localFilenameGeneratorExpression.getValue(context, remoteFileName, String.class);
return this.localFilenameGeneratorExpression.getValue(evaluationContext, remoteFileName, String.class);
}
return remoteFileName;
}

View File

@@ -110,24 +110,25 @@ endpoint itself is a Polling Consumer for a channel with a queue.
<xsd:attribute name="filename-pattern" type="xsd:string">
<xsd:annotation>
<xsd:documentation>
Allows you to provide file name pattern to determine the file names that needs to be scanned
and is based on simple pattern matching algorithm (e.g., "*.txt, fo*.txt" etc.)
Allows you to provide a file name pattern to determine the file names that need to be scanned.
This is based on simple pattern matching (e.g., "*.txt, fo*.txt" etc.)
</xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="local-filename-generator-expression" type="xsd:string">
<xsd:annotation>
<xsd:documentation>
Allows you to provide SpEL expression which will compute the file name of
the local file (transfered file). Root object of SpEL is the name of the original
file (e.g., "#this.toUpperCase() + '.a'" where #this represents the original name of the remote file)
Allows you to provide a SpEL expression to generate the file name of
the local (transferred) file. The root object of the SpEL evaluation is the name of the original
file. For example, a valid expression would be "#this.toUpperCase() + '.a'" where #this represents the
original name of the remote file.
</xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="filename-regex" type="xsd:string">
<xsd:annotation>
<xsd:documentation>
Allows you to provide Regular Expression to determine the file names that needs to be scanned.
Allows you to provide a Regular Expression to determine the file names that need to be scanned.
(e.g., "f[o]+\.txt" etc.)
</xsd:documentation>
</xsd:annotation>
@@ -156,7 +157,7 @@ endpoint itself is a Polling Consumer for a channel with a queue.
</tool:annotation>
</xsd:appinfo>
<xsd:documentation>
Allows you to specify a reference to
Allows you to specify a reference to a
[org.springframework.integration.file.filters.FileListFilter] bean.
</xsd:documentation>
</xsd:annotation>
@@ -171,28 +172,28 @@ endpoint itself is a Polling Consumer for a channel with a queue.
<xsd:attribute name="remote-directory" type="xsd:string" use="required">
<xsd:annotation>
<xsd:documentation>
Identifies directory path (e.g., "/temp/mytransfers") where file will be transferred FROM.
Identifies the directory path (e.g., "/temp/mytransfers") where files will be transferred FROM.
</xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="remote-file-separator" type="xsd:string" default="/">
<xsd:annotation>
<xsd:documentation>
Allows you to provide remote file/directory separator character. DEFAULT: '/'
Allows you to provide a remote file/directory separator character. DEFAULT: '/'
</xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="local-directory" type="xsd:string" use="required">
<xsd:annotation>
<xsd:documentation>
Identifies directory path (e.g., "/local/mytransfers") where file will be transferred TO.
Identifies the directory path (e.g., "/local/mytransfers") where files will be transferred TO.
</xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="auto-create-local-directory" type="xsd:string">
<xsd:annotation>
<xsd:documentation>
Tells this adapter if local directory must be auto-created if it doesn''t exist. Default is TRUE.
Tells this adapter if the local directory must be auto-created if it doesn't exist. Default is TRUE.
</xsd:documentation>
</xsd:annotation>
</xsd:attribute>

View File

@@ -195,8 +195,8 @@ endpoint itself is a Polling Consumer for a channel with a queue.
</tool:annotation>
</xsd:appinfo>
<xsd:documentation>
Identifies channel attached to this adapter. Depending on the type of the adapter
this channel could be the receiving channel (e.g., outbound-channel-adapter) or channel where
Identifies the channel attached to this adapter. Depending on the type of the adapter
this channel could be the receiving channel (e.g., outbound-channel-adapter) or the channel where
messages will be sent to by this adapter (e.g., inbound-channel-adapter).
</xsd:documentation>
</xsd:annotation>
@@ -209,7 +209,7 @@ endpoint itself is a Polling Consumer for a channel with a queue.
</tool:annotation>
</xsd:appinfo>
<xsd:documentation>
Allows you to specify a reference to
Allows you to specify a reference to a
[org.springframework.integration.file.filters.FileListFilter] bean.
</xsd:documentation>
</xsd:annotation>
@@ -217,24 +217,25 @@ endpoint itself is a Polling Consumer for a channel with a queue.
<xsd:attribute name="filename-pattern" type="xsd:string">
<xsd:annotation>
<xsd:documentation>
Allows you to provide file name pattern to determine the file names that needs to be scanned
and is based on simple pattern matching algorithm (e.g., "*.txt, fo*.txt" etc.)
Allows you to provide a file name pattern to determine the file names that need to be scanned.
This is based on simple pattern matching (e.g., "*.txt, fo*.txt" etc.)
</xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="local-filename-generator-expression" type="xsd:string">
<xsd:annotation>
<xsd:documentation>
Allows you to provide SpEL expression which will compute the file name of
the local file (transfered file). Root object of SpEL is the name of the original
file (e.g., "#this.toUpperCase() + '.a'" where #this represents the original name of the remote file)
Allows you to provide a SpEL expression to generate the file name of
the local (transferred) file. The root object of the SpEL evaluation is the name of the original
file. For example, a valid expression would be "#this.toUpperCase() + '.a'" where #this represents the
original name of the remote file.
</xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="filename-regex" type="xsd:string">
<xsd:annotation>
<xsd:documentation>
Allows you to provide Regular Expression to determine the file names that needs to be scanned.
Allows you to provide a Regular Expression to determine the file names that need to be scanned.
(e.g., "f[o]+\.txt" etc.)
</xsd:documentation>
</xsd:annotation>
@@ -242,28 +243,28 @@ endpoint itself is a Polling Consumer for a channel with a queue.
<xsd:attribute name="remote-file-separator" type="xsd:string" default="/">
<xsd:annotation>
<xsd:documentation>
Allows you to provide remote file/directory separator character. DEFAULT: '/'
Allows you to provide a remote file/directory separator character. DEFAULT: '/'
</xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="remote-directory" type="xsd:string" use="required">
<xsd:annotation>
<xsd:documentation>
Identifies directory path (e.g., "/temp/mytransfers") where file will be transferred FROM.
Identifies the directory path (e.g., "/temp/mytransfers") where files will be transferred FROM.
</xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="local-directory" type="xsd:string" use="required">
<xsd:annotation>
<xsd:documentation>
Identifies directory path (e.g., "/local/mytransfers") where file will be transferred TO.
Identifies the directory path (e.g., "/local/mytransfers") where files will be transferred TO.
</xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="auto-create-local-directory" type="xsd:string">
<xsd:annotation>
<xsd:documentation>
Tells this adapter if local directory must be auto-created if it doesn''t exist. Default is TRUE.
Tells this adapter if the local directory must be auto-created if it doesn't exist. Default is TRUE.
</xsd:documentation>
</xsd:annotation>
</xsd:attribute>