Search in sources :

Example 1 with SparkTransferManager

use of org.jivesoftware.spark.filetransfer.SparkTransferManager in project Spark by igniterealtime.

the class FileTransferSettingsPlugin method addTransferListener.

/**
 * Adds a {@link FileTransferListener} to allow this plugin to intercept {@link FileTransferRequest}s.
 */
private void addTransferListener() {
    SparkTransferManager transferManager = SparkManager.getTransferManager();
    transferManager.addTransferListener(request -> {
        FileTransferSettings settings = (FileTransferSettings) prefManager.getPreferenceData("transferSettings");
        try {
            if (requestContainsBannedFile(request, settings)) {
                request.reject();
                String responseMessage = settings.getCannedRejectionMessage();
                if (responseMessage != null && responseMessage.length() > 0) {
                    Message message = new Message();
                    message.setTo(request.getRequestor());
                    message.setBody(responseMessage);
                    SparkManager.getConnection().sendStanza(message);
                }
                return true;
            } else {
                return false;
            }
        } catch (SmackException ex) {
            Log.warning("Unable to handle file transfer.", ex);
            return false;
        }
    });
}
Also used : Message(org.jivesoftware.smack.packet.Message) SmackException(org.jivesoftware.smack.SmackException) SparkTransferManager(org.jivesoftware.spark.filetransfer.SparkTransferManager)

Aggregations

SmackException (org.jivesoftware.smack.SmackException)1 Message (org.jivesoftware.smack.packet.Message)1 SparkTransferManager (org.jivesoftware.spark.filetransfer.SparkTransferManager)1