|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.afcs.warts.util.HtmlUtils
The HtmlUtils class contains utility methods for manipulating strings with HTML formatting that might be useful to servlets and JSPs.
REFACTOR: Much of the string replacement functionality could be made to re-use some generic routine. This is fairly problematic though, because in some cases we want to replace one character with another, in others one with many, and in others replace several characters in one sweep.
LICENSE: This code is released to the public domain and may be used for any purpose whatsoever without permission or acknowledgment.
Method Summary | |
static java.lang.String |
breakUpContiguousNonWhitespace(java.lang.String input,
int maxContiguousNonWhitespaceChars)
This method ensures that there are at most maxContiguousNonWhitespaceChars continuous non-whitespace characters in the specified string, returning a string with extra whitespace if need be to ensure that the string will break nicely across multiple lines in a browser. |
static boolean |
containsHtmlSpecialCharacters(java.lang.String inputString)
Returns true if the string received might contain HTML special characters that might cause problems in element content, i.e., ampersands or less-than signs. |
static java.lang.String |
escapeHtmlAttributeSpecialCharacters(java.lang.String inputString)
Returns a copy of the input string where all HTML special characters that might cause problems in element attributes (such as ampersands, less-than signs, apostrophes and quotes) have been escaped with the appropriate HTML entities. |
static char[] |
escapeHtmlSpecialCharacter(char inputCharacter)
Returns the array of characters that represents the HTML escaped version of the specified character. |
static java.lang.String |
escapeHtmlSpecialCharacters(java.lang.String inputString)
Returns a copy of the input string where all HTML special characters that might cause problems in element content (such as ampersands and less-than signs) have been escaped with the appropriate HTML entities. |
static java.lang.String |
escapeHtmlSpecialCharacters(java.lang.String inputString,
boolean contentOnlyChars)
Returns a copy of the input string where all HTML special characters that might cause problems in element content or attributes have been escaped with the appropriate HTML entities. |
static java.lang.String |
hyperlinkEmailAddress(java.lang.String emailAddress)
This method converts the specified email address into a hyperlink that contains the email address as the visible text, and uses the 'mailto:' protocol to open a mail application if a user clicks on the link. |
static java.lang.String |
insertHtmlLineBreaks(java.lang.String inputString)
Returns a copy of the input string where all linebreaks have been replaced with the corresponding HTML linebreak tag ( <br> ). |
static java.lang.String |
insertNonBreakingSpaces(java.lang.String inputString)
Returns a copy of the input string where all spaces ( ) have been replaced with non-breaking spaces ( ). |
static java.lang.String |
prepareTextForHtmlDisplay(java.lang.String inputString)
Returns an HTML-formatted representation of the string received, where all special characters have been escaped, and all carriage returns have been converted to HTML line breaks. |
static java.lang.String |
stripTagsAndTrim(java.lang.String inputString)
Given a string that may contain XML or HTML tags, which are bounded by a less-than and greater-than sign, this method removes the tags from the input string, and trims any whitespace from the end of the string. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
public static java.lang.String breakUpContiguousNonWhitespace(java.lang.String input, int maxContiguousNonWhitespaceChars)
input
- The string to check.maxContiguousNonWhitespaceChars
- The maximum number of contiguous
non-whitespace characters to allow.
java.lang.IllegalArgumentException
- If maxContiguousNonWhitespaceChars is
less than 10 (which would be stupid).public static boolean containsHtmlSpecialCharacters(java.lang.String inputString)
inputString
- The string to scan for special characters.
public static java.lang.String escapeHtmlAttributeSpecialCharacters(java.lang.String inputString)
inputString
- The string in which special characters should be
escaped.
public static java.lang.String escapeHtmlSpecialCharacters(java.lang.String inputString)
inputString
- The string in which special characters should be
escaped.
public static java.lang.String hyperlinkEmailAddress(java.lang.String emailAddress)
emailAddress
- The email address to convert to a hyperlink.
public static java.lang.String insertHtmlLineBreaks(java.lang.String inputString)
<br>
). A real linebreak is placed after each HTML
line break. Note that only linebreaks of the form '\r\n' are caught
and converted, because this is the format that multipart form submissions
must take according to the HTML 4.0 specification, and hence what we
expect to find in the database, or display.
inputString
- The string to insert HTML linebreaks into.
public static java.lang.String insertNonBreakingSpaces(java.lang.String inputString)
inputString
- The string to replace spaces with non-breaking
spaces in.
public static java.lang.String prepareTextForHtmlDisplay(java.lang.String inputString)
inputString
- The string to process.
public static java.lang.String stripTagsAndTrim(java.lang.String inputString)
inputString
- The string to process
public static char[] escapeHtmlSpecialCharacter(char inputCharacter)
inputCharacter
- The character to escape.
public static java.lang.String escapeHtmlSpecialCharacters(java.lang.String inputString, boolean contentOnlyChars)
inputString
- The string in which special characters should be
escaped.contentOnlyChars
- Whether to just escape content problem characters,
or attribute problem characters.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |