DLESE Tools
v1.6.0

org.dlese.dpc.util
Class HTMLTools

java.lang.Object
  extended by org.dlese.dpc.util.HTMLTools

public class HTMLTools
extends Object

This class holds a number of handy static methods for use in HTML and XML processing.

Version:
$Id: HTMLTools.java,v 1.9 2009/03/20 23:34:00 jweather Exp $
Author:
John Weatherley

Constructor Summary
HTMLTools()
           
 
Method Summary
static String encodeCharacterEntityReferences(String input, boolean isSGML)
          Encodes a regular String with caracter entity references, for example the ampersand character & becomes &.
static StringBuffer javaScriptEncode(char[] chars)
          Encodes an Array of chars so that they will be valid inside JavaScript quotes.
static StringBuffer javaScriptEncode(String string)
          Encodes a String so that it will be valid inside JavaScript quotes.
static String javaScriptEncodeToStr(String string)
          Same behavior as javaScriptEncode(char[]).
static String removeHTMLComments(String input)
          Removes all HTML comments from a String.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HTMLTools

public HTMLTools()
Method Detail

removeHTMLComments

public static String removeHTMLComments(String input)
Removes all HTML comments from a String.

Parameters:
input - HTML String
Returns:
HTML with all comments removed

encodeCharacterEntityReferences

public static String encodeCharacterEntityReferences(String input,
                                                     boolean isSGML)
Encodes a regular String with caracter entity references, for example the ampersand character & becomes &amp;. See Entities Reference for a nice table of character entity references. Ampersands that are already encoded will not be touched. If the input string is an SGML variant like HTML or XML then all occurances of the characters <, > and " are left alone.

Parameters:
input - A String.
isSGML - True if the input string is a an SGML variant such as HTML or XML, false if not.
Returns:
A String that is encoded with character entity references.

javaScriptEncode

public static final StringBuffer javaScriptEncode(char[] chars)
Encodes an Array of chars so that they will be valid inside JavaScript quotes.

Parameters:
chars - An array of chars
Returns:
The resulting, encoded StringBuffer

javaScriptEncode

public static final StringBuffer javaScriptEncode(String string)
Encodes a String so that it will be valid inside JavaScript quotes.

Parameters:
string - A String
Returns:
The resulting, encoded StringBuffer

javaScriptEncodeToStr

public static final String javaScriptEncodeToStr(String string)
Same behavior as javaScriptEncode(char[]).

Parameters:
string - A String
Returns:
The resulting, encoded String

DLESE Tools
v1.6.0