Class Utils


  • public class Utils
    extends java.lang.Object

    Common utilities.

    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.util.Map<java.lang.Character,​java.lang.String> RESERVED_XML_CHARS  
      static java.lang.String VAR_END  
      static java.lang.String VAR_START  
    • Constructor Summary

      Constructors 
      Constructor Description
      Utils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String escapeXml​(java.lang.String s, CleanerProperties props, boolean isDomCreation)
      Escapes XML string.
      static java.lang.String evaluateTemplate​(java.lang.String template, java.util.Map variables)
      Evaluates string template for specified map of variables.
      static java.lang.String fullUrl​(java.lang.String pageUrl, java.lang.String link)
      Calculates full URL for specified page URL and link which could be full, absolute or relative like there can be found in A or IMG tags.
      static java.lang.String getCharsetFromContent​(java.net.URL url)  
      static java.lang.String getCharsetFromContentTypeString​(java.lang.String contentType)  
      static java.lang.String getXmlName​(java.lang.String name)  
      static java.lang.String getXmlNSPrefix​(java.lang.String name)  
      static boolean isEmptyString​(java.lang.Object o)  
      static boolean isFullUrl​(java.lang.String link)
      Checks if specified link is full URL.
      static boolean isHexadecimalDigit​(char ch)  
      static boolean isIdentifierHelperChar​(char ch)
      Checks if specified character can be part of xml identifier (tag name of attribute name) and is not standard identifier character.
      static boolean isReservedXmlChar​(char ch)  
      static boolean isValidInt​(java.lang.String s, int radix)  
      static boolean isValidXmlChar​(char ch)  
      static boolean isValidXmlIdentifier​(java.lang.String s)
      Chacks whether specified string can be valid tag name or attribute name in xml.
      static boolean isWhitespaceString​(java.lang.Object object)
      Checks whether specified object's string representation is empty string (containing of only whitespaces).
      static java.lang.String ltrim​(java.lang.String s)
      Trims specified string from left.
      static java.lang.String rtrim​(java.lang.String s)
      Trims specified string from right.
      static java.lang.String[] tokenize​(java.lang.String s, java.lang.String delimiters)  
      static void updateTagTransformations​(CleanerTransformations transformations, java.lang.String key, java.lang.String value)  
      • Methods inherited from class java.lang.Object

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

      • VAR_START

        public static java.lang.String VAR_START
      • VAR_END

        public static java.lang.String VAR_END
      • RESERVED_XML_CHARS

        public static final java.util.Map<java.lang.Character,​java.lang.String> RESERVED_XML_CHARS
    • Constructor Detail

      • Utils

        public Utils()
    • Method Detail

      • ltrim

        public static java.lang.String ltrim​(java.lang.String s)
        Trims specified string from left.
        Parameters:
        s -
      • rtrim

        public static java.lang.String rtrim​(java.lang.String s)
        Trims specified string from right.
        Parameters:
        s -
      • getCharsetFromContentTypeString

        public static java.lang.String getCharsetFromContentTypeString​(java.lang.String contentType)
      • getCharsetFromContent

        public static java.lang.String getCharsetFromContent​(java.net.URL url)
                                                      throws java.io.IOException
        Throws:
        java.io.IOException
      • isHexadecimalDigit

        public static boolean isHexadecimalDigit​(char ch)
      • isValidXmlChar

        public static boolean isValidXmlChar​(char ch)
      • isReservedXmlChar

        public static boolean isReservedXmlChar​(char ch)
      • isValidInt

        public static boolean isValidInt​(java.lang.String s,
                                         int radix)
      • escapeXml

        public static java.lang.String escapeXml​(java.lang.String s,
                                                 CleanerProperties props,
                                                 boolean isDomCreation)
        Escapes XML string.
        Parameters:
        s - String to be escaped
        props - Cleaner properties gover affect escaping behaviour
        isDomCreation - Tells if escaped content will be part of the DOM
      • isWhitespaceString

        public static boolean isWhitespaceString​(java.lang.Object object)
        Checks whether specified object's string representation is empty string (containing of only whitespaces).
        Parameters:
        object - Object whose string representation is checked
        Returns:
        true, if empty string, false otherwise
      • isIdentifierHelperChar

        public static boolean isIdentifierHelperChar​(char ch)
        Checks if specified character can be part of xml identifier (tag name of attribute name) and is not standard identifier character.
        Parameters:
        ch - Character to be checked
        Returns:
        True if it can be part of xml identifier
      • isValidXmlIdentifier

        public static boolean isValidXmlIdentifier​(java.lang.String s)
        Chacks whether specified string can be valid tag name or attribute name in xml.
        Parameters:
        s - String to be checked
        Returns:
        True if string is valid xml identifier, false otherwise
      • isEmptyString

        public static boolean isEmptyString​(java.lang.Object o)
        Parameters:
        o -
        Returns:
        True if specified string is null of contains only whitespace characters
      • evaluateTemplate

        public static java.lang.String evaluateTemplate​(java.lang.String template,
                                                        java.util.Map variables)
        Evaluates string template for specified map of variables. Template string can contain dynamic parts in the form of ${VARNAME}. Each such part is replaced with value of the variable if such exists in the map, or with empty string otherwise.
        Parameters:
        template - Template string
        variables - Map of variables (can be null)
        Returns:
        Evaluated string
      • tokenize

        public static java.lang.String[] tokenize​(java.lang.String s,
                                                  java.lang.String delimiters)
      • updateTagTransformations

        public static void updateTagTransformations​(CleanerTransformations transformations,
                                                    java.lang.String key,
                                                    java.lang.String value)
      • isFullUrl

        public static boolean isFullUrl​(java.lang.String link)
        Checks if specified link is full URL.
        Parameters:
        link -
        Returns:
        True, if full URl, false otherwise.
      • fullUrl

        public static java.lang.String fullUrl​(java.lang.String pageUrl,
                                               java.lang.String link)
        Calculates full URL for specified page URL and link which could be full, absolute or relative like there can be found in A or IMG tags.
      • getXmlNSPrefix

        public static java.lang.String getXmlNSPrefix​(java.lang.String name)
        Parameters:
        name -
        Returns:
        For xml element name or attribute name returns prefix (part before :) or null if there is no prefix
      • getXmlName

        public static java.lang.String getXmlName​(java.lang.String name)
        Parameters:
        name -
        Returns:
        For xml element name or attribute name returns name after prefix (part after :)