Package io.jans.casa.misc
Class Utils
java.lang.Object
io.jans.casa.misc.Utils
Provides miscellaneous utilities.
- Author:
- jgomer
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> T[]arrayFromValue(Class<T> cls, T value) Returns an array of length zero or one of the specified typestatic ObjectcloneObject(Object obj) Returns a clone of the object passsed.static <T> intThis method takes aListas input, applies a map turning elements into booleans, and returns the index of first true occurrence.static StringgetImageDataUriEncoding(byte[] bytes, String hintName) Computes thedata-urirepresentation of an image whose bytes are given a parameter.static booleanhostAvailabilityCheck(SocketAddress address, int timeout) Checks if a socket connection can be established.static booleanisClassFile(Path path) Checks whether thePathinstance passed seems to correspond to a java class file.static booleanstatic <T> booleanisEmpty(Collection<T> collection) static <K,V> boolean static <T> booleanisEmpty(T[] array) static booleanChecks whether thePathinstance passed seems to correspond to a jar file.static booleanisNotEmpty(String string) static <T> booleanisNotEmpty(Collection<T> collection) static <K,V> boolean isNotEmpty(Map<K, V> map) static <T> booleanisNotEmpty(T[] array) static booleanisValidUrl(String strUrl) Checks if the string passed as parameter resembles a valid URL.static StringjsonFromObject(Object obj) Returns a json representation of an arbitrary object using a defaultcom.fasterxmlJackson mapper object.static <T> List<T>listfromArray(T[] array) Builds aListof elements using the contents of the array supplied.static <T> TmanagedBean(Class<T> clazz) Given a type obtains a reference to a CDI managed bean living in Gluu Casa webapp.static <T> List<T>nonNullList(List<T> list) static booleanWhether this call is being performed on Windows operating system or not.static byte[]randomBytes(int keyLen) Generates a sequence of random bytes (usingSecureRandomclass).Builds a map of name/value entries based on the configuration properties associated to an object of classCustomScript.Analog method toscriptConfigPropertiesAsMap(CustomScript), this time for obtaining module propertiesstatic io.jans.util.security.StringEncrypterReturns a default instance of an encryption/decryption utility object.static io.jans.util.security.StringEncrypterstringEncrypter(String saltFile) static booleanurlAvailabilityCheck(URL siteURL)
-
Method Details
-
onWindows
public static boolean onWindows()Whether this call is being performed on Windows operating system or not.- Returns:
- A boolean value
-
isEmpty
-
isNotEmpty
-
isEmpty
public static <T> boolean isEmpty(T[] array) -
isNotEmpty
public static <T> boolean isNotEmpty(T[] array) -
isEmpty
-
isNotEmpty
-
isEmpty
-
isNotEmpty
-
isJarFile
Checks whether thePathinstance passed seems to correspond to a jar file.- Parameters:
path- Path of file- Returns:
- A boolean value. A shallow check is performed: if the file exists and has .jar extension
-
isClassFile
Checks whether thePathinstance passed seems to correspond to a java class file.- Parameters:
path- Path of file- Returns:
- A boolean value. A shallow check is performed: if the file exists and has .class extension
-
managedBean
Given a type obtains a reference to a CDI managed bean living in Gluu Casa webapp. Use interfaces belonging to packageio.jans.casa.servicewhen calling this method.- Type Parameters:
T- The required type- Parameters:
clazz- AClassrepresenting the required type- Returns:
- An instance object
-
jsonFromObject
Returns a json representation of an arbitrary object using a defaultcom.fasterxmlJackson mapper object.- Parameters:
obj- Object to convert to json representation- Returns:
- A string with result of the operation. The empty object {} is returned in case of failure when serializing
-
getImageDataUriEncoding
Computes thedata-urirepresentation of an image whose bytes are given a parameter. This is useful to represent images inlined in CSS.- Parameters:
bytes- Array of byteshintName- A file name this image may have if it were physical stored in disk. This is used as a hint for the mime content of the bytes if it cannot be inferred automatically. Pass null if you cannot provide a hint about which could be a suitable file name (note that file extension is the useful portion of this String)- Returns:
- The data-uri representation (uses Base64 encoding)
-
cloneObject
Returns a clone of the object passsed.- Parameters:
obj- Object to be cloned- Returns:
- A deep clone (using Jackson objectmapper conversion: object -> json string -> object) (null if the cloning process thew an exception)
-
listfromArray
Builds aListof elements using the contents of the array supplied.- Type Parameters:
T- Type of elements- Parameters:
array- Array of elements- Returns:
- A list (empty if provided array has length zero or is null)
-
arrayFromValue
Returns an array of length zero or one of the specified type- Type Parameters:
T- Type of elements- Parameters:
cls- Class to which the elements of the array belongvalue- Single value the resulting array will contain. If null, the resulting array will be empty- Returns:
- An array of T instances
-
nonNullList
-
hostAvailabilityCheck
Checks if a socket connection can be established.- Parameters:
address- ASocketAddressto establish the connection.timeout- A timeout for connection in ms- Returns:
- Whether the connection was established
-
isValidUrl
Checks if the string passed as parameter resembles a valid URL.- Parameters:
strUrl- String to check- Returns:
- Whether it has the form a valid URL or not
-
firstTrue
This method takes aListas input, applies a map turning elements into booleans, and returns the index of first true occurrence.- Type Parameters:
T- Type of the list elements- Parameters:
list- Input listmap- mapping function (converts every T into a Boolean)- Returns:
- Index of the first occurrence of True (-1 if all were False)
-
randomBytes
public static byte[] randomBytes(int keyLen) Generates a sequence of random bytes (usingSecureRandomclass).- Parameters:
keyLen- Number of bytes to return- Returns:
- Array of random bytes
-
scriptConfigPropertiesAsMap
Builds a map of name/value entries based on the configuration properties associated to an object of classCustomScript.- Parameters:
script- ACustomScriptinstance- Returns:
- A Mapping of property name / property value for the script
-
scriptModulePropertiesAsMap
Analog method toscriptConfigPropertiesAsMap(CustomScript), this time for obtaining module properties- Parameters:
script- ACustomScriptinstance- Returns:
- A Mapping of property name / property value for the script
-
stringEncrypter
public static io.jans.util.security.StringEncrypter stringEncrypter(String saltFile) throws io.jans.util.security.StringEncrypter.EncryptionException - Throws:
io.jans.util.security.StringEncrypter.EncryptionException
-
stringEncrypter
public static io.jans.util.security.StringEncrypter stringEncrypter() throws io.jans.util.security.StringEncrypter.EncryptionExceptionReturns a default instance of an encryption/decryption utility object. This is compatible with theEncryptionServiceaccessible in Gluu custom scripts- Returns:
- Utility object
- Throws:
io.jans.util.security.StringEncrypter.EncryptionException
-
urlAvailabilityCheck
- Throws:
Exception
-