com.samskivert.servlet.util
Class HTMLUtil

java.lang.Object
  extended by com.samskivert.servlet.util.HTMLUtil

public class HTMLUtil
extends Object

HTML related utility functions.


Field Summary
protected static Pattern _url
           
 
Constructor Summary
HTMLUtil()
           
 
Method Summary
static String entify(String text)
          Converts instances of <, >, & and " into their entified equivalents: <, >, & and ".
static String makeLinear(String text)
          Inserts a <br> tag before every newline.
static String makeParagraphs(String text)
          Inserts a <p> tag between every two consecutive newlines.
static String restrictHTML(String src)
          Restrict all HTML from the specified String.
static String restrictHTML(String src, boolean allowFormatting, boolean allowImages, boolean allowLinks)
          Restrict HTML except for the specified tags.
static String restrictHTML(String src, String[] regexes)
          Restrict HTML from the specified string except for the specified regular expressions.
static String simpleFormat(String text)
          Does some simple HTML markup, matching bare image URLs and wrapping them in image tags, matching other URLs and wrapping them in href tags, and wrapping * prefixed lists into ul-style HTML lists.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_url

protected static Pattern _url
Constructor Detail

HTMLUtil

public HTMLUtil()
Method Detail

entify

public static String entify(String text)
Converts instances of <, >, & and " into their entified equivalents: <, >, & and ". These characters are mentioned in the HTML spec as being common candidates for entification.

Returns:
the entified string.

makeParagraphs

public static String makeParagraphs(String text)
Inserts a <p> tag between every two consecutive newlines.


makeLinear

public static String makeLinear(String text)
Inserts a <br> tag before every newline.


simpleFormat

public static String simpleFormat(String text)
Does some simple HTML markup, matching bare image URLs and wrapping them in image tags, matching other URLs and wrapping them in href tags, and wrapping * prefixed lists into ul-style HTML lists.


restrictHTML

public static String restrictHTML(String src)
Restrict all HTML from the specified String.


restrictHTML

public static String restrictHTML(String src,
                                  boolean allowFormatting,
                                  boolean allowImages,
                                  boolean allowLinks)
Restrict HTML except for the specified tags.

Parameters:
allowFormatting - enables <i>, <b>, <u>, <font>, <br>, <p>, and <hr>.
allowImages - enabled <img ...>.
allowLinks - enabled <a href ...>.

restrictHTML

public static String restrictHTML(String src,
                                  String[] regexes)
Restrict HTML from the specified string except for the specified regular expressions.



Copyright © 2000-2008 Michael Bayne. All Rights Reserved.