aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/thedevstack/conversationsplus/xmpp/stanzas/AbstractStanza.java
blob: 78c715417d6aabe7cc4bf14d0d78fa152ff55704 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package de.thedevstack.conversationsplus.xmpp.stanzas;

import de.thedevstack.conversationsplus.entities.Account;
import de.thedevstack.conversationsplus.xml.Element;
import de.thedevstack.conversationsplus.xmpp.jid.Jid;

public class AbstractStanza extends Element {

	protected AbstractStanza(final String name) {
		super(name);
	}

	public Jid getTo() {
		return getAttributeAsJid("to");
	}

	public Jid getFrom() {
		return getAttributeAsJid("from");
	}

	public void setTo(final Jid to) {
		if (to != null) {
			setAttribute("to", to.toString());
		}
	}

	public void setFrom(final Jid from) {
		if (from != null) {
			setAttribute("from", from.toString());
		}
	}

	public boolean fromServer(final Account account) {
		return getFrom() == null
			|| getFrom().equals(account.getServer())
			|| getFrom().equals(account.getJid().toBareJid())
			|| getFrom().equals(account.getJid());
	}

	public boolean toServer(final Account account) {
		return getTo() == null
			|| getTo().equals(account.getServer())
			|| getTo().equals(account.getJid().toBareJid())
			|| getTo().equals(account.getJid());
	}

	public boolean fromAccount(final Account account) {
		return getFrom() != null && getFrom().toBareJid().equals(account.getJid().toBareJid());
	}
}