AbstractStanza.java

 1package eu.siacs.conversations.xmpp.stanzas;
 2
 3import eu.siacs.conversations.entities.Account;
 4import eu.siacs.conversations.xml.Element;
 5import rocks.xmpp.addr.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.toEscapedString());
24		}
25	}
26
27	public void setFrom(final Jid from) {
28		if (from != null) {
29			setAttribute("from", from.toEscapedString());
30		}
31	}
32
33	public boolean fromServer(final Account account) {
34		return getFrom() == null
35			|| getFrom().equals(Jid.of(account.getServer()))
36			|| getFrom().equals(account.getJid().asBareJid())
37			|| getFrom().equals(account.getJid());
38	}
39
40	public boolean toServer(final Account account) {
41		return getTo() == null
42			|| getTo().equals(Jid.of(account.getServer()))
43			|| getTo().equals(account.getJid().asBareJid())
44			|| getTo().equals(account.getJid());
45	}
46
47	public boolean fromAccount(final Account account) {
48		return getFrom() != null && getFrom().asBareJid().equals(account.getJid().asBareJid());
49	}
50}