Package com.avoka.core.util
Class CoreUtils
java.lang.Object
com.avoka.core.util.CoreUtils
- All Implemented Interfaces:
Serializable
Provides FC core utility methods.
- See Also:
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
Close the given closeable resource and ignore any exceptions thrown.static String
Creates an 32 char alternative key using MD5 encoding with random textstatic String
decodeBase64
(String value) Return a Base 64 decoded string from the given encoded value.static String
decodeBytesAsString
(byte[] byteData) Return an string from the decoded byte array.static String
Decrypt the given cyphertext value.static String
decryptSafely
(String cyphertext) Decrypt the given cyphertext value without throwing an error if null is passed instatic byte[]
encodeStringAsBytes
(String value) Return an encoded version of the String value.static String
Encrypt the given plain text valuestatic String
escapeJson
(String value) Escape the JSON string value.static String
generateHmacSHA256Hash
(String convertme, String keyString) This method will generate HmacSHA256 hash or the fingerprintstatic String
getFileName
(String path) Extract the file name from a path (e.g.static String
getMimeType
(String filename) Return the mime-type or content-type for the given filename.static boolean
isBlankList
(List<String> valueList) Return true if the list is empty or only contains blank valuesstatic boolean
isFileExtensionMatched
(String fileName, String fileExtension) Return true if the provided file name's extension matches the given file extensionstatic boolean
isGuidKeyValue
(String value) Return true if the specified value could be GUID Key value.static boolean
Return true if the system health monitoring is enabled, or false if disabled by a JVM argumentcom.avoka.disable.health.monitoring
.static boolean
isNonNegativeInteger
(String value) Return true if value can be coerced into a positive integer (long) value, which does not start with 0.static boolean
isPositiveInteger
(String value) Return true if value can be coerced into a positive integer (long) value, which does not start with 0.static boolean
Return true if value can be coerced into a primary key, a positive long value which does not start with 0.static boolean
Checks if is XXS safe.static String
limitLength
(String value, int maxlength) Return the value string limited to maxlength characters.static String
limitLength
(String value, int maxlength, String suffix) Return the value string limited to maxlength characters.static String
normalizeValue
(String value) Normalize the value for a file system name.parseDocumentFromString
(String xml, boolean namespaceAware, boolean validating) Deprecated.- see XMLUtils insteadstatic String
stripCDATAWrapper
(String value) Return a string stripped of any CDATA section wrapper from the given string value.static String
stripControlChars
(String source) Strip ISO control characters, with the exception of '\n', '\r', '\t' form the given string returning the result.static String
toBase64
(byte[] byteData) Return a Base 64 encoded string from the given byte array.static String
Return a field label string from the given field name.static String
toMD5Hash
(byte[] bytes) Return an 32 char MD5 encoded string from the given byte array.static String
Return an 32 char MD5 encoded string from the given plain text.static String
Return a field name string from the given field label.static String
toSHA256Hash
(byte[] bytes) Return a Hex encoded SHA-256 hash of the given form XML data or attachment file data.static String
toSHA256Hash
(String plaintext) Return a Hex encoded SHA-256 hash of the given string value.static String
toSHA384Hash
(byte[] bytes, byte[] salt, int numberOfIterations) Return a Hex encoded SHA-384 hash of the given form XML data or attachment file data.
-
Constructor Details
-
CoreUtils
public CoreUtils()
-
-
Method Details
-
close
Close the given closeable resource and ignore any exceptions thrown.- Parameters:
closeable
- the resource to close- Since:
- 4.2.0
-
encodeStringAsBytes
Return an encoded version of the String value. The value will be serialized and ZLib compressed.- Parameters:
value
- the string value to encode- Returns:
- a serialized and compressed byte array
- Throws:
IllegalArgumentException
- if the value parameter is null
-
decodeBytesAsString
Return an string from the decoded byte array.- Parameters:
byteData
- the encoded string byte data- Returns:
- an String value from the encoded byte data
-
parseDocumentFromString
@Deprecated public Document parseDocumentFromString(String xml, boolean namespaceAware, boolean validating) throws ParserConfigurationException, SAXException Deprecated.- see XMLUtils insteadThis does the same as DOMUtil.parseDocumentFromString()- Parameters:
xml
- the XML string contentnamespaceAware
- whether to parse the document to aware the namespacevalidating
- whether to validate the document- Returns:
- a new XML Document fromt he given XML string
- Throws:
ParserConfigurationException
- throw a exception if there is a configuration errorSAXException
- throw a exception if there is a parse error
-
toBase64
Return a Base 64 encoded string from the given byte array.- Parameters:
byteData
- the byte array data to encode- Returns:
- a base64 encoded byte array
-
decodeBase64
Return a Base 64 decoded string from the given encoded value.- Parameters:
value
- the value to encode- Returns:
- the decoded string value
-
toMD5Hash
Return an 32 char MD5 encoded string from the given plain text. The returned value is MD5 hash compatible with Tomcat catalina Realm. Adapted from org.apache.catalina.util.MD5Encoder- Parameters:
plaintext
- the plain text value to encode- Returns:
- encoded MD5 string
-
toMD5Hash
Return an 32 char MD5 encoded string from the given byte array. The returned value is MD5 hash compatible with Tomcat catalina Realm. Adapted from org.apache.catalina.util.MD5Encoder- Parameters:
bytes
- the bytes array to encode- Returns:
- encoded MD5 string
-
createAltKey
Creates an 32 char alternative key using MD5 encoding with random text- Returns:
- an 32 char MD5 encoded string
-
limitLength
Return the value string limited to maxlength characters. If the string gets curtailed, "..." is appended to it. Adapted from Velocity Tools Formatter.- Parameters:
value
- the string value to limit the length ofmaxlength
- the maximum string length- Returns:
- a length limited string
-
limitLength
Return the value string limited to maxlength characters. If the string gets curtailed and the suffix parameter is appended to it. Adapted from Velocity Tools Formatter.- Parameters:
value
- the string value to limit the length ofmaxlength
- the maximum string lengthsuffix
- the suffix to append to the length limited string- Returns:
- a length limited string
-
encrypt
Encrypt the given plain text value- Parameters:
plaintext
- the plain text value to encrypt- Returns:
- the cypher text for the given plain text value.
-
decrypt
Decrypt the given cyphertext value.- Parameters:
cyphertext
- the cyper text value to decrypt (required)- Returns:
- the cypher text for the given plain text value.
-
decryptSafely
Decrypt the given cyphertext value without throwing an error if null is passed in- Parameters:
cyphertext
- the cypher text value to decrypt- Returns:
- the decrypted plain text value, or an empty string if the input string was empty or null
- Since:
- 4.2.0
-
getFileName
Extract the file name from a path (e.g. returning "file.txt" for "C:\data\txt\file.txt"). Treats "\" and "/" as separators.- Parameters:
path
- the file path- Returns:
- the file name or null if the path was null
-
toSHA256Hash
Return a Hex encoded SHA-256 hash of the given form XML data or attachment file data.- Parameters:
bytes
- the byte array to hash- Returns:
- SHA-256 hash, encoded as a 64 character Hex string
-
toSHA256Hash
Return a Hex encoded SHA-256 hash of the given string value. Please note the string value will be encode as a byte array using the UTF-8 charset before hashing.- Parameters:
plaintext
- string value to hash- Returns:
- SHA-256 hash, encoded as a 64 character Hex string
-
toSHA384Hash
Return a Hex encoded SHA-384 hash of the given form XML data or attachment file data.- Parameters:
bytes
- the byte array to hash (required)salt
- the saltnumberOfIterations
- the number of times that the hash will be applied (must be a positive number)- Returns:
- SHA-384 hash, encoded as a 96 character hex string
- Since:
- 4.3.4
-
getMimeType
Return the mime-type or content-type for the given filename.- Parameters:
filename
- the filename to obtain the mime-type for- Returns:
- the mime-type for the given filename, or null if not found
-
stripCDATAWrapper
Return a string stripped of any CDATA section wrapper from the given string value.- Parameters:
value
- the string parameter- Returns:
- a string stripped of any CDATA section wrapper from the given string value.
-
isBlankList
Return true if the list is empty or only contains blank values- Parameters:
valueList
- the value list to test- Returns:
- true if the list is empty or only contains blank values
- Since:
- 3.6.0
-
isFileExtensionMatched
Return true if the provided file name's extension matches the given file extension- Parameters:
fileName
- the file name to checkfileExtension
- the file extension to match with- Returns:
- true if the provided file name's extension matches the given file extension
- Since:
- 22.4.1
-
isXssSafe
Checks if is XXS safe. Please see dangerous characters: XSS Filter Evasion Cheat Sheet- Parameters:
value
- the value to test- Returns:
- true, if is XSS safe or is null
- Since:
- 3.6.0
-
stripControlChars
Strip ISO control characters, with the exception of '\n', '\r', '\t' form the given string returning the result.- Parameters:
source
- the source string- Returns:
- the string value stripped of ISO Control characters.
- Since:
- 3.6.0
-
isHealthMonitoringEnabled
public static boolean isHealthMonitoringEnabled()Return true if the system health monitoring is enabled, or false if disabled by a JVM argumentcom.avoka.disable.health.monitoring
.- Returns:
- true if the system health monitoring is enabled, or false if disabled by a JVM argument
- Since:
- 4.0.0
-
isPrimaryKeyValue
Return true if value can be coerced into a primary key, a positive long value which does not start with 0.- Parameters:
pk
- the primary key value- Returns:
- true if value can be coerced into a Long primary key, a positive long value which does not start with 0.
- Since:
- 4.0.2
-
isGuidKeyValue
Return true if the specified value could be GUID Key value.- Parameters:
value
- the value to test- Returns:
- true if the specified value could be GUID Key value
- Since:
- 4.3.0
-
isPositiveInteger
Return true if value can be coerced into a positive integer (long) value, which does not start with 0.- Parameters:
value
- the string value to test- Returns:
- true true if value can be coerced into a positive integer (long) value, which does not start with 0.
- Since:
- 4.1.0
-
isNonNegativeInteger
Return true if value can be coerced into a positive integer (long) value, which does not start with 0.- Parameters:
value
- the string value to test- Returns:
- true true if value can be coerced into a positive integer (long) value, which does not start with 0.
- Since:
- 4.3.4
-
escapeJson
Escape the JSON string value. http://stackoverflow.com/questions/3020094/how-should-i-escape-strings-in-json- Parameters:
value
- the string value to escape as value JSON text- Returns:
- the JSON escaped string value
- Since:
- 4.1.0
-
normalizeValue
Normalize the value for a file system name.- Parameters:
value
- the value to normalize (required)- Returns:
- the normalized value for a file system name
- Since:
- 17.10.0
-
toLabel
Return a field label string from the given field name. For example:
faxNumber -> Fax Number
Note toLabel will return an empty String ("") if a null String name is specified.
Copied from Apache ClickUtils method of the same name.
- Parameters:
name
- the field name (required)- Returns:
- a field label string from the given field name
- Since:
- 17.10.0
-
toName
Return a field name string from the given field label.
A label of " OK do it!" is returned as "okDoIt". Any characters will also be removed.
A label of "customerSelect" is returned as "customerSelect".Copied from Apache ClickUtils method of the same name.
- Parameters:
label
- the field label or caption (required)- Returns:
- a field name string from the given field label
- Since:
- 17.10.0
-
generateHmacSHA256Hash
This method will generate HmacSHA256 hash or the fingerprint- Parameters:
convertme
- the string to convert to HmacSHA256 hashkeyString
- the key material of the secret key. The contents of the array are copied to protect against subsequent modification.- Returns:
- HmacSHA256 hash - the fingerprint
- Since:
- 19.11.0
-