org.apache.velocity.anakia
Class NodeList

java.lang.Object
  extended by 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.Cloneable

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
NodeList()
          Creates an empty node list.
NodeList(org.jdom.Document document)
          Creates a node list that holds a single Document node.
NodeList(org.jdom.Element element)
          Creates a node list that holds a single Element node.
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.
 
Method Summary
 void add(int index, java.lang.Object o)
           
 boolean add(java.lang.Object o)
           
 boolean addAll(java.util.Collection c)
           
 boolean addAll(int index, java.util.Collection c)
           
 void clear()
           
 java.lang.Object clone()
          Returns a NodeList that contains the same nodes as this node list.
 boolean contains(java.lang.Object o)
           
 boolean containsAll(java.util.Collection c)
           
 boolean equals(java.lang.Object o)
          Tests for equality with another object.
 java.lang.Object get(int index)
           
 java.util.List getList()
          Retrieves the underlying list used to store the nodes.
 int hashCode()
          Returns the hash code of the contained list.
 int indexOf(java.lang.Object o)
           
 boolean isEmpty()
           
 java.util.Iterator iterator()
           
 int lastIndexOf(java.lang.Object o)
           
 java.util.ListIterator listIterator()
           
 java.util.ListIterator listIterator(int index)
           
 java.lang.Object remove(int index)
           
 boolean remove(java.lang.Object o)
           
 boolean removeAll(java.util.Collection c)
           
 boolean retainAll(java.util.Collection c)
           
 NodeList selectNodes(java.lang.String xpathString)
          Applies an XPath expression to the node list and returns the resulting node list.
 java.lang.Object set(int index, java.lang.Object o)
           
 int size()
           
 java.util.List subList(int fromIndex, int toIndex)
           
 java.lang.Object[] toArray()
           
 java.lang.Object[] toArray(java.lang.Object[] a)
           
 java.lang.String 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
 

Constructor Detail

NodeList

public NodeList()
Creates an empty node list.


NodeList

public NodeList(org.jdom.Document document)
Creates a node list that holds a single Document node.

Parameters:
document -

NodeList

public NodeList(org.jdom.Element element)
Creates a node list that holds a single Element node.

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 the List interface 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:
toString in class java.lang.Object
Returns:
The Nodelist as printable object.

clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
Returns a NodeList that contains the same nodes as this node list.

Overrides:
clone in class java.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:
hashCode in interface java.util.Collection
Specified by:
hashCode in interface java.util.List
Overrides:
hashCode in class java.lang.Object
Returns:
The hashcode of the list.

equals

public boolean equals(java.lang.Object o)
Tests for equality with another object.

Specified by:
equals in interface java.util.Collection
Specified by:
equals in interface java.util.List
Overrides:
equals in class java.lang.Object
Parameters:
o - the object to test for equality
Returns:
true if the other object is also a NodeList and their contained List objects 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:
add in interface java.util.Collection
Specified by:
add in interface java.util.List
See Also:
List.add(java.lang.Object)

add

public void add(int index,
                java.lang.Object o)
Specified by:
add in interface java.util.List
See Also:
List.add(int, java.lang.Object)

addAll

public boolean addAll(java.util.Collection c)
Specified by:
addAll in interface java.util.Collection
Specified by:
addAll in interface java.util.List
See Also:
List.addAll(java.util.Collection)

addAll

public boolean addAll(int index,
                      java.util.Collection c)
Specified by:
addAll in interface java.util.List
See Also:
List.addAll(int, java.util.Collection)

clear

public void clear()
Specified by:
clear in interface java.util.Collection
Specified by:
clear in interface java.util.List
See Also:
List.clear()

contains

public boolean contains(java.lang.Object o)
Specified by:
contains in interface java.util.Collection
Specified by:
contains in interface java.util.List
See Also:
List.contains(java.lang.Object)

containsAll

public boolean containsAll(java.util.Collection c)
Specified by:
containsAll in interface java.util.Collection
Specified by:
containsAll in interface java.util.List
See Also:
List.containsAll(java.util.Collection)

get

public java.lang.Object get(int index)
Specified by:
get in interface java.util.List
See Also:
List.get(int)

indexOf

public int indexOf(java.lang.Object o)
Specified by:
indexOf in interface java.util.List
See Also:
List.indexOf(java.lang.Object)

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface java.util.Collection
Specified by:
isEmpty in interface java.util.List
See Also:
List.isEmpty()

iterator

public java.util.Iterator iterator()
Specified by:
iterator in interface java.lang.Iterable
Specified by:
iterator in interface java.util.Collection
Specified by:
iterator in interface java.util.List
See Also:
List.iterator()

lastIndexOf

public int lastIndexOf(java.lang.Object o)
Specified by:
lastIndexOf in interface java.util.List
See Also:
List.lastIndexOf(java.lang.Object)

listIterator

public java.util.ListIterator listIterator()
Specified by:
listIterator in interface java.util.List
See Also:
List.listIterator()

listIterator

public java.util.ListIterator listIterator(int index)
Specified by:
listIterator in interface java.util.List
See Also:
List.listIterator(int)

remove

public java.lang.Object remove(int index)
Specified by:
remove in interface java.util.List
See Also:
List.remove(int)

remove

public boolean remove(java.lang.Object o)
Specified by:
remove in interface java.util.Collection
Specified by:
remove in interface java.util.List
See Also:
List.remove(java.lang.Object)

removeAll

public boolean removeAll(java.util.Collection c)
Specified by:
removeAll in interface java.util.Collection
Specified by:
removeAll in interface java.util.List
See Also:
List.removeAll(java.util.Collection)

retainAll

public boolean retainAll(java.util.Collection c)
Specified by:
retainAll in interface java.util.Collection
Specified by:
retainAll in interface java.util.List
See Also:
List.retainAll(java.util.Collection)

set

public java.lang.Object set(int index,
                            java.lang.Object o)
Specified by:
set in interface java.util.List
See Also:
List.set(int, java.lang.Object)

size

public int size()
Specified by:
size in interface java.util.Collection
Specified by:
size in interface java.util.List
See Also:
List.size()

subList

public java.util.List subList(int fromIndex,
                              int toIndex)
Specified by:
subList in interface java.util.List
See Also:
List.subList(int, int)

toArray

public java.lang.Object[] toArray()
Specified by:
toArray in interface java.util.Collection
Specified by:
toArray in interface java.util.List
See Also:
List.toArray()

toArray

public java.lang.Object[] toArray(java.lang.Object[] a)
Specified by:
toArray in interface java.util.Collection
Specified by:
toArray in interface java.util.List
See Also:
List.toArray(java.lang.Object[])


Copyright © 2000-2012. All Rights Reserved.