All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.mule.modules.ftpclient.RenameStrategy Maven / Gradle / Ivy

There is a newer version: 1.0.8
Show newest version
package org.mule.modules.ftpclient;

import java.util.function.Consumer;

import org.mule.api.MuleContext;
import org.mule.api.MuleMessage;
import org.mule.api.expression.ExpressionManager;

/**
 * A strategy which can rename files (within the same directory).
 */
public class RenameStrategy implements CompletionStrategy {

    private MuleContext muleContext;
    private String filenameExpression;
    private String originalFilenameExpression;

    public RenameStrategy(MuleContext muleContext, String filenameExpression, String originalFilenameExpression) {
        this.muleContext = muleContext;
        this.filenameExpression = filenameExpression;
        this.originalFilenameExpression = originalFilenameExpression;
    }

    @Override
    public Consumer createCompletionHandler(MuleMessage message, String filename,
            String translatedName) {
        ExpressionManager expressionManager = muleContext.getExpressionManager();
        String moveToFilename = (String) expressionManager.evaluate(filenameExpression, null, message, true);
        String moveToOriginalFilename = (String) expressionManager.evaluate(originalFilenameExpression, null, message,
                true);
        return new FileArchiver(translatedName, moveToFilename, filename, moveToOriginalFilename);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy