java.lang.Object
net.luis.utils.io.data.xml.XmlHelper
Helper class for xml related operations.
-
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivate
Private constructor to prevent instantiation.
This is a static helper class. -
Method Summary
Modifier and TypeMethodDescription(package private) static @NotNull String
Escapes the given value for xml.
The following characters are replaced:
& -> &
" -> "
' -> '
< -> <
> -> >
(package private) static @NotNull String
unescapeXml
(@NotNull String value) Unescapes the given value from xml.
The following characters are replaced:
& -> &
" -> "
' -> '
< -> <
> -> >
(package private) static @NotNull String
validateAttributeKey
(@NotNull String name) Validates the given xml attribute name.
In addition to the base validation, the name must match the patternXML_ATTRIBUTE_NAME_PATTERN
.private static void
validateBase
(@NotNull String str, @NotNull String message) Validates the given string.
The base validation checks if the string is not null, not empty and not blank.(package private) static @NotNull String
validateElementName
(@NotNull String name) Validates the given xml element name.
In addition to the base validation, the name must match the patternXML_ELEMENT_NAME_PATTERN
.
-
Field Details
-
XML_ELEMENT_NAME_PATTERN
Pattern for valid xml element names. -
XML_ATTRIBUTE_NAME_PATTERN
Pattern for valid xml attribute keys.
-
-
Constructor Details
-
XmlHelper
private XmlHelper()Private constructor to prevent instantiation.
This is a static helper class.
-
-
Method Details
-
validateBase
Validates the given string.
The base validation checks if the string is not null, not empty and not blank.- Parameters:
str
- The string to validatemessage
- The message to use in the exception- Throws:
NullPointerException
- If the string is nullIllegalArgumentException
- If the string is empty or blank
-
validateElementName
Validates the given xml element name.
In addition to the base validation, the name must match the patternXML_ELEMENT_NAME_PATTERN
.- Parameters:
name
- The name to validate- Returns:
- The validated name
- Throws:
NullPointerException
- If the name is nullIllegalArgumentException
- If the base validation fails or the name does not match the pattern
-
validateAttributeKey
Validates the given xml attribute name.
In addition to the base validation, the name must match the patternXML_ATTRIBUTE_NAME_PATTERN
.- Parameters:
name
- The name to validate- Returns:
- The validated name
- Throws:
NullPointerException
- If the name is nullIllegalArgumentException
- If the base validation fails or the name does not match the pattern
-
escapeXml
Escapes the given value for xml.
The following characters are replaced:
& -> &
" -> "
' -> '
< -> <
> -> >
- Parameters:
value
- The value to escape- Returns:
- The escaped value
- Throws:
NullPointerException
- If the value is null
-
unescapeXml
Unescapes the given value from xml.
The following characters are replaced:
& -> &
" -> "
' -> '
< -> <
> -> >
- Parameters:
value
- The value to unescape- Returns:
- The unescaped value
- Throws:
NullPointerException
- If the value is null
-