JinglePacket.java

 1package eu.siacs.conversations.xmpp.stanzas.jingle;
 2
 3import eu.siacs.conversations.xml.Element;
 4import eu.siacs.conversations.xmpp.stanzas.IqPacket;
 5
 6public class JinglePacket extends IqPacket {
 7	Content content = null;
 8	Reason reason = null;
 9	Element jingle = new Element("jingle");
10	
11	@Override
12	public Element addChild(Element child) {
13		if ("jingle".equals(child.getName())) {
14			Element contentElement = child.findChild("content");
15			if (contentElement!=null) {
16				this.content = new Content();
17				this.content.setChildren(contentElement.getChildren());
18				this.content.setAttributes(contentElement.getAttributes());
19			}
20			Element reasonElement = child.findChild("reason");
21			if (reasonElement!=null) {
22				this.reason = new Reason();
23				this.reason.setChildren(reasonElement.getChildren());
24				this.reason.setAttributes(reasonElement.getAttributes());
25			}
26			this.jingle.setAttributes(child.getAttributes());
27		}
28		return child;
29	}
30	
31	public JinglePacket setContent(Content content) {
32		this.content = content;
33		return this;
34	}
35	
36	public JinglePacket setReason(Reason reason) {
37		this.reason = reason;
38		return this;
39	}
40	
41	private void build() {
42		this.children.clear();
43		this.jingle.clearChildren();
44		this.jingle.setAttribute("xmlns", "urn:xmpp:jingle:1");
45		if (this.content!=null) {
46			jingle.addChild(this.content);
47		}
48		if (this.reason != null) {
49			jingle.addChild(this.reason);
50		}
51		this.children.add(jingle);
52		this.setAttribute("type", "set");
53	}
54
55	public String getSessionId() {
56		return this.jingle.getAttribute("sid");
57	}
58	
59	public void setSessionId(String sid) {
60		this.jingle.setAttribute("sid", sid);
61	}
62	
63	@Override
64	public String toString() {
65		this.build();
66		return super.toString();
67	}
68
69	public void setAction(String action) {
70		this.jingle.setAttribute("action", action);
71	}
72	
73	public void setInitiator(String initiator) {
74		this.jingle.setAttribute("initiator", initiator);
75	}
76}