- All Superinterfaces:
Element
- All Known Implementing Classes:
XMLElementAdapter,XMLElementImpl
The definition of an XMLElement.
The default implementation of the methods
addCDATA(CharSequence),
addChild(XMLElement),
addComment(CharSequence),
addText(CharSequence),
setAttribute(String, CharSequence, Optional),
setNamespace(String),
setNamespace(URI),
setNamespace(String,String),
setNamespace(String,URI),
and
setNamespace(Namespace)
will always throw an
IllegalOperationException;
classes that implement this interface will have to provide appropriate
implementations for these methods if they want to support the respective
feature.
- Author:
- Thomas Thrien (thomas.thrien@tquadrat.org)
- Version:
- $Id: XMLElement.java 1071 2023-09-30 01:49:32Z tquadrat $
- Since:
- 0.0.5
- UML Diagram
-
UML Diagram for "org.tquadrat.foundation.xml.builder.XMLElement"
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic enumThe flags that are used to configure a new instance ofXMLElement(respectively an instance of an implementation of this interface. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final XMLElement[]An empty array ofXMLElementobjects.static final Optional<? extends CharSequence> The indicator that values for an attribute should not be appended. -
Method Summary
Modifier and TypeMethodDescriptiondefault XMLElementaddCDATA(boolean flag) Adds the providedbooleanvalue as aCDATAelement to this XML element.default XMLElementaddCDATA(char c) Adds the providedcharvalue as aCDATAelement to this XML element.default XMLElementaddCDATA(double number) Adds the provideddoublevalue as aCDATAelement to this XML element.default XMLElementaddCDATA(int number) Adds the providedintvalue as aCDATAelement to this XML element.default XMLElementaddCDATA(long number) Adds the providedlongvalue as aCDATAelement to this XML element.default <E extends Enum<E>>
XMLElementaddCDATA(E value) Adds the providedenuminstance as aCDATAelement to this XML element.default XMLElementAdds the providedBooleaninstance as aCDATAelement to this XML element.default XMLElementAdds the providedCharacterinstance as aCDATAelement to this XML element.default XMLElementaddCDATA(CharSequence text) Adds aCDATAelement to this XML element.default XMLElementAdds the providedNumberinstance as aCDATAelement to this XML element.default XMLElementAdds the providedInstantinstance as aCDATAelement to this XML element.default XMLElementAdds the providedLocalDateinstance as aCDATAelement to this XML element.default XMLElementaddCDATA(LocalDateTime date) Adds the providedLocalDateTimeinstance as aCDATAelement to this XML element.default XMLElementaddCDATA(ZonedDateTime date) Adds the providedZonedDateTimeinstance as aCDATAelement to this XML element.default <E extends XMLElement>
XMLElementaddChild(E child) Adds a child to this element.default XMLElementaddComment(CharSequence comment) Adds a comment.default XMLElementaddPredefinedMarkup(CharSequence markup) Adds predefined markup.default XMLElementaddText(boolean flag) Adds the providedbooleanvalue as text to this element.default XMLElementaddText(char c) Adds the providedcharvalue as text to this element.default XMLElementaddText(double number) Adds the provideddoublevalue as text to this element.default XMLElementaddText(int number) Adds the providedintvalue as text to this element.default XMLElementaddText(long number) Adds the providedlongvalue as text to this element.default <E extends Enum<E>>
XMLElementaddText(E value) Adds the providedenuminstance as text element to this element.default XMLElementAdds the providedBooleaninstance as text to this element.default XMLElementAdds the providedCharacterinstance as text to this element.default XMLElementaddText(CharSequence text) Adds text to this element.default XMLElementAdds the providedNumberinstance as text to this element.default XMLElementAdds the providedInstantinstance as text to this element.default XMLElementAdds the providedLocalDateinstance as text to this element.default XMLElementaddText(LocalDateTime date) Adds the providedLocalDateTimeinstance as text to this element.default XMLElementaddText(ZonedDateTime date) Adds the providedZonedDateTimeinstance as text to this element.getFlags()Returns the flags for this element.default XMLElementsetAttribute(String name, boolean flag) Sets the attribute with the given name.default XMLElementsetAttribute(String name, double number) Sets the attribute with the given name.default XMLElementsetAttribute(String name, int number) Sets the attribute with the given name.default XMLElementsetAttribute(String name, long number) Sets the attribute with the given name.default <E extends Enum<E>>
XMLElementsetAttribute(String name, E enumValue) Sets the attribute with the given name.default XMLElementsetAttribute(String name, Boolean flag) Sets the attribute with the given name.default XMLElementsetAttribute(String name, CharSequence value) Sets the attribute with the given name.default XMLElementsetAttribute(String name, CharSequence value, Optional<? extends CharSequence> append) Sets the attribute with the given name.default XMLElementsetAttribute(String name, Number number) Sets the attribute with the given name.default XMLElementsetAttribute(String name, Instant date) Sets the attribute with the given name.default XMLElementsetAttribute(String name, LocalDate date) Sets the attribute with the given name.default XMLElementsetAttribute(String name, LocalDateTime date) Sets the attribute with the given name.default XMLElementsetAttribute(String name, ZonedDateTime date) Sets the attribute with the given name.default XMLElementsetAttributeIfNotEmpty(String name, CharSequence value) Sets the attribute with the given name if the provided value is not empty.default XMLElementsetAttributeIfNotEmpty(String name, Optional<? extends CharSequence> optional) Sets the attribute with the given name if the provided value is not empty.default XMLElementSets the id for the element.default XMLElementsetNamespace(String identifier) Sets the given namespace.default XMLElementsetNamespace(String prefix, String identifier) Sets the given namespace.default XMLElementsetNamespace(String prefix, URI identifier) Sets the given namespace.default XMLElementsetNamespace(URI identifier) Sets the given namespace.default XMLElementsetNamespace(Namespace namespace) Sets the given namespace.<E extends Element>
voidsetParent(E parent) Sets the parent for this element.Methods inherited from interface org.tquadrat.foundation.xml.builder.spi.Element
getAttribute, getAttributes, getChildren, getElementName, getNamespaces, getParent, hasChildren, isBlock, toString
-
Field Details
-
EMPTY_XMLElement_ARRAY
An empty array ofXMLElementobjects. -
NO_APPEND
The indicator that values for an attribute should not be appended.- See Also:
-
-
Method Details
-
addCDATA
Adds the provided
booleanvalue as aCDATAelement to this XML element.To convert the boolean to text, the method
Boolean.toString(boolean)is used.- Parameters:
flag- The value.- Returns:
- This instance.
- Throws:
IllegalOperationException- No text allowed for this element.
-
addCDATA
Adds the provided
Booleaninstance as aCDATAelement to this XML element.To convert the boolean to text, the method
Boolean.toString()is used.- Parameters:
flag- The value.- Returns:
- This instance.
- Throws:
IllegalOperationException- No text allowed for this element.
-
addCDATA
Adds the provided
charvalue as aCDATAelement to this XML element.To convert the character to text, the method
Character.toString(char)is used.- Parameters:
c- The character.- Returns:
- This instance.
- Throws:
IllegalOperationException- No text allowed for this element.
-
addCDATA
Adds the provided
Characterinstance as aCDATAelement to this XML element.To convert the character to text, the method
Character.toString()is used.- Parameters:
c- The character.- Returns:
- This instance.
- Throws:
IllegalOperationException- No text allowed for this element.
-
addCDATA
Adds aCDATAelement to this XML element.- Parameters:
text- The text.- Returns:
- This instance.
- Throws:
IllegalOperationException- No text allowed for this element.
-
addCDATA
Adds the provided
doublevalue as aCDATAelement to this XML element.To convert the number to text, the method
Double.toString(double)is used.- Parameters:
number- The number.- Returns:
- This instance.
- Throws:
IllegalOperationException- No text allowed for this element.
-
addCDATA
Adds the provided
enuminstance as aCDATAelement to this XML element.To convert the value to text, the method
Enum.name()is used.- Type Parameters:
E- The type of theenumvalue.- Parameters:
value- The value.- Returns:
- This instance.
- Throws:
IllegalOperationException- No text allowed for this element.
-
addCDATA
Adds the provided
Instantinstance as aCDATAelement to this XML element.To convert the date to text, the method
Instant.toString()is used.- Parameters:
date- The date.- Returns:
- This instance.
- Throws:
IllegalOperationException- No text allowed for this element.
-
addCDATA
Adds the provided
intvalue as aCDATAelement to this XML element.To convert the number to text, the method
Integer.toString(int)is used.- Parameters:
number- The number.- Returns:
- This instance.
- Throws:
IllegalOperationException- No text allowed for this element.
-
addCDATA
Adds the provided
LocalDateinstance as aCDATAelement to this XML element.To convert the date to text, the method
LocalDate.toString()is used.- Parameters:
date- The date.- Returns:
- This instance.
- Throws:
IllegalOperationException- No text allowed for this element.
-
addCDATA
Adds the provided
LocalDateTimeinstance as aCDATAelement to this XML element.To convert the date to text, the method
LocalDateTime.toString()is used.- Parameters:
date- The date.- Returns:
- This instance.
- Throws:
IllegalOperationException- No text allowed for this element.
-
addCDATA
Adds the provided
longvalue as aCDATAelement to this XML element.To convert the number to text, the method
Long.toString(long)is used.- Parameters:
number- The number.- Returns:
- This instance.
- Throws:
IllegalOperationException- No text allowed for this element.
-
addCDATA
Adds the provided
Numberinstance as aCDATAelement to this XML element.To convert the number to text, the method
Object.toString()is used.- Parameters:
number- The number.- Returns:
- This instance.
- Throws:
IllegalOperationException- No text allowed for this element.
-
addCDATA
Adds the provided
ZonedDateTimeinstance as aCDATAelement to this XML element.To convert the date to text, the method
ZonedDateTime.toString()is used.- Parameters:
date- The date.- Returns:
- This instance.
- Throws:
IllegalOperationException- No text allowed for this element.
-
addChild
default <E extends XMLElement> XMLElement addChild(E child) throws IllegalArgumentException, IllegalOperationException, IllegalStateException Adds a child to this element.- Type Parameters:
E- The implementation type for thechildren.- Parameters:
child- The child to add.- Returns:
- This instance.
- Throws:
IllegalArgumentException- The given child is not valid for this element.IllegalOperationException- No children are allowed for this element.IllegalStateException- The child has already a parent that is not this element.
-
addComment
Adds a comment.- Parameters:
comment- The comment text.- Returns:
- This instance.
- Throws:
IllegalOperationException- No comment allowed for this element.
-
addPredefinedMarkup
Adds predefined markup.
The given markup will not be validated, it just may not be
null. So the caller is responsible that it will be proper markup.As the markup may be formatted differently (or not formatted at all), the pretty printed output may be distorted when this is used.
- Parameters:
markup- The predefined markup.- Returns:
- This instance.
- Throws:
IllegalOperationException- No children are allowed for this element.
-
addText
Adds the provided
booleanvalue as text to this element.To convert the boolean to text, the method
Boolean.toString(boolean)is used.- Parameters:
flag- The value.- Returns:
- This instance.
- Throws:
IllegalOperationException- No text allowed for this element.
-
addText
Adds the provided
Booleaninstance as text to this element.To convert the boolean to text, the method
Boolean.toString()is used.- Parameters:
flag- The value.- Returns:
- This instance.
- Throws:
IllegalOperationException- No text allowed for this element.
-
addText
Adds the provided
charvalue as text to this element.To convert the character to text, the method
Character.toString(char)is used.- Parameters:
c- The character.- Returns:
- This instance.
- Throws:
IllegalOperationException- No text allowed for this element.
-
addText
Adds the provided
Characterinstance as text to this element.To convert the character to text, the method
Character.toString()is used.- Parameters:
c- The character.- Returns:
- This instance.
- Throws:
IllegalOperationException- No text allowed for this element.
-
addText
Adds text to this element. Special characters will be escaped according to the rules for the respective SGML flavour.- Parameters:
text- The text.- Returns:
- This instance.
- Throws:
IllegalOperationException- No text allowed for this element.
-
addText
Adds the provided
doublevalue as text to this element.To convert the number to text, the method
Double.toString(double)is used.- Parameters:
number- The number.- Returns:
- This instance.
- Throws:
IllegalOperationException- No text allowed for this element.
-
addText
Adds the provided
enuminstance as text element to this element.To convert the value to text, the method
Enum.name()is used.- Type Parameters:
E- The type of theenumvalue.- Parameters:
value- The value.- Returns:
- This instance.
- Throws:
IllegalOperationException- No text allowed for this element.
-
addText
Adds the provided
Instantinstance as text to this element.To convert the date to text, the method
Instant.toString()is used.- Parameters:
date- The date.- Returns:
- This instance.
- Throws:
IllegalOperationException- No text allowed for this element.
-
addText
Adds the provided
intvalue as text to this element.To convert the number to text, the method
Integer.toString(int)is used.- Parameters:
number- The number.- Returns:
- This instance.
- Throws:
IllegalOperationException- No text allowed for this element.
-
addText
Adds the provided
LocalDateinstance as text to this element.To convert the date to text, the method
LocalDate.toString()is used.- Parameters:
date- The date.- Returns:
- This instance.
- Throws:
IllegalOperationException- No text allowed for this element.
-
addText
Adds the provided
LocalDateTimeinstance as text to this element.To convert the date to text, the method
LocalDateTime.toString()is used.- Parameters:
date- The date.- Returns:
- This instance.
- Throws:
IllegalOperationException- No text allowed for this element.
-
addText
Adds the provided
longvalue as text to this element.To convert the number to text, the method
Long.toString(long)is used.- Parameters:
number- The number.- Returns:
- This instance.
- Throws:
IllegalOperationException- No text allowed for this element.
-
addText
Adds the provided
Numberinstance as text to this element.To convert the number to text, the method
Object.toString()is used.- Parameters:
number- The number.- Returns:
- This instance.
- Throws:
IllegalOperationException- No text allowed for this element.
-
addText
Adds the provided
ZonedDateTimeinstance as text to this element.To convert the date to text, the method
ZonedDateTime.toString()is used.- Parameters:
date- The date.- Returns:
- This instance.
- Throws:
IllegalOperationException- No text allowed for this element.
-
getFlags
Returns the flags for this element.- Returns:
- The flags.
- See Also:
-
setAttribute
default XMLElement setAttribute(String name, boolean flag) throws IllegalArgumentException, IllegalOperationException Sets the attribute with the given name.
The method uses
Boolean.toString(boolean)to convert the provided flag to aString.- Parameters:
name- The name of the attribute; the name is case-sensitive.flag- The attribute's value.- Returns:
- This instance.
- Throws:
IllegalArgumentException- An attribute with the given name is not valid for the elementIllegalOperationException- No attributes are allowed for this element.
-
setAttribute
default XMLElement setAttribute(String name, Boolean flag) throws IllegalArgumentException, IllegalOperationException Sets the attribute with the given name.
The method uses
Boolean.toString()to convert the provided flag to aString.- Parameters:
name- The name of the attribute; the name is case-sensitive.flag- The attribute's value; ifnullthe attribute will be removed.- Returns:
- This instance.
- Throws:
IllegalArgumentException- An attribute with the given name is not valid for the elementIllegalOperationException- No attributes are allowed for this element.
-
setAttribute
default XMLElement setAttribute(String name, CharSequence value) throws IllegalArgumentException, IllegalOperationException Sets the attribute with the given name.- Parameters:
name- The name of the attribute; the name is case-sensitive.value- The attribute's value; ifnullthe attribute will be removed.- Returns:
- This instance.
- Throws:
IllegalArgumentException- An attribute with the given name is not valid for the elementIllegalOperationException- No attributes are allowed for this element.
-
setAttribute
default XMLElement setAttribute(String name, CharSequence value, Optional<? extends CharSequence> append) throws IllegalArgumentException, IllegalOperationException Sets the attribute with the given name.- Parameters:
name- The name of the attribute; the name is case-sensitive.value- The attribute's value; ifnullthe attribute will be removed.append- If not empty (NO_APPEND), the new value will be appended to an already existing one, and the provided char sequence is used as the separator.- Returns:
- This instance.
- Throws:
IllegalArgumentException- An attribute with the given name is not valid for the elementIllegalOperationException- No attributes are allowed for this element.
-
setAttribute
default XMLElement setAttribute(String name, double number) throws IllegalArgumentException, IllegalOperationException Sets the attribute with the given name.
The method uses
Double.toString(double)to convert the provided number to aString.- Parameters:
name- The name of the attribute; the name is case-sensitive.number- The attribute's value.- Returns:
- This instance.
- Throws:
IllegalArgumentException- An attribute with the given name is not valid for the elementIllegalOperationException- No attributes are allowed for this element.
-
setAttribute
default <E extends Enum<E>> XMLElement setAttribute(String name, E enumValue) throws IllegalArgumentException, IllegalOperationException Sets the attribute with the given name.
The method uses
Enum.name()to convert the provided value to aString.- Type Parameters:
E- The concrete enum type ofvalue.- Parameters:
name- The name of the attribute; the name is case-sensitive.enumValue- The attribute's value; ifnullthe attribute will be removed.- Returns:
- This instance.
- Throws:
IllegalArgumentException- An attribute with the given name is not valid for the elementIllegalOperationException- No attributes are allowed for this element.
-
setAttribute
default XMLElement setAttribute(String name, Instant date) throws IllegalArgumentException, IllegalOperationException Sets the attribute with the given name.
The method uses
Instant.toString()to convert the provided number to aString.- Parameters:
name- The name of the attribute; the name is case-sensitive.date- The attribute's value; ifnullthe attribute will be removed.- Returns:
- This instance.
- Throws:
IllegalArgumentException- An attribute with the given name is not valid for the elementIllegalOperationException- No attributes are allowed for this element.
-
setAttribute
default XMLElement setAttribute(String name, int number) throws IllegalArgumentException, IllegalOperationException Sets the attribute with the given name.
The method uses
Integer.toString(int)to convert the provided number to aString.- Parameters:
name- The name of the attribute; the name is case-sensitive.number- The attribute's value.- Returns:
- This instance.
- Throws:
IllegalArgumentException- An attribute with the given name is not valid for the elementIllegalOperationException- No attributes are allowed for this element.
-
setAttribute
default XMLElement setAttribute(String name, LocalDate date) throws IllegalArgumentException, IllegalOperationException Sets the attribute with the given name.
The method uses
LocalDate.toString()to convert the provided number to aString.- Parameters:
name- The name of the attribute; the name is case-sensitive.date- The attribute's value; ifnullthe attribute will be removed.- Returns:
- This instance.
- Throws:
IllegalArgumentException- An attribute with the given name is not valid for the elementIllegalOperationException- No attributes are allowed for this element.
-
setAttribute
default XMLElement setAttribute(String name, LocalDateTime date) throws IllegalArgumentException, IllegalOperationException Sets the attribute with the given name.
The method uses
LocalDateTime.toString()to convert the provided number to aString.- Parameters:
name- The name of the attribute; the name is case-sensitive.date- The attribute's value; ifnullthe attribute will be removed.- Returns:
- This instance.
- Throws:
IllegalArgumentException- An attribute with the given name is not valid for the elementIllegalOperationException- No attributes are allowed for this element.
-
setAttribute
default XMLElement setAttribute(String name, long number) throws IllegalArgumentException, IllegalOperationException Sets the attribute with the given name.
The method uses
Long.toString(long)to convert the provided number to aString.- Parameters:
name- The name of the attribute; the name is case-sensitive.number- The attribute's value.- Returns:
- This instance.
- Throws:
IllegalArgumentException- An attribute with the given name is not valid for the elementIllegalOperationException- No attributes are allowed for this element.
-
setAttribute
default XMLElement setAttribute(String name, Number number) throws IllegalArgumentException, IllegalOperationException Sets the attribute with the given name.
The method uses
Object.toString()to convert the provided number to aString.- Parameters:
name- The name of the attribute; the name is case-sensitive.number- The attribute's value; ifnullthe attribute will be removed.- Returns:
- This instance.
- Throws:
IllegalArgumentException- An attribute with the given name is not valid for the elementIllegalOperationException- No attributes are allowed for this element.
-
setAttribute
default XMLElement setAttribute(String name, ZonedDateTime date) throws IllegalArgumentException, IllegalOperationException Sets the attribute with the given name.
The method uses
ZonedDateTime.toString()to convert the provided number to aString.- Parameters:
name- The name of the attribute; the name is case-sensitive.date- The attribute's value; ifnullthe attribute will be removed.- Returns:
- This instance.
- Throws:
IllegalArgumentException- An attribute with the given name is not valid for the elementIllegalOperationException- No attributes are allowed for this element.
-
setAttributeIfNotEmpty
default XMLElement setAttributeIfNotEmpty(String name, CharSequence value) throws IllegalArgumentException, IllegalOperationException Sets the attribute with the given name if the provided value is not empty.
The method uses
StringUtils.isNotEmpty(CharSequence)to test if the given value is empty.- Parameters:
name- The name of the attribute.value- The value for the attribute; can benull.- Returns:
- This instance.
- Throws:
IllegalArgumentException- An attribute with the given name is not valid for the elementIllegalOperationException- No attributes are allowed for this element.
-
setAttributeIfNotEmpty
default XMLElement setAttributeIfNotEmpty(String name, Optional<? extends CharSequence> optional) throws IllegalArgumentException, IllegalOperationException Sets the attribute with the given name if the provided value is not empty.- Parameters:
name- The name of the attribute.optional- The value for the attribute.- Returns:
- This instance.
- Throws:
IllegalArgumentException- An attribute with the given name is not valid for the elementIllegalOperationException- No attributes are allowed for this element.
-
setId
Sets the id for the element.
The value will be validated using the method that is provided by a call to
XMLBuilderUtils.getNMTokenValidator().- Parameters:
id- The id.- Returns:
- This instance.
- Throws:
IllegalArgumentException- An attribute with the given name is not valid for the element or the value is not a valid NMToken.IllegalOperationException- No attributes are allowed for this element.- See Also:
-
setNamespace
default XMLElement setNamespace(String identifier) throws IllegalOperationException, URISyntaxException Sets the given namespace.- Parameters:
identifier- The namespace identifier.- Returns:
- This instance.
- Throws:
IllegalOperationException- Namespaces are not allowed for this element.URISyntaxException- The provided URI String is invalid.
-
setNamespace
Sets the given namespace.- Parameters:
identifier- The namespace identifier.- Returns:
- This instance.
- Throws:
IllegalOperationException- Namespaces are not allowed for this element.
-
setNamespace
default XMLElement setNamespace(String prefix, String identifier) throws IllegalOperationException, URISyntaxException Sets the given namespace.
The given prefix is validated using the method that is provided by
XMLBuilderUtils.getPrefixValidator().- Parameters:
prefix- The namespace prefix.identifier- The namespace identifier.- Returns:
- This instance.
- Throws:
IllegalOperationException- Namespaces are not allowed for this element.URISyntaxException- The provided URI String is invalid.
-
setNamespace
Sets the given namespace.
The given prefix is validated using the method that is provided by
XMLBuilderUtils.getPrefixValidator().- Parameters:
prefix- The namespace prefix.identifier- The namespace identifier.- Returns:
- This instance.
- Throws:
IllegalOperationException- Namespaces are not allowed for this element.
-
setNamespace
Sets the given namespace.- Parameters:
namespace- The namespace.- Returns:
- This instance.
- Throws:
IllegalOperationException- Namespaces are not allowed for this element.
-
setParent
Sets the parent for this element.
-
