Class ReportStringUtil

java.lang.Object
org.apache.ofbiz.htmlreport.util.ReportStringUtil

public final class ReportStringUtil extends Object
Provides String utility functions.

  • Field Details

    • FALSE

      public static final String FALSE
      Constant for "false".
    • LINE_SEPARATOR

      public static final 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 the trimToSize(String, int, int, String) method.
    • TABULATOR

      public static final String TABULATOR
      a convenient shorthand for tabulations.
      See Also:
    • TRUE

      public static final String TRUE
      Constant for "true".
  • Method Details

    • changeFileNameSuffixTo

      public static String changeFileNameSuffixTo(String filename, String suffix)
      Changes the filename suffix.
      Parameters:
      filename - the filename to be changed
      suffix - the new suffix of the file
      Returns:
      the filename with the replaced suffix
    • collectionAsString

      public static String collectionAsString(Collection<String> collection, String separator)
      Returns a string representation for the given collection using the given separator.

      Parameters:
      collection - the collection to print
      separator - the item separator
      Returns:
      the string representation for the given collection
    • escapeHtml

      public static String escapeHtml(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 String escapeJavaScript(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 String escapePattern(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 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(String value)
      Returns true if the provided String is either null 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(String value)
      Returns true if the provided String is either null 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(Object value1, Object value2)
      Returns true if the provided Objects are either both null or equal according to Object.equals(Object).

      Parameters:
      value1 - the first object to compare
      value2 - the second object to compare
      Returns:
      true if the provided Objects are either both null or equal according to Object.equals(Object)
    • isNotEmpty

      public static boolean isNotEmpty(String value)
      Returns true if the provided String is neither null 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(String value)
      Returns true if the provided String is neither null nor 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
    • lastIndexOf

      public static int lastIndexOf(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 check
      chars - 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(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 String substitute(String source, String searchString, String replaceString)
      Substitutes searchString in the given source String with replaceString.

      This is a high-performance implementation which should be used as a replacement for String.replaceAll(java.lang.String, java.lang.String) in case no regular expression evaluation is required.

      Parameters:
      source - the content which is scanned
      searchString - the String which is searched in content
      replaceString - the String which replaces searchString
      Returns:
      the substituted String
    • toUnicodeLiteral

      public static String toUnicodeLiteral(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 String trimToSize(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 trim
      length - 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 String trimToSize(String source, int length, 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). If length if larger then 100, then length* = length / 2, otherwise length* = length.

      Parameters:
      source - the string to trim
      length - the maximum length of the string to be returned
      suffix - 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 String trimToSize(String source, int length, int area, String suffix)
      Returns a substring of the source, which is at most length characters long, cut in the last area 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 trim
      length - the maximum length of the string to be returned
      area - the area at the end of the string in which to find a sentence ender or whitespace
      suffix - the suffix to append in case the String was trimmed
      Returns:
      a substring of the source, which is at most length characters long