org.thymeleaf.dom
Class Element

Object
  extended by org.thymeleaf.dom.Node
      extended by org.thymeleaf.dom.NestableNode
          extended by org.thymeleaf.dom.NestableAttributeHolderNode
              extended by org.thymeleaf.dom.Element
All Implemented Interfaces:
Serializable

public final class Element
extends NestableAttributeHolderNode

An Element node in a Thymeleaf DOM tree. In XML-based templates, Elements normally correspond to tags.

Elements are nestable nodes, and therefore have children. Besides, they have a sequence of attributes, each of them with a value. Attributes are modeled by means of the Attribute class.

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

Nested Class Summary
static class Element.RepresentationInTemplate
           Specifies whether this element was a standalone element at the original template file, or maybe an open element with a closing tag, or just an open element (non-XML-well-formed).
 
Nested classes/interfaces inherited from class org.thymeleaf.dom.Node
Node.NodeLocalVariablesMap
 
Field Summary
 
Fields inherited from class org.thymeleaf.dom.Node
NODE_PROPERTY_XML_ENCODING, NODE_PROPERTY_XML_STANDALONE, NODE_PROPERTY_XML_VERSION
 
Constructor Summary
Element(String name)
           
Element(String name, Element.RepresentationInTemplate representationInTemplate)
           
Element(String name, String documentName)
           
Element(String name, String documentName, Element.RepresentationInTemplate representationInTemplate)
           
Element(String name, String documentName, Integer lineNumber)
           
Element(String name, String documentName, Integer lineNumber, Element.RepresentationInTemplate representationInTemplate)
           
 
Method Summary
static String[] applyPrefixToElementName(String name, String dialectPrefix)
           Applies a prefix (a dialect prefix) to the specified name in order to obtain a complete valid element (tag) name.
 Element cloneElementNodeWithNewName(NestableNode newParent, String newElementName, boolean cloneProcessors)
           Clones this element node, setting it a new name in the process.
 String getNormalizedName()
           Returns the normalized name of the element.
 String getNormalizedPrefix()
          Deprecated. Deprecated in 2.1.0. There is no actual usage of this method
 String getOriginalName()
           Returns the original name of the element.
static String getPrefixFromElementName(String elementName)
           Returns the prefix being applied to an element.
 Element.RepresentationInTemplate getRepresentationInTemplate()
           Optionally specifies whether this element is written at the original document as a standalone element, an open element with a closing tag, or just an open element (non-XML-well-formed).
static String getUnprefixedElementName(String elementName)
           Returns the equivalent, un-prefixed name of an element from its complete (prefixed, if applies) version.
 String getUnprefixedNormalizedName()
          Deprecated. Deprecated in 2.1.0. There is no actual usage of this method
 boolean hasNormalizedName(String dialectPrefix, String normalizedElementName)
           Returns whether the element matches its name with any of the specified normalized names.
 boolean hasPrefix()
          Deprecated. Deprecated in 2.1.0. There is no actual usage of this method
 boolean isMinimizableIfWeb()
           Returns whether this element is minimizable when performing XHTML or HTML5 output.
static String normalizeElementName(String name)
           Normalizes an element name by converting it to lower-case.
 void setRepresentationInTemplate(Element.RepresentationInTemplate representationInTemplate)
           Sets a new value to the 'representationInTemplate' property.
 
Methods inherited from class org.thymeleaf.dom.NestableAttributeHolderNode
clearAttributes, getAttributeFromNormalizedName, getAttributeMap, getAttributeOriginalNameFromNormalizedName, getAttributeValue, getAttributeValueFromNormalizedName, getAttributeValueFromNormalizedName, hasAttribute, hasAttributes, hasNormalizedAttribute, hasNormalizedAttribute, numAttributes, removeAttribute, setAttribute, setAttribute, setAttributes, unsafeGetAttributeNormalizedNames, unsafeGetAttributes
 
Methods inherited from class org.thymeleaf.dom.NestableNode
addChild, clearChildren, extractChild, getChildren, getElementChildren, getFirstChild, getFirstElementChild, hasChildren, insertAfter, insertBefore, insertChild, moveAllChildren, numChildren, removeChild, removeChild, setChildren, setProcessCommentNodes, setProcessTextNodes, unsafeGetChildrenNodeArray, visit
 
Methods inherited from class org.thymeleaf.dom.Node
addAllNonExistingNodeLocalVariables, applyDialectPrefix, cloneNode, getDocumentName, getLineNumber, getNodeLocalVariableNames, getNodeProperty, getNodePropertyNames, getParent, getProcessCommentNodes, getProcessTextNodes, getRecomputeProcessorsAfterEachExecution, getRecomputeProcessorsImmediately, hasNodeLocalVariables, hasNodeProperty, hasParent, isProcessable, isSkippable, normalizeName, setAllNodeLocalVariables, setNodeLocalVariable, setNodeProperty, setParent, setProcessable, setRecomputeProcessorsAfterEachExecution, setRecomputeProcessorsImmediately, setSkippable, unsafeGetNodeProperties
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Element

public Element(String name)

Element

public Element(String name,
               String documentName)

Element

public Element(String name,
               String documentName,
               Integer lineNumber)

Element

public Element(String name,
               Element.RepresentationInTemplate representationInTemplate)

Element

public Element(String name,
               String documentName,
               Element.RepresentationInTemplate representationInTemplate)

Element

public Element(String name,
               String documentName,
               Integer lineNumber,
               Element.RepresentationInTemplate representationInTemplate)
Method Detail

getOriginalName

public String getOriginalName()

