mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-11-27 14:32:06 +01:00
Improve jft api
This commit is contained in:
parent
a9e80dc788
commit
ef23aad7b2
10 changed files with 48 additions and 3 deletions
|
@ -92,7 +92,12 @@ public final class JingleFileTransferManager extends Manager implements JingleDe
|
|||
public OutgoingFileOfferController sendFile(File file, FullJid to)
|
||||
throws SmackException.NotConnectedException, InterruptedException, XMPPException.XMPPErrorException,
|
||||
SmackException.NoResponseException, SmackException.FeatureNotSupportedException {
|
||||
return sendFile(file, null, to);
|
||||
}
|
||||
|
||||
public OutgoingFileOfferController sendFile(File file, String alternativeFilename, FullJid to)
|
||||
throws XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException,
|
||||
SmackException.NoResponseException, SmackException.FeatureNotSupportedException {
|
||||
if (file == null || !file.exists()) {
|
||||
throw new IllegalArgumentException("File MUST NOT be null and MUST exist.");
|
||||
}
|
||||
|
@ -107,6 +112,9 @@ public final class JingleFileTransferManager extends Manager implements JingleDe
|
|||
session.addContent(content);
|
||||
|
||||
JingleOutgoingFileOffer offer = new JingleOutgoingFileOffer(file);
|
||||
if (alternativeFilename != null) {
|
||||
offer.getFile().setName(alternativeFilename);
|
||||
}
|
||||
content.setDescription(offer);
|
||||
|
||||
JingleTransportManager transportManager = jingleManager.getBestAvailableTransportManager(to);
|
||||
|
|
|
@ -26,4 +26,7 @@ public abstract class AbstractJingleFileOffer<D extends AbstractJingleFileTransf
|
|||
public AbstractJingleFileOffer(D fileTransferFile) {
|
||||
super(fileTransferFile);
|
||||
}
|
||||
|
||||
@Override
|
||||
public abstract D getFile();
|
||||
}
|
||||
|
|
|
@ -27,4 +27,6 @@ public abstract class AbstractJingleFileRequest<D extends AbstractJingleFileTran
|
|||
super(fileTransferFile);
|
||||
}
|
||||
|
||||
@Override
|
||||
public abstract D getFile();
|
||||
}
|
||||
|
|
|
@ -37,6 +37,7 @@ import org.jivesoftware.smackx.jingle.element.JingleContentDescriptionInfoElemen
|
|||
import org.jivesoftware.smackx.jingle.element.JingleElement;
|
||||
|
||||
/**
|
||||
* Behind the scenes logic of an incoming Jingle file offer.
|
||||
* Created by vanitas on 26.07.17.
|
||||
*/
|
||||
public class JingleIncomingFileOffer extends AbstractJingleFileOffer<RemoteFile> implements IncomingFileOfferController {
|
||||
|
@ -130,4 +131,9 @@ public class JingleIncomingFileOffer extends AbstractJingleFileOffer<RemoteFile>
|
|||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RemoteFile getFile() {
|
||||
return (RemoteFile) this.file;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -58,4 +58,9 @@ public class JingleIncomingFileRequest extends AbstractJingleFileRequest<RemoteF
|
|||
public void onBytestreamReady(BytestreamSession bytestreamSession) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public RemoteFile getFile() {
|
||||
return (RemoteFile) file;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -87,4 +87,9 @@ public class JingleOutgoingFileOffer extends AbstractJingleFileOffer<LocalFile>
|
|||
public boolean isRequest() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LocalFile getFile() {
|
||||
return (LocalFile) file;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,6 +31,11 @@ public class JingleOutgoingFileRequest extends AbstractJingleFileRequest<RemoteF
|
|||
super(file);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RemoteFile getFile() {
|
||||
return (RemoteFile) file;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JingleElement handleDescriptionInfo(JingleContentDescriptionInfoElement info) {
|
||||
return null;
|
||||
|
|
|
@ -27,6 +27,7 @@ import org.jivesoftware.smackx.hashes.element.HashElement;
|
|||
public class LocalFile extends AbstractJingleFileTransferFile {
|
||||
|
||||
private File file;
|
||||
private String name;
|
||||
private String description;
|
||||
private String mediaType;
|
||||
private HashElement hashElement;
|
||||
|
@ -42,6 +43,8 @@ public class LocalFile extends AbstractJingleFileTransferFile {
|
|||
public LocalFile(File file, String description, String mediaType) {
|
||||
super();
|
||||
this.file = file;
|
||||
String path = file.getAbsolutePath();
|
||||
name = path.substring(path.lastIndexOf(File.separator) + 1);
|
||||
this.description = description;
|
||||
this.mediaType = mediaType;
|
||||
}
|
||||
|
@ -51,6 +54,9 @@ public class LocalFile extends AbstractJingleFileTransferFile {
|
|||
return new Date(file.lastModified());
|
||||
}
|
||||
|
||||
public void setDate(Date date) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getSize() {
|
||||
return file.length();
|
||||
|
@ -58,8 +64,11 @@ public class LocalFile extends AbstractJingleFileTransferFile {
|
|||
|
||||
@Override
|
||||
public String getName() {
|
||||
String path = file.getAbsolutePath();
|
||||
return path.substring(path.lastIndexOf(File.separator) + 1);
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -24,7 +24,7 @@ import org.jivesoftware.smack.XMPPConnection;
|
|||
import org.jivesoftware.smack.XMPPException;
|
||||
|
||||
/**
|
||||
* Created by vanitas on 27.07.17.
|
||||
* User interface for an incoming Jingle file offer.
|
||||
*/
|
||||
public interface IncomingFileOfferController extends JingleFileTransferController {
|
||||
Future<Void> accept(XMPPConnection connection, File target) throws InterruptedException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, SmackException.NoResponseException;
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
*/
|
||||
package org.jivesoftware.smackx.jft.controller;
|
||||
|
||||
import org.jivesoftware.smackx.jft.component.file.AbstractJingleFileTransferFile;
|
||||
import org.jivesoftware.smackx.jft.listener.ProgressListener;
|
||||
import org.jivesoftware.smackx.jingle.JingleDescriptionController;
|
||||
|
||||
|
@ -28,4 +29,5 @@ public interface JingleFileTransferController extends JingleDescriptionControlle
|
|||
|
||||
void removeProgressListener(ProgressListener listener);
|
||||
|
||||
AbstractJingleFileTransferFile getFile();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue