Class ReportStringUtil
- java.lang.Object
-
- org.apache.ofbiz.htmlreport.util.ReportStringUtil
-
public final class ReportStringUtil extends java.lang.Object
Provides String utility functions.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
FALSE
Constant for"false"
.static java.lang.String
LINE_SEPARATOR
a convenient shorthand to the line separator constant.static char[]
SENTENCE_ENDING_CHARS
Contains all chars that end a sentence in thetrimToSize(String, int, int, String)
method.static java.lang.String
TABULATOR
a convenient shorthand for tabulations.static java.lang.String
TRUE
Constant for"true"
.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.String
changeFileNameSuffixTo(java.lang.String filename, java.lang.String suffix)
Changes the filename suffix.static java.lang.String
collectionAsString(java.util.Collection<java.lang.String> collection, java.lang.String separator)
Returns a string representation for the given collection using the given separator.static java.lang.String
escapeHtml(java.lang.String source)
Replaces occurrences of special control characters in the given input with a HTML representation.static java.lang.String
escapeJavaScript(java.lang.String source)
Escapes a String so it may be used in JavaScript String definitions.static java.lang.String
escapePattern(java.lang.String source)
Escapes a String so it may be used as a Perl5 regular expression.static java.lang.String
formatRuntime(long runtime)
Formats a runtime in the format hh:mm:ss, to be used e.g.static boolean
isEmpty(java.lang.String value)
Returnstrue
if the provided String is eithernull
or the empty String""
.static boolean
isEmptyOrWhitespaceOnly(java.lang.String value)
Returnstrue
if the provided String is eithernull
or contains only white spaces.static boolean
isEqual(java.lang.Object value1, java.lang.Object value2)
Returnstrue
if the provided Objects are either bothnull
or equal according toObject.equals(Object)
.static boolean
isNotEmpty(java.lang.String value)
Returnstrue
if the provided String is neithernull
nor the empty String""
.static boolean
isNotEmptyOrWhitespaceOnly(java.lang.String value)
Returnstrue
if the provided String is neithernull
nor contains only white spaces.static int
lastIndexOf(java.lang.String source, char[] chars)
Returns the last index of any of the given chars in the given source.static int
lastWhitespaceIn(java.lang.String source)
Returns the last index a whitespace char the given source.static java.lang.String
substitute(java.lang.String source, java.lang.String searchString, java.lang.String replaceString)
SubstitutessearchString
in the given source String withreplaceString
.static java.lang.String
toUnicodeLiteral(java.lang.String s)
Returns the java String literal for the given String.static java.lang.String
trimToSize(java.lang.String source, int length)
Returns a substring of the source, which is at most length characters long.static java.lang.String
trimToSize(java.lang.String source, int length, int area, java.lang.String suffix)
Returns a substring of the source, which is at most length characters long, cut in the lastarea
chars in the source at a sentence ending char or whitespace.static java.lang.String
trimToSize(java.lang.String source, int length, java.lang.String suffix)
Returns a substring of the source, which is at most length characters long.
-
-
-
Field Detail
-
FALSE
public static final java.lang.String FALSE
Constant for"false"
.
-
LINE_SEPARATOR
public static final java.lang.String LINE_SEPARATOR
a convenient shorthand to the line separator constant.
-
SENTENCE_ENDING_CHARS
public static final char[] SENTENCE_ENDING_CHARS
Contains all chars that end a sentence in thetrimToSize(String, int, int, String)
method.
-
TABULATOR
public static final java.lang.String TABULATOR
a convenient shorthand for tabulations.- See Also:
- Constant Field Values
-
TRUE
public static final java.lang.String TRUE
Constant for"true"
.
-
-
Method Detail
-
changeFileNameSuffixTo
public static java.lang.String changeFileNameSuffixTo(java.lang.String filename, java.lang.String suffix)
Changes the filename suffix.- Parameters:
filename
- the filename to be changedsuffix
- the new suffix of the file- Returns:
- the filename with the replaced suffix
-
collectionAsString
public static java.lang.String collectionAsString(java.util.Collection<java.lang.String> collection, java.lang.String separator)
Returns a string representation for the given collection using the given separator.- Parameters:
collection
- the collection to printseparator
- the item separator- Returns:
- the string representation for the given collection
-
escapeHtml
public static java.lang.String escapeHtml(java.lang.String source)
Replaces occurrences of special control characters in the given input with a HTML representation.This method currently replaces line breaks to
<br/>
and special HTML chars like< > & "
with their HTML entity representation.- Parameters:
source
- the String to escape- Returns:
- the escaped String
-
escapeJavaScript
public static java.lang.String escapeJavaScript(java.lang.String source)
Escapes a String so it may be used in JavaScript String definitions.This method replaces line breaks, quotation marks and \ characters.
- Parameters:
source
- the String to escape- Returns:
- the escaped String
-
escapePattern
public static java.lang.String escapePattern(java.lang.String source)
Escapes a String so it may be used as a Perl5 regular expression.This method replaces the following characters in a String:
{}[]()\$^.*+/
- Parameters:
source
- the string to escape- Returns:
- the escaped string
-
formatRuntime
public static java.lang.String formatRuntime(long runtime)
Formats a runtime in the format hh:mm:ss, to be used e.g. in reports.If the runtime is greater then 24 hours, the format dd:hh:mm:ss is used.
- Parameters:
runtime
- the time to format- Returns:
- the formatted runtime
-
isEmpty
public static boolean isEmpty(java.lang.String value)
Returnstrue
if the provided String is eithernull
or the empty String""
.- Parameters:
value
- the value to check- Returns:
- true, if the provided value is null or the empty String, false otherwise
-
isEmptyOrWhitespaceOnly
public static boolean isEmptyOrWhitespaceOnly(java.lang.String value)
Returnstrue
if the provided String is eithernull
or contains only white spaces.- Parameters:
value
- the value to check- Returns:
- true, if the provided value is null or contains only white spaces, false otherwise
-
isEqual
public static boolean isEqual(java.lang.Object value1, java.lang.Object value2)
Returnstrue
if the provided Objects are either bothnull
or equal according toObject.equals(Object)
.- Parameters:
value1
- the first object to comparevalue2
- the second object to compare- Returns:
true
if the provided Objects are either bothnull
or equal according toObject.equals(Object)
-
isNotEmpty
public static boolean isNotEmpty(java.lang.String value)
Returnstrue
if the provided String is neithernull
nor the empty String""
.- Parameters:
value
- the value to check- Returns:
- true, if the provided value is not null and not the empty String, false otherwise
-
isNotEmptyOrWhitespaceOnly
public static boolean isNotEmptyOrWhitespaceOnly(java.lang.String value)
Returnstrue
if the provided String is neithernull
nor contains only white spaces.- Parameters:
value
- the value to check- Returns:
true
, if the provided value isnull
or contains only white spaces,false
otherwise
-
lastIndexOf
public static int lastIndexOf(java.lang.String source, char[] chars)
Returns the last index of any of the given chars in the given source.If no char is found, -1 is returned.
- Parameters:
source
- the source to checkchars
- the chars to find- Returns:
- the last index of any of the given chars in the given source, or -1
-
lastWhitespaceIn
public static int lastWhitespaceIn(java.lang.String source)
Returns the last index a whitespace char the given source.If no whitespace char is found, -1 is returned.
- Parameters:
source
- the source to check- Returns:
- the last index a whitespace char the given source, or -1
-
substitute
public static java.lang.String substitute(java.lang.String source, java.lang.String searchString, java.lang.String replaceString)
SubstitutessearchString
in the given source String withreplaceString
.This is a high-performance implementation which should be used as a replacement for
in case no regular expression evaluation is required.String.replaceAll(java.lang.String, java.lang.String)
- Parameters:
source
- the content which is scannedsearchString
- the String which is searched in contentreplaceString
- the String which replacessearchString
- Returns:
- the substituted String
-
toUnicodeLiteral
public static java.lang.String toUnicodeLiteral(java.lang.String s)
Returns the java String literal for the given String.This is the form of the String that had to be written into source code using the unicode escape sequence for special characters.
Example: "�" would be transformed to "\\u00C4".
- Parameters:
s
- a string that may contain non-ascii characters- Returns:
- the java unicode escaped string Literal of the given input string
-
trimToSize
public static java.lang.String trimToSize(java.lang.String source, int length)
Returns a substring of the source, which is at most length characters long.This is the same as calling
trimToSize(String, int, String)
with the parameters(source, length, " ...")
.- Parameters:
source
- the string to trimlength
- the maximum length of the string to be returned- Returns:
- a substring of the source, which is at most length characters long
-
trimToSize
public static java.lang.String trimToSize(java.lang.String source, int length, java.lang.String suffix)
Returns a substring of the source, which is at most length characters long.If a char is cut, the given
suffix
is appended to the result.This is almost the same as calling
trimToSize(String, int, int, String)
with the parameters(source, length, length*, suffix)
. Iflength
if larger then 100, thenlength* = length / 2
, otherwiselength* = length
.- Parameters:
source
- the string to trimlength
- the maximum length of the string to be returnedsuffix
- the suffix to append in case the String was trimmed- Returns:
- a substring of the source, which is at most length characters long
-
trimToSize
public static java.lang.String trimToSize(java.lang.String source, int length, int area, java.lang.String suffix)
Returns a substring of the source, which is at most length characters long, cut in the lastarea
chars in the source at a sentence ending char or whitespace.If a char is cut, the given
suffix
is appended to the result.- Parameters:
source
- the string to trimlength
- the maximum length of the string to be returnedarea
- the area at the end of the string in which to find a sentence ender or whitespacesuffix
- the suffix to append in case the String was trimmed- Returns:
- a substring of the source, which is at most length characters long
-
-