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;
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 void setTo(final Jid to) {
22 if (to != null) {
23 setAttribute("to", to);
24 }
25 }
26
27 public void setFrom(final Jid from) {
28 if (from != null) {
29 setAttribute("from", from);
30 }
31 }
32
33 public boolean fromServer(final Account account) {
34 final Jid from = getFrom();
35 return from == null
36 || from.equals(account.getDomain())
37 || from.equals(account.getJid().asBareJid())
38 || from.equals(account.getJid());
39 }
40
41 public boolean toServer(final Account account) {
42 final Jid to = getTo();
43 return to == null
44 || to.equals(account.getDomain())
45 || to.equals(account.getJid().asBareJid())
46 || to.equals(account.getJid());
47 }
48
49 public boolean fromAccount(final Account account) {
50 final Jid from = getFrom();
51 return from != null && from.asBareJid().equals(account.getJid().asBareJid());
52 }
53}