Class NgcStringUtils

java.lang.Object
com.saperion.ngc.util.NgcStringUtils

public final class NgcStringUtils extends Object
String utilities for NGC.
  • Method Details

    • prepareDatabaseName

      public static String prepareDatabaseName(String dbName)
      Removes all '[', ']' and '"' from the passed string.
      Parameters:
      dbName - original database name
      Returns:
      cleaned database name
    • makeFolderClassName

      public static String makeFolderClassName(String folderClassPath)
      Converts a folder classe's path to a fully qualified folder class name.
      Parameters:
      folderClassPath - path string
      Returns:
      folder class name
    • appendToFilename

      public static String appendToFilename(String filename, String appendix)
      Appends the given appendix to the given filename. The result will look like: - <filename w/o ending>_. if an ending is existing in the given filename, or - _ if no ending was detected.
      Parameters:
      filename - The filename to be appended.
      appendix - The appendix to append the given filename with.
      Returns:
      the appended filename.
    • escapeForJavaScript

      public static String escapeForJavaScript(String toEscape)
      Escapes a String so that it is safe to be used as a function-argument or data value in JavaScript.
      Parameters:
      toEscape - string to escape
      Returns:
      escaped string
    • escapeForJavaScript

      public static StringBuffer escapeForJavaScript(StringBuffer toEscape)
      Escapes a StringBuffer so that it is safe to be used as a function-argument or data value in JavaScript.
      Parameters:
      toEscape - stringBuffer to escape
      Returns:
      escaped stringBuffer
    • escapeForHtml

      public static String escapeForHtml(String toEscape)
      Escapes a String so that it is safe to be used in HTML.
      Parameters:
      toEscape - string to escape
      Returns:
      escaped string
    • replaceLast

      public static String replaceLast(String string, String toReplace, String replacement)
      Replaces the substring toReplace with the string replacement in the given string at the last index of toReplace.
      Parameters:
      string - the string to replace substring at last index
      toReplace - substring to replace at the last index in the string
      replacement - replacement for the substring toReplace in the string
      Returns:
      the string with replaced string at the last index
    • urlEncode

      public static String urlEncode(String toEncode)
      Encodes a string for URL-usage using the NgClientConstants.DEFAULT_ENCODING.
      Parameters:
      toEncode - string to encode
      Returns:
      the encoded string
    • urlDecode

      public static String urlDecode(String toDecode)
      Decodes a string for URL-usage unsing the NgClientConstants.DEFAULT_ENCODING.
      Parameters:
      toDecode - string to decode
      Returns:
      decoded string
    • getHqlCharsToEscape

      public static Set<Character> getHqlCharsToEscape(com.saperion.config.SQLType sqlType)
      Returns the configured set of characters that must be replaced in a string used in a LIKE statement in HQL. The characters can be configured in webclient.properties using the properties The following defaults are used:
      • MSSQL: _, [, ], ^
      • Oracle: _
      • Others: _
      To disable escaping, the properties above can be set to 'none'. In this case, this method returns an empty set.
      Parameters:
      sqlType - the database-type to escape the string for
      Returns:
      set of characters to replace. Never null.
    • getHqlEscapeCharacter

      public static char getHqlEscapeCharacter()
      Returns the escape-character to be used in HQL. By default '!' is returned. The character can be configured in webclient.properties using the property NgClientConstants.WEBCONFIG_HQL_ESCAPE_CHARACTER.
      Returns:
      the escape-character
    • escapeStringForHql

      public static String escapeStringForHql(String toEscape, com.saperion.config.SQLType sqlType)
      Escapes the specified string for HQL LIKE usage. The characters to replace and the replace-character can be configured. See getHqlEscapeCharacter() and getHqlCharsToEscape(SQLType).
      Parameters:
      toEscape - the string to escape
      sqlType - the type of SQL database in use
      Returns:
      the escaped string or the original string if escaping was not necessary
    • mustBeEscapedForHql

      public static boolean mustBeEscapedForHql(String toEscape, com.saperion.config.SQLType sqlType)
      Checks if the specified string must be escaped before being used in HQL LIKE statements. See getHqlCharsToEscape(SQLType) and getHqlEscapeCharacter() for configuration.
      Parameters:
      toEscape - string to check
      sqlType - the type of SQL database in use
      Returns:
      true is escaping is necessary, false otherwise
    • mapToString

      public static String mapToString(Map<?,?> map)
      Formats a map as a string for debugging purposes. The toString methods of the keys and values are used to create the string.
      Parameters:
      map - the map to format
      Returns:
      a string representation of the map