1package eu.siacs.conversations.xmpp.jingle.stanzas;
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 Content getJingleContent() {
37 if (this.content==null) {
38 this.content = new Content();
39 }
40 return this.content;
41 }
42
43 public JinglePacket setReason(Reason reason) {
44 this.reason = reason;
45 return this;
46 }
47
48 private void build() {
49 this.children.clear();
50 this.jingle.clearChildren();
51 this.jingle.setAttribute("xmlns", "urn:xmpp:jingle:1");
52 if (this.content!=null) {
53 jingle.addChild(this.content);
54 }
55 if (this.reason != null) {
56 jingle.addChild(this.reason);
57 }
58 this.children.add(jingle);
59 this.setAttribute("type", "set");
60 }
61
62 public String getSessionId() {
63 return this.jingle.getAttribute("sid");
64 }
65
66 public void setSessionId(String sid) {
67 this.jingle.setAttribute("sid", sid);
68 }
69
70 @Override
71 public String toString() {
72 this.build();
73 return super.toString();
74 }
75
76 public void setAction(String action) {
77 this.jingle.setAttribute("action", action);
78 }
79
80 public String getAction() {
81 return this.jingle.getAttribute("action");
82 }
83
84 public void setInitiator(String initiator) {
85 this.jingle.setAttribute("initiator", initiator);
86 }
87
88 public boolean isAction(String action) {
89 return action.equalsIgnoreCase(this.getAction());
90 }
91}