Skip to content

Commit

Permalink
Fix select1Dynamic not supporting expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
seadowg committed Jan 24, 2024
1 parent df9980e commit 3e9c225
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/test/java/org/javarosa/core/util/XFormsElement.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@

import kotlin.Pair;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import static java.util.Arrays.asList;
import static java.util.Collections.emptyMap;

public interface XFormsElement {
Expand All @@ -43,7 +43,7 @@ static Map<String, String> parseAttributes(String name) {
return emptyMap();
Map<String, String> attributes = new HashMap<>();
String[] words = name.split(" ");
for (String word : Arrays.asList(words).subList(1, words.length)) {
for (String word : asList(words).subList(1, words.length)) {
String[] parts = word.split("(?<!\\))=(\"|')");
attributes.put(parts[0], parts[1].substring(0, parts[1].length() - 1));
}
Expand All @@ -59,7 +59,7 @@ static String parseName(String name) {
static XFormsElement t(String name, XFormsElement... children) {
if (children.length == 0)
return new EmptyXFormsElement(parseName(name), parseAttributes(name));
return new TagXFormsElement(parseName(name), parseAttributes(name), Arrays.asList(children));
return new TagXFormsElement(parseName(name), parseAttributes(name), asList(children));
}

static XFormsElement t(String name, String innerHtml) {
Expand Down Expand Up @@ -135,7 +135,16 @@ static XFormsElement select1(String ref, XFormsElement... children) {
}

static XFormsElement select1Dynamic(String ref, String nodesetRef) {
return select1Dynamic(ref, nodesetRef, "value", "label");
XFormsElement value = t("value ref=\"value\"");
XFormsElement label = t("label ref=\"label\"");

HashMap<String, String> itemsetAttributes = new HashMap<>();
itemsetAttributes.put("nodeset", nodesetRef);
TagXFormsElement itemset = new TagXFormsElement("itemset", itemsetAttributes, asList(value, label));

HashMap<String, String> select1Attributes = new HashMap<>();
select1Attributes.put("ref", ref);
return new TagXFormsElement("select1", select1Attributes, asList(itemset));
}

static XFormsElement select1Dynamic(String ref, String nodesetRef, String valueRef, String labelRef) {
Expand Down Expand Up @@ -186,13 +195,13 @@ static XFormsElement setvalueLiteral(String event, String ref, String innerHtml)

class HeadXFormsElement extends TagXFormsElement {
public HeadXFormsElement(XFormsElement[] children) {
super("h:head", emptyMap(), Arrays.asList(children));
super("h:head", emptyMap(), asList(children));
}
}

class BodyXFormsElement extends TagXFormsElement {
public BodyXFormsElement(XFormsElement[] children) {
super("h:body", emptyMap(), Arrays.asList(children));
super("h:body", emptyMap(), asList(children));
}
}
}

0 comments on commit 3e9c225

Please sign in to comment.