FormValueElement

public class FormValueElement implements FormNode

Object representation of the forwarded form from CommCareHQ.

Methods

addAttribute

public void addAttribute(String key, String value)

addFormValueElement

public void addFormValueElement(String key, FormValueElement element)

containsAttribute

public boolean containsAttribute(String key)

getAllElements

public List<FormValueElement> getAllElements(String elementName)

Returns a list of all descendant elements with a given element name, in the order in which they are encountered in a preorder traversal of this element tree. Lookup starts with this element and hence this element will be part of the returned list if it matches the given element name.

Note: This method will return an empty list if no matching node is found.

Parameters:
  • elementName – The name of the element to match on.
Returns:

A list containing matching elements.

getAllElements

public List<FormValueElement> getAllElements(String elementName, List<String> restrictedElements)

Returns a list of all descendant elements with a given element name, in the order in which they are encountered in a preorder traversal of this element tree. Lookup starts with this element and hence this element will be part of the returned list if it matches the given element name.

Lookup within an element and its descendants is skipped if it is part of restrictedElements list.

Note: This method will return an empty list if no matching node is found.

Parameters:
  • elementName – The name of the element to match on.
  • restrictedElements – The list containing all restricted elements.
Returns:

A list containing matching elements.

getAttributes

public Map<String, String> getAttributes()

getChildElement

public FormValueElement getChildElement(String elementName)

Returns child element with the given elementName.

Parameters:
  • elementName – the name of the child element
Returns:

the matching child element, null if element with the given name does not exist

getChildElements

public List<FormValueElement> getChildElements(String elementName)

Returns child element with the given elementName and wraps it into a list.

Parameters:
  • elementName – the name of the child element
Returns:

the matching child element wrapped into a list

getElement

public FormValueElement getElement(String elementName)

Returns first element found of all descendant elements with a given element name. The lookup happens in a preorder traversal of this element tree. Lookup starts with this element and hence this element will be returned if it matches the given element name.

Note: This method will return null if no matching node is found.

Parameters:
  • elementName – The name of the element to match on.
Returns:

First element matching the given name.

getElement

public FormValueElement getElement(String elementName, List<String> restrictedElements)

Returns first element found of all descendant elements with a given element name. The lookup happens in a preorder traversal of this element tree. Lookup starts with this element and hence this element will be part of the returned list if it matches the given element name.

Lookup within an element and its descendants is skipped if it is part of restrictedElements list.

Note: This method will return null if no matching node is found.

Parameters:
  • elementName – The name of the element to match on.
  • restrictedElements – The list containing all restricted elements.
Returns:

First element matching the given name.

getElementByAttribute

public FormValueElement getElementByAttribute(String attribute, String value)

Returns element with the attribute attribute set to value.

Parameters:
  • attribute – the name of the attribute
  • value – the value of the attribute
Returns:

the matching element, null if no matching element is found

getElementByAttribute

public FormValueElement getElementByAttribute(String attribute, String value, List<String> restrictedElements)

Returns element with the attribute attribute set to value and is not one of the restrictedElements.

Parameters:
  • attribute – the name of the attribute
  • value – the value of the attribute
  • restrictedElements – the restricted elements
Returns:

the matching element, null if no matching element is found

getElementName

public String getElementName()

getElements

public Map<String, FormValueElement> getElements()

Returns a map of form elements names and related elements.

Returns:map of elements and their names

getElementsByAttribute

public List<FormValueElement> getElementsByAttribute(String attribute, String value)

Returns a list of elements with the attribute attribute set to value.

Parameters:
  • attribute – the name of the attribute
  • value – the value of the attribute
Returns:

the list of matching elements

getElementsByAttribute

public List<FormValueElement> getElementsByAttribute(String attribute, String value, List<String> restrictedElements)

Returns a list of elements with the attribute attribute set to value that aren’t any of the restrictedElements.

Parameters:
  • attribute – the name of the attribute
  • value – the value of the attribute
  • restrictedElements – the restricted elements
Returns:

the list of matching elements

getElementsByAttribute

public List<FormValueElement> getElementsByAttribute(String attribute, String value, List<String> restrictedElements, boolean breakOnFirst)

Returns a list of elements with the attribute attribute set to value that aren’t any of the restrictedElements. If the breakOnFirst is set to true, the list will contain only a single element.

Parameters:
  • attribute – the name of the attribute
  • value – the value of the attribute
  • restrictedElements – the restricted elements
  • breakOnFirst – defines whether method should return a single value list or not
Returns:

the list of matching elements

getSubElements

public Multimap<String, FormValueElement> getSubElements()

getValue

public String getValue()

searchFirst

public FormNode searchFirst(String path)

Returns first node (elements and attributes) found at the given path, in the order in which they are encountered in a preorder traversal of this element tree. Lookup starts with this element and hence this element will be part of the returned list if it matches the given path.

For usage and other information see search(String).

Note: This method will return null if no matching node is found.

Parameters:
  • path – Lookup path.
Returns:

First node found at lookup path.

setAttributes

public void setAttributes(Map<String, String> attributes)

setElementName

public void setElementName(String elementName)

setSubElements

public void setSubElements(Multimap<String, FormValueElement> subElements)

setValue

public void setValue(String value)