From 15150ac49917de45acc3c8676e6dc5dd3efe8b4b Mon Sep 17 00:00:00 2001 From: Gary Russell Date: Wed, 15 Apr 2015 12:49:29 +0300 Subject: [PATCH] INT-3699: RemoteFileTemplate Javadocs JIRA: https://jira.spring.io/browse/INT-3699 Also javadocs for related classes. INT-3699: Polishing - PR Comments --- .../file/remote/RemoteFileTemplate.java | 66 +++++++++++++++++++ .../AbstractRemoteFileOutboundGateway.java | 2 + .../FileTransferringMessageHandler.java | 34 +++++++++- .../AbstractInboundFileSynchronizer.java | 25 +++++++ 4 files changed, 126 insertions(+), 1 deletion(-) diff --git a/spring-integration-file/src/main/java/org/springframework/integration/file/remote/RemoteFileTemplate.java b/spring-integration-file/src/main/java/org/springframework/integration/file/remote/RemoteFileTemplate.java index 83d45e61da..2b8bbdd2ac 100644 --- a/spring-integration-file/src/main/java/org/springframework/integration/file/remote/RemoteFileTemplate.java +++ b/spring-integration-file/src/main/java/org/springframework/integration/file/remote/RemoteFileTemplate.java @@ -45,6 +45,8 @@ import org.springframework.util.Assert; import org.springframework.util.StringUtils; /** + * A general abstraction for dealing with remote files. + * * @author Iwein Fuld * @author Mark Fisher * @author Josh Long @@ -87,60 +89,121 @@ public class RemoteFileTemplate implements RemoteFileOperations, Initializ private volatile BeanFactory beanFactory; + /** + * Construct a {@link RemoteFileTemplate} with the supplied session factory. + * @param sessionFactory the session factory. + */ public RemoteFileTemplate(SessionFactory sessionFactory) { Assert.notNull(sessionFactory, "sessionFactory must not be null"); this.sessionFactory = sessionFactory; } + /** + * Determine whether the remote directory should automatically be created when + * sending files to the remote system. + * @param autoCreateDirectory true to create the directory. + */ public void setAutoCreateDirectory(boolean autoCreateDirectory) { this.autoCreateDirectory = autoCreateDirectory; } + /** + * Set the file separator when dealing with remote files; default '/'. + * @param remoteFileSeparator the separator. + */ public void setRemoteFileSeparator(String remoteFileSeparator) { Assert.notNull(remoteFileSeparator, "'remoteFileSeparator' must not be null"); this.remoteFileSeparator = remoteFileSeparator; } + /** + * @return the remote file separator. + */ public final String getRemoteFileSeparator() { return remoteFileSeparator; } + /** + * Set the remote directory expression used to determine the remote directory to which + * files will be sent. + * @param remoteDirectoryExpression the remote directory expression. + */ public void setRemoteDirectoryExpression(Expression remoteDirectoryExpression) { Assert.notNull(remoteDirectoryExpression, "remoteDirectoryExpression must not be null"); this.directoryExpressionProcessor = new ExpressionEvaluatingMessageProcessor(remoteDirectoryExpression, String.class); } + /** + * Set a temporary remote directory expression; used when transferring files to the remote + * system. After a successful transfer the file is renamed using the + * {@link #setRemoteDirectoryExpression(Expression) remoteDirectoryExpression}. + * @param temporaryRemoteDirectoryExpression the temporary remote directory expression. + */ public void setTemporaryRemoteDirectoryExpression(Expression temporaryRemoteDirectoryExpression) { Assert.notNull(temporaryRemoteDirectoryExpression, "temporaryRemoteDirectoryExpression must not be null"); this.temporaryDirectoryExpressionProcessor = new ExpressionEvaluatingMessageProcessor(temporaryRemoteDirectoryExpression, String.class); } + /** + * Set the file name expression to determine the full path to the remote file when retrieving + * a file using the {@link #get(Message, InputStreamCallback)} method, with the message + * being the root object of the evaluation. + * @param fileNameExpression the file name expression. + */ public void setFileNameExpression(Expression fileNameExpression) { Assert.notNull(fileNameExpression, "fileNameExpression must not be null"); this.fileNameProcessor = new ExpressionEvaluatingMessageProcessor(fileNameExpression, String.class); } + /** + * @return the temporary file suffix. + */ public String getTemporaryFileSuffix() { return this.temporaryFileSuffix; } + /** + * @return whether a temporary file name is used when sending files to the remote + * system. + */ public boolean isUseTemporaryFileName() { return useTemporaryFileName; } + /** + * Set whether a temporary file name is used when sending files to the remote system. + * @param useTemporaryFileName true to use a temporary file name. + * @see #setTemporaryFileSuffix(String) + */ public void setUseTemporaryFileName(boolean useTemporaryFileName) { this.useTemporaryFileName = useTemporaryFileName; } + /** + * Set the file name generator used to generate the remote filename to be used when transferring + * files to the remote system. Default {@link DefaultFileNameGenerator}. + * @param fileNameGenerator the file name generator. + */ public void setFileNameGenerator(FileNameGenerator fileNameGenerator) { this.fileNameGenerator = (fileNameGenerator != null) ? fileNameGenerator : new DefaultFileNameGenerator(); this.fileNameGeneratorSet = fileNameGenerator != null; } + /** + * Set the charset to use when converting String payloads to bytes as the content of the + * remote file. Default {@code UTF-8}. + * @param charset the charset. + */ public void setCharset(String charset) { this.charset = charset; } + /** + * Set the temporary suffix to use when transferring files to the remote system. + * Default ".writing". + * @param temporaryFileSuffix the suffix + * @see #setUseTemporaryFileName(boolean) + */ public void setTemporaryFileSuffix(String temporaryFileSuffix) { Assert.notNull(temporaryFileSuffix, "'temporaryFileSuffix' must not be null"); this.hasExplicitlySetSuffix = true; @@ -302,6 +365,9 @@ public class RemoteFileTemplate implements RemoteFileOperations, Initializ }); } + /** + * @see #setFileNameExpression(Expression) + */ @Override public boolean get(Message message, InputStreamCallback callback) { Assert.notNull(this.fileNameProcessor, "A 'fileNameExpression' is needed to use get"); diff --git a/spring-integration-file/src/main/java/org/springframework/integration/file/remote/gateway/AbstractRemoteFileOutboundGateway.java b/spring-integration-file/src/main/java/org/springframework/integration/file/remote/gateway/AbstractRemoteFileOutboundGateway.java index a2ee362ebf..48274a99ee 100644 --- a/spring-integration-file/src/main/java/org/springframework/integration/file/remote/gateway/AbstractRemoteFileOutboundGateway.java +++ b/spring-integration-file/src/main/java/org/springframework/integration/file/remote/gateway/AbstractRemoteFileOutboundGateway.java @@ -265,6 +265,7 @@ public abstract class AbstractRemoteFileOutboundGateway extends AbstractReply /** * @param remoteFileSeparator the remoteFileSeparator to set + * @see RemoteFileTemplate#setRemoteFileSeparator(String) */ public void setRemoteFileSeparator(String remoteFileSeparator) { this.remoteFileTemplate.setRemoteFileSeparator(remoteFileSeparator); @@ -292,6 +293,7 @@ public abstract class AbstractRemoteFileOutboundGateway extends AbstractReply /** * @param temporaryFileSuffix the temporaryFileSuffix to set + * @see RemoteFileTemplate#setTemporaryFileSuffix(String) */ public void setTemporaryFileSuffix(String temporaryFileSuffix) { this.remoteFileTemplate.setTemporaryFileSuffix(temporaryFileSuffix); diff --git a/spring-integration-file/src/main/java/org/springframework/integration/file/remote/handler/FileTransferringMessageHandler.java b/spring-integration-file/src/main/java/org/springframework/integration/file/remote/handler/FileTransferringMessageHandler.java index 1903239fe3..1c3c3650de 100644 --- a/spring-integration-file/src/main/java/org/springframework/integration/file/remote/handler/FileTransferringMessageHandler.java +++ b/spring-integration-file/src/main/java/org/springframework/integration/file/remote/handler/FileTransferringMessageHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2015 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. @@ -59,18 +59,34 @@ public class FileTransferringMessageHandler extends AbstractMessageHandler { } + /** + * @param autoCreateDirectory true to automatically create the direcotory. + * @see RemoteFileTemplate#setAutoCreateDirectory(boolean) + */ public void setAutoCreateDirectory(boolean autoCreateDirectory) { this.remoteFileTemplate.setAutoCreateDirectory(autoCreateDirectory); } + /** + * @param remoteFileSeparator the remote file separator. + * @see RemoteFileTemplate#setRemoteFileSeparator(String) + */ public void setRemoteFileSeparator(String remoteFileSeparator) { this.remoteFileTemplate.setRemoteFileSeparator(remoteFileSeparator); } + /** + * @param remoteDirectoryExpression the remote directory expression + * @see RemoteFileTemplate#setRemoteDirectoryExpression(Expression) + */ public void setRemoteDirectoryExpression(Expression remoteDirectoryExpression) { this.remoteFileTemplate.setRemoteDirectoryExpression(remoteDirectoryExpression); } + /** + * @param temporaryRemoteDirectoryExpression the temporary remote directory expression + * @see RemoteFileTemplate#setTemporaryRemoteDirectoryExpression(Expression) + */ public void setTemporaryRemoteDirectoryExpression(Expression temporaryRemoteDirectoryExpression) { this.remoteFileTemplate.setTemporaryRemoteDirectoryExpression(temporaryRemoteDirectoryExpression); } @@ -83,18 +99,34 @@ public class FileTransferringMessageHandler extends AbstractMessageHandler { return this.remoteFileTemplate.isUseTemporaryFileName(); } + /** + * @param useTemporaryFileName true to use a temporary file name. + * @see RemoteFileTemplate#setUseTemporaryFileName(boolean) + */ public void setUseTemporaryFileName(boolean useTemporaryFileName) { this.remoteFileTemplate.setUseTemporaryFileName(useTemporaryFileName); } + /** + * @param fileNameGenerator the file name generator. + * @see RemoteFileTemplate#setFileNameGenerator(FileNameGenerator) + */ public void setFileNameGenerator(FileNameGenerator fileNameGenerator) { this.remoteFileTemplate.setFileNameGenerator(fileNameGenerator); } + /** + * @param charset the charset. + * @see RemoteFileTemplate#setCharset(String) + */ public void setCharset(String charset) { this.remoteFileTemplate.setCharset(charset); } + /** + * @param temporaryFileSuffix the temporary file suffix. + * @see RemoteFileTemplate#setTemporaryFileSuffix(String) + */ public void setTemporaryFileSuffix(String temporaryFileSuffix) { this.remoteFileTemplate.setTemporaryFileSuffix(temporaryFileSuffix); } diff --git a/spring-integration-file/src/main/java/org/springframework/integration/file/remote/synchronizer/AbstractInboundFileSynchronizer.java b/spring-integration-file/src/main/java/org/springframework/integration/file/remote/synchronizer/AbstractInboundFileSynchronizer.java index e35b5a5ae0..f5cd1cdfd5 100644 --- a/spring-integration-file/src/main/java/org/springframework/integration/file/remote/synchronizer/AbstractInboundFileSynchronizer.java +++ b/spring-integration-file/src/main/java/org/springframework/integration/file/remote/synchronizer/AbstractInboundFileSynchronizer.java @@ -108,16 +108,28 @@ public abstract class AbstractInboundFileSynchronizer implements InboundFileS } + /** + * @param remoteFileSeparator the remote file separator. + * @see RemoteFileTemplate#setRemoteFileSeparator(String) + */ public void setRemoteFileSeparator(String remoteFileSeparator) { Assert.notNull(remoteFileSeparator, "'remoteFileSeparator' must not be null"); this.remoteFileSeparator = remoteFileSeparator; } + /** + * Set an expression used to determine the local file name. + * @param localFilenameGeneratorExpression the expression. + */ public void setLocalFilenameGeneratorExpression(Expression localFilenameGeneratorExpression) { Assert.notNull(localFilenameGeneratorExpression, "'localFilenameGeneratorExpression' must not be null"); this.localFilenameGeneratorExpression = localFilenameGeneratorExpression; } + /** + * Set a temporary file suffix to be used while transferring files. Default ".writing". + * @param temporaryFileSuffix the file suffix. + */ public void setTemporaryFileSuffix(String temporaryFileSuffix) { this.temporaryFileSuffix = temporaryFileSuffix; } @@ -131,14 +143,27 @@ public abstract class AbstractInboundFileSynchronizer implements InboundFileS this.remoteDirectory = remoteDirectory; } + /** + * Set the filter to be applied to the remote files before transferring. + * @param filter the file list filter. + */ public void setFilter(FileListFilter filter) { this.filter = filter; } + /** + * Set to true to enable deletion of remote files after successful transfer. + * @param deleteRemoteFiles true to delete. + */ public void setDeleteRemoteFiles(boolean deleteRemoteFiles) { this.deleteRemoteFiles = deleteRemoteFiles; } + /** + * Set to true to enable the preservation of the remote file timestamp when + * transferring. + * @param preserveTimestamp true to preserve. + */ public void setPreserveTimestamp(boolean preserveTimestamp) { this.preserveTimestamp = preserveTimestamp; }