net.sf.jett.util
Class RichTextStringUtil

java.lang.Object
  extended by net.sf.jett.util.RichTextStringUtil

public class RichTextStringUtil
extends java.lang.Object

The RichTextStringUtil utility class provides methods for RichTextString manipulation.

Author:
Randy Gettman

Constructor Summary
RichTextStringUtil()
           
 
Method Summary
static void applyFont(org.apache.poi.ss.usermodel.RichTextString richTextString, org.apache.poi.ss.usermodel.Cell cell)
          Take the first Font from the given RichTextString and apply it to the given Cell's CellStyle.
static org.apache.poi.ss.usermodel.RichTextString createFormattedString(int numFormattingRuns, org.apache.poi.ss.usermodel.CreationHelper helper, java.lang.String value, java.util.ArrayList<java.lang.Integer> beginList, java.util.ArrayList<java.lang.Integer> newLengthList, java.util.ArrayList<java.lang.Object> fontList)
          Construct a RichTextString of the same type as richTextString, format it, and return it.
static void determineFormattingRunStats(org.apache.poi.ss.usermodel.RichTextString richTextString, java.util.ArrayList<java.lang.Integer> beginList, java.util.ArrayList<java.lang.Integer> lengthList, java.util.ArrayList<java.lang.Object> fontList)
          Determine formatting run statistics for the given RichTextString.
static void formatString(org.apache.poi.ss.usermodel.RichTextString string, int numFormattingRuns, java.util.ArrayList<java.lang.Integer> beginList, java.util.ArrayList<java.lang.Integer> newLengthList, java.util.ArrayList<java.lang.Object> fontList)
          Format a RichTextString that has already been created.
static java.lang.Object getFontAtIndex(org.apache.poi.ss.usermodel.RichTextString richTextString, int fmtIndex)
          Gets the font index of the Font in use at the specified position in the given RichTextString.
static org.apache.poi.ss.usermodel.RichTextString replaceAll(org.apache.poi.ss.usermodel.RichTextString richTextString, org.apache.poi.ss.usermodel.CreationHelper helper, java.lang.String target, java.lang.String replacement)
          Replaces all occurrences of the given target string with the replacement string.
static org.apache.poi.ss.usermodel.RichTextString replaceAll(org.apache.poi.ss.usermodel.RichTextString richTextString, org.apache.poi.ss.usermodel.CreationHelper helper, java.lang.String target, java.lang.String replacement, boolean firstOnly)
          Replaces all occurrences of the given target string with the replacement string.
static org.apache.poi.ss.usermodel.RichTextString replaceAll(org.apache.poi.ss.usermodel.RichTextString richTextString, org.apache.poi.ss.usermodel.CreationHelper helper, java.lang.String target, java.lang.String replacement, boolean firstOnly, int startIdx)
          Replaces all occurrences of the given target string with the replacement string.
static org.apache.poi.ss.usermodel.RichTextString replaceValues(org.apache.poi.ss.usermodel.RichTextString richTextString, org.apache.poi.ss.usermodel.CreationHelper helper, java.util.List<java.lang.String> targets, java.util.List<java.lang.String> replacements)
          Replaces all strings in the given List of strings to replace with the corresponding replacement string in the given List.
static org.apache.poi.ss.usermodel.RichTextString substring(org.apache.poi.ss.usermodel.RichTextString richTextString, org.apache.poi.ss.usermodel.CreationHelper helper, int beginIndex, int endIndex)
          Extracts a substring of a RichTextString as another RichTextString.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RichTextStringUtil

public RichTextStringUtil()
Method Detail

replaceAll

public static org.apache.poi.ss.usermodel.RichTextString replaceAll(org.apache.poi.ss.usermodel.RichTextString richTextString,
                                                                    org.apache.poi.ss.usermodel.CreationHelper helper,
                                                                    java.lang.String target,
                                                                    java.lang.String replacement)
Replaces all occurrences of the given target string with the replacement string. Preserves rich text formatting as much as possible.

Parameters:
richTextString - The RichTextString to manipulate.
helper - A CreationHelper that can create the proper RichTextString.
target - The string to replace.
replacement - The replacement string.
Returns:
A new RichTextString with replaced values, or the same RichTextString if replace is null or empty.

replaceAll

public static org.apache.poi.ss.usermodel.RichTextString replaceAll(org.apache.poi.ss.usermodel.RichTextString richTextString,
                                                                    org.apache.poi.ss.usermodel.CreationHelper helper,
                                                                    java.lang.String target,
                                                                    java.lang.String replacement,
                                                                    boolean firstOnly)
Replaces all occurrences of the given target string with the replacement string. Preserves rich text formatting as much as possible.

Parameters:
richTextString - The RichTextString to manipulate.
helper - A CreationHelper that can create the proper RichTextString.
target - The string to replace.
replacement - The replacement string.
firstOnly - Whether to stop after replacing the first found instance of target.
Returns:
A new RichTextString with replaced values, or the same RichTextString if replace is null or empty.

replaceAll

public static org.apache.poi.ss.usermodel.RichTextString replaceAll(org.apache.poi.ss.usermodel.RichTextString richTextString,
                                                                    org.apache.poi.ss.usermodel.CreationHelper helper,
                                                                    java.lang.String target,
                                                                    java.lang.String replacement,
                                                                    boolean firstOnly,
                                                                    int startIdx)
