Package org.apache.velocity.anakia
Class NodeList
java.lang.Object
org.apache.velocity.anakia.NodeList
- All Implemented Interfaces:
Cloneable
,Iterable
,Collection
,List
Provides a class for wrapping a list of JDOM objects primarily for use in template
engines and other kinds of text transformation tools.
It has a
toString()
method that will output the XML serialized form of the
nodes it contains - again focusing on template engine usage, as well as the
selectNodes(String)
method that helps selecting a different set of nodes
starting from the nodes in this list. The class also implements the List
interface by simply delegating calls to the contained list (the subList(int, int)
method is implemented by delegating to the contained list and wrapping the returned
sublist into a NodeList
).- Version:
- $Id: NodeList.java 463298 2006-10-12 16:10:32Z henning $
- Author:
- Attila Szegedi
-
Constructor Summary
ConstructorsConstructorDescriptionNodeList()
Creates an empty node list.Creates a node list that holds a list of nodes.Creates a node list that holds a list of nodes.NodeList
(org.jdom.Document document) Creates a node list that holds a singleDocument
node.NodeList
(org.jdom.Element element) Creates a node list that holds a singleElement
node. -
Method Summary
Modifier and TypeMethodDescriptionvoid
boolean
boolean
addAll
(int index, Collection c) boolean
addAll
(Collection c) void
clear()
clone()
Returns a NodeList that contains the same nodes as this node list.boolean
boolean
boolean
Tests for equality with another object.get
(int index) getList()
Retrieves the underlying list used to store the nodes.int
hashCode()
Returns the hash code of the contained list.int
boolean
isEmpty()
iterator()
int
listIterator
(int index) remove
(int index) boolean
boolean
boolean
selectNodes
(String xpathString) Applies an XPath expression to the node list and returns the resulting node list.int
size()
subList
(int fromIndex, int toIndex) Object[]
toArray()
Object[]
toString()
This method returns the string resulting from concatenation of string representations of its nodes.Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
Methods inherited from interface java.util.List
replaceAll, sort, spliterator
-
Constructor Details
-
NodeList
public NodeList()Creates an empty node list. -
NodeList
public NodeList(org.jdom.Document document) Creates a node list that holds a singleDocument
node.- Parameters:
document
-
-
NodeList
public NodeList(org.jdom.Element element) Creates a node list that holds a singleElement
node.- Parameters:
element
-
-
NodeList
Creates a node list that holds a list of nodes.- Parameters:
nodes
- the list of nodes this template should hold. The created template will copy the passed nodes list, so changes to the passed list will not affect the model.
-
NodeList
Creates a node list that holds a list of nodes.- Parameters:
nodes
- the list of nodes this template should hold.copy
- if true, the created template will copy the passed nodes list, so changes to the passed list will not affect the model. If false, the model will reference the passed list and will sense changes in it, altough no operations on the list will be synchronized.
-
-
Method Details
-
getList
Retrieves the underlying list used to store the nodes. Note however, that you can fully use the underlying list through theList
interface of this class itself. You would probably access the underlying list only for synchronization purposes.- Returns:
- The internal node List.
-
toString
This method returns the string resulting from concatenation of string representations of its nodes. Each node is rendered using its XML serialization format. This greatly simplifies creating XML-transformation templates, as to output a node contained in variable x as XML fragment, you simply write ${x} in the template (or whatever your template engine uses as its expression syntax). -
clone
Returns a NodeList that contains the same nodes as this node list.- Overrides:
clone
in classObject
- Returns:
- A clone of this list.
- Throws:
CloneNotSupportedException
- if the contained list's class does not have an accessible no-arg constructor.
-
hashCode
public int hashCode()Returns the hash code of the contained list. -
equals
Tests for equality with another object. -
selectNodes
Applies an XPath expression to the node list and returns the resulting node list. In order for this method to work, your application must have access to werken.xpath library classes. The implementation does cache the parsed format of XPath expressions in a weak hash map, keyed by the string representation of the XPath expression. As the string object passed as the argument is usually kept in the parsed template, this ensures that each XPath expression is parsed only once during the lifetime of the template that first invoked it.- Parameters:
xpathString
- the XPath expression you wish to apply- Returns:
- a NodeList representing the nodes that are the result of application of the XPath to the current node list. It can be empty.
-
add
- Specified by:
add
in interfaceCollection
- Specified by:
add
in interfaceList
- See Also:
-
add
-
addAll
- Specified by:
addAll
in interfaceCollection
- Specified by:
addAll
in interfaceList
- See Also:
-
addAll
-
clear
public void clear()- Specified by:
clear
in interfaceCollection
- Specified by:
clear
in interfaceList
- See Also:
-
contains
- Specified by:
contains
in interfaceCollection
- Specified by:
contains
in interfaceList
- See Also:
-
containsAll
- Specified by:
containsAll
in interfaceCollection
- Specified by:
containsAll
in interfaceList
- See Also:
-
get
-
indexOf
-
isEmpty
public boolean isEmpty()- Specified by:
isEmpty
in interfaceCollection
- Specified by:
isEmpty
in interfaceList
- See Also:
-
iterator
-
lastIndexOf
- Specified by:
lastIndexOf
in interfaceList
- See Also:
-
listIterator
- Specified by:
listIterator
in interfaceList
- See Also:
-
listIterator
- Specified by:
listIterator
in interfaceList
- See Also:
-
remove
-
remove
- Specified by:
remove
in interfaceCollection
- Specified by:
remove
in interfaceList
- See Also:
-
removeAll
- Specified by:
removeAll
in interfaceCollection
- Specified by:
removeAll
in interfaceList
- See Also:
-
retainAll
- Specified by:
retainAll
in interfaceCollection
- Specified by:
retainAll
in interfaceList
- See Also:
-
set
-
size
public int size()- Specified by:
size
in interfaceCollection
- Specified by:
size
in interfaceList
- See Also:
-
subList
-
toArray
- Specified by:
toArray
in interfaceCollection
- Specified by:
toArray
in interfaceList
- See Also:
-
toArray
- Specified by:
toArray
in interfaceCollection
- Specified by:
toArray
in interfaceList
- See Also:
-