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)
|
public OutgoingFileOfferController sendFile(File file, FullJid to)
|
||||||
throws SmackException.NotConnectedException, InterruptedException, XMPPException.XMPPErrorException,
|
throws SmackException.NotConnectedException, InterruptedException, XMPPException.XMPPErrorException,
|
||||||
SmackException.NoResponseException, SmackException.FeatureNotSupportedException {
|
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()) {
|
if (file == null || !file.exists()) {
|
||||||
throw new IllegalArgumentException("File MUST NOT be null and MUST exist.");
|
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);
|
session.addContent(content);
|
||||||
|
|
||||||
JingleOutgoingFileOffer offer = new JingleOutgoingFileOffer(file);
|
JingleOutgoingFileOffer offer = new JingleOutgoingFileOffer(file);
|
||||||
|
if (alternativeFilename != null) {
|
||||||
|
offer.getFile().setName(alternativeFilename);
|
||||||
|
}
|
||||||
content.setDescription(offer);
|
content.setDescription(offer);
|
||||||
|
|
||||||
JingleTransportManager transportManager = jingleManager.getBestAvailableTransportManager(to);
|
JingleTransportManager transportManager = jingleManager.getBestAvailableTransportManager(to);
|
||||||
|
|
|
@ -26,4 +26,7 @@ public abstract class AbstractJingleFileOffer<D extends AbstractJingleFileTransf
|
||||||
public AbstractJingleFileOffer(D fileTransferFile) {
|
public AbstractJingleFileOffer(D fileTransferFile) {
|
||||||
super(fileTransferFile);
|
super(fileTransferFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public abstract D getFile();
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,4 +27,6 @@ public abstract class AbstractJingleFileRequest<D extends AbstractJingleFileTran
|
||||||
super(fileTransferFile);
|
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;
|
import org.jivesoftware.smackx.jingle.element.JingleElement;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Behind the scenes logic of an incoming Jingle file offer.
|
||||||
* Created by vanitas on 26.07.17.
|
* Created by vanitas on 26.07.17.
|
||||||
*/
|
*/
|
||||||
public class JingleIncomingFileOffer extends AbstractJingleFileOffer<RemoteFile> implements IncomingFileOfferController {
|
public class JingleIncomingFileOffer extends AbstractJingleFileOffer<RemoteFile> implements IncomingFileOfferController {
|
||||||
|
@ -130,4 +131,9 @@ public class JingleIncomingFileOffer extends AbstractJingleFileOffer<RemoteFile>
|
||||||
|
|
||||||
return null;
|
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) {
|
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() {
|
public boolean isRequest() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LocalFile getFile() {
|
||||||
|
return (LocalFile) file;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,6 +31,11 @@ public class JingleOutgoingFileRequest extends AbstractJingleFileRequest<RemoteF
|
||||||
super(file);
|
super(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public RemoteFile getFile() {
|
||||||
|
return (RemoteFile) file;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JingleElement handleDescriptionInfo(JingleContentDescriptionInfoElement info) {
|
public JingleElement handleDescriptionInfo(JingleContentDescriptionInfoElement info) {
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -27,6 +27,7 @@ import org.jivesoftware.smackx.hashes.element.HashElement;
|
||||||
public class LocalFile extends AbstractJingleFileTransferFile {
|
public class LocalFile extends AbstractJingleFileTransferFile {
|
||||||
|
|
||||||
private File file;
|
private File file;
|
||||||
|
private String name;
|
||||||
private String description;
|
private String description;
|
||||||
private String mediaType;
|
private String mediaType;
|
||||||
private HashElement hashElement;
|
private HashElement hashElement;
|
||||||
|
@ -42,6 +43,8 @@ public class LocalFile extends AbstractJingleFileTransferFile {
|
||||||
public LocalFile(File file, String description, String mediaType) {
|
public LocalFile(File file, String description, String mediaType) {
|
||||||
super();
|
super();
|
||||||
this.file = file;
|
this.file = file;
|
||||||
|
String path = file.getAbsolutePath();
|
||||||
|
name = path.substring(path.lastIndexOf(File.separator) + 1);
|
||||||
this.description = description;
|
this.description = description;
|
||||||
this.mediaType = mediaType;
|
this.mediaType = mediaType;
|
||||||
}
|
}
|
||||||
|
@ -51,6 +54,9 @@ public class LocalFile extends AbstractJingleFileTransferFile {
|
||||||
return new Date(file.lastModified());
|
return new Date(file.lastModified());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setDate(Date date) {
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getSize() {
|
public long getSize() {
|
||||||
return file.length();
|
return file.length();
|
||||||
|
@ -58,8 +64,11 @@ public class LocalFile extends AbstractJingleFileTransferFile {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
String path = file.getAbsolutePath();
|
return name;
|
||||||
return path.substring(path.lastIndexOf(File.separator) + 1);
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -24,7 +24,7 @@ import org.jivesoftware.smack.XMPPConnection;
|
||||||
import org.jivesoftware.smack.XMPPException;
|
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 {
|
public interface IncomingFileOfferController extends JingleFileTransferController {
|
||||||
Future<Void> accept(XMPPConnection connection, File target) throws InterruptedException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, SmackException.NoResponseException;
|
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;
|
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.jft.listener.ProgressListener;
|
||||||
import org.jivesoftware.smackx.jingle.JingleDescriptionController;
|
import org.jivesoftware.smackx.jingle.JingleDescriptionController;
|
||||||
|
|
||||||
|
@ -28,4 +29,5 @@ public interface JingleFileTransferController extends JingleDescriptionControlle
|
||||||
|
|
||||||
void removeProgressListener(ProgressListener listener);
|
void removeProgressListener(ProgressListener listener);
|
||||||
|
|
||||||
|
AbstractJingleFileTransferFile getFile();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue