- java.lang.Object
-
- org.glassfish.soteria.Utils
-
public final class Utils extends Object
An assortment of various utility methods.- Author:
- Arjan Tijms
-
-
Field Summary
Fields Modifier and Type Field Description static MethodcleanSubjectMethodstatic MethodvalidateRequestMethod
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static StringdecodeURL(String string)static StringencodeURL(String string)static StringgetBaseURL(jakarta.servlet.http.HttpServletRequest request)static jakarta.el.ELProcessorgetELProcessor(String name, Object bean)static jakarta.el.ELProcessorgetELProcessor(String name1, Object bean1, String name2, Object bean2)static jakarta.el.ELProcessorgetELProcessor(String name1, Object bean1, String name2, Object bean2, String name3, Object bean3)static MethodgetMethod(Class<?> base, String name, Class<?>... parameterTypes)static <T> TgetParam(jakarta.interceptor.InvocationContext invocationContext, int param)static Map<String,List<String>>getParameterMapFromState(String state)static StringgetSingleParameterFromQueryString(String queryString, String paramName)static StringgetSingleParameterFromState(String state, String paramName)static booleanisEmpty(Object[] array)Returnstrueif the given array is null or is empty.static booleanisEmpty(String string)Returns true if the given string is null or is empty.static booleanisEmpty(Collection<?> collection)Returnstrueif the given collection is null or is empty.static booleanisFacesAjaxRequest(jakarta.servlet.http.HttpServletRequest request)static booleanisImplementationOf(Method implementationMethod, Method interfaceMethod)static <T> booleanisOneOf(T object, T... objects)Returnstrueif the given object equals one of the given objects.static booleannotNull(Object... objects)static voidredirect(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, String location)static voidredirect(jakarta.servlet.http.HttpServletResponse response, String location)static StringserializeURLSafe(String string)Serialize the given string to the short possible unique URL-safe representation.static longstream(InputStream input, OutputStream output)static byte[]toByteArray(InputStream input)Read the given input stream into a byte array.static jakarta.security.enterprise.CallerPrincipaltoCallerPrincipal(Principal principal)static Map<String,List<String>>toParameterMap(String queryString)Converts the given request query string to request parameter values map.static StringtoQueryString(Map<String,List<String>> parameterMap)Converts the given request parameter values map to request query string.static <E> Set<E>unmodifiableSet(Object... values)static StringunserializeURLSafe(String string)Unserialize the given serialized URL-safe string.
-
-
-
Method Detail
-
notNull
public static boolean notNull(Object... objects)
-
isEmpty
public static boolean isEmpty(String string)
Returns true if the given string is null or is empty.- Parameters:
string- The string to be checked on emptiness.- Returns:
- True if the given string is null or is empty.
-
isEmpty
public static boolean isEmpty(Object[] array)
Returnstrueif the given array is null or is empty.- Parameters:
array- The array to be checked on emptiness.- Returns:
trueif the given array is null or is empty.
-
isEmpty
public static boolean isEmpty(Collection<?> collection)
Returnstrueif the given collection is null or is empty.- Parameters:
collection- The collection to be checked on emptiness.- Returns:
trueif the given collection is null or is empty.
-
isOneOf
@SafeVarargs public static <T> boolean isOneOf(T object, T... objects)
Returnstrueif the given object equals one of the given objects.- Type Parameters:
T- The generic object type.- Parameters:
object- The object to be checked if it equals one of the given objects.objects- The argument list of objects to be tested for equality.- Returns:
trueif the given object equals one of the given objects.
-
getParam
public static <T> T getParam(jakarta.interceptor.InvocationContext invocationContext, int param)
-
getBaseURL
public static String getBaseURL(jakarta.servlet.http.HttpServletRequest request)
-
redirect
public static void redirect(jakarta.servlet.http.HttpServletResponse response, String location)
-
getELProcessor
public static jakarta.el.ELProcessor getELProcessor(String name1, Object bean1, String name2, Object bean2)
-
getELProcessor
public static jakarta.el.ELProcessor getELProcessor(String name1, Object bean1, String name2, Object bean2, String name3, Object bean3)
-
toCallerPrincipal
public static jakarta.security.enterprise.CallerPrincipal toCallerPrincipal(Principal principal)
-
redirect
public static void redirect(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, String location)
-
isFacesAjaxRequest
public static boolean isFacesAjaxRequest(jakarta.servlet.http.HttpServletRequest request)
-
getSingleParameterFromState
public static String getSingleParameterFromState(String state, String paramName)
-
getParameterMapFromState
public static Map<String,List<String>> getParameterMapFromState(String state)
-
toParameterMap
public static Map<String,List<String>> toParameterMap(String queryString)
Converts the given request query string to request parameter values map.- Parameters:
queryString- The request query string.- Returns:
- The request query string as request parameter values map.
-
toQueryString
public static String toQueryString(Map<String,List<String>> parameterMap)
Converts the given request parameter values map to request query string.- Parameters:
parameterMap- The request parameter values map.- Returns:
- The request parameter values map as request query string.
-
getSingleParameterFromQueryString
public static String getSingleParameterFromQueryString(String queryString, String paramName)
-
serializeURLSafe
public static String serializeURLSafe(String string)
Serialize the given string to the short possible unique URL-safe representation. The current implementation will decode the given string with UTF-8 and then compress it with ZLIB using "best compression" algorithm and then Base64-encode the resulting bytes without the=padding, whereafter the Base64 characters+and/are been replaced by respectively-and_to make it URL-safe (so that no platform-sensitive URL-encoding needs to be done when used in URLs).- Parameters:
string- The string to be serialized.- Returns:
- The serialized URL-safe string, or
nullwhen the given string is itselfnull.
-
unserializeURLSafe
public static String unserializeURLSafe(String string)
Unserialize the given serialized URL-safe string. This does the inverse ofserializeURLSafe(String).- Parameters:
string- The serialized URL-safe string to be unserialized.- Returns:
- The unserialized string, or
nullwhen the given string is by itselfnull. - Throws:
IllegalArgumentException- When the given serialized URL-safe string is not in valid format as returned byserializeURLSafe(String).
-
stream
public static long stream(InputStream input, OutputStream output) throws IOException
- Throws:
IOException
-
toByteArray
public static byte[] toByteArray(InputStream input) throws IOException
Read the given input stream into a byte array. The given input stream will implicitly be closed after streaming, regardless of whether an exception is been thrown or not.- Parameters:
input- The input stream.- Returns:
- The input stream as a byte array.
- Throws:
IOException- When an I/O error occurs.
-
isImplementationOf
public static boolean isImplementationOf(Method implementationMethod, Method interfaceMethod)
-
-