AbstractAcknowledgeableStanza.java

 1package eu.siacs.conversations.xmpp.stanzas;
 2
 3import eu.siacs.conversations.xml.Element;
 4import eu.siacs.conversations.xmpp.InvalidJid;
 5
 6abstract public class AbstractAcknowledgeableStanza extends AbstractStanza {
 7
 8    protected AbstractAcknowledgeableStanza(String name) {
 9        super(name);
10    }
11
12
13    public String getId() {
14        return this.getAttribute("id");
15    }
16
17    public void setId(final String id) {
18        setAttribute("id", id);
19    }
20
21    private Element getErrorConditionElement() {
22        final Element error = findChild("error");
23        if (error == null) {
24            return null;
25        }
26        for (final Element element : error.getChildren()) {
27            if (!element.getName().equals("text")) {
28                return element;
29            }
30        }
31        return null;
32    }
33
34    public String getErrorCondition() {
35        final Element condition = getErrorConditionElement();
36        return condition == null ? null : condition.getName();
37    }
38
39    public boolean valid() {
40        return InvalidJid.isValid(getFrom()) && InvalidJid.isValid(getTo());
41    }
42}