1package eu.siacs.conversations.xmpp.stanzas;
2
3import eu.siacs.conversations.entities.Account;
4import eu.siacs.conversations.xml.Element;
5import eu.siacs.conversations.xmpp.jid.Jid;
6
7public class AbstractStanza extends Element {
8
9 protected AbstractStanza(final String name) {
10 super(name);
11 }
12
13 public Jid getTo() {
14 return getAttributeAsJid("to");
15 }
16
17 public Jid getFrom() {
18 return getAttributeAsJid("from");
19 }
20
21 public String getId() {
22 return this.getAttribute("id");
23 }
24
25 public void setTo(final Jid to) {
26 if (to != null) {
27 setAttribute("to", to.toString());
28 }
29 }
30
31 public void setFrom(final Jid from) {
32 if (from != null) {
33 setAttribute("from", from.toString());
34 }
35 }
36
37 public void setId(final String id) {
38 setAttribute("id", id);
39 }
40
41 public boolean fromServer(final Account account) {
42 return getFrom() == null
43 || getFrom().equals(account.getServer())
44 || getFrom().equals(account.getJid().toBareJid())
45 || getFrom().equals(account.getJid());
46 }
47
48 public boolean toServer(final Account account) {
49 return getTo() == null
50 || getTo().equals(account.getServer())
51 || getTo().equals(account.getJid().toBareJid())
52 || getTo().equals(account.getJid());
53 }
54
55 public boolean fromAccount(final Account account) {
56 return getFrom() != null && getFrom().toBareJid().equals(account.getJid().toBareJid());
57 }
58}