Package org.apache.tiles.request.servlet

# Class ServletUtil

java.lang.Object
org.apache.tiles.request.servlet.ServletUtil

public final class ServletUtil extends Object
Utilities for Tiles request servlet support.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static ApplicationContext`
  `getApplicationContext(jakarta.servlet.ServletContext servletContext)`
  Returns the application context getting it from the servlet context.
  `static jakarta.servlet.ServletContext`
  `getServletContext(ApplicationContext applicationContext)`
  Gets a servlet context from a TilesApplicationContext.
  `static ServletRequest`
  `getServletRequest(Request request)`
  Opens a TilesRequestContext until it finds a ServletTilesRequestContext.
  `static IOException`
  `wrapServletException(jakarta.servlet.ServletException ex, String message)`
  Wraps a ServletException to create an IOException with the root cause if present.

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Method Details

  - ### wrapServletException

    public static IOException wrapServletException(jakarta.servlet.ServletException ex, String message)
    Wraps a ServletException to create an IOException with the root cause if present.
    Parameters:
      `ex` - The exception to wrap.
      `message` - The message of the exception.
    Returns:
      The wrapped exception.

  - ### getApplicationContext

    public static ApplicationContext getApplicationContext(jakarta.servlet.ServletContext servletContext)
    Returns the application context getting it from the servlet context. It must be first saved creating a `ServletApplicationContext` and using `ApplicationAccess.register(ApplicationContext)`.
    Parameters:
      `servletContext` - The servlet context.
    Returns:
      The application context, if found, `null` otherwise.

  - ### getServletRequest

    public static ServletRequest getServletRequest(Request request)
    Opens a TilesRequestContext until it finds a ServletTilesRequestContext.
    Parameters:
      `request` - The request to open.
    Returns:
      The servlet-based request context.
    Throws:
      `NotAServletEnvironmentException` - If a servlet-based request context could not be found.

  - ### getServletContext

    public static jakarta.servlet.ServletContext getServletContext(ApplicationContext applicationContext)
    Gets a servlet context from a TilesApplicationContext.
    Parameters:
      `applicationContext` - The application context to analyze.
    Returns:
      The servlet context.
    Throws:
      `NotAServletEnvironmentException` - If the application context is not servlet-based.