2014-04-08 23:15:55 +02:00
|
|
|
package eu.siacs.conversations.xmpp.jingle.stanzas;
|
2014-03-27 02:02:59 +01:00
|
|
|
|
2014-04-11 21:13:09 +02:00
|
|
|
import java.util.ArrayList;
|
2014-04-07 20:05:45 +02:00
|
|
|
import java.util.List;
|
|
|
|
|
2014-03-27 02:02:59 +01:00
|
|
|
import eu.siacs.conversations.xml.Element;
|
2014-04-13 11:32:45 +02:00
|
|
|
import eu.siacs.conversations.xmpp.jingle.JingleFile;
|
2014-03-27 02:02:59 +01:00
|
|
|
|
|
|
|
public class Content extends Element {
|
|
|
|
private Content(String name) {
|
|
|
|
super(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
public Content() {
|
|
|
|
super("content");
|
|
|
|
}
|
2014-04-07 20:05:45 +02:00
|
|
|
|
2014-04-13 18:09:40 +02:00
|
|
|
public void setFileOffer(JingleFile actualFile) {
|
2014-04-07 20:05:45 +02:00
|
|
|
Element description = this.addChild("description", "urn:xmpp:jingle:apps:file-transfer:3");
|
|
|
|
Element offer = description.addChild("offer");
|
|
|
|
Element file = offer.addChild("file");
|
2014-04-13 11:32:45 +02:00
|
|
|
file.addChild("size").setContent(""+actualFile.getSize());
|
2014-04-07 20:05:45 +02:00
|
|
|
file.addChild("name").setContent(actualFile.getName());
|
|
|
|
}
|
2014-04-13 18:09:40 +02:00
|
|
|
|
|
|
|
public Element getFileOffer() {
|
|
|
|
Element description = this.findChild("description", "urn:xmpp:jingle:apps:file-transfer:3");
|
|
|
|
if (description==null) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
Element offer = description.findChild("offer");
|
|
|
|
if (offer==null) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return offer.findChild("file");
|
|
|
|
}
|
2014-04-07 20:05:45 +02:00
|
|
|
|
2014-04-11 21:13:09 +02:00
|
|
|
public void setCandidates(String transportId, List<Element> canditates) {
|
2014-04-07 20:05:45 +02: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 21:13:09 +02:00
|
|
|
transport.setAttribute("sid", transportId);
|
2014-04-07 20:05:45 +02:00
|
|
|
transport.clearChildren();
|
|
|
|
for(Element canditate : canditates) {
|
|
|
|
transport.addChild(canditate);
|
|
|
|
}
|
|
|
|
}
|
2014-04-11 21:13:09 +02: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 22:49:26 +02:00
|
|
|
|
2014-04-13 21:10:36 +02:00
|
|
|
public String getTransportId() {
|
|
|
|
Element transport = this.findChild("transport", "urn:xmpp:jingle:transports:s5b:1");
|
|
|
|
if (transport==null) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return transport.getAttribute("sid");
|
|
|
|
}
|
|
|
|
|
2014-04-11 22:49:26 +02: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-04-13 21:10:36 +02:00
|
|
|
|
|
|
|
public void setUsedCandidate(String transportId, String cid) {
|
|
|
|
Element transport = this.findChild("transport", "urn:xmpp:jingle:transports:s5b:1");
|
|
|
|
if (transport==null) {
|
|
|
|
transport = this.addChild("transport", "urn:xmpp:jingle:transports:s5b:1");
|
|
|
|
}
|
|
|
|
transport.setAttribute("sid", transportId);
|
|
|
|
transport.clearChildren();
|
|
|
|
Element usedCandidate = transport.addChild("candidate-used");
|
|
|
|
usedCandidate.setAttribute("cid",cid);
|
|
|
|
}
|
2014-04-13 18:09:40 +02:00
|
|
|
|
|
|
|
public void addCandidate(Element candidate) {
|
|
|
|
Element transport = this.findChild("transport", "urn:xmpp:jingle:transports:s5b:1");
|
|
|
|
if (transport==null) {
|
|
|
|
transport = this.addChild("transport", "urn:xmpp:jingle:transports:s5b:1");
|
|
|
|
}
|
|
|
|
transport.addChild(candidate);
|
|
|
|
}
|
2014-03-27 02:02:59 +01:00
|
|
|
}
|