org.thymeleaf.dom
Class Node

Object
  extended by org.thymeleaf.dom.Node
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
AbstractTextNode, Comment, NestableNode

public abstract class Node
extends Object
implements java.io.Serializable

Base abstract class for all nodes in a Thymeleaf DOM tree.

Since:
2.0.0
Author:
Daniel Fernández
See Also:
Serialized Form

Field Summary
static String NODE_PROPERTY_XML_ENCODING
           Name of the property set by XML-based parsers into Document nodes for specifying the "XML Encoding" info from the XML Declaration.
static String NODE_PROPERTY_XML_STANDALONE
           Name of the property set by XML-based parsers into Document nodes for specifying the "XML Standalone" flag from the XML Declaration.
static String NODE_PROPERTY_XML_VERSION
           Name of the property set by XML-based parsers into Document nodes for specifying the "XML Version" info from the XML Declaration.
 
Method Summary
static String applyDialectPrefix(String name, String dialectPrefix)
           Applies a prefix (a dialect prefix) to the specified name.
 Node cloneNode(NestableNode newParent, boolean cloneProcessors)
           Creates a clone of this node.
 String getDocumentName()
           Returns the name of the document this node comes from.
 Integer getLineNumber()
           Returns the number of the line where this node appears in the original template document.
 java.util.Set<String> getNodeLocalVariableNames()
           Returns the set of node local variable names.
 Object getNodeProperty(String name)
           Returns the value of a specific node property, or null if the property has not been set.
 java.util.Set<String> getNodePropertyNames()
           Returns the names of all the currently set node properties.
 NestableNode getParent()
           Returns the parent of a node.
 boolean getRecomputeProcessorsAfterEachExecution()
           Returns the value of a flag indicating whether the list of processors to be applied to this node should be recomputed after the execution of each processor.
 boolean getRecomputeProcessorsImmediately()
           Returns the value of a flag indicating whether the processors to be applied to this node should be recomputed once after the execution of the current processor ends.
 boolean hasNodeLocalVariables()
           Returns whether the node has any node local variables set or not.
 boolean hasNodeProperty(String name)
           Returns whether a node contains a specific node property or not.
 boolean hasParent()
           Returns whether this node has a parent node or not.
 boolean isSkippable()
           Returns the value of a flag indicating whether there is any reason to process this node (and its children).
static String normalizeName(String name)
           Normalizes an element or attribute name by converting it to lower-case.
 void setAllNodeLocalVariables(java.util.Map<String,Object> variables)
           Sets several node local variables at once.
 void setNodeLocalVariable(String name, Object value)
           Sets a new node local variable.
 void setNodeProperty(String name, Object value)
           Sets a value for a node property.
 void setParent(NestableNode parent)
           Sets a new parent for the node.
 void setRecomputeProcessorsAfterEachExecution(boolean recomputeProcessorsAfterEachExecution)
           Sets the value of a flag indicating whether the processors to be applied to this node should be recomputed after the execution of each processor.
 void setRecomputeProcessorsImmediately(boolean recomputeProcessorsImmediately)
           Sets the value of a flag indicating whether the processors to be applied to this node should be recomputed once after the execution of the current processor ends.
 void setSkippable(boolean skippable)
           Sets the value of a flag indicating whether there is any reason to process this node (and its children).
 java.util.Map<String,Object> unsafeGetNodeLocalVariables()
           Returns the real inner map object containing the node local variables.
 java.util.Map<String,Object> unsafeGetNodeProperties()
           Returns the real inner map object containing the node properties.
abstract  void visit(DOMVisitor visitor)
           Apply a DOM visitor.
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NODE_PROPERTY_XML_ENCODING

public static final String NODE_PROPERTY_XML_ENCODING

Name of the property set by XML-based parsers into Document nodes for specifying the "XML Encoding" info from the XML Declaration.

Value: "XML_ENCODING"

See Also:
Constant Field Values

NODE_PROPERTY_XML_VERSION

public static final String NODE_PROPERTY_XML_VERSION

Name of the property set by XML-based parsers into Document nodes for specifying the "XML Version" info from the XML Declaration.

Value: "XML_VERSION"

See Also:
Constant Field Values

NODE_PROPERTY_XML_STANDALONE

public static final String NODE_PROPERTY_XML_STANDALONE

Name of the property set by XML-based parsers into Document nodes for specifying the "XML Standalone" flag from the XML Declaration.

Value: "XML_STANDALONE"

See Also:
Constant Field Values
Method Detail

normalizeName

public static String normalizeName(String name)

Normalizes an element or attribute name by converting it to lower-case. Elements and attributes are processed as case-insensitive, and this method allows normalizing their names before processing.

Parameters:
name - the name to be normalized.
Returns:
the normalized name.

applyDialectPrefix

