aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/thedevstack/conversationsplus/xmpp/chatstate/ChatState.java
blob: 929d485aa2f2234d51bb26143621daf973bdbcee (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
package de.thedevstack.conversationsplus.xmpp.chatstate;

import de.thedevstack.conversationsplus.xml.Element;

public enum ChatState {

	ACTIVE, INACTIVE, GONE, COMPOSING, PAUSED, mIncomingChatState;

	public static ChatState parse(Element element) {
		final String NAMESPACE = "http://jabber.org/protocol/chatstates";
		if (element.hasChild("active",NAMESPACE)) {
			return ACTIVE;
		} else if (element.hasChild("inactive",NAMESPACE)) {
			return INACTIVE;
		} else if (element.hasChild("composing",NAMESPACE)) {
			return COMPOSING;
		} else if (element.hasChild("gone",NAMESPACE)) {
			return GONE;
		} else if (element.hasChild("paused",NAMESPACE)) {
			return PAUSED;
		} else {
			return null;
		}
	}

	public static Element toElement(ChatState state) {
		final String NAMESPACE = "http://jabber.org/protocol/chatstates";
		final Element element = new Element(state.toString().toLowerCase());
		element.setAttribute("xmlns",NAMESPACE);
		return element;
	}
}