Replaces all occurrences of the given target string with the replacement string. Preserves rich text formatting as much as possible.

Parameters:
richTextString - The RichTextString to manipulate.
helper - A CreationHelper that can create the proper RichTextString.
target - The string to replace.
replacement - The replacement string.
firstOnly - Whether to stop after replacing the first found instance of target.
startIdx - Start replacing after this 0-based index into the richTextString.
Returns:
A new RichTextString with replaced values, or the same RichTextString if replace is null or empty.

replaceValues

public static org.apache.poi.ss.usermodel.RichTextString replaceValues(org.apache.poi.ss.usermodel.RichTextString richTextString,
                                                                       org.apache.poi.ss.usermodel.CreationHelper helper,
                                                                       java.util.List<java.lang.String> targets,
                                                                       java.util.List<java.lang.String> replacements)
Replaces all strings in the given List of strings to replace with the corresponding replacement string in the given List. Preserves rich text formatting as much as possible.

Parameters:
richTextString - The RichTextString to manipulate.
helper - A CreationHelper that can create the proper RichTextString.
targets - The List of strings to replace.
replacements - The corresponding List of replacement strings.
Returns:
A new RichTextString with replaced values, or the same RichTextString if replace is null or empty.

substring

public static org.apache.poi.ss.usermodel.RichTextString substring(org.apache.poi.ss.usermodel.RichTextString richTextString,
                                                                   org.apache.poi.ss.usermodel.CreationHelper helper,
                                                                   int beginIndex,
                                                                   int endIndex)
Extracts a substring of a RichTextString as another RichTextString. Preserves the formatting that is in place from the given string.

Parameters:
richTextString - The RichTextString of which to take a substring.
helper - A CreationHelper that can create the proper RichTextString.
beginIndex - The beginning index, inclusive.
endIndex - The ending index, exclusive.
Returns:
The specified substring as a RichTextString, with the original formatting from the original string intact.
Since:
0.2.0

determineFormattingRunStats

public static void determineFormattingRunStats(org.apache.poi.ss.usermodel.RichTextString richTextString,
                                               java.util.ArrayList<java.lang.Integer> beginList,
                                               java.util.ArrayList<java.lang.Integer> lengthList,
                                               java.util.ArrayList<java.lang.Object> fontList)
Determine formatting run statistics for the given RichTextString. Adds elements to the arrays.

Parameters:
richTextString - The RichTextString.
beginList - Adds to this List the beginning indexes of all formatting runs found.
lengthList - Adds to this List the length of all formatting runs found.
fontList - Adds to this List the fonts of all formatting runs found. If HSSF, stores short font indexes. If XSSF, stores XSSFFont objects.

createFormattedString

public static org.apache.poi.ss.usermodel.RichTextString createFormattedString(int numFormattingRuns,
                                                                               org.apache.poi.ss.usermodel.CreationHelper helper,
                                                                               java.lang.String value,
                                                                               java.util.ArrayList<java.lang.Integer> beginList,
                                                                               java.util.ArrayList<java.lang.Integer> newLengthList,
                                                                               java.util.ArrayList<java.lang.Object> fontList)
Construct a RichTextString of the same type as richTextString, format it, and return it.

Parameters:
numFormattingRuns - The number of formatting runs.
value - The new string value of the new RichTextString to construct.
helper - A CreationHelper that can create the proper RichTextString.
beginList - A List of beginning indexes of formatting runs.
newLengthList - A List of run lengths of formatting runs.
fontList - A List of fonts of formatting runs. If HSSF, the items are shorts. If XSSF, the items are XSSFFonts.
Returns:
A new RichTextString, the same type as richTextString, with value as it contents, formatted as specified.

formatString

public static void formatString(org.apache.poi.ss.usermodel.RichTextString string,
                                int numFormattingRuns,
                                java.util.ArrayList<java.lang.Integer> beginList,
                                java.util.ArrayList<java.lang.Integer> newLengthList,
                                java.util.ArrayList<java.lang.Object> fontList)
Format a RichTextString that has already been created.

Parameters:
string - A RichTextString.
numFormattingRuns - The number of formatting runs.
beginList - A List of beginning indexes of formatting runs.
newLengthList - A List of run lengths of formatting runs.
fontList - A List of fonts of formatting runs. If HSSF, the items are shorts. If XSSF, the items are XSSFFonts.

getFontAtIndex

public static java.lang.Object getFontAtIndex(org.apache.poi.ss.usermodel.RichTextString richTextString,
                                              int fmtIndex)
Gets the font index of the Font in use at the specified position in the given RichTextString.

Parameters:
richTextString - The RichTextString.
fmtIndex - The 0-based index of the formatting run.
Returns:
The font index: If HSSF, a short. If XSSF, an XSSFFont.

applyFont

public static void applyFont(org.apache.poi.ss.usermodel.RichTextString richTextString,
                             org.apache.poi.ss.usermodel.Cell cell)
Take the first Font from the given RichTextString and apply it to the given Cell's CellStyle.

Parameters:
cell - The Cell.
richTextString - The RichTextString that contains the desired Font.
Since:
0.2.0


Copyright © 2012-2013 Jett Team. All Rights Reserved.