Class NgcStringUtils


  • public final class NgcStringUtils
    extends java.lang.Object
    String utilities for NGC.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String appendToFilename​(java.lang.String filename, java.lang.String appendix)
      Appends the given appendix to the given filename.
      static java.lang.String escapeForHtml​(java.lang.String toEscape)
      Escapes a String so that it is safe to be used in HTML.
      static java.lang.String escapeForJavaScript​(java.lang.String toEscape)
      Escapes a String so that it is safe to be used as a function-argument or data value in JavaScript.
      static java.lang.StringBuffer escapeForJavaScript​(java.lang.StringBuffer toEscape)
      Escapes a StringBuffer so that it is safe to be used as a function-argument or data value in JavaScript.
      static java.lang.String escapeStringForHql​(java.lang.String toEscape, com.saperion.config.SQLType sqlType)
      Escapes the specified string for HQL LIKE usage.
      static java.util.Set<java.lang.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.
      static char getHqlEscapeCharacter()
      Returns the escape-character to be used in HQL.
      static java.lang.String makeFolderClassName​(java.lang.String folderClassPath)
      Converts a folder classe's path to a fully qualified folder class name.
      static java.lang.String mapToString​(java.util.Map<?,​?> map)
      Formats a map as a string for debugging purposes.
      static boolean mustBeEscapedForHql​(java.lang.String toEscape, com.saperion.config.SQLType sqlType)
      Checks if the specified string must be escaped before being used in HQL LIKE statements.
      static java.lang.String prepareDatabaseName​(java.lang.String dbName)
      Removes all '[', ']' and '"' from the passed string.
      static java.lang.String replaceLast​(java.lang.String string, java.lang.String toReplace, java.lang.String replacement)
      Replaces the substring toReplace with the string replacement in the given string at the last index of toReplace.
      static java.lang.String urlDecode​(java.lang.String toDecode)
      Decodes a string for URL-usage unsing the NgClientConstants.DEFAULT_ENCODING.
      static java.lang.String urlEncode​(java.lang.String toEncode)
      Encodes a string for URL-usage using the NgClientConstants.DEFAULT_ENCODING.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • prepareDatabaseName

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

        public static java.lang.String makeFolderClassName​(java.lang.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 java.lang.String appendToFilename​(java.lang.String filename,
                                                        java.lang.String appendix)
        Appends the given appendix to the given filename. The result will look like: - _. 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 java.lang.String escapeForJavaScript​(java.lang.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 java.lang.StringBuffer escapeForJavaScript​(java.lang.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 java.lang.String escapeForHtml​(java.lang.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 java.lang.String replaceLast​(java.lang.String string,
                                                   java.lang.String toReplace,
                                                   java.lang.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 java.lang.String urlEncode​(java.lang.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 java.lang.String urlDecode​(java.lang.String toDecode)
        Decodes a string for URL-usage unsing the NgClientConstants.DEFAULT_ENCODING.
        Parameters:
        toDecode - string to decode
        Returns:
        decoded string
      • getHqlCharsToEscape

        public static java.util.Set<java.lang.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 java.lang.String escapeStringForHql​(java.lang.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​(java.lang.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 java.lang.String mapToString​(java.util.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