1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
package eu.siacs.conversations.xmpp.jingle.stanzas;
import java.util.ArrayList;
import java.util.List;
import eu.siacs.conversations.xml.Element;
import eu.siacs.conversations.xmpp.jingle.JingleFile;
public class Content extends Element {
private Content(String name) {
super(name);
}
public Content() {
super("content");
}
public void setFileOffer(JingleFile 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.getSize());
file.addChild("name").setContent(actualFile.getName());
}
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");
}
public void setCandidates(String transportId, List<Element> canditates) {
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();
for(Element canditate : canditates) {
transport.addChild(canditate);
}
}
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();
}
}
public String getTransportId() {
Element transport = this.findChild("transport", "urn:xmpp:jingle:transports:s5b:1");
if (transport==null) {
return null;
}
return transport.getAttribute("sid");
}
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");
}
}
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);
}
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);
}
}
|