java.lang.Object
com.irurueta.authserver.authorization.api.web.pages.PageRenderer

@Component public class PageRenderer extends Object
Renders a server-rendered page (a Thymeleaf template) to the text/html answer of an operation generated from the pages contract. The view is resolved through the application's view resolvers, in their order, with the locale of the request, and rendered against the current request into a wrapper that captures what it writes, so everything a template relies on keeps working: the CSRF hidden field that th:action adds, @{...} links and the messages. Every page gets the branding as the "branding" model attribute.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final BrandingProvider
    Supplies the branding of the pages.
    private final jakarta.servlet.http.HttpServletRequest
    The current request, injected as a thread-bound proxy.
    private final jakarta.servlet.http.HttpServletResponse
    The current response, injected as a thread-bound proxy.
    (package private) static final org.springframework.http.MediaType
    Media type of the rendered pages.
    private final List<org.springframework.web.servlet.ViewResolver>
    View resolvers of the application, in their order.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    org.springframework.http.ResponseEntity<String>
    render(String viewName, Map<String,?> model)
    Renders a page.
    private org.springframework.web.servlet.View
    resolve(String viewName, Locale locale)
    Resolves a view through the view resolvers, in their order.
    private static org.springframework.web.servlet.View
    resolveWith(org.springframework.web.servlet.ViewResolver resolver, String viewName, Locale locale)
    Resolves a view with one resolver.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • TEXT_HTML_UTF8

      static final org.springframework.http.MediaType TEXT_HTML_UTF8
      Media type of the rendered pages.
    • viewResolvers

      private final List<org.springframework.web.servlet.ViewResolver> viewResolvers
      View resolvers of the application, in their order.
    • brandingProvider

      private final BrandingProvider brandingProvider
      Supplies the branding of the pages.
    • request

      private final jakarta.servlet.http.HttpServletRequest request
      The current request, injected as a thread-bound proxy.
    • response

      private final jakarta.servlet.http.HttpServletResponse response
      The current response, injected as a thread-bound proxy.
  • Constructor Details

    • PageRenderer

      public PageRenderer()
  • Method Details

    • render

      public org.springframework.http.ResponseEntity<String> render(String viewName, Map<String,?> model)
      Renders a page.
      Parameters:
      viewName - name of the view (the Thymeleaf template).
      model - model attributes of the page; the branding is added to them.
      Returns:
      a 200 with the page as text/html.
      Throws:
      IllegalStateException - if no view resolver knows the view, or the view cannot be rendered.
    • resolve

      private org.springframework.web.servlet.View resolve(String viewName, Locale locale)
      Resolves a view through the view resolvers, in their order.
      Parameters:
      viewName - name of the view.
      locale - locale of the request.
      Returns:
      the view of the first resolver that knows it.
      Throws:
      IllegalStateException - if no view resolver knows the view.
    • resolveWith

      private static org.springframework.web.servlet.View resolveWith(org.springframework.web.servlet.ViewResolver resolver, String viewName, Locale locale)
      Resolves a view with one resolver.
      Parameters:
      resolver - the view resolver.
      viewName - name of the view.
      locale - locale of the request.
      Returns:
      the view, or null when the resolver does not know it.
      Throws:
      IllegalStateException - if the resolver fails.