org.thymeleaf.fragment
Class ElementAndAttributeNameFragmentSpec

Object
  extended by org.thymeleaf.fragment.ElementAndAttributeNameFragmentSpec
All Implemented Interfaces:
IFragmentSpec

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.

Since:
2.0.9
Author:
Daniel Fernández

Constructor Summary
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.
 
Method Summary
 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.
 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()
           
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ElementAndAttributeNameFragmentSpec

public ElementAndAttributeNameFragmentSpec(String elementName,
                                           String attributeName,
                                           String attributeValue)

Create a fragment spec specifying element name and/or attribute name+value.

Parameters:
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).

ElementAndAttributeNameFragmentSpec

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.

Parameters:
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).
Since:
2.0.12
Method Detail

getElementName

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.

Returns:
the element name, or null if it has not been set.

getAttributeName

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.

Returns:
the attribute name, of null if it has not been set.

getAttributeValue

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.

Returns:
the attribute value, or null if it has not been set.

isReturnOnlyChildren

public boolean isReturnOnlyChildren()

Returns whether this spec should only return the children of the selected nodes (true) or the selected nodes themselves (false, default).

Returns:
whether this spec should only return the children of the selected nodes or not (default: false).
Since:
2.0.12

extractFragment

public final List<Node> extractFragment(Configuration configuration,
                                        List<Node> nodes)
Description copied from interface: IFragmentSpec

Executes the fragment specification against a list of nodes representing a DOM tree (or a set of trees), returning the extracted nodes.

Specified by:
extractFragment in interface IFragmentSpec
Parameters:
configuration - the configuration object.
nodes - the list of nodes on which to apply extraction.
Returns:
the extracted nodes.

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2013 The THYMELEAF team. All Rights Reserved.