org.openbp.common.string
Class TextUtil

java.lang.Object
  extended by org.openbp.common.string.TextUtil

public final class TextUtil
extends java.lang.Object

Text utilities.

Author:
Heiko Erhardt

Method Summary
static void appendHTMLLine(java.lang.String line, java.lang.StringBuffer output, int maxLength)
          Appends the given text as HTML line to the output.
static java.util.List breakIntoLines(java.lang.String s, boolean trim, int maxLength)
          Breaks a single string into a list of lines.
static java.lang.String concatLines(java.util.Iterator lineIterator)
          Concatenates several lines into one string.
static java.lang.String convertToHTML(java.lang.String[] paragraphs, boolean boldTitle, int separatorPos, int maxLength)
          Converts regular text to an HTML form that can be used for display in browsers or tool tips.
static java.lang.String decodeMultiLineString(java.lang.String s)
          Trims the string and converts all newline and tab escape representations to their character values.
static java.lang.String encodeMultiLineString(java.lang.String s)
          Trims the string and converts all newline and tab character to an escape representation.
static java.lang.String extractSummary(java.lang.String text)
          Extracts a summary from an object description.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

extractSummary

public static java.lang.String extractSummary(java.lang.String text)
Extracts a summary from an object description. The summary is the text up to the first point that is followed by a whitespace or up to the first new line in the string. Any white spaces in the string will be compressed to a single space.

Parameters:
text - Description text
Returns:
The summary string or null if the text is null or empty

breakIntoLines

public static java.util.List breakIntoLines(java.lang.String s,
                                            boolean trim,
                                            int maxLength)
Breaks a single string into a list of lines. Every line is limited to a particular length. Internally, a java.text.BreakIterator is used to break the lines, maintaining punctaction and hyphenated words. Newline characters are considered line breaks also (they will be removed from the resulting lines).

Parameters:
s - The string to break
trim - true Remove leading and trailing spaces and tabulators from each line
false Do not trim the lines
maxLength - Maximum length per line or -1 for unlimited line length
Returns:
A list of line strings

concatLines

public static java.lang.String concatLines(java.util.Iterator lineIterator)
Concatenates several lines into one string. The lines are separated by a '\n' character.

Parameters:
lineIterator - Iterator of String objects
Returns:
The result string or null

encodeMultiLineString

public static java.lang.String encodeMultiLineString(java.lang.String s)
Trims the string and converts all newline and tab character to an escape representation. Newlines: "\n"
Tabs: "\t"

Parameters:
s - String to encode
Returns:
The encoded string or null if the string is null or contains white space only

decodeMultiLineString

public static java.lang.String decodeMultiLineString(java.lang.String s)
Trims the string and converts all newline and tab escape representations to their character values. Newlines: "\n"
Tabs: "\t"

Parameters:
s - String to decode
Returns:
The decoded string or null if the string is null or contains white space only

convertToHTML

public static java.lang.String convertToHTML(java.lang.String[] paragraphs,
                                             boolean boldTitle,
                                             int separatorPos,
                                             int maxLength)
Converts regular text to an HTML form that can be used for display in browsers or tool tips. Newlines will be substituted by their HTML counterpart.

Parameters:
paragraphs - Array of strings, each one denoting a single paragraph or null
boldTitle - true Treat the first paragraph as title and print it bold.
false No special handling for the first paragraph
separatorPos - Position for the separator line (-1 if no separator should be used, 0 for separator after paragraphs[0] etc.
maxLength - Maximum length per line or -1 for unlimited line length
Returns:
The HTML text or null

appendHTMLLine

public static void appendHTMLLine(java.lang.String line,
                                  java.lang.StringBuffer output,
                                  int maxLength)
Appends the given text as HTML line to the output.

Parameters:
line - Line to append
output - Output string buffer
maxLength - Maximum length per line or -1 for unlimited line length


Copyright © 2011. All Rights Reserved.