Class SuffixParser

java.lang.Object
io.wcm.handler.url.suffix.SuffixParser

@ProviderType public final class SuffixParser extends Object
Parses suffixes from Sling URLs build with SuffixBuilder.
  • Constructor Summary

    Constructors
    Constructor
    Description
    SuffixParser(@NotNull org.apache.sling.api.SlingHttpServletRequest request)
    Create a SuffixParser with the default SuffixStateKeepingStrategy (which discards all existing suffix state when constructing a new suffix)
  • Method Summary

    Modifier and Type
    Method
    Description
    <T> T
    get(@NotNull String key, @NotNull Class<T> clazz)
    Extract the value of a named suffix part from this request's suffix
    <T> T
    get(@NotNull String key, T defaultValue)
    Extract the value of a named suffix part from this request's suffix
    @Nullable com.day.cq.wcm.api.Page
    Parse the suffix as page paths and return the first page that exists with a page path relative to the current page path.
    @Nullable com.day.cq.wcm.api.Page
    getPage(@NotNull com.day.cq.wcm.api.Page basePage)
    Parse the suffix as page paths and return the first page that exists.
    @Nullable com.day.cq.wcm.api.Page
    getPage(@NotNull Predicate<com.day.cq.wcm.api.Page> filter)
    Parse the suffix as page paths, return the first page from the suffix (relativ to the current page) that matches the given filter.
    @Nullable com.day.cq.wcm.api.Page
    getPage(@Nullable Predicate<com.day.cq.wcm.api.Page> filter, @Nullable com.day.cq.wcm.api.Page basePage)
    Get the first item returned by getPages(Predicate, Page) or null if list is empty
    @NotNull List<com.day.cq.wcm.api.Page>
    Get the pages selected in the suffix of the URL with page paths relative to the current page path.
    @NotNull List<com.day.cq.wcm.api.Page>
    getPages(@NotNull Predicate<com.day.cq.wcm.api.Page> filter)
    Get the pages selected in the suffix of the URL with page paths relative to the current page path.
    @NotNull List<com.day.cq.wcm.api.Page>
    getPages(@Nullable Predicate<com.day.cq.wcm.api.Page> filter, @Nullable com.day.cq.wcm.api.Page basePage)
    Get the pages selected in the suffix of the URL
    @Nullable org.apache.sling.api.resource.Resource
    Get a resource within the current page by interpreting the suffix as a JCR path relative to this page's jcr:content node
    @Nullable org.apache.sling.api.resource.Resource
    getResource(@NotNull Predicate<org.apache.sling.api.resource.Resource> filter)
    Parse the suffix as resource paths, return the first resource from the suffix (relativ to the current page's content) that matches the given filter.
    @Nullable org.apache.sling.api.resource.Resource
    getResource(@Nullable Predicate<org.apache.sling.api.resource.Resource> filter, @Nullable org.apache.sling.api.resource.Resource baseResource)
    Get the first item returned by getResources(Predicate, Resource) or null if list is empty
    @Nullable org.apache.sling.api.resource.Resource
    getResource(@NotNull org.apache.sling.api.resource.Resource baseResource)
    Parse the suffix as resource paths and return the first resource that exists
    @NotNull List<org.apache.sling.api.resource.Resource>
    Get the resources within the current page selected in the suffix of the URL
    @NotNull List<org.apache.sling.api.resource.Resource>
    getResources(@NotNull Predicate<org.apache.sling.api.resource.Resource> filter)
    Get the resources selected in the suffix of the URL
    @NotNull List<org.apache.sling.api.resource.Resource>
    getResources(@Nullable Predicate<org.apache.sling.api.resource.Resource> filter, @Nullable org.apache.sling.api.resource.Resource baseResource)
    Get the resources selected in the suffix of the URL
    @NotNull List<org.apache.sling.api.resource.Resource>
    getResources(@NotNull org.apache.sling.api.resource.Resource baseResource)
    Get the resources selected in the suffix of the URL

    Methods inherited from class java.lang.Object

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

    • SuffixParser

      public SuffixParser(@NotNull @NotNull org.apache.sling.api.SlingHttpServletRequest request)
      Create a SuffixParser with the default SuffixStateKeepingStrategy (which discards all existing suffix state when constructing a new suffix)
      Parameters:
      request - Sling request
  • Method Details

    • get

      @Nullable public <T> T get(@NotNull @NotNull String key, @NotNull @NotNull Class<T> clazz)
      Extract the value of a named suffix part from this request's suffix
      Type Parameters:
      T - Parameter type.
      Parameters:
      key - key of the suffix part
      clazz - Type expected for return value. Only String, Boolean, Integer, Long are supported.
      Returns:
      the value of that named parameter (or the default value if not used)
    • get

      @Nullable public <T> T get(@NotNull @NotNull String key, @Nullable T defaultValue)
      Extract the value of a named suffix part from this request's suffix
      Type Parameters:
      T - Parameter type.
      Parameters:
      key - key of the suffix part
      defaultValue - the default value to return if suffix part not set. Only String, Boolean, Integer, Long are supported.
      Returns:
      the value of that named parameter (or the default value if not used)
    • getResource

      @Nullable public @Nullable org.apache.sling.api.resource.Resource getResource()
      Get a resource within the current page by interpreting the suffix as a JCR path relative to this page's jcr:content node
      Returns:
      the Resource or null if no such resource exists
    • getResource

      @Nullable public @Nullable org.apache.sling.api.resource.Resource getResource(@NotNull @NotNull org.apache.sling.api.resource.Resource baseResource)
      Parse the suffix as resource paths and return the first resource that exists
      Parameters:
      baseResource - the suffix path is relative to this resource path (null for current page's jcr:content node)
      Returns:
      the resource or null if no such resource was selected by suffix
    • getResource

      @Nullable public @Nullable org.apache.sling.api.resource.Resource getResource(@NotNull @NotNull Predicate<org.apache.sling.api.resource.Resource> filter)
      Parse the suffix as resource paths, return the first resource from the suffix (relativ to the current page's content) that matches the given filter.
      Parameters:
      filter - a filter that selects only the resource you're interested in.
      Returns:
      the resource or null if no such resource was selected by suffix
    • getResource

      @Nullable public @Nullable org.apache.sling.api.resource.Resource getResource(@Nullable @Nullable Predicate<org.apache.sling.api.resource.Resource> filter, @Nullable @Nullable org.apache.sling.api.resource.Resource baseResource)
      Get the first item returned by getResources(Predicate, Resource) or null if list is empty
      Parameters:
      filter - the resource filter
      baseResource - the suffix path is relative to this resource path (null for current page's jcr:content node)
      Returns:
      the first Resource or null
    • getResources

      @NotNull public @NotNull List<org.apache.sling.api.resource.Resource> getResources()
      Get the resources within the current page selected in the suffix of the URL
      Returns:
      a list containing the Resources
    • getResources

      @NotNull public @NotNull List<org.apache.sling.api.resource.Resource> getResources(@NotNull @NotNull org.apache.sling.api.resource.Resource baseResource)
      Get the resources selected in the suffix of the URL
      Parameters:
      baseResource - the suffix path is relative to this resource path (null for current page's jcr:content node)
      Returns:
      a list containing the Resources
    • getResources

      @NotNull public @NotNull List<org.apache.sling.api.resource.Resource> getResources(@NotNull @NotNull Predicate<org.apache.sling.api.resource.Resource> filter)
      Get the resources selected in the suffix of the URL
      Parameters:
      filter - optional filter to select only specific resources
      Returns:
      a list containing the Resources
    • getResources

      @NotNull public @NotNull List<org.apache.sling.api.resource.Resource> getResources(@Nullable @Nullable Predicate<org.apache.sling.api.resource.Resource> filter, @Nullable @Nullable org.apache.sling.api.resource.Resource baseResource)
      Get the resources selected in the suffix of the URL
      Parameters:
      filter - optional filter to select only specific resources
      baseResource - the suffix path is relative to this resource path (null for current page's jcr:content node)
      Returns:
      a list containing the Resources
    • getPage

      @Nullable public @Nullable com.day.cq.wcm.api.Page getPage()
      Parse the suffix as page paths and return the first page that exists with a page path relative to the current page path.
      Returns:
      the page or null if no such page was selected by suffix
    • getPage

      @Nullable public @Nullable com.day.cq.wcm.api.Page getPage(@NotNull @NotNull com.day.cq.wcm.api.Page basePage)
      Parse the suffix as page paths and return the first page that exists.
      Parameters:
      basePage - the suffix page is relative to this page path (null for current page)
      Returns:
      the page or null if no such page was selected by suffix
    • getPage

      @Nullable public @Nullable com.day.cq.wcm.api.Page getPage(@NotNull @NotNull Predicate<com.day.cq.wcm.api.Page> filter)
      Parse the suffix as page paths, return the first page from the suffix (relativ to the current page) that matches the given filter.
      Parameters:
      filter - a filter that selects only the page you're interested in.
      Returns:
      the page or null if no such page was selected by suffix
    • getPage

      @Nullable public @Nullable com.day.cq.wcm.api.Page getPage(@Nullable @Nullable Predicate<com.day.cq.wcm.api.Page> filter, @Nullable @Nullable com.day.cq.wcm.api.Page basePage)
      Get the first item returned by getPages(Predicate, Page) or null if list is empty
      Parameters:
      filter - the resource filter
      basePage - the suffix path is relative to this page path (null for current page)
      Returns:
      the first Page or null
    • getPages

      @NotNull public @NotNull List<com.day.cq.wcm.api.Page> getPages()
      Get the pages selected in the suffix of the URL with page paths relative to the current page path.
      Returns:
      a list containing the Pages
    • getPages

      @NotNull public @NotNull List<com.day.cq.wcm.api.Page> getPages(@NotNull @NotNull Predicate<com.day.cq.wcm.api.Page> filter)
      Get the pages selected in the suffix of the URL with page paths relative to the current page path.
      Parameters:
      filter - optional filter to select only specific pages
      Returns:
      a list containing the Pages
    • getPages

      @NotNull public @NotNull List<com.day.cq.wcm.api.Page> getPages(@Nullable @Nullable Predicate<com.day.cq.wcm.api.Page> filter, @Nullable @Nullable com.day.cq.wcm.api.Page basePage)
      Get the pages selected in the suffix of the URL
      Parameters:
      filter - optional filter to select only specific pages
      basePage - the suffix path is relative to this page path (null for current page)
      Returns:
      a list containing the Pages