|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Object org.thymeleaf.dom.Node org.thymeleaf.dom.NestableNode org.thymeleaf.dom.Element
public final class Element
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.
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 | |
---|---|
void |
clearAttributes()
Clears all the attributes of the element. |
Element |
cloneElementNodeWithNewName(NestableNode newParent,
String newElementName,
boolean cloneProcessors)
Clones this element node, setting it a new name in the process. |
Attribute |
getAttributeFromNormalizedName(String normalizedAttributeName)
Returns an attribute, if it exists (null if not). |
Map<String,Attribute> |
getAttributeMap()
Returns a map with all the names (normalized) and values of the element attributes. |
String |
getAttributeOriginalNameFromNormalizedName(String normalizedAttributeName)
Returns the original name of an attribute from its normalized name. |
String |
getAttributeValue(String attributeName)
Returns the value of an attribute from its attribute name, without needing this name to be normalized (because the specified name will be normalized before performing the comparison). |
String |
getAttributeValueFromNormalizedName(String normalizedAttributeName)
Returns the value of an attribute from its normalized name. |
String |
getNormalizedName()
Returns the normalized name of the element. |
String |
getNormalizedPrefix()
Returns the normalized prefix of this element (part of its name), if it exists, or null if the element is unprefixed. |
String |
getOriginalName()
Returns the original name of the 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). |
String |
getUnprefixedNormalizedName()
Returns the normalized version of the element name, without its prefix (if it has one). |
boolean |
hasAttribute(String attributeName)
Returns whether an attribute exists in the element or not. |
boolean |
hasAttributes()
Returns whether this element has any attributes or not. |
boolean |
hasNormalizedAttribute(String normalizedAttributeName)
Returns whether an attribute exists in the element or not. |
boolean |
hasPrefix()
Returns whether the element name has a prefix or not. |
boolean |
isMinimizableIfWeb()
Returns whether this element is minimizable when performing XHTML or HTML5 output. |
int |
numAttributes()
Returns the number of attributes contained in this element. |
void |
removeAttribute(String attributeName)
Removes a specific attribute from the element. |
void |
setAttribute(String name,
boolean onlyName,
String value)
Establishes a new value for an element attribute. |
void |
setAttribute(String name,
String value)
Establishes a new value for an element attribute. |
void |
setAttributes(Map<String,String> newAttributes)
Establishes the value for several attributes at a time. |
void |
setRepresentationInTemplate(Element.RepresentationInTemplate representationInTemplate)
Sets a new value to the 'representationInTemplate' property. |
String[] |
unsafeGetAttributeNormalizedNames()
Returns the inner array used for storing the normalized names of all the existing attributes. |
Attribute[] |
unsafeGetAttributes()
Returns the inner array used for storing the element attributes. |
Methods inherited from class org.thymeleaf.dom.NestableNode |
---|
addChild, clearChildren, extractChild, getChildren, getElementChildren, getFirstChild, getFirstElementChild, hasChildren, insertAfter, insertBefore, insertChild, moveAllChildren, numChildren, removeChild, removeChild, setChildren, unsafeGetChildrenNodeArray, visit |
Methods inherited from class Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public Element(String name)
public Element(String name, String documentName)
public Element(String name, String documentName, Integer lineNumber)
public Element(String name, Element.RepresentationInTemplate representationInTemplate)
public Element(String name, String documentName, Element.RepresentationInTemplate representationInTemplate)
public Element(String name, String documentName, Integer lineNumber, Element.RepresentationInTemplate representationInTemplate)
Method Detail |
---|
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.
public String getNormalizedName()
Returns the normalized name of the element. Element names are normalized by
means of the Node.normalizeName(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.
public String getNormalizedPrefix()
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, using the
Node.normalizeName(String)
method.
public String getUnprefixedNormalizedName()
Returns the normalized version of the element name, without its prefix (if it has one).
public boolean hasPrefix()
Returns whether the element name has a prefix or not.
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.
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).
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).
representationInTemplate
- the original representation of the Element at the template, or null.public boolean hasAttributes()
Returns whether this element has any attributes or not.
public int numAttributes()
Returns the number of attributes contained in this element.
public boolean hasAttribute(String attributeName)
Returns whether an attribute exists in the element or not. The specified name does not have to be normalized, because a normalization operation will be performed before comparing.
attributeName
- the name of the attribute to be checked.
public boolean hasNormalizedAttribute(String normalizedAttributeName)
Returns whether an attribute exists in the element or not. The specified name has to be already normalized because no normalization operations will be performed before comparing.
normalizedAttributeName
- the name of the attribute to be checked, already normalized.
public Attribute getAttributeFromNormalizedName(String normalizedAttributeName)
Returns an attribute, if it exists (null if not). The specified name has to be already normalized because no normalization operations will be performed before comparing.
normalizedAttributeName
- the name of the attribute to retrieve.
public String[] unsafeGetAttributeNormalizedNames()
Returns the inner array used for storing the normalized names of all the existing attributes. This method is unsafe and for internal use, and should not be called directly. Modifications to this array could produce severe DOM inconsistencies.
public Attribute[] unsafeGetAttributes()
Returns the inner array used for storing the element attributes. This method is unsafe and for internal use, and should not be called directly. Modifications to this array could produce severe DOM inconsistencies.
public String getAttributeOriginalNameFromNormalizedName(String normalizedAttributeName)
Returns the original name of an attribute from its normalized name.
normalizedAttributeName
- the normalized name of the attribute.
public String getAttributeValueFromNormalizedName(String normalizedAttributeName)
Returns the value of an attribute from its normalized name.
normalizedAttributeName
- the normalized name of the attribute.
public String getAttributeValue(String attributeName)
Returns the value of an attribute from its attribute name, without needing this name to be normalized (because the specified name will be normalized before performing the comparison).
attributeName
- the attribute name.
public Map<String,Attribute> getAttributeMap()
Returns a map with all the names (normalized) and values of the element attributes.
The map object returned by this method is a new instance, created ad-hoc with each method call.
public void setAttribute(String name, String value)
Establishes a new value for an element attribute. If the attribute already exists, its value is substituted by the one specified.
name
- the name of the attribute.value
- the value of the attribute.public void setAttribute(String name, boolean onlyName, String value)
Establishes a new value for an element attribute. If the attribute already exists, its value is substituted by the one specified.
name
- the name of the attribute.value
- the value of the attribute.public void setAttributes(Map<String,String> newAttributes)
Establishes the value for several attributes at a time. If any of the specified attributes already exists, their values will be substituted by the one specified in the parameter map.
newAttributes
- the new attributes to be established.public void clearAttributes()
Clears all the attributes of the element.
public void removeAttribute(String attributeName)
Removes a specific attribute from the element. The specified name does not have to be normalized (it will be normalized before performing the removal operation).
attributeName
- the name of tha attribute to remove (does not have to be
normalized).public final Element cloneElementNodeWithNewName(NestableNode newParent, String newElementName, boolean cloneProcessors)
Clones this element node, setting it a new name in the process.
newParent
- the new parent node to be assigned to the cloned element.newElementName
- the new element namecloneProcessors
- whether the precomputed list of processors should be cloned too or not.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |