freemarker.ext.jdom
Class NodeListModel

java.lang.Object
  extended by freemarker.ext.jdom.NodeListModel
All Implemented Interfaces:
TemplateCollectionModel, TemplateHashModel, TemplateMethodModel, TemplateModel, TemplateScalarModel, TemplateSequenceModel

Deprecated. Use NodeModel instead.

public class NodeListModel
extends java.lang.Object
implements TemplateHashModel, TemplateMethodModel, TemplateCollectionModel, TemplateSequenceModel, TemplateScalarModel

Provides a template for wrapping JDOM objects. It is capable of storing not only a single JDOM node, but a list of JDOM nodes at once (hence the name). Each node is an instance of any of the core JDOM node classes (except namespaces, which are not supported at the moment), or String for representing text. See individual method documentation for exact details on how the class works. In short:

Note: There is a JDOM independent re-implementation of this class: freemarker.ext.xml.NodeListModel

Version:
$Id: NodeListModel.java,v 1.52.2.2 2006/11/14 10:39:58 szegedia Exp $
Author:
Attila Szegedi

Field Summary
 
Fields inherited from interface freemarker.template.TemplateScalarModel
EMPTY_STRING
 
Fields inherited from interface freemarker.template.TemplateModel
NOTHING
 
Constructor Summary
NodeListModel(org.jdom.Document document)
          Deprecated. Creates a node list that holds a single Document node.
NodeListModel(org.jdom.Element element)
          Deprecated. Creates a node list that holds a single Element node.
NodeListModel(java.util.List nodes)
          Deprecated. Creates a node list that holds a list of nodes.
NodeListModel(java.util.List nodes, boolean copy)
          Deprecated. Creates a node list that holds a list of nodes.
 
Method Summary
 java.lang.Object exec(java.util.List arguments)
          Deprecated. Applies an XPath expression to the node list and returns the resulting node list.
 TemplateModel get(int i)
          Deprecated. Retrieves the i-th element of the node list.
 TemplateModel get(java.lang.String key)
          Deprecated. Provides node list traversal as well as special functions: filtering by name, filtering by node type, shallow-copying, and duplicate removal.
 java.lang.String getAsString()
          Deprecated. This method returns the string resulting from concatenation of string representations of its nodes.
 boolean isEmpty()
          Deprecated. Returns true if this model contains no nodes.
 TemplateModelIterator iterator()
          Deprecated. Retrieves a template model iterator that is used to iterate over the elements in this collection.
static void main(java.lang.String[] args)
          Deprecated. Loads a template from a file passed as the first argument, loads an XML document from the standard input, passes it to the template as variable document and writes the result of template processing to standard output.
 void registerNamespace(java.lang.String prefix, java.lang.String uri)
          Deprecated. Registers an XML namespace with this node list.
 int size()
          Deprecated.  
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NodeListModel

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


NodeListModel

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


NodeListModel

public NodeListModel(java.util.List nodes)
Deprecated. 
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.

NodeListModel

public NodeListModel(java.util.List nodes,
                     boolean copy)
Deprecated. 
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, although no operations on the list will be synchronized.
Method Detail

isEmpty

public boolean isEmpty()
Deprecated. 
Returns true if this model contains no nodes.

Specified by:
isEmpty in interface TemplateHashModel

getAsString

public java.lang.String getAsString()
                             throws TemplateModelException
Deprecated. 
This method returns the string resulting from concatenation of string representations of its nodes. Each node is rendered using its XML serialization format, while text (String) is rendered as itself. 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.

Specified by:
getAsString in interface TemplateScalarModel
Throws:
TemplateModelException

get

public TemplateModel get(java.lang.String key)
                  throws TemplateModelException
