org.apache.velocity.anakia

Class NodeList

Implemented Interfaces:
Cloneable, List

public class NodeList
extends java.lang.Object
implements List, 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 java.util.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,v 1.2.4.1 2004/03/03 23:22:04 geirm Exp $
Author:
Attila Szegedi

Nested Class Summary

private static class
NodeList.AttributeXMLOutputter
A special subclass of XMLOutputter that will be used to output Attribute nodes.

Field Summary

private static NodeList.AttributeXMLOutputter
DEFAULT_OUTPUTTER
private List
nodes
The contained nodes

Constructor Summary

NodeList()
Creates an empty node list.
NodeList(Document document)
Creates a node list that holds a single Document node.
NodeList(Element element)
Creates a node list that holds a single Element node.
NodeList(List nodes)
Creates a node list that holds a list of nodes.
NodeList(List nodes, boolean copy)
Creates a node list that holds a list of nodes.
NodeList(Object object)

Method Summary

boolean
add(Object o)
void
add(int index, Object o)
boolean
addAll(Collection c)
boolean
addAll(int index, Collection c)
void
clear()
Object
clone()
Returns a NodeList that contains the same nodes as this node list.
private void
cloneNodes()
boolean
contains(Object o)
boolean
containsAll(Collection c)
boolean
equals(Object o)
Tests for equality with another object.
Object
get(int index)
List
getList()
Retrieves the underlying list used to store the nodes.
int
hashCode()
Returns the hash code of the contained list.
int
indexOf(Object o)
boolean
isEmpty()
Iterator
iterator()
int
lastIndexOf(Object o)
ListIterator
listIterator()
ListIterator
listIterator(int index)
boolean
remove(Object o)
Object
remove(int index)
boolean
removeAll(Collection c)
boolean
retainAll(Collection c)
NodeList
selectNodes(String xpathString)
Applies an XPath expression to the node list and returns the resulting node list.
Object
set(int index, Object o)
int
size()
List
subList(int fromIndex, int toIndex)
Object[]
toArray()
Object[]
toArray(Object[] a)
String
toString()
This method returns the string resulting from concatenation of string representations of its nodes.

Field Details

DEFAULT_OUTPUTTER

private static final NodeList.AttributeXMLOutputter DEFAULT_OUTPUTTER

nodes

private List nodes
The contained nodes

Constructor Details

NodeList

public NodeList()
Creates an empty node list.

NodeList

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

NodeList

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

NodeList

public NodeList(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(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.

NodeList

private NodeList(Object object)

Method Details

add

public boolean add(Object o)

add

public void add(int index,
                Object o)

addAll

public boolean addAll(Collection c)

addAll

public boolean addAll(int index,
                      Collection c)

clear

public void clear()

clone

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

cloneNodes

private void cloneNodes()
            throws CloneNotSupportedException

contains

public boolean contains(Object o)

containsAll

public boolean containsAll(Collection c)

equals

public boolean equals(Object o)
Tests for equality with another 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.

get

public Object get(int index)

getList

public 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.

hashCode

public int hashCode()
Returns the hash code of the contained list.

indexOf

public int indexOf(Object o)

isEmpty

public boolean isEmpty()

iterator

public Iterator iterator()

lastIndexOf

public int lastIndexOf(Object o)

listIterator

public ListIterator listIterator()

listIterator

public ListIterator listIterator(int index)

remove

public boolean remove(Object o)

remove

public Object remove(int index)

removeAll

public boolean removeAll(Collection c)

retainAll

public boolean retainAll(Collection c)

selectNodes

public NodeList selectNodes(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:
Returns:
a NodeList representing the nodes that are the result of application of the XPath to the current node list. It can be empty.

set

public Object set(int index,
                  Object o)

size

public int size()

subList

public List subList(int fromIndex,
                    int toIndex)

toArray

public Object[] toArray()

toArray

public Object[] toArray(Object[] a)

toString

public 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).

Copyright B) 2002 Apache Software Foundation. All Rights Reserved.