Class JsonRenderer

java.lang.Object
org.apache.sling.servlets.get.impl.helpers.JsonRenderer
All Implemented Interfaces:
Renderer

public class JsonRenderer extends Object implements Renderer
The JsonRendererServlet renders the current resource in JSON on behalf of the DefaultGetServlet.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    Selector that causes hierarchy to be rendered as arrays instead of child objects - useful to preserve the order of those child objects
    static final int
    How much to indent in tidy mode
    static final String
    Recursion level selector that means "all levels"
    static final String
    Selector that means "pretty-print the output
  • Constructor Summary

    Constructors
    Constructor
    Description
    JsonRenderer(long maximumResults, boolean ecmaSupport)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected int
    getMaxRecursionLevel(org.apache.sling.api.SlingJakartaHttpServletRequest req)
    Get recursion level from selectors.
    protected boolean
    hasSelector(org.apache.sling.api.SlingJakartaHttpServletRequest req, String selectorToCheck)
    Checks if the provided request contains a certain selector.
    protected boolean
    isTidy(org.apache.sling.api.SlingJakartaHttpServletRequest req)
    True if our request wants the "tidy" pretty-printed format
    void
    render(org.apache.sling.api.SlingJakartaHttpServletRequest req, org.apache.sling.api.SlingJakartaHttpServletResponse resp)
     

    Methods inherited from class java.lang.Object

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

    • INFINITY

      public static final String INFINITY
      Recursion level selector that means "all levels"
      See Also:
    • TIDY

      public static final String TIDY
      Selector that means "pretty-print the output
      See Also:
    • HARRAY

      public static final String HARRAY
      Selector that causes hierarchy to be rendered as arrays instead of child objects - useful to preserve the order of those child objects
      See Also:
    • INDENT_SPACES

      public static final int INDENT_SPACES
      How much to indent in tidy mode
      See Also:
  • Constructor Details

    • JsonRenderer

      public JsonRenderer(long maximumResults, boolean ecmaSupport)
  • Method Details

    • render

      public void render(org.apache.sling.api.SlingJakartaHttpServletRequest req, org.apache.sling.api.SlingJakartaHttpServletResponse resp) throws IOException
      Specified by:
      render in interface Renderer
      Throws:
      IOException
    • getMaxRecursionLevel

      protected int getMaxRecursionLevel(org.apache.sling.api.SlingJakartaHttpServletRequest req) throws IllegalArgumentException
      Get recursion level from selectors. as per SLING-167: the last selector, if present, gives the recursion level.
      Parameters:
      req - the request
      Returns:
      the recursion level
      Throws:
      IllegalArgumentException - if the detected selector is not a number
    • hasSelector

      protected boolean hasSelector(org.apache.sling.api.SlingJakartaHttpServletRequest req, String selectorToCheck)
      Checks if the provided request contains a certain selector.
      Parameters:
      req - the request
      selectorToCheck - the selector
      Returns:
      true if the selector is present, false otherwise
    • isTidy

      protected boolean isTidy(org.apache.sling.api.SlingJakartaHttpServletRequest req)
      True if our request wants the "tidy" pretty-printed format
      Parameters:
      req - the request
      Returns:
      true if the request contains the TIDY selector, false otherwise