Deprecated. 
Provides node list traversal as well as special functions: filtering by name, filtering by node type, shallow-copying, and duplicate removal. While not as powerful as the full XPath support built into the exec(List) method, it does not require the external Jaxen library to be present at run time. Below are listed the recognized keys. In key descriptions, "applicable to this-and-that node type" means that if a key is applied to a node list that contains a node of non-applicable type a TemplateMethodModel will be thrown. However, you can use _ftype key to explicitly filter out undesired node types prior to applying the restricted-applicability key. Also "current nodes" means nodes contained in this set. The order of nodes in the resulting set is the order of evaluation of the key on each node in this set from left to right. Evaluation of the key on a single node always yields the results in "natural" order (that of the document preorder traversal), even for uptree traversals. As a consequence, if this node list's nodes are listed in natural order, applying any of the keys will produce a node list that is also naturally ordered. As a special case, all node lists that are directly or indirectly generated from a single Document or Element node through repeated invocations of this method will be naturally ordered.

Specified by:
get in interface TemplateHashModel
Parameters:
key - a key that identifies a required set of nodes
Returns:
a new NodeListModel that represents the requested set of nodes.
Throws:
TemplateModelException

iterator

public TemplateModelIterator iterator()
Deprecated. 
Description copied from interface: TemplateCollectionModel
Retrieves a template model iterator that is used to iterate over the elements in this collection.

Specified by:
iterator in interface TemplateCollectionModel

get

public TemplateModel get(int i)
                  throws TemplateModelException
Deprecated. 
Retrieves the i-th element of the node list.

Specified by:
get in interface TemplateSequenceModel
Returns:
the item at the specified index, or null if the index is out of bounds. Note that a null value is interpreted by FreeMarker as "variable does not exist", and accessing a missing variables is usually considered as an error in the FreeMarker Template Language, so the usage of a bad index will not remain hidden.
Throws:
TemplateModelException

size

public int size()
Deprecated. 
Specified by:
size in interface TemplateSequenceModel
Returns:
the number of items in the list.

exec

public java.lang.Object exec(java.util.List arguments)
                      throws TemplateModelException
Deprecated. 
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 Jaxen 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 FreeMarker template, this ensures that each XPath expression is parsed only once during the lifetime of the FreeMarker template that contains it.

Specified by:
exec in interface TemplateMethodModel
Parameters:
arguments - the list of arguments. Must contain exactly one string that is the XPath expression you wish to apply. The XPath expression can use any namespace prefixes that were defined using the registerNamespace(String, String) method or the nodelist._registerNamespace(prefix, uri) expression in the template.
Returns:
a NodeListModel representing the nodes that are the result of application of the XPath to the current node list.
Throws:
TemplateModelException

registerNamespace

public void registerNamespace(java.lang.String prefix,
                              java.lang.String uri)
Deprecated. 
Registers an XML namespace with this node list. Once registered, you can refer to the registered namespace using its prefix in the get(String) method from this node list and all other node lists that are derived from this node list. Use the nodelist["prefix:localname"] or the nodelist["@prefix:localname"] syntax to reach elements and attributes whose names are namespace-scoped. Note that the namespace prefix need not match the actual prefix used by the XML document itself since namespaces are compared solely by their URI. You can also register namespaces during template evaluation using the nodelist._registerNamespace(prefix, uri) syntax in the template. This mechanism is completely independent from the namespace declarations in the XML document itself; its purpose is to give you an easy way to refer to namespace-scoped elements in get(String) and in XPath expressions passed to exec(List). Note also that the namespace prefix registry is shared among all node lists that are created from a single node list - modifying the registry in one affects all others as well. If you want to obtain a namespace "detached" copy of the node list, use the _copy key on it (or call nodeList.get("_copy") directly from your Java code. The returned node list has all the namespaces that the original node list has, but they can be manipulated independently thereon.


main

public static void main(java.lang.String[] args)
                 throws java.lang.Exception
Deprecated. 
Loads a template from a file passed as the first argument, loads an XML document from the standard input, passes it to the template as variable document and writes the result of template processing to standard output.

Throws:
java.lang.Exception