public static String applyDialectPrefix(String name,
                                        String dialectPrefix)

Applies a prefix (a dialect prefix) to the specified name.

The result looks like: "${prefix}:${name}".

Parameters:
name - the name to be prefixed
dialectPrefix - the prefix to be applied
Returns:
the prefixed name

getDocumentName

public String getDocumentName()

Returns the name of the document this node comes from. Can be null, if node does not come from parsing a document (for example, could come from parsing an externalized message).

Returns:
the document name

getLineNumber

public Integer getLineNumber()

Returns the number of the line where this node appears in the original template document. Might be null if the parser used to create the node is not able to obtain this information for nodes, or if this kind of information does not apply (for example, when parsing externalized messages).

Returns:
the line number

setNodeProperty

public final void setNodeProperty(String name,
                                  Object value)

Sets a value for a node property.

Node properties might contain arbitrary information, normally set by parsers into node objects for use from processors.

Users might need to create parsers that add specific properties to some nodes in order to give processing hints to their processors or result writers.

Parameters:
name - the name of the property
value - the value of the property

hasNodeProperty

public final boolean hasNodeProperty(String name)

Returns whether a node contains a specific node property or not.

Node properties might contain arbitrary information, normally set by parsers into node objects for use from processors.

Users might need to create parsers that add specific properties to some nodes in order to give processing hints to their processors or result writers.

Parameters:
name - the name of the property to check
Returns:
true if the node contains the property, false if not

getNodeProperty

public final Object getNodeProperty(String name)

Returns the value of a specific node property, or null if the property has not been set.

Node properties might contain arbitrary information, normally set by parsers into node objects for use from processors.

Users might need to create parsers that add specific properties to some nodes in order to give processing hints to their processors or result writers.

Parameters:
name - the name of the property to be retrieved
Returns:
the value of the property

getNodePropertyNames

public final java.util.Set<String> getNodePropertyNames()

Returns the names of all the currently set node properties.

Node properties might contain arbitrary information, normally set by parsers into node objects for use from processors.

Users might need to create parsers that add specific properties to some nodes in order to give processing hints to their processors or result writers.

Returns:
the set of property names.

unsafeGetNodeProperties

public final java.util.Map<String,Object> unsafeGetNodeProperties()

Returns the real inner map object containing the node properties. This method is only meant for internal use. DO NOT call this method directly from your code.

Returns:
the map of node properties.

hasParent

public final boolean hasParent()

Returns whether this node has a parent node or not.

A node does not have a parent if its parent property is set to null. Document nodes always have no parent, and other types of node might also have null parent if they represent the root of a DOM subtree.

Returns:
true if the node has a parent, false if not.

getParent

public final NestableNode getParent()

Returns the parent of a node. Will return null if this node has no parent.

Returns:
the parent of the node, or null if there is no parent.

setParent

public final void setParent(NestableNode parent)

Sets a new parent for the node.

Parameters:
parent - the new parent.

getRecomputeProcessorsAfterEachExecution

public final boolean getRecomputeProcessorsAfterEachExecution()

Returns the value of a flag indicating whether the list of processors to be applied to this node should be recomputed after the execution of each processor.

This flag is usually set by processors with very high precedence in order to signal the fact that they would like the engine to recompute the list of processors to be applied to the node after each of the subsequent processors finish their execution.

Returns:
true if the list of applicable processors must be recomputed after each execution, false if not.

setRecomputeProcessorsAfterEachExecution

public final void setRecomputeProcessorsAfterEachExecution(boolean recomputeProcessorsAfterEachExecution)

Sets the value of a flag indicating whether the processors to be applied to this node should be recomputed after the execution of each processor.

This flag is usually set by processors with very high precedence in order to signal the fact that they would like the engine to recompute the list of processors to be applied to the node after each of the subsequent processors finish their execution.

Parameters:
recomputeProcessorsAfterEachExecution - the new value for the flag

getRecomputeProcessorsImmediately

public final boolean getRecomputeProcessorsImmediately()

Returns the value of a flag indicating whether the processors to be applied to this node should be recomputed once after the execution of the current processor ends.

This flag is usually set by processors in order to signal the fact that they have modified the node in a way that should modify the list of processors to be applied to it (for example, by adding an attribute which might have a processor associated).

If this flag is set to true, the engine will automatically recompute the applicable processors before looking for the next processor to execute.

Returns:
true if the list of applicable processors must be recomputed, false if not.

setRecomputeProcessorsImmediately

public final void setRecomputeProcessorsImmediately(boolean recomputeProcessorsImmediately)

Sets the value of a flag indicating whether the processors to be applied to this node should be recomputed once after the execution of the current processor ends.

This flag is usually set by processors in order to signal the fact that they have modified the node in a way that should modify the list of processors to be applied to it (for example, by adding an attribute which might have a processor associated).

