Class WebUtils

java.lang.Object
io.jans.casa.misc.WebUtils

public final class WebUtils extends Object
Provides utility methods for web-related functionalities. A good place to call these methods are ZK View Models or ZK page initiators, that is, a context where there is a ZK Execution.
Author:
jgomer
  • Field Details

    • USER_PAGE_URL

      public static final String USER_PAGE_URL
      The page where users are redirected to after they have successfully logged in.
      See Also:
    • ADMIN_PAGE_URL

      public static final String ADMIN_PAGE_URL
      See Also:
    • DEFAULT_LOCALE

      public static final Locale DEFAULT_LOCALE
  • Method Details

    • getServletRequest

      public static jakarta.servlet.http.HttpServletRequest getServletRequest()
      Gets the current HttpServletRequest object.
      Returns:
      The servlet request
    • getServletResponse

      public static jakarta.servlet.http.HttpServletResponse getServletResponse()
      Gets the current HttpServletResponse object.
      Returns:
      The servlet response
    • getRequestHeader

      public static String getRequestHeader(String headerName)
      Gets the value of the selected header.
      Parameters:
      headerName - Header name
      Returns:
      Value of the header or null if the servlet request does not contain such header
    • invalidateSession

      public static void invalidateSession(jakarta.servlet.http.HttpServletRequest request)
      Invalidates the current http session.
      Parameters:
      request - An HttpServletRequest instance from which the session can be obtained
    • getRemoteIP

      public static String getRemoteIP()
      Gets the IP address of the originator of the current servlet request.
      Returns:
      A string value with the address (null if no IP could be obtained)
    • execRedirect

      public static void execRedirect(String url)
      Performs a redirect to the url passed avoiding any UI rendering (see "Forward and redirect" in ZK developer's reference manual). It is equivalent to calling execRedirect(url, true)
      Parameters:
      url - A String where the browser will be redirected to
    • execRedirect

      public static void execRedirect(String url, boolean voidUI)
      Performs a redirect to the url passed. The boolean parameter determines if the underlying ZK execution can be voided (see "Forward and redirect" in ZK developer's reference manual).
      Parameters:
      url - A String where the browser will be redirected to
      voidUI - Whether to void the execution
    • getQueryParam

      public static String getQueryParam(String param)
      Gets the query parameter whose name is passed as parameter.
      Parameters:
      param - Parameter name
      Returns:
      The first value of the named parameter in the request, null if the parameter is not part of it
    • validateImageUrl

      public static String validateImageUrl(String url)
      Reads the contents of the URL passes as param and returns null if the contents received are not image-like (e.g. different file format or HTTP error)
      Parameters:
      url - String with URL to inspect
      Returns:
      The value received in parameter if it points to a valid image, null otherwise
    • getFullRequestURL

      public static String getFullRequestURL()
    • getValueFromCookie

      public static String getValueFromCookie(String cookieName)