Package com.saperion.ngc.util
Class NgcStringUtils
- java.lang.Object
-
- com.saperion.ngc.util.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 theNgClientConstants.DEFAULT_ENCODING
.static java.lang.String
urlEncode(java.lang.String toEncode)
Encodes a string for URL-usage using theNgClientConstants.DEFAULT_ENCODING
.
-
-
-
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 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
public static java.lang.String urlEncode(java.lang.String toEncode)
Encodes a string for URL-usage using theNgClientConstants.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 theNgClientConstants.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 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
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. 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
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. 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
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
-
-