public final class ElementAndAttributeNameFragmentSpec extends Object implements IFragmentSpec
Fragment specification that extracts a specific element from a Node tree by its name, or by the value of one of its attributes.
Objects of this class are thread-safe.
Constructor and Description |
---|
ElementAndAttributeNameFragmentSpec(String elementName,
String attributeName,
String attributeValue)
Create a fragment spec specifying element name and/or attribute name+value.
|
ElementAndAttributeNameFragmentSpec(String elementName,
String attributeName,
String attributeValue,
boolean returnOnlyChildren)
Create a fragment spec specifying element name and/or attribute name+value, and
specifying whether the selected element itself (or selected elements if more than
one) must be returned or only its/their children.
|
ElementAndAttributeNameFragmentSpec(String elementName,
String attributeName,
String attributeValue,
Map<String,Object> parameterValues)
Create a fragment spec specifying element name and/or attribute name+value.
|
ElementAndAttributeNameFragmentSpec(String elementName,
String attributeName,
String attributeValue,
Map<String,Object> parameterValues,
boolean returnOnlyChildren)
Create a fragment spec specifying element name and/or attribute name+value, and
specifying whether the selected element itself (or selected elements if more than
one) must be returned or only its/their children.
|
Modifier and Type | Method and Description |
---|---|
List<Node> |
extractFragment(Configuration configuration,
List<Node> nodes)
Executes the fragment specification against a list of nodes representing a DOM tree
(or a set of trees), returning the extracted nodes.
|
String |
getAttributeName()
Returns the (optional) attribute name.
|
String |
getAttributeValue()
Returns the attribute value, if attributeName has been set.
|
String |
getElementName()
Returns the (optional) element name.
|
Map<String,Object> |
getParameterValues()
Returns the map of parameter values that will be applied as local variables to the extracted nodes.
|
boolean |
hasParameterValues()
Returns whether this fragment specifies parameter values, to be set as local variables into the extracted
nodes.
|
boolean |
isReturnOnlyChildren()
Returns whether this spec should only return the children of the selected nodes
(true) or the selected nodes themselves (false, default).
|
String |
toString() |
public ElementAndAttributeNameFragmentSpec(String elementName, String attributeName, String attributeValue)
Create a fragment spec specifying element name and/or attribute name+value.
elementName
- the element name to look for, optional.attributeName
- the attribute name to look for, optional.attributeValue
- the value of the attribute (if attribute name has been specified).public ElementAndAttributeNameFragmentSpec(String elementName, String attributeName, String attributeValue, Map<String,Object> parameterValues)
Create a fragment spec specifying element name and/or attribute name+value.
This constructor allows the specification of a series of fragment parameters, which will be applied as local variables to the extracted nodes.
elementName
- the element name to look for, optional.attributeName
- the attribute name to look for, optional.attributeValue
- the value of the attribute (if attribute name has been specified).parameterValues
- the fragment parameters, which will be applied as local variables to the nodes
returned as extraction result. Might be null if no parameters are applied.public ElementAndAttributeNameFragmentSpec(String elementName, String attributeName, String attributeValue, boolean returnOnlyChildren)
Create a fragment spec specifying element name and/or attribute name+value, and specifying whether the selected element itself (or selected elements if more than one) must be returned or only its/their children.
If returnOnlyChildren is true, the element with the specified name and/or containing the specified attribute will be discarded, and only its/their children will be returned.
elementName
- the element name to look for, optional.attributeName
- the attribute name to look for, optional.attributeValue
- the value of the attribute (if attribute name has been specified).returnOnlyChildren
- whether the selected elements should be returned (false),
or only their children (true).public ElementAndAttributeNameFragmentSpec(String elementName, String attributeName, String attributeValue, Map<String,Object> parameterValues, boolean returnOnlyChildren)
Create a fragment spec specifying element name and/or attribute name+value, and specifying whether the selected element itself (or selected elements if more than one) must be returned or only its/their children.
This constructor allows the specification of a series of fragment parameters, which will be applied as local variables to the extracted nodes.
If returnOnlyChildren is true, the element with the specified name and/or containing the specified attribute will be discarded, and only its/their children will be returned.
elementName
- the element name to look for, optional.attributeName
- the attribute name to look for, optional.attributeValue
- the value of the attribute (if attribute name has been specified).parameterValues
- the fragment parameters, which will be applied as local variables to the nodes
returned as extraction result. Might be null if no parameters are applied.returnOnlyChildren
- whether the selected elements should be returned (false),
or only their children (true).public String getElementName()
Returns the (optional) element name.
If this property is not null, this fragment specification will look for element(s) with the name specified here (note the element name is the tag name when processing markup).
Both elementName and attributeName can be set (non-null), and at least one of them must be set.
public String getAttributeName()
Returns the (optional) attribute name.
If this property is not null, this fragment specification will look for element(s) containing an attribute with the name specified here.
If this property is specified (not null), attributeValue must be specified too.
Both elementName and attributeName can be set (non-null), and at least one of them must be set.
public String getAttributeValue()
Returns the attribute value, if attributeName has been set. If attributeName is not null, this property should be set a value too.
This is the value that the attribute specified in attributeName should have in order for an element to be considered extractable by this fragment specification.
Both elementName and attributeName can be set (non-null), and at least one of them must be set.
public boolean isReturnOnlyChildren()
Returns whether this spec should only return the children of the selected nodes (true) or the selected nodes themselves (false, default).
public Map<String,Object> getParameterValues()
Returns the map of parameter values that will be applied as local variables to the extracted nodes.
public boolean hasParameterValues()
Returns whether this fragment specifies parameter values, to be set as local variables into the extracted nodes.
public List<Node> extractFragment(Configuration configuration, List<Node> nodes)
IFragmentSpec
Executes the fragment specification against a list of nodes representing a DOM tree (or a set of trees), returning the extracted nodes.
extractFragment
in interface IFragmentSpec
configuration
- the configuration object.nodes
- the list of nodes on which to apply extraction.Copyright © 2014 The THYMELEAF team. All rights reserved.