2014-04-08 21:15:55 +00:00
|
|
|
package eu.siacs.conversations.xmpp.jingle.stanzas;
|
2014-03-27 01:02:59 +00:00
|
|
|
|
2014-04-07 18:05:45 +00:00
|
|
|
import java.io.File;
|
2014-04-11 19:13:09 +00:00
|
|
|
import java.util.ArrayList;
|
2014-04-07 18:05:45 +00:00
|
|
|
import java.util.List;
|
|
|
|
|
2014-03-27 01:02:59 +00:00
|
|
|
import eu.siacs.conversations.xml.Element;
|
|
|
|
|
|
|
|
public class Content extends Element {
|
|
|
|
private Content(String name) {
|
|
|
|
super(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
public Content() {
|
|
|
|
super("content");
|
|
|
|
}
|
2014-04-07 18:05:45 +00:00
|
|
|
|
|
|
|
public void offerFile(File actualFile) {
|
|
|
|
Element description = this.addChild("description", "urn:xmpp:jingle:apps:file-transfer:3");
|
|
|
|
Element offer = description.addChild("offer");
|
|
|
|
Element file = offer.addChild("file");
|
|
|
|
file.addChild("size").setContent(""+actualFile.length());
|
|
|
|
file.addChild("name").setContent(actualFile.getName());
|
|
|
|
}
|
|
|
|
|
2014-04-11 19:13:09 +00:00
|
|
|
public void setCandidates(String transportId, List<Element> canditates) {
|
2014-04-07 18:05:45 +00:00
|
|
|
Element transport = this.findChild("transport", "urn:xmpp:jingle:transports:s5b:1");
|
|
|
|
if (transport==null) {
|
|
|
|
transport = this.addChild("transport", "urn:xmpp:jingle:transports:s5b:1");
|
|
|
|
}
|
2014-04-11 19:13:09 +00:00
|
|
|
transport.setAttribute("sid", transportId);
|
2014-04-07 18:05:45 +00:00
|
|
|
transport.clearChildren();
|
|
|
|
for(Element canditate : canditates) {
|
|
|
|
transport.addChild(canditate);
|
|
|
|
}
|
|
|
|
}
|
2014-04-11 19:13:09 +00:00
|
|
|
|
|
|
|
public List<Element> getCanditates() {
|
|
|
|
Element transport = this.findChild("transport", "urn:xmpp:jingle:transports:s5b:1");
|
|
|
|
if (transport==null) {
|
|
|
|
return new ArrayList<Element>();
|
|
|
|
} else {
|
|
|
|
return transport.getChildren();
|
|
|
|
}
|
|
|
|
}
|
2014-04-11 20:49:26 +00:00
|
|
|
|
|
|
|
public String getUsedCandidate() {
|
|
|
|
Element transport = this.findChild("transport", "urn:xmpp:jingle:transports:s5b:1");
|
|
|
|
if (transport==null) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
Element usedCandidate = transport.findChild("candidate-used");
|
|
|
|
if (usedCandidate==null) {
|
|
|
|
return null;
|
|
|
|
} else {
|
|
|
|
return usedCandidate.getAttribute("cid");
|
|
|
|
}
|
|
|
|
}
|
2014-03-27 01:02:59 +00:00
|
|
|
}
|