aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/eu/siacs/conversations/xmpp/forms/Field.java
blob: ee2c51a9c19a3ca259e451a5dcf426a5bc01a47c (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 eu.siacs.conversations.xmpp.forms;

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

import eu.siacs.conversations.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;
	}
}