If this flag is set to true, the engine will automatically recompute the applicable processors before looking for the next processor to execute.

Parameters:
recomputeProcessorsImmediately - the new value for the flag

isSkippable

public final boolean isSkippable()

Returns the value of a flag indicating whether there is any reason to process this node (and its children).

This flag can be set by the engine -and also by processors- in order to avoid the execution of certain parts of the DOM tree, both because it is known that there is nothing to execute (and therefore it would be a waste of time trying to process it) and also because we want to signal that specific parts of the tree should not be executed for security reasons (for example, to avoid code injection).

Returns:
the value of the 'skippable' flag

setSkippable

public final void setSkippable(boolean skippable)

Sets the value of a flag indicating whether there is any reason to process this node (and its children).

This flag can be set by the engine -and also by processors- in order to avoid the execution of certain parts of the DOM tree, both because it is known that there is nothing to execute (and therefore it would be a waste of time trying to process it) and also because we want to signal that specific parts of the tree should not be executed for security reasons (for example, to avoid code injection).

Parameters:
skippable - the new value for the flag

hasNodeLocalVariables

public final boolean hasNodeLocalVariables()

Returns whether the node has any node local variables set or not.

Node local variables are variables that are set locally to a specific node, and that will be added to the evaluation context of any expressions --for example: OGNL or Spring EL-- executed on that node or any of its children.

For example, the thing variable in <div th:each="thing : ${things}">...<div> is a node local variable that will only exist inside the <div> element and that will be made available to any expressions executed within those limits.

Note that there is an important difference between node local variables and node properties, as the latter are never added to the expression evaluation context and are only meant for internally carrying around metainformation about the DOM nodes.

Returns:
true if the node has any node local variables set, false if not

getNodeLocalVariableNames

public final java.util.Set<String> getNodeLocalVariableNames()

Returns the set of node local variable names.

Node local variables are variables that are set locally to a specific node, and that will be added to the evaluation context of any expressions --for example: OGNL or Spring EL-- executed on that node or any of its children.

For example, the thing variable in <div th:each="thing : ${things}">...<div> is a node local variable that will only exist inside the <div> element and that will be made available to any expressions executed within those limits.

Note that there is an important difference between node local variables and node properties, as the latter are never added to the expression evaluation context and are only meant for internally carrying around metainformation about the DOM nodes.

Returns:
the set of local variable names

unsafeGetNodeLocalVariables

public final java.util.Map<String,Object> unsafeGetNodeLocalVariables()

Returns the real inner map object containing the node local variables. This method is only meant for internal use. DO NOT call this method directly from your code.

Returns:
the map of node local variables

setNodeLocalVariable

public final void setNodeLocalVariable(String name,
                                       Object value)

Sets a new node local variable.

Node local variables are variables that are set locally to a specific node, and that will be added to the evaluation context of any expressions --for example: OGNL or Spring EL-- executed on that node or any of its children.

For example, the thing variable in <div th:each="thing : ${things}">...<div> is a node local variable that will only exist inside the <div> element and that will be made available to any expressions executed within those limits.

Note that there is an important difference between node local variables and node properties, as the latter are never added to the expression evaluation context and are only meant for internally carrying around metainformation about the DOM nodes.

Parameters:
name - the name of the local variable
value - the new value for the local variable

setAllNodeLocalVariables

public final void setAllNodeLocalVariables(java.util.Map<String,Object> variables)

Sets several node local variables at once.

Node local variables are variables that are set locally to a specific node, and that will be added to the evaluation context of any expressions --for example: OGNL or Spring EL-- executed on that node or any of its children.

For example, the thing variable in <div th:each="thing : ${things}">...<div> is a node local variable that will only exist inside the <div> element and that will be made available to any expressions executed within those limits.

Note that there is an important difference between node local variables and node properties, as the latter are never added to the expression evaluation context and are only meant for internally carrying around metainformation about the DOM nodes.

Parameters:
variables - the variables to be set

cloneNode

public final Node cloneNode(NestableNode newParent,
                            boolean cloneProcessors)

Creates a clone of this node.

When cloning, it can be specified whether we want to clone also the available preprocessing information (the lists of processors that should be applicable to each node), and also the new parent to be assigned to the DOM tree resulting from cloning (parent can be null).

Node cloning is always performed in depth.

Parameters:
newParent - the new parent node of the resulting cloned DOM tree, if any (can be specified as null).
cloneProcessors - whether the lists of applicable processors for each node should also be cloned or not.
Returns:
the cloned node.

visit

public abstract void visit(DOMVisitor visitor)

Apply a DOM visitor.

Parameters:
visitor - the visitor to be executed for this node.


Copyright © 2012 The THYMELEAF team. All Rights Reserved.