Class XmlHelper

java.lang.Object
net.luis.utils.io.data.xml.XmlHelper

final class XmlHelper extends Object
Helper class for xml related operations.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    (package private) static final Pattern
    Pattern for valid xml attribute keys.
    (package private) static final Pattern
    Pattern for valid xml element names.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    private
    Private constructor to prevent instantiation.
    This is a static helper class.
  • Method Summary

    Modifier and Type
    Method
    Description
    (package private) static @NotNull String
    escapeXml(@NotNull String value)
    Escapes the given value for xml.
    The following characters are replaced:
    & -> &amp; " -> &quot; ' -> &apos; < -> &lt; > -> &gt;
    (package private) static @NotNull String
    unescapeXml(@NotNull String value)
    Unescapes the given value from xml.
    The following characters are replaced:
    &amp; -> & &quot; -> " &apos; -> ' &lt; -> < &gt; -> >
    (package private) static @NotNull String
    Validates the given xml attribute name.
    In addition to the base validation, the name must match the pattern XML_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 pattern XML_ELEMENT_NAME_PATTERN.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • XML_ELEMENT_NAME_PATTERN

      static final Pattern XML_ELEMENT_NAME_PATTERN
      Pattern for valid xml element names.
    • XML_ATTRIBUTE_NAME_PATTERN

      static final Pattern 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

      private static void validateBase(@NotNull @NotNull String str, @NotNull @NotNull String message)
      Validates the given string.
      The base validation checks if the string is not null, not empty and not blank.
      Parameters:
      str - The string to validate
      message - The message to use in the exception
      Throws:
      NullPointerException - If the string is null
      IllegalArgumentException - If the string is empty or blank
    • validateElementName

      @NotNull static @NotNull String validateElementName(@NotNull @NotNull String name)
      Validates the given xml element name.
      In addition to the base validation, the name must match the pattern XML_ELEMENT_NAME_PATTERN.
      Parameters:
      name - The name to validate
      Returns:
      The validated name
      Throws:
      NullPointerException - If the name is null
      IllegalArgumentException - If the base validation fails or the name does not match the pattern
    • validateAttributeKey

      @NotNull static @NotNull String validateAttributeKey(@NotNull @NotNull String name)
      Validates the given xml attribute name.
      In addition to the base validation, the name must match the pattern XML_ATTRIBUTE_NAME_PATTERN.
      Parameters:
      name - The name to validate
      Returns:
      The validated name
      Throws:
      NullPointerException - If the name is null
      IllegalArgumentException - If the base validation fails or the name does not match the pattern
    • escapeXml

      @NotNull static @NotNull String escapeXml(@NotNull @NotNull String value)
      Escapes the given value for xml.
      The following characters are replaced:
      • & -> &amp;
      • " -> &quot;
      • ' -> &apos;
      • < -> &lt;
      • > -> &gt;
      Parameters:
      value - The value to escape
      Returns:
      The escaped value
      Throws:
      NullPointerException - If the value is null
    • unescapeXml

      @NotNull static @NotNull String unescapeXml(@NotNull @NotNull String value)
      Unescapes the given value from xml.
      The following characters are replaced:
      • &amp; -> &
      • &quot; -> "
      • &apos; -> '
      • &lt; -> <
      • &gt; -> >
      Parameters:
      value - The value to unescape
      Returns:
      The unescaped value
      Throws:
      NullPointerException - If the value is null