Class GraniteUi

java.lang.Object
io.wcm.wcm.ui.granite.util.GraniteUi

@ProviderType public final class GraniteUi extends Object
Helper methods for GraniteUI components.

It uses some heuristics to get the current content path in context of a GraniteUI component:

  1. Inside create page wizard, try to get content path from referrer header
  2. Try to get content path from request suffix
  3. Try to get content path from "item" request parameter (inside multifield component)
  • Method Summary

    Modifier and Type
    Method
    Description
    static @Nullable com.day.cq.wcm.api.Page
    getContentPage(@NotNull javax.servlet.http.HttpServletRequest request)
    Current content page.
    static @Nullable org.apache.sling.api.resource.Resource
    getContentResource(@NotNull javax.servlet.http.HttpServletRequest request)
    Current content resource
    static @Nullable org.apache.sling.api.resource.Resource
    getContentResourceOrParent(@NotNull javax.servlet.http.HttpServletRequest request)
    Get current content resource If it does not exist, go up the content path and return the first resource that exists.
    static @Nullable String
    getExistingResourceType(@NotNull org.apache.sling.api.resource.ResourceResolver resourceResolver, @NotNull String @NotNull ... resourceTypes)
    From the list of resource types get the first one that exists.

    Methods inherited from class java.lang.Object

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

    • getContentResource

      @Nullable public static @Nullable org.apache.sling.api.resource.Resource getContentResource(@NotNull @NotNull javax.servlet.http.HttpServletRequest request)
      Current content resource
      Parameters:
      request - Request
      Returns:
      Current content resource or null
    • getContentResourceOrParent

      @Nullable public static @Nullable org.apache.sling.api.resource.Resource getContentResourceOrParent(@NotNull @NotNull javax.servlet.http.HttpServletRequest request)
      Get current content resource If it does not exist, go up the content path and return the first resource that exists.
      Parameters:
      request - Request
      Returns:
      Current content resource or the first existing parent/ancestor.
    • getContentPage

      @Nullable public static @Nullable com.day.cq.wcm.api.Page getContentPage(@NotNull @NotNull javax.servlet.http.HttpServletRequest request)
      Current content page. If the current resource does not exist the content page of the next-existing parent resource is returned.
      Parameters:
      request - Request
      Returns:
      Current content page or null
    • getExistingResourceType

      @Nullable public static @Nullable String getExistingResourceType(@NotNull @NotNull org.apache.sling.api.resource.ResourceResolver resourceResolver, @NotNull @NotNull String @NotNull ... resourceTypes)
      From the list of resource types get the first one that exists.
      Parameters:
      resourceResolver - Resource resolver
      resourceTypes - ResourceTypes
      Returns:
      Existing resource type