AbstractStanza.java

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