aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/thedevstack/conversationsplus/xmpp/forms/Field.java
blob: 9eb2d08d1b2a5d4bfadc89d8b40042dde2c60580 (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.forms;

import java.util.Collection;
import java.util.Iterator;

import de.thedevstack.conversationsplus.xml.Element;

public class Field extends Element {

	public Field(String name) {
		super("field");
		this.setAttribute("var",name);
	}

	private Field() {
		super("field");
	}

	public String getName() {
		return this.getAttribute("var");
	}

	public void setValue(String value) {
		this.children.clear();
		this.addChild("value").setContent(value);
	}

	public void setValues(Collection<String> values) {
		this.children.clear();
		for(String value : values) {
			this.addChild("value").setContent(value);
		}
	}

	public void removeNonValueChildren() {
		for(Iterator<Element> iterator = this.children.iterator(); iterator.hasNext();) {
			Element element = iterator.next();
			if (!element.getName().equals("value")) {
				iterator.remove();
			}
		}
	}

	public static Field parse(Element element) {
		Field field = new Field();
		field.setAttributes(element.getAttributes());
		field.setChildren(element.getChildren());
		return field;
	}
}