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 singleDocumentnode.NodeList(org.jdom.Element element) Creates a node list that holds a singleElementnode. -
Method Summary
Modifier and TypeMethodDescriptionvoidbooleanbooleanaddAll(int index, Collection c) booleanaddAll(Collection c) voidclear()clone()Returns a NodeList that contains the same nodes as this node list.booleanbooleanbooleanTests for equality with another object.get(int index) getList()Retrieves the underlying list used to store the nodes.inthashCode()Returns the hash code of the contained list.intbooleanisEmpty()iterator()intlistIterator(int index) remove(int index) booleanbooleanbooleanselectNodes(String xpathString) Applies an XPath expression to the node list and returns the resulting node list.intsize()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, waitMethods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArrayMethods 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 singleDocumentnode.- Parameters:
document-
-
NodeList
public NodeList(org.jdom.Element element) Creates a node list that holds a singleElementnode.- 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 theListinterface 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:
clonein 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:
addin interfaceCollection- Specified by:
addin interfaceList- See Also:
-
add
-
addAll
- Specified by:
addAllin interfaceCollection- Specified by:
addAllin interfaceList- See Also:
-
addAll
-
clear
public void clear()- Specified by:
clearin interfaceCollection- Specified by:
clearin interfaceList- See Also:
-
contains
- Specified by:
containsin interfaceCollection- Specified by:
containsin interfaceList- See Also:
-
containsAll
- Specified by:
containsAllin interfaceCollection- Specified by:
containsAllin interfaceList- See Also:
-
get
-
indexOf
-
isEmpty
public boolean isEmpty()- Specified by:
isEmptyin interfaceCollection- Specified by:
isEmptyin interfaceList- See Also:
-
iterator
-
lastIndexOf
- Specified by:
lastIndexOfin interfaceList- See Also:
-
listIterator
- Specified by:
listIteratorin interfaceList- See Also:
-
listIterator
- Specified by:
listIteratorin interfaceList- See Also:
-
remove
-
remove
- Specified by:
removein interfaceCollection- Specified by:
removein interfaceList- See Also:
-
removeAll
- Specified by:
removeAllin interfaceCollection- Specified by:
removeAllin interfaceList- See Also:
-
retainAll
- Specified by:
retainAllin interfaceCollection- Specified by:
retainAllin interfaceList- See Also:
-
set
-
size
public int size()- Specified by:
sizein interfaceCollection- Specified by:
sizein interfaceList- See Also:
-
subList
-
toArray
- Specified by:
toArrayin interfaceCollection- Specified by:
toArrayin interfaceList- See Also:
-
toArray
- Specified by:
toArrayin interfaceCollection- Specified by:
toArrayin interfaceList- See Also:
-