net.sf.joost.emitter
Class HtmlEncoder

java.lang.Object
  |
  +--net.sf.joost.emitter.HtmlEncoder

public final class HtmlEncoder
extends Object

Encodes text strings and URLs to be HTML-safe.


Field Summary
private static float newSizeFactor
           
static String[] TABLE_HTML
          Lookup table for use in encode() method.
static String[] TABLE_HTML_STRICT
          Lookup table for use in encodeTextXxx() methods.
 
Constructor Summary
HtmlEncoder()
           
 
Method Summary
static String decodeUrl(String string)
          Encodes HTML JavaScript for page output using ISO-88591-1 encoding.
static String decodeUrl(String string, String encoding)
          Encodes HTML JavaScript for page output.
static String encode(String string)
          Encode string to HTML-safe text.
static String encodeText(String string)
          Encodes text int HTML-safe text and preserves format except spaces.
static String encodeTextSmart(String string)
          Encodes text int HTML-safe text and preserves format using smart spaces.
static String encodeTextStrict(String string)
          Encodes text int HTML-safe text and preserves format.
static String encodeUrl(String string)
          Encodes HTML JavaScript for page output using ISO-88591-1 encoding.
static String encodeUrl(String string, String encoding)
          Encodes HTML JavaScript for page output.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

newSizeFactor

private static float newSizeFactor

TABLE_HTML

public static final String[] TABLE_HTML
Lookup table for use in encode() method.

See Also:
encode(java.lang.String)

TABLE_HTML_STRICT

public static final String[] TABLE_HTML_STRICT
Lookup table for use in encodeTextXxx() methods.

See Also:
encodeText(java.lang.String), encodeTextSmart(java.lang.String), encodeTextStrict(java.lang.String)
Constructor Detail

HtmlEncoder

public HtmlEncoder()
Method Detail

encode

public static String encode(String string)
Encode string to HTML-safe text. Extra characters are encoded as decimals, and five special characters are replaced with their HTML values:
  • ' with '
  • " with "
  • & with &
  • < with &lt;
  • > with &gt;
  • Parameters:
    string - input string
    Returns:
    HTML-safe string
    See Also:
    encodeText(java.lang.String)

    encodeTextStrict

    public static String encodeTextStrict(String string)
    Encodes text int HTML-safe text and preserves format. Additionaly, the following characters are replaced:
  • ' ' with &nbsp;
  • \n with <br>
  • \r with <br>


  • Additionaly, this method takes care about CRLF and LF texts and handles both. Common problem with this method is that spaces are not breakable, so they may break the outline of the page.

    Parameters:
    string - input string
    Returns:
    HTML-safe format

    encodeText

    public static String encodeText(String string)
    Encodes text int HTML-safe text and preserves format except spaces. Additionaly, the following characters are replaced:
  • \n with <br>
  • \r with <br>


  • Additionaly, this method takes care about CRLF and LF texts and handles both.

    Parameters:
    string - input string
    Returns:
    HTML-safe format

    encodeTextSmart

    public static String encodeTextSmart(String string)
    Encodes text int HTML-safe text and preserves format using smart spaces. Additionaly, the following characters are replaced:
  • \n with <br>
  • \r with <br>


  • Additionaly, this method takes care about CRLF and LF texts and handles both.
    This method is special since it preserves format, but with combination of not-breakable spaces and common spaces, so breaks are availiable.

    Parameters:
    string - input string
    Returns:
    HTML-safe format

    encodeUrl

    public static String encodeUrl(String string)
    Encodes HTML JavaScript for page output using ISO-88591-1 encoding. Null strings are converted to empty ones. Unfortunatelly, this encoding is not comatible with the javascripts functions escape/unescape.

    Parameters:
    string - input string
    Returns:
    HTML ready string.

    encodeUrl

    public static String encodeUrl(String string,
                                   String encoding)
    Encodes HTML JavaScript for page output. Null strings are converted to empty ones.

    Parameters:
    string - input string
    encoding -
    Returns:
    HTML ready string.

    decodeUrl

    public static String decodeUrl(String string)
    Encodes HTML JavaScript for page output using ISO-88591-1 encoding. Null strings are converted to empty ones.

    Parameters:
    string - input
    Returns:
    HTML ready string.

    decodeUrl

    public static String decodeUrl(String string,
                                   String encoding)
    Encodes HTML JavaScript for page output. Null strings are converted to empty ones.

    Parameters:
    string - input
    encoding - encoding
    Returns:
    HTML ready string.