public abstract class NodeModel extends Object implements TemplateNodeModel, TemplateHashModel, TemplateSequenceModel, AdapterTemplateModel, WrapperTemplateModel, freemarker.core._UnexpectedTypeErrorExplainerTemplateModel
Note that DefaultObjectWrapper
automatically wraps W3C DOM Node
-s into this, so you may not need to
do that with this class manually. Though, before dropping the Node
-s into the data-model, you may want to
apply simplify(Node)
on them.
NOTHING
Modifier | Constructor and Description |
---|---|
protected |
NodeModel(Node node) |
Modifier and Type | Method and Description |
---|---|
boolean |
equals(Object other) |
TemplateModel |
exec(List args) |
Object[] |
explainTypeError(Class[] expectedClasses) |
TemplateModel |
get(int i)
Retrieves the i-th template model in this sequence.
|
TemplateModel |
get(String key)
Gets a TemplateModel from the hash.
|
Object |
getAdaptedObject(Class hint)
Retrieves the underlying object, or some other object semantically
equivalent to its value narrowed by the class hint.
|
TemplateSequenceModel |
getChildNodes() |
static DocumentBuilderFactory |
getDocumentBuilderFactory() |
static ErrorHandler |
getErrorHandler() |
Node |
getNode() |
String |
getNodeNamespace() |
String |
getNodeType() |
TemplateNodeModel |
getParentNode() |
Object |
getWrappedObject()
Retrieves the original object wrapped by this model.
|
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) |
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
getNodeName
isEmpty
protected NodeModel(Node node)
public static void setDocumentBuilderFactory(DocumentBuilderFactory docBuilderFactory)
public static DocumentBuilderFactory getDocumentBuilderFactory()
public static void setErrorHandler(ErrorHandler errorHandler)
public static ErrorHandler getErrorHandler()
public static NodeModel parse(InputSource is, boolean removeComments, boolean removePIs) throws SAXException, IOException, ParserConfigurationException
removeComments
- whether to remove all comment nodes
(recursively) from the tree before processingremovePIs
- whether to remove all processing instruction nodes
(recursively from the tree before processingSAXException
IOException
ParserConfigurationException
public static NodeModel parse(InputSource is) throws SAXException, IOException, ParserConfigurationException
public static NodeModel parse(File f, boolean removeComments, boolean removePIs) throws SAXException, IOException, ParserConfigurationException
removeComments
- whether to remove all comment nodes
(recursively) from the tree before processingremovePIs
- whether to remove all processing instruction nodes
(recursively from the tree before processingSAXException
IOException
ParserConfigurationException
public static NodeModel parse(File f) throws SAXException, IOException, ParserConfigurationException
public Node getNode()
public TemplateModel get(String key) throws TemplateModelException
TemplateHashModel
get
in interface TemplateHashModel
key
- the name by which the TemplateModel
is identified in the template.TemplateModelException
public TemplateNodeModel getParentNode()
getParentNode
in interface TemplateNodeModel
public TemplateSequenceModel getChildNodes()
getChildNodes
in interface TemplateNodeModel
public final String getNodeType() throws TemplateModelException
getNodeType
in interface TemplateNodeModel
TemplateModelException
public TemplateModel exec(List args) throws TemplateModelException
TemplateModelException
public final int size()
size
in interface TemplateSequenceModel
public final TemplateModel get(int i)
TemplateSequenceModel
get
in interface TemplateSequenceModel
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, unless the default value for that case was also specified in the
template.public String getNodeNamespace()
getNodeNamespace
in interface TemplateNodeModel
public static void removeComments(Node node)
simplify(org.w3c.dom.Node)
public static void removePIs(Node node)
simplify(org.w3c.dom.Node)
public static void mergeAdjacentText(Node node)
simplify(org.w3c.dom.Node)
public static void simplify(Node node)
public static void useDefaultXPathSupport()
public static void useJaxenXPathSupport() throws Exception
Exception
- if the Jaxen classes are not present.public static void useXalanXPathSupport() throws Exception
Exception
- if the Xalan XPath classes are not present.public static void useSunInternalXPathSupport() throws Exception
Exception
public static void setXPathSupportClass(Class cl)
cl
- the class, or null
to disable XPath support.public static Class getXPathSupportClass()
null
if XPath support is disabled.public Object getAdaptedObject(Class hint)
AdapterTemplateModel
getAdaptedObject
in interface AdapterTemplateModel
hint
- the desired class of the returned value. An implementation
should make reasonable effort to retrieve an object of the requested
class, but if that is impossible, it must at least return the underlying
object as-is. As a minimal requirement, an implementation must always
return the exact underlying object when
hint.isInstance(underlyingObject) holds. When called
with java.lang.Object.class, it should return a generic Java
object (i.e. if the model is wrapping a scripting language object that is
further wrapping a Java object, the deepest underlying Java object should
be returned).public Object getWrappedObject()
WrapperTemplateModel
getWrappedObject
in interface WrapperTemplateModel