diff options
Diffstat (limited to '')
-rw-r--r-- | src/main/java/de/thedevstack/conversationsplus/xmpp/forms/Data.java | 20 | ||||
-rw-r--r-- | src/main/java/de/thedevstack/conversationsplus/xmpp/forms/Field.java | 33 |
2 files changed, 47 insertions, 6 deletions
diff --git a/src/main/java/de/thedevstack/conversationsplus/xmpp/forms/Data.java b/src/main/java/de/thedevstack/conversationsplus/xmpp/forms/Data.java index 591d8ada..cb612a07 100644 --- a/src/main/java/de/thedevstack/conversationsplus/xmpp/forms/Data.java +++ b/src/main/java/de/thedevstack/conversationsplus/xmpp/forms/Data.java @@ -53,16 +53,16 @@ public class Data extends Element { public void submit() { this.setAttribute("type","submit"); - removeNonFieldChildren(); + removeUnnecessaryChildren(); for(Field field : getFields()) { field.removeNonValueChildren(); } } - private void removeNonFieldChildren() { + private void removeUnnecessaryChildren() { for(Iterator<Element> iterator = this.children.iterator(); iterator.hasNext();) { Element element = iterator.next(); - if (!element.getName().equals("field")) { + if (!element.getName().equals("field") && !element.getName().equals("title")) { iterator.remove(); } } @@ -76,10 +76,20 @@ public class Data extends Element { } public void setFormType(String formType) { - this.put("FORM_TYPE",formType); + this.put("FORM_TYPE", formType); } public String getFormType() { - return this.getAttribute("FORM_TYPE"); + String type = getValue("FORM_TYPE"); + return type == null ? "" : type; + } + + public String getValue(String name) { + Field field = this.getFieldByName(name); + return field == null ? null : field.getValue(); + } + + public String getTitle() { + return findChildContent("title"); } } diff --git a/src/main/java/de/thedevstack/conversationsplus/xmpp/forms/Field.java b/src/main/java/de/thedevstack/conversationsplus/xmpp/forms/Field.java index 9eb2d08d..88b3155c 100644 --- a/src/main/java/de/thedevstack/conversationsplus/xmpp/forms/Field.java +++ b/src/main/java/de/thedevstack/conversationsplus/xmpp/forms/Field.java @@ -1,7 +1,9 @@ package de.thedevstack.conversationsplus.xmpp.forms; +import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; +import java.util.List; import de.thedevstack.conversationsplus.xml.Element; @@ -16,7 +18,7 @@ public class Field extends Element { super("field"); } - public String getName() { + public String getFieldName() { return this.getAttribute("var"); } @@ -47,4 +49,33 @@ public class Field extends Element { field.setChildren(element.getChildren()); return field; } + + public String getValue() { + return findChildContent("value"); + } + + public List<String> getValues() { + List<String> values = new ArrayList<>(); + for(Element child : getChildren()) { + if ("value".equals(child.getName())) { + String content = child.getContent(); + if (content != null) { + values.add(content); + } + } + } + return values; + } + + public String getLabel() { + return getAttribute("label"); + } + + public String getType() { + return getAttribute("type"); + } + + public boolean isRequired() { + return hasChild("required"); + } } |