org.htmlcleaner
Class Utils

java.lang.Object
  extended by org.htmlcleaner.Utils

public class Utils
extends Object

Common utilities.


Field Summary
static Map<Character,String> RESERVED_XML_CHARS
           
static String VAR_END
           
static String VAR_START
           
 
Constructor Summary
Utils()
           
 
Method Summary
static String escapeXml(String s, CleanerProperties props, boolean isDomCreation)
          Escapes XML string.
static String evaluateTemplate(String template, Map variables)
          Evaluates string template for specified map of variables.
static String fullUrl(String pageUrl, 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 String getCharsetFromContent(URL url)
           
static String getCharsetFromContentTypeString(String contentType)
           
static String getXmlName(String name)
           
static String getXmlNSPrefix(String name)
           
static boolean isEmptyString(Object o)
           
static boolean isFullUrl(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(String s, int radix)
           
static boolean isValidXmlChar(char ch)
           
static boolean isValidXmlIdentifier(String s)
          Chacks whether specified string can be valid tag name or attribute name in xml.
static boolean isWhitespaceString(Object object)
          Checks whether specified object's string representation is empty string (containing of only whitespaces).
static String ltrim(String s)
          Trims specified string from left.
static String rtrim(String s)
          Trims specified string from right.
static String[] tokenize(String s, String delimiters)
           
static void updateTagTransformations(CleanerTransformations transformations, String key, 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 String VAR_START

VAR_END

public static String VAR_END

RESERVED_XML_CHARS

public static final Map<Character,String> RESERVED_XML_CHARS
Constructor Detail

Utils

public Utils()
Method Detail

ltrim

public static String ltrim(String s)
Trims specified string from left.

Parameters:
s -

rtrim

public static String rtrim(String s)
Trims specified string from right.

Parameters:
s -

getCharsetFromContentTypeString

public static String getCharsetFromContentTypeString(String contentType)

getCharsetFromContent

public static String getCharsetFromContent(URL url)
                                    throws IOException
Throws:
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(String s,
                                 int radix)

escapeXml

public static String escapeXml(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(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(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(Object o)
Parameters:
o -
Returns:
True if specified string is null of contains only whitespace characters

evaluateTemplate

public static String evaluateTemplate(String template,
                                      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 String[] tokenize(String s,
                                String delimiters)

updateTagTransformations

public static void updateTagTransformations(CleanerTransformations transformations,
                                            String key,
                                            String value)

isFullUrl

public static boolean isFullUrl(String link)
Checks if specified link is full URL.

Parameters:
link -
Returns:
True, if full URl, false otherwise.

fullUrl

public static String fullUrl(String pageUrl,
                             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 String getXmlNSPrefix(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 String getXmlName(String name)
Parameters:
name -
Returns:
For xml element name or attribute name returns name after prefix (part after :)


Copyright © 2006-2011. All Rights Reserved.