freemarker.ext.dom

Class NodeModel

Implemented Interfaces:
AdapterTemplateModel, TemplateHashModel, TemplateModel, TemplateNodeModel, TemplateSequenceModel, WrapperTemplateModel

public abstract class NodeModel
extends java.lang.Object
implements TemplateNodeModel, TemplateHashModel, TemplateSequenceModel, AdapterTemplateModel, WrapperTemplateModel

A base class for wrapping a W3C DOM Node as a FreeMarker template model.
Version:
$Id: NodeModel.java,v 1.80 2005/06/22 11:33:31 ddekany Exp $
Author:
Jonathan Revusky

Fields inherited from interface freemarker.template.TemplateModel

NOTHING

Constructor Summary

NodeModel(Node node)

Method Summary

boolean
equals(Object other)
TemplateModel
exec(List args)
TemplateModel
get(String key)
TemplateModel
get(int i)
Object
getAdaptedObject(Class hint)
TemplateSequenceModel
getChildNodes()
static DocumentBuilderFactory
getDocumentBuilderFactory()
Node
getNode()
String
getNodeNamespace()
String
getNodeType()
TemplateNodeModel
getParentNode()
Object
getWrappedObject()
static Class
getXPathSupportClass()
Get the currently used freemarker.ext.dom.XPathSupport used as the XPath engine.
int
hashCode()
static void
mergeAdjacentText(Node node)
Merges adjacent text/cdata nodes, so that there are no adjacent text/cdata nodes.
static NodeModel
parse(File f)
Create a NodeModel from an XML file.
static NodeModel
parse(File f, boolean removeComments, boolean removePIs)
Create a NodeModel from an XML file.
static NodeModel
parse(InputSource is)
Create a NodeModel from an XML input source.
static NodeModel
parse(InputSource is, boolean removeComments, boolean removePIs)
Create a NodeModel from a SAX input source.
static void
removeComments(Node node)
Recursively removes all comment nodes from the subtree.
static void
removePIs(Node node)
Recursively removes all processing instruction nodes from the subtree.
static void
setDocumentBuilderFactory(DocumentBuilderFactory docBuilderFactory)
Sets the DOM Parser implementation to be used when building NodeModel objects from XML files.
static void
setErrorHandler(ErrorHandler errorHandler)
sets the error handler to use when parsing the document.
static void
setXPathSupportClass(Class cl)
Set an alternative implementation of freemarker.ext.dom.XPathSupport to use as the XPath engine.
static void
simplify(Node node)
Removes comments and processing instruction, and then unites adjacent text nodes.
int
size()
static void
useDefaultXPathSupport()
Tells the system to use (restore) the default (initial) XPath system used by this FreeMarker version on this system.
static void
useJaxenXPathSupport()
Convenience method.
static void
useSunInternalXPathSupport()
static void
useXalanXPathSupport()
Convenience method.
static NodeModel
wrap(Node node)

Constructor Details

NodeModel

protected NodeModel(Node node)

Method Details

equals

public boolean equals(Object other)

exec

public TemplateModel exec(List args)
            throws TemplateModelException

get

public TemplateModel get(String key)
            throws TemplateModelException
Specified by:
get in interface TemplateHashModel

get

public final TemplateModel get(int i)
Specified by:
get in interface TemplateSequenceModel

getAdaptedObject

public Object getAdaptedObject(Class hint)
Specified by:
getAdaptedObject in interface AdapterTemplateModel

getChildNodes

public TemplateSequenceModel getChildNodes()
Specified by:
getChildNodes in interface TemplateNodeModel

getDocumentBuilderFactory

public static DocumentBuilderFactory getDocumentBuilderFactory()
Returns:
the DOM Parser implementation that is used when building NodeModel objects from XML files.

getNode

public Node getNode()
Returns:
the underling W3C DOM Node object that this TemplateNodeModel is wrapping.

getNodeNamespace

public String getNodeNamespace()
Specified by:
getNodeNamespace in interface TemplateNodeModel

getNodeType

public final String getNodeType()
            throws TemplateModelException
Specified by:
getNodeType in interface TemplateNodeModel

getParentNode

public TemplateNodeModel getParentNode()
Specified by:
getParentNode in interface TemplateNodeModel

getWrappedObject

public Object getWrappedObject()
Specified by:
getWrappedObject in interface WrapperTemplateModel

getXPathSupportClass

public static Class getXPathSupportClass()
Get the currently used freemarker.ext.dom.XPathSupport used as the XPath engine. Returns null if XPath support is disabled.

hashCode

public final int hashCode()

mergeAdjacentText

public static void mergeAdjacentText(Node node)
Merges adjacent text/cdata nodes, so that there are no adjacent text/cdata nodes. Operates recursively on the entire subtree. You thus lose information about any CDATA sections occurring in the doc.

parse

public static NodeModel parse(File f)
            throws SAXException,
                   IOException,
                   ParserConfigurationException
Create a NodeModel from an XML file. By default, all comments and processing instruction nodes are stripped from the tree.

parse

public static NodeModel parse(File f,
                              boolean removeComments,
                              boolean removePIs)
            throws SAXException,
                   IOException,
                   ParserConfigurationException
Create a NodeModel from an XML file.
Parameters:
removeComments - whether to remove all comment nodes (recursively) from the tree before processing
removePIs - whether to remove all processing instruction nodes (recursively from the tree before processing

parse

public static NodeModel parse(InputSource is)
            throws SAXException,
                   IOException,
                   ParserConfigurationException
Create a NodeModel from an XML input source. By default, all comments and processing instruction nodes are stripped from the tree.

parse

public static NodeModel parse(InputSource is,
                              boolean removeComments,
                              boolean removePIs)
            throws SAXException,
                   IOException,
                   ParserConfigurationException
Create a NodeModel from a SAX input source. Adjacent text nodes will be merged (and CDATA sections are considered as text nodes).
Parameters:
removeComments - whether to remove all comment nodes (recursively) from the tree before processing
removePIs - whether to remove all processing instruction nodes (recursively from the tree before processing

removeComments

public static void removeComments(Node node)
Recursively removes all comment nodes from the subtree.

removePIs

public static void removePIs(Node node)
Recursively removes all processing instruction nodes from the subtree.

setDocumentBuilderFactory

public static void setDocumentBuilderFactory(DocumentBuilderFactory docBuilderFactory)
Sets the DOM Parser implementation to be used when building NodeModel objects from XML files.

setErrorHandler

public static void setErrorHandler(ErrorHandler errorHandler)
sets the error handler to use when parsing the document.

setXPathSupportClass

public static void setXPathSupportClass(Class cl)
Set an alternative implementation of freemarker.ext.dom.XPathSupport to use as the XPath engine.
Parameters:
cl - the class, or null to disable XPath support.

simplify

public static void simplify(Node node)
Removes comments and processing instruction, and then unites adjacent text nodes. Note that CDATA sections count as text nodes.

size

public final int size()
Specified by:
size in interface TemplateSequenceModel

useDefaultXPathSupport

public static void useDefaultXPathSupport()
Tells the system to use (restore) the default (initial) XPath system used by this FreeMarker version on this system.

useJaxenXPathSupport

public static void useJaxenXPathSupport()
            throws Exception
Convenience method. Tells the system to use Jaxen for XPath queries.

useSunInternalXPathSupport

public static void useSunInternalXPathSupport()
            throws Exception

useXalanXPathSupport

public static void useXalanXPathSupport()
            throws Exception
Convenience method. Tells the system to use Xalan for XPath queries.

wrap

public static NodeModel wrap(Node node)