FormValueElement¶
-
public class
FormValueElement
implements FormNode¶ Object representation of the forwarded form from CommCareHQ.
Methods¶
addFormValueElement¶
-
public void
addFormValueElement
(String key, FormValueElement element)¶
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.
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 tovalue
.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 tovalue
and is not one of therestrictedElements
.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
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 tovalue
.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 tovalue
that aren’t any of therestrictedElements
.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 tovalue
that aren’t any of therestrictedElements
. If thebreakOnFirst
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
()¶
search¶
-
public List<FormNode>
search
(String path)¶ Returns a list of all descendant nodes (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.
Path should start with “//”.
Example: For FormValueElement similar to following XML:
<this thisAttribute="thisAttribute"> <foo> <bar barAttribute="barAttribute1"> <child>child1</child> <child>child2</child> </bar> <child>child3</child> </foo> <foo> <bar barAttribute="barAttribute2" otherBarAttribute="otherBarAttribute"> <child>child4</child> <child>child5</child> <otherChild>otherChild</otherChild> </bar> </foo> </this>
Search for //foo will return both foo elements Search for //foo/bar/child will return elements having values child1, child2, child4, child5. Search for //foo/child will return one element having value as child3. Search for //foo/bar/@barAttribute will return two attribute nodes having values as barAttribute1 and barAttribute2. Search for //foo/bar/@otherBarAttribute will return one attribute element having value as otherBarAttribute. Search for // will return this element. Search for //@thisAttribute will return “thisAttribute node on this element. Paths //foo/bar/#anyValue will return same result as //foo/bar or //foo/bar/#anyOtherValue.
Note: This method will return an empty list if no matching node is found.
Parameters: - path – Lookup path.
Returns: A list containing matching nodes.
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.
setSubElements¶
-
public void
setSubElements
(Multimap<String, FormValueElement> subElements)¶