NodeList (Velocity 1.7 API)
Keywords: org.apache.velocity.anakia.NodeList class

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.apache.velocity.anakia
Class NodeList

    java.lang.Object
      org.apache.velocity.anakia.NodeList

All Implemented Interfaces:
  Cloneable, Collection, List

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

Method Summary
`void` | `add(int index, Object o)`
`boolean` | `add(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.
`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)`
`Object` | `remove(int index)`
`boolean` | `remove(Object o)`
`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.

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(Document document)

  Creates a node list that holds a single `Document` node.

Parameters:
  `document` -

### NodeList

    public NodeList(Element element)

  Creates a node list that holds a single `Element` node.

Parameters:
  `element` -

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

Method Detail

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

  Returns:
    The internal node List.

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

  Returns:
    The Nodelist as printable object.

### clone

    public Object clone()
                 throws CloneNotSupportedException

  Returns a NodeList that contains the same nodes as this node list.

  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.

  Specified by:
    `hashCode` in interface `List`
  Returns:
    The hashcode of the list.

### equals

    public boolean equals(Object o)

  Tests for equality with another object.

  Specified by:
    `equals` in interface `List`
  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(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(Object o)

  Specified by:
    `add` in interface `List`
  See Also:
    `List.add(java.lang.Object)`

### add

    public void add(int index,
                    Object o)

  Specified by:
    `add` in interface `List`
  See Also:
    `List.add(int, java.lang.Object)`

### addAll

    public boolean addAll(Collection c)

  Specified by:
    `addAll` in interface `List`
  See Also:
    `List.addAll(java.util.Collection)`

### addAll

    public boolean addAll(int index,
                          Collection c)

  Specified by:
    `addAll` in interface `List`
  See Also:
    `List.addAll(int, java.util.Collection)`

### clear

    public void clear()

  Specified by:
    `clear` in interface `List`
  See Also:
    `List.clear()`

### contains

    public boolean contains(Object o)

  Specified by:
    `contains` in interface `List`
  See Also:
    `List.contains(java.lang.Object)`

### containsAll

    public boolean containsAll(Collection c)

  Specified by:
    `containsAll` in interface `List`
  See Also:
    `List.containsAll(java.util.Collection)`

### get

    public Object get(int index)

  Specified by:
    `get` in interface `List`
  See Also:
    `List.get(int)`

### indexOf

    public int indexOf(Object o)

  Specified by:
    `indexOf` in interface `List`
  See Also:
    `List.indexOf(java.lang.Object)`

### isEmpty

    public boolean isEmpty()

  Specified by:
    `isEmpty` in interface `List`
  See Also:
    `List.isEmpty()`

### iterator

    public Iterator iterator()

  Specified by:
    `iterator` in interface `List`
  See Also:
    `List.iterator()`

### lastIndexOf

    public int lastIndexOf(Object o)

  Specified by:
    `lastIndexOf` in interface `List`
  See Also:
    `List.lastIndexOf(java.lang.Object)`

### listIterator

    public ListIterator listIterator()

  Specified by:
    `listIterator` in interface `List`
  See Also:
    `List.listIterator()`

### listIterator

    public ListIterator listIterator(int index)

  Specified by:
    `listIterator` in interface `List`
  See Also:
    `List.listIterator(int)`

### remove

    public Object remove(int index)

  Specified by:
    `remove` in interface `List`
  See Also:
    `List.remove(int)`

### remove

    public boolean remove(Object o)

  Specified by:
    `remove` in interface `List`
  See Also:
    `List.remove(java.lang.Object)`

### removeAll

    public boolean removeAll(Collection c)

  Specified by:
    `removeAll` in interface `List`
  See Also:
    `List.removeAll(java.util.Collection)`

### retainAll

    public boolean retainAll(Collection c)

  Specified by:
    `retainAll` in interface `List`
  See Also:
    `List.retainAll(java.util.Collection)`

### set

    public Object set(int index,
                      Object o)

  Specified by:
    `set` in interface `List`
  See Also:
    `List.set(int, java.lang.Object)`

### size

    public int size()

  Specified by:
    `size` in interface `List`
  See Also:
    `List.size()`

### subList

    public List subList(int fromIndex,
                        int toIndex)

  Specified by:
    `subList` in interface `List`
  See Also:
    `List.subList(int, int)`

### toArray

    public Object[] toArray()

  Specified by:
    `toArray` in interface `List`
  See Also:
    `List.toArray()`

### toArray

    public Object[] toArray(Object[] a)

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

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2000-2010 Apache Software Foundation. All Rights Reserved.