Content.java

 1package eu.siacs.conversations.xmpp.jingle.stanzas;
 2
 3import java.io.File;
 4import java.util.ArrayList;
 5import java.util.List;
 6
 7import eu.siacs.conversations.xml.Element;
 8
 9public class Content extends Element {
10	private Content(String name) {
11		super(name);
12	}
13	
14	public Content() {
15		super("content");
16	}
17
18	public void offerFile(File actualFile, String hash) {
19		Element description = this.addChild("description", "urn:xmpp:jingle:apps:file-transfer:3");
20		Element offer = description.addChild("offer");
21		Element file = offer.addChild("file");
22		file.addChild("size").setContent(""+actualFile.length());
23		file.addChild("name").setContent(actualFile.getName());
24		file.addChild("hash","urn:xmpp:hashes:1").setAttribute("algo", "sha-1").setContent(hash);
25	}
26
27	public void setCandidates(String transportId, List<Element> canditates) {
28		Element transport = this.findChild("transport", "urn:xmpp:jingle:transports:s5b:1");
29		if (transport==null) {
30			transport = this.addChild("transport", "urn:xmpp:jingle:transports:s5b:1");
31		}
32		transport.setAttribute("sid", transportId);
33		transport.clearChildren();
34		for(Element canditate : canditates) {
35			transport.addChild(canditate);
36		}
37	}
38	
39	public List<Element> getCanditates() {
40		Element transport = this.findChild("transport", "urn:xmpp:jingle:transports:s5b:1");
41		if (transport==null) {
42			return new ArrayList<Element>();
43		} else {
44			return transport.getChildren();
45		}
46	}
47	
48	public String getUsedCandidate() {
49		Element transport = this.findChild("transport", "urn:xmpp:jingle:transports:s5b:1");
50		if (transport==null) {
51			return null;
52		}
53		Element usedCandidate = transport.findChild("candidate-used");
54		if (usedCandidate==null) {
55			return null;
56		} else {
57			return usedCandidate.getAttribute("cid");
58		}
59	}
60}