2014-04-08 21:15:55 +00:00
|
|
|
package eu.siacs.conversations.xmpp.jingle.stanzas;
|
2014-03-27 01:02:59 +00:00
|
|
|
|
|
|
|
import eu.siacs.conversations.xml.Element;
|
|
|
|
import eu.siacs.conversations.xmpp.stanzas.IqPacket;
|
|
|
|
|
|
|
|
public class JinglePacket extends IqPacket {
|
|
|
|
Content content = null;
|
|
|
|
Reason reason = null;
|
2014-04-07 18:05:45 +00:00
|
|
|
Element jingle = new Element("jingle");
|
2014-03-27 01:02:59 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public Element addChild(Element child) {
|
|
|
|
if ("jingle".equals(child.getName())) {
|
|
|
|
Element contentElement = child.findChild("content");
|
|
|
|
if (contentElement!=null) {
|
|
|
|
this.content = new Content();
|
|
|
|
this.content.setChildren(contentElement.getChildren());
|
|
|
|
this.content.setAttributes(contentElement.getAttributes());
|
|
|
|
}
|
|
|
|
Element reasonElement = child.findChild("reason");
|
|
|
|
if (reasonElement!=null) {
|
|
|
|
this.reason = new Reason();
|
|
|
|
this.reason.setChildren(reasonElement.getChildren());
|
|
|
|
this.reason.setAttributes(reasonElement.getAttributes());
|
|
|
|
}
|
2014-04-07 18:05:45 +00:00
|
|
|
this.jingle.setAttributes(child.getAttributes());
|
2014-03-27 01:02:59 +00:00
|
|
|
}
|
|
|
|
return child;
|
|
|
|
}
|
|
|
|
|
|
|
|
public JinglePacket setContent(Content content) {
|
|
|
|
this.content = content;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2014-04-11 19:13:09 +00:00
|
|
|
public Content getJingleContent() {
|
|
|
|
if (this.content==null) {
|
|
|
|
this.content = new Content();
|
|
|
|
}
|
|
|
|
return this.content;
|
|
|
|
}
|
|
|
|
|
2014-03-27 01:02:59 +00:00
|
|
|
public JinglePacket setReason(Reason reason) {
|
|
|
|
this.reason = reason;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void build() {
|
|
|
|
this.children.clear();
|
2014-04-07 18:05:45 +00:00
|
|
|
this.jingle.clearChildren();
|
|
|
|
this.jingle.setAttribute("xmlns", "urn:xmpp:jingle:1");
|
2014-03-27 01:02:59 +00:00
|
|
|
if (this.content!=null) {
|
|
|
|
jingle.addChild(this.content);
|
|
|
|
}
|
|
|
|
if (this.reason != null) {
|
|
|
|
jingle.addChild(this.reason);
|
|
|
|
}
|
|
|
|
this.children.add(jingle);
|
2014-04-07 18:05:45 +00:00
|
|
|
this.setAttribute("type", "set");
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getSessionId() {
|
|
|
|
return this.jingle.getAttribute("sid");
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setSessionId(String sid) {
|
|
|
|
this.jingle.setAttribute("sid", sid);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String toString() {
|
|
|
|
this.build();
|
|
|
|
return super.toString();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setAction(String action) {
|
|
|
|
this.jingle.setAttribute("action", action);
|
|
|
|
}
|
|
|
|
|
2014-04-10 12:12:08 +00:00
|
|
|
public String getAction() {
|
|
|
|
return this.jingle.getAttribute("action");
|
|
|
|
}
|
|
|
|
|
2014-04-07 18:05:45 +00:00
|
|
|
public void setInitiator(String initiator) {
|
|
|
|
this.jingle.setAttribute("initiator", initiator);
|
2014-03-27 01:02:59 +00:00
|
|
|
}
|
2014-04-10 12:12:08 +00:00
|
|
|
|
|
|
|
public boolean isAction(String action) {
|
|
|
|
return action.equalsIgnoreCase(this.getAction());
|
|
|
|
}
|
2014-03-27 01:02:59 +00:00
|
|
|
}
|