Package com.saperion.ngc.util
Class NgcStringUtils
java.lang.Object
com.saperion.ngc.util.NgcStringUtils
String utilities for NGC.
-
Method Summary
Modifier and TypeMethodDescriptionstatic String
appendToFilename
(String filename, String appendix) Appends the given appendix to the given filename.static String
escapeForHtml
(String toEscape) Escapes a String so that it is safe to be used in HTML.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.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.static String
escapeStringForHql
(String toEscape, com.saperion.config.SQLType sqlType) Escapes the specified string for HQL LIKE usage.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
Returns the escape-character to be used in HQL.static String
makeFolderClassName
(String folderClassPath) Converts a folder classe's path to a fully qualified folder class name.static String
mapToString
(Map<?, ?> map) Formats a map as a string for debugging purposes.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.static String
prepareDatabaseName
(String dbName) Removes all '[', ']' and '"' from the passed string.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.static String
Decodes a string for URL-usage unsing theNgClientConstants.DEFAULT_ENCODING
.static String
Encodes a string for URL-usage using theNgClientConstants.DEFAULT_ENCODING
.
-
Method Details
-
prepareDatabaseName
Removes all '[', ']' and '"' from the passed string.- Parameters:
dbName
- original database name- Returns:
- cleaned database name
-
makeFolderClassName
Converts a folder classe's path to a fully qualified folder class name.- Parameters:
folderClassPath
- path string- Returns:
- folder class name
-
appendToFilename
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
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
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
Escapes a String so that it is safe to be used in HTML.- Parameters:
toEscape
- string to escape- Returns:
- escaped string
-
replaceLast
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 indextoReplace
- substring to replace at the last index in the stringreplacement
- replacement for the substring toReplace in the string- Returns:
- the string with replaced string at the last index
-
urlEncode
Encodes a string for URL-usage using theNgClientConstants.DEFAULT_ENCODING
.- Parameters:
toEncode
- string to encode- Returns:
- the encoded string
-
urlDecode
Decodes a string for URL-usage unsing theNgClientConstants.DEFAULT_ENCODING
.- Parameters:
toDecode
- string to decode- Returns:
- decoded string
-
getHqlCharsToEscape
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 propertiesNgClientConstants.WEBCONFIG_HQL_CHARS_TO_ESCAPE
NgClientConstants.WEBCONFIG_HQL_CHARS_TO_ESCAPE_MSSQL
NgClientConstants.WEBCONFIG_HQL_CHARS_TO_ESCAPE_ORACLE
- MSSQL: _, [, ], ^
- Oracle: _
- Others: _
- 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 propertyNgClientConstants.WEBCONFIG_HQL_ESCAPE_CHARACTER
.- Returns:
- the escape-character
-
escapeStringForHql
Escapes the specified string for HQL LIKE usage. The characters to replace and the replace-character can be configured. SeegetHqlEscapeCharacter()
andgetHqlCharsToEscape(SQLType)
.- Parameters:
toEscape
- the string to escapesqlType
- the type of SQL database in use- Returns:
- the escaped string or the original string if escaping was not necessary
-
mustBeEscapedForHql
Checks if the specified string must be escaped before being used in HQL LIKE statements. SeegetHqlCharsToEscape(SQLType)
andgetHqlEscapeCharacter()
for configuration.- Parameters:
toEscape
- string to checksqlType
- the type of SQL database in use- Returns:
- true is escaping is necessary, false otherwise
-
mapToString
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
-