Returns the original name of the element. Given the fact that the engine works using the normalized versions of element names (in order to be case-insensitive), it is necessary to make a distinction between the 'original' name of an element (as it is written in the template file) and its 'normalized' name.

If the element name has a prefix, this 'original name' includes such prefix.

Returns:
the original name of the element.

getNormalizedName

public String getNormalizedName()

Returns the normalized name of the element. Element names are normalized by means of the normalizeElementName(String) method so that the engine can work in a case-insensitive way.

If the element name has a prefix, this 'normalized name' includes such prefix.

Returns:
the normalized name of the element.

hasNormalizedName

public boolean hasNormalizedName(String dialectPrefix,
                                 String normalizedElementName)

Returns whether the element matches its name with any of the specified normalized names.

Parameters:
dialectPrefix - the dialect prefix to be applied to the specified attribute. Can be null.
normalizedElementName - the normalized name of the attribute.
Returns:
the normalized name of the element.
Since:
2.1.0

getNormalizedPrefix

@Deprecated
public String getNormalizedPrefix()
Deprecated. Deprecated in 2.1.0. There is no actual usage of this method

Returns the normalized prefix of this element (part of its name), if it exists, or null if the element is unprefixed.

Prefixes are normalized in the same way as element names.

Returns:
the normalized prefix.

getUnprefixedNormalizedName

@Deprecated
public String getUnprefixedNormalizedName()
Deprecated. Deprecated in 2.1.0. There is no actual usage of this method

Returns the normalized version of the element name, without its prefix (if it has one).

Returns:
the unprefixed normalized name.

hasPrefix

@Deprecated
public boolean hasPrefix()
Deprecated. Deprecated in 2.1.0. There is no actual usage of this method

Returns whether the element name has a prefix or not.

Returns:
true if the element name has a prefix, false if not.

isMinimizableIfWeb

public boolean isMinimizableIfWeb()

Returns whether this element is minimizable when performing XHTML or HTML5 output.

Minimizing tags means writing them as <tag/> instead of <tag></tag> when they have no body. XML allows this for every tag, bug the the XHTML/HTML5 specifications do not allow minimizing most of the tags (for example, <div>, <p>, <textarea>, etc cannot be minimized).

This flag precomputes whether the tag can be minimized or not when written as XHTML or HTML5.

Returns:
true if the tag is minimizable in web-output scenarios, false if not.

getRepresentationInTemplate

public Element.RepresentationInTemplate getRepresentationInTemplate()

Optionally specifies whether this element is written at the original document as a standalone element, an open element with a closing tag, or just an open element (non-XML-well-formed).

This flag might be ignored by certain parser implementations, and therefore it can be null. This can happen when parsers cannot determine the difference between a standalone or an open+closed element, or when parsers have no support for non-XML-well-formed code. This can also happen when the document format being parsed is not XML or HTML, and therefore this flag does not apply.

Note that this flag only influences how the element should be written if there are no changes in the amount of children it contains. For example, an originally-standalone element to which children are added will be written as an open plus a close tags (and a body between them containing its children).

Returns:
the original representation of the Element at the template, or null.
Since:
2.0.14

setRepresentationInTemplate

public void setRepresentationInTemplate(Element.RepresentationInTemplate representationInTemplate)

Sets a new value to the 'representationInTemplate' property.

This method should only be called from parsers, as a result of adjusts on DOM creation during parsing. It is not intended to be called from processors, as this property should reflect the way the element was represented at the original template.

This flag might be ignored by certain parser implementations, and therefore it can be null. This can happen when parsers cannot determine the difference between a standalone or an open+closed element, or when parsers have no support for non-XML-well-formed code. This can also happen when the document format being parsed is not XML or HTML, and therefore this flag does not apply.

Note that this flag only influences how the element should be written if there are no changes in the amount of children it contains. For example, an originally-standalone element to which children are added will be written as an open plus a close tags (and a body between them containing its children).

Parameters:
representationInTemplate - the original representation of the Element at the template, or null.
Since:
2.0.15

cloneElementNodeWithNewName

public Element cloneElementNodeWithNewName(NestableNode newParent,
                                           String newElementName,
                                           boolean cloneProcessors)

Clones this element node, setting it a new name in the process.

Parameters:
newParent - the new parent node to be assigned to the cloned element.
newElementName - the new element name
cloneProcessors - whether the precomputed list of processors should be cloned too or not.
Returns:
the cloned element.

normalizeElementName

public static String normalizeElementName(String name)

Normalizes an element name by converting it to lower-case. Elements 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.
Since:
2.1.0

applyPrefixToElementName

public static String[] applyPrefixToElementName(String name,
                                                String dialectPrefix)

Applies a prefix (a dialect prefix) to the specified name in order to obtain a complete valid element (tag) name.

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

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

getUnprefixedElementName

public static String getUnprefixedElementName(String elementName)

Returns the equivalent, un-prefixed name of an element from its complete (prefixed, if applies) version.

It supports both namespace prefix style (using :) and HTML5 custom element style (using '-' as a separator). Examples: table -> table, th:block -> block, th-block -> block.

Parameters:
elementName - the complete (prefixed, if applies) version of an element name.
Returns:
the unprefixed version of the specified element name.
Since:
2.1.0

getPrefixFromElementName

public static String getPrefixFromElementName(String elementName)

Returns the prefix being applied to an element.

Parameters:
elementName - the complete (prefixed, if applies) version of an element name.
Returns:
the prefix being applied to the name, or null if the element has no prefix.
Since:
2.1.0


Copyright © 2013 The THYMELEAF team. All Rights Reserved.