Package org.apache.velocity.anakia
Class NodeList
- java.lang.Object
-
- org.apache.velocity.anakia.NodeList
-
- All Implemented Interfaces:
java.lang.Cloneable,java.lang.Iterable,java.util.Collection,java.util.List
public class NodeList extends java.lang.Object implements java.util.List, java.lang.CloneableProvides a class for wrapping a list of JDOM objects primarily for use in template engines and other kinds of text transformation tools. It has atoString()method that will output the XML serialized form of the nodes it contains - again focusing on template engine usage, as well as theselectNodes(String)method that helps selecting a different set of nodes starting from the nodes in this list. The class also implements theListinterface by simply delegating calls to the contained list (thesubList(int, int)method is implemented by delegating to the contained list and wrapping the returned sublist into aNodeList).- Version:
- $Id: NodeList.java 463298 2006-10-12 16:10:32Z henning $
- Author:
- Attila Szegedi
-
-
Constructor Summary
Constructors Constructor Description NodeList()Creates an empty node list.NodeList(java.util.List nodes)Creates a node list that holds a list of nodes.NodeList(java.util.List nodes, boolean copy)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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(int index, java.lang.Object o)booleanadd(java.lang.Object o)booleanaddAll(int index, java.util.Collection c)booleanaddAll(java.util.Collection c)voidclear()java.lang.Objectclone()Returns a NodeList that contains the same nodes as this node list.booleancontains(java.lang.Object o)booleancontainsAll(java.util.Collection c)booleanequals(java.lang.Object o)Tests for equality with another object.java.lang.Objectget(int index)java.util.ListgetList()Retrieves the underlying list used to store the nodes.inthashCode()Returns the hash code of the contained list.intindexOf(java.lang.Object o)booleanisEmpty()java.util.Iteratoriterator()intlastIndexOf(java.lang.Object o)java.util.ListIteratorlistIterator()java.util.ListIteratorlistIterator(int index)java.lang.Objectremove(int index)booleanremove(java.lang.Object o)booleanremoveAll(java.util.Collection c)booleanretainAll(java.util.Collection c)NodeListselectNodes(java.lang.String xpathString)Applies an XPath expression to the node list and returns the resulting node list.java.lang.Objectset(int index, java.lang.Object o)intsize()java.util.ListsubList(int fromIndex, int toIndex)java.lang.Object[]toArray()java.lang.Object[]toArray(java.lang.Object[] a)java.lang.StringtoString()This method returns the string resulting from concatenation of string representations of its nodes.
-
-
-
Constructor Detail
-
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
public NodeList(java.util.List nodes)
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
public NodeList(java.util.List nodes, boolean copy)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 Detail
-
getList
public java.util.List 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
public java.lang.String 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).- Overrides:
toStringin classjava.lang.Object- Returns:
- The Nodelist as printable object.
-
clone
public java.lang.Object clone() throws java.lang.CloneNotSupportedExceptionReturns a NodeList that contains the same nodes as this node list.- Overrides:
clonein classjava.lang.Object- Returns:
- A clone of this list.
- Throws:
java.lang.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.- Specified by:
hashCodein interfacejava.util.Collection- Specified by:
hashCodein interfacejava.util.List- Overrides:
hashCodein classjava.lang.Object- Returns:
- The hashcode of the list.
-
equals
public boolean equals(java.lang.Object o)
Tests for equality with another object.- Specified by:
equalsin interfacejava.util.Collection- Specified by:
equalsin interfacejava.util.List- Overrides:
equalsin classjava.lang.Object- Parameters:
o- the object to test for equality- Returns:
- true if the other object is also a NodeList and their contained
Listobjects evaluate as equals.
-
selectNodes
public NodeList selectNodes(java.lang.String xpathString)
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
public boolean add(java.lang.Object o)
- Specified by:
addin interfacejava.util.Collection- Specified by:
addin interfacejava.util.List- See Also:
List.add(java.lang.Object)
-
add
public void add(int index, java.lang.Object o)- Specified by:
addin interfacejava.util.List- See Also:
List.add(int, java.lang.Object)
-
addAll
public boolean addAll(java.util.Collection c)
- Specified by:
addAllin interfacejava.util.Collection- Specified by:
addAllin interfacejava.util.List- See Also:
List.addAll(java.util.Collection)
-
addAll
public boolean addAll(int index, java.util.Collection c)- Specified by:
addAllin interfacejava.util.List- See Also:
List.addAll(int, java.util.Collection)
-
clear
public void clear()
- Specified by:
clearin interfacejava.util.Collection- Specified by:
clearin interfacejava.util.List- See Also:
List.clear()
-
contains
public boolean contains(java.lang.Object o)
- Specified by:
containsin interfacejava.util.Collection- Specified by:
containsin interfacejava.util.List- See Also:
List.contains(java.lang.Object)
-
containsAll
public boolean containsAll(java.util.Collection c)
- Specified by:
containsAllin interfacejava.util.Collection- Specified by:
containsAllin interfacejava.util.List- See Also:
List.containsAll(java.util.Collection)
-
get
public java.lang.Object get(int index)
- Specified by:
getin interfacejava.util.List- See Also:
List.get(int)
-
indexOf
public int indexOf(java.lang.Object o)
- Specified by:
indexOfin interfacejava.util.List- See Also:
List.indexOf(java.lang.Object)
-
isEmpty
public boolean isEmpty()
- Specified by:
isEmptyin interfacejava.util.Collection- Specified by:
isEmptyin interfacejava.util.List- See Also:
List.isEmpty()
-
iterator
public java.util.Iterator iterator()
- Specified by:
iteratorin interfacejava.util.Collection- Specified by:
iteratorin interfacejava.lang.Iterable- Specified by:
iteratorin interfacejava.util.List- See Also:
List.iterator()
-
lastIndexOf
public int lastIndexOf(java.lang.Object o)
- Specified by:
lastIndexOfin interfacejava.util.List- See Also:
List.lastIndexOf(java.lang.Object)
-
listIterator
public java.util.ListIterator listIterator()
- Specified by:
listIteratorin interfacejava.util.List- See Also:
List.listIterator()
-
listIterator
public java.util.ListIterator listIterator(int index)
- Specified by:
listIteratorin interfacejava.util.List- See Also:
List.listIterator(int)
-
remove
public java.lang.Object remove(int index)
- Specified by:
removein interfacejava.util.List- See Also:
List.remove(int)
-
remove
public boolean remove(java.lang.Object o)
- Specified by:
removein interfacejava.util.Collection- Specified by:
removein interfacejava.util.List- See Also:
List.remove(java.lang.Object)
-
removeAll
public boolean removeAll(java.util.Collection c)
- Specified by:
removeAllin interfacejava.util.Collection- Specified by:
removeAllin interfacejava.util.List- See Also:
List.removeAll(java.util.Collection)
-
retainAll
public boolean retainAll(java.util.Collection c)
- Specified by:
retainAllin interfacejava.util.Collection- Specified by:
retainAllin interfacejava.util.List- See Also:
List.retainAll(java.util.Collection)
-
set
public java.lang.Object set(int index, java.lang.Object o)- Specified by:
setin interfacejava.util.List- See Also:
List.set(int, java.lang.Object)
-
size
public int size()
- Specified by:
sizein interfacejava.util.Collection- Specified by:
sizein interfacejava.util.List- See Also:
List.size()
-
subList
public java.util.List subList(int fromIndex, int toIndex)- Specified by:
subListin interfacejava.util.List- See Also:
List.subList(int, int)
-
toArray
public java.lang.Object[] toArray()
- Specified by:
toArrayin interfacejava.util.Collection- Specified by:
toArrayin interfacejava.util.List- See Also:
List.toArray()
-
toArray
public java.lang.Object[] toArray(java.lang.Object[] a)
- Specified by:
toArrayin interfacejava.util.Collection- Specified by:
toArrayin interfacejava.util.List- See Also:
List.toArray(java.lang.Object[])
-
-