Package cdc.util.xml

Class XmlUtils


  • public final class XmlUtils
    extends Object
    Xml utilities.
    Author:
    Damien Carbonne
    • Method Detail

      • codePointToString

        public static String codePointToString​(int codePoint)
      • isWhiteSpace

        public static boolean isWhiteSpace​(int codePoint)
        Returns true if a code point is a white space.
        Parameters:
        codePoint - The code point.
        Returns:
        true if codePoint is a white space.
      • isWhiteSpace

        public static boolean isWhiteSpace​(String s)
        Returns true if a string is null or contains only white spaces.
        Parameters:
        s - The string.
        Returns:
        true if s is null or contains only white spaces.
      • isWhiteSpace

        public static boolean isWhiteSpace​(char[] ch,
                                           int offset,
                                           int count)
      • isXml10Char

        public static boolean isXml10Char​(int codePoint)
        Returns true if a code point is valid for XML 1.0.

        Note: A valid character may need escape.

        Parameters:
        codePoint - The code point.
        Returns:
        true if codePoint is a valid XML 1.0 code point.
      • isXml11Char

        public static boolean isXml11Char​(int codePoint)
        Returns true if a code point is valid for XML 1.1.

        Note: A valid character may need escape.

        Parameters:
        codePoint - The code point.
        Returns:
        true if codePoint is a valid XML 1.1 code point.
      • isXmlChar

        public static boolean isXmlChar​(int codePoint,
                                        XmlVersion version)
      • isValidXml10

        public static boolean isValidXml10​(String s)
        Returns true if a string is null or contains only valid XML 1.0 characters.

        Note: A valid character may need escape.

        Parameters:
        s - The string.
        Returns:
        true if s is null or contains only valid XML 1.0 characters.
      • isValidXml11

        public static boolean isValidXml11​(String s)
        Returns true if a string is null or contains only valid XML 1.1 characters.

        Note: A valid character may need escape.

        Parameters:
        s - The string.
        Returns:
        true if s is null or contains only valid XML 1.1 characters.
      • isValidXml

        public static boolean isValidXml​(String s,
                                         XmlVersion version)
      • isNameStartChar

        public static boolean isNameStartChar​(int codePoint)
        Returns true if a code point is valid as first character of an xml name.
        Parameters:
        codePoint - The code point.
        Returns:
        true if codePoint is valid as first character of an xml name.
      • isNameChar

        public static boolean isNameChar​(int codePoint)
      • isValidName

        public static boolean isValidName​(String s)
        Returns true if a string is a valid xml name.

        If must not be null or empty, its first character must be a valid start character, and other characters must be valid.

        Parameters:
        s - The string.
        Returns:
        true if s is a valid xml name.
      • validate

        public static String validate​(String s,
                                      XmlVersion version,
                                      FailureReaction reaction,
                                      int def)
        Checks that a string contains only valid characters, and replaces invalid chars.
        Parameters:
        s - The string.
        version - The Xml version.
        reaction - The reaction to adopt in when an invalid character is met.
        def - The default code point to use to replace invalid characters.
        Returns:
        A validated string.
        Throws:
        IllegalArgumentException - when invalid characters are met and reaction is FAIL.
      • needsEscape

        public static boolean needsEscape​(String s,
                                          XmlUtils.Context context,
                                          XmlUtils.EscapingPolicy policy)
        Returns true is a string must be escaped.
        • < and & must always be escaped.
        • > does not need escape. It is escaped if required with policy.
        • " needs to be escaped in attributes delimited by ". Otherwise, is escaped if required by policy.
        • ' needs to be escaped in attributes delimited by '. Otherwise, is escaped if required by policy.
        • \t, \n and \r should be escaped in attributes. They are if escaped if required by policy.
        Parameters:
        s - The string.
        context - The context.
        policy - The escaping policy.
        Returns:
        true is s must be escaped incontext and using policy.
      • escape

        public static String escape​(String s,
                                    XmlUtils.Context context,
                                    XmlUtils.EscapingPolicy policy)
        Returns an escaped version of a string.
        Parameters:
        s - The string.
        context - The context.
        policy - The escaping policy.
        Returns:
        The escaped version of s incontext and using policy.