Package com.vaadin.flow.dom
Class ElementUtil
- java.lang.Object
-
- com.vaadin.flow.dom.ElementUtil
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Optional<Element>fromJsoup(org.jsoup.nodes.Node node)Converts a given JSoupNodeand its children into a matchingElementhierarchy.static booleanisCustomElement(Element element)Checks whether the given element is a custom element or not.static booleanisScript(Element element)Checks whether the given element is ascriptor not.static booleanisValidAttributeName(String attribute)Checks if the given attribute name is valid.static booleanisValidStylePropertyName(String name)Checks if the given style property name is valid.static booleanisValidStylePropertyValue(String value)Checks if the given style property value is valid.static booleanisValidTagName(String tag)Checks if the given tag name is valid.static voidsetComponent(Element element, Component component)Defines a mapping between this element and the givenComponent.static voidsetIgnoreParentInert(Element element, boolean ignoreParentInert)Sets whether or not the element should inherit or not inherit its parent's inert state.static voidsetInert(Element element, boolean inert)Sets whether or not the given element is inert.static org.jsoup.nodes.NodetoJsoup(org.jsoup.nodes.Document document, Element element)Converts the given element and its children to a JSoup node with children.static voidvalidateStylePropertyName(String name)Validates the given style property name and throws an exception if the name is invalid.static voidvalidateStylePropertyValue(String value)Checks if the given style property value is valid.
-
-
-
Method Detail
-
isValidTagName
public static boolean isValidTagName(String tag)
Checks if the given tag name is valid.- Parameters:
tag- the tag name- Returns:
- true if the string is valid as a tag name, false otherwise
-
isValidAttributeName
public static boolean isValidAttributeName(String attribute)
Checks if the given attribute name is valid.- Parameters:
attribute- the name of the attribute in lower case- Returns:
- true if the name is valid, false otherwise
-
validateStylePropertyName
public static void validateStylePropertyName(String name)
Validates the given style property name and throws an exception if the name is invalid.- Parameters:
name- the style property name to validate
-
isValidStylePropertyName
public static boolean isValidStylePropertyName(String name)
Checks if the given style property name is valid.- Parameters:
name- the name to validate- Returns:
- true if the name is valid, false otherwise
-
isValidStylePropertyValue
public static boolean isValidStylePropertyValue(String value)
Checks if the given style property value is valid.- Parameters:
value- the value to validate- Returns:
- true if the value is valid, false otherwise
-
validateStylePropertyValue
public static void validateStylePropertyValue(String value)
Checks if the given style property value is valid.Throws an exception if it's certain the value is invalid
- Parameters:
value- the value to validate
-
setComponent
public static void setComponent(Element element, Component component)
Defines a mapping between this element and the givenComponent.An element can only be mapped to one component and the mapping cannot be changed. The only exception is
Compositewhich can overwrite the mapping for its content.- Parameters:
element- the element to map to the componentcomponent- the component this element is attached to
-
toJsoup
public static org.jsoup.nodes.Node toJsoup(org.jsoup.nodes.Document document, Element element)Converts the given element and its children to a JSoup node with children.- Parameters:
document- A JSoup documentelement- The element to convert- Returns:
- A JSoup node containing the converted element
-
fromJsoup
public static Optional<Element> fromJsoup(org.jsoup.nodes.Node node)
Converts a given JSoupNodeand its children into a matchingElementhierarchy.Only nodes of type
TextNodeandElementare converted - other node types return an empty optional.- Parameters:
node- JSoup node to convert- Returns:
- element with the matching hierarchy as the given node, or empty
-
isCustomElement
public static boolean isCustomElement(Element element)
Checks whether the given element is a custom element or not.Custom elements (Web Components) are recognized by having at least one dash in the tag name.
- Parameters:
element- the element to check- Returns:
trueif a custom element,falseif not
-
isScript
public static boolean isScript(Element element)
Checks whether the given element is ascriptor not.- Parameters:
element- the element to check- Returns:
trueif a script,falseif not
-
setIgnoreParentInert
public static void setIgnoreParentInert(Element element, boolean ignoreParentInert)
Sets whether or not the element should inherit or not inherit its parent's inert state. Default value isfalse.- Parameters:
element- the element to updateignoreParentInert-truefor ignoring parent inert,falsefor not ignoring- See Also:
setInert(Element, boolean)
-
setInert
public static void setInert(Element element, boolean inert)
Sets whether or not the given element is inert. When an element is inert, it does not receive any updates or interaction from the client side. The inert state is inherited to all child elements, unless those are ignoring the inert state.- Parameters:
element- the element to updateinert-truefor inert- See Also:
setIgnoreParentInert(Element, boolean)
-
-