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;
}
});
}
Aggregations