Class SuffixBuilder

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

@ProviderType public final class SuffixBuilder extends Object
Builds suffixes to be used in Sling URLs and that can be parsed with SuffixParser.
  • Constructor Details

    • SuffixBuilder

      public SuffixBuilder()
      Create a SuffixBuilder which discards all existing suffix state when constructing a new suffix.
    • SuffixBuilder

      public SuffixBuilder(@NotNull @NotNull org.apache.sling.api.SlingHttpServletRequest request, @NotNull @NotNull SuffixStateKeepingStrategy stateStrategy)
      Create a SuffixBuilder with a custom SuffixStateKeepingStrategy (see convenience methods like thatKeepsResourceParts(SlingHttpServletRequest) for often-used strategies)
      Parameters:
      request - Sling request
      stateStrategy - the strategy to use to decide which parts of the suffix of the current request needs to be kept in new constructed links
    • SuffixBuilder

      public SuffixBuilder(@NotNull @NotNull org.apache.sling.api.SlingHttpServletRequest request, @NotNull @NotNull Predicate<String> suffixPartFilter)
      Create a SuffixBuilder that keeps only the suffix parts matched by the given filter when constructing a new suffix
      Parameters:
      request - Sling request
      suffixPartFilter - the filter that is called for each suffix part
  • Method Details

    • thatDiscardsAllSuffixState

      @NotNull public static @NotNull SuffixBuilder thatDiscardsAllSuffixState()
      Returns:
      a SuffixBuilder that discards all existing suffix state when constructing a new suffix
    • thatKeepsResourceParts

      @NotNull public static @NotNull SuffixBuilder thatKeepsResourceParts(@NotNull @NotNull org.apache.sling.api.SlingHttpServletRequest request)
      Parameters:
      request - Sling request
      Returns:
      a SuffixBuilder that discards everything but the *resource* parts of the suffix
    • thatKeepsNamedParts

      @NotNull public static @NotNull SuffixBuilder thatKeepsNamedParts(@NotNull @NotNull org.apache.sling.api.SlingHttpServletRequest request, @NotNull @NotNull String @NotNull ... keysToKeep)
      Parameters:
      request - Sling request
      keysToKeep - Keys to keep
      Returns:
      a SuffixBuilder that keeps only the named key/value-parts defined by pKeysToKeep
    • thatKeepsNamedPartsAndResources

      @NotNull public static @NotNull SuffixBuilder thatKeepsNamedPartsAndResources(@NotNull @NotNull org.apache.sling.api.SlingHttpServletRequest request, @NotNull @NotNull String @NotNull ... keysToKeep)
      Parameters:
      request - Sling request
      keysToKeep - Keys to keep
      Returns:
      a SuffixBuilder that keeps the named key/value-parts defined by pKeysToKeep and all resource parts
    • thatKeepsAllParts

      @NotNull public static @NotNull SuffixBuilder thatKeepsAllParts(@NotNull @NotNull org.apache.sling.api.SlingHttpServletRequest request)
      Parameters:
      request - Sling request
      Returns:
      a SuffixBuilder that keeps all parts from the current request's suffix when constructing a new suffix
    • thatDiscardsResourceParts

      @NotNull public static @NotNull SuffixBuilder thatDiscardsResourceParts(@NotNull @NotNull org.apache.sling.api.SlingHttpServletRequest request)
      Parameters:
      request - Sling request
      Returns:
      a SuffixBuilder that will discard the resource parts, but keep all named key/value-parts
    • thatDiscardsNamedParts

      @NotNull public static @NotNull SuffixBuilder thatDiscardsNamedParts(@NotNull @NotNull org.apache.sling.api.SlingHttpServletRequest request, @NotNull @NotNull String @NotNull ... keysToDiscard)
      Parameters:
      request - Sling request
      keysToDiscard - the keys of the named parts to discard
      Returns:
      a SuffixBuilder that will keep all parts except those named key/value-parts defined by pKeysToDiscard
    • thatDiscardsResourceAndNamedParts

      @NotNull public static @NotNull SuffixBuilder thatDiscardsResourceAndNamedParts(@NotNull @NotNull org.apache.sling.api.SlingHttpServletRequest request, @NotNull @NotNull String @NotNull ... keysToDiscard)
      Parameters:
      request - Sling request
      keysToDiscard - the keys of the named parts to discard
      Returns:
      SuffixBuilder that will discard all resource parts and the named parts defined by pKeysToDiscard
    • thatDiscardsSpecificResourceAndNamedParts

      @NotNull public static @NotNull SuffixBuilder thatDiscardsSpecificResourceAndNamedParts(@NotNull @NotNull org.apache.sling.api.SlingHttpServletRequest request, @NotNull @NotNull String resourcePathToDiscard, @NotNull @NotNull String @NotNull ... keysToDiscard)
      Parameters:
      request - Sling request
      resourcePathToDiscard - relative path of the resource to discard
      keysToDiscard - the keys of the named parts to discard
      Returns:
      SuffixBuilder that will discard *one specific resource path* and the named parts defined by pKeysToDiscard
    • put

      @NotNull public @NotNull SuffixBuilder put(@NotNull @NotNull String key, @NotNull @NotNull Object value)
      Puts a key-value pair into the suffix.
      Parameters:
      key - the key
      value - the value
      Returns:
      this
    • putAll

      @NotNull public @NotNull SuffixBuilder putAll(@NotNull @NotNull Map<String,Object> map)
      Puts a map of key-value pairs into the suffix.
      Parameters:
      map - map of key-value pairs
      Returns:
      this
    • resource

      @NotNull public @NotNull SuffixBuilder resource(@NotNull @NotNull org.apache.sling.api.resource.Resource resource, @NotNull @NotNull org.apache.sling.api.resource.Resource suffixBaseResource)
      Puts a relative path of a resource into the suffix.
      Parameters:
      resource - the resource
      suffixBaseResource - the base resource used to construct the relative path
      Returns:
      this
    • resources

      @NotNull public @NotNull SuffixBuilder resources(@NotNull @NotNull List<org.apache.sling.api.resource.Resource> resources, @NotNull @NotNull org.apache.sling.api.resource.Resource baseResource)
      Constructs a suffix that contains multiple key-value pairs and address resources. Depending on the SuffixStateKeepingStrategy, the suffix contains further parts from the current request that should be kept when constructing new links.
      Parameters:
      resources - resources to address
      baseResource - base resource to construct relative path
      Returns:
      the suffix containing the map-content as encoded key value-pairs (and eventually other parts)
    • page

      @NotNull public @NotNull SuffixBuilder page(@NotNull @NotNull com.day.cq.wcm.api.Page page, @NotNull @NotNull com.day.cq.wcm.api.Page suffixBasePage)
      Puts a relative path of a page into the suffix.
      Parameters:
      page - the page
      suffixBasePage - the base page used to construct the relative path
      Returns:
      this
    • pages

      @NotNull public @NotNull SuffixBuilder pages(@NotNull @NotNull List<com.day.cq.wcm.api.Page> pages, @NotNull @NotNull com.day.cq.wcm.api.Page suffixBasePage)
      Constructs a suffix that contains multiple key-value pairs and address pages. Depending on the SuffixStateKeepingStrategy, the suffix contains further parts from the current request that should be kept when constructing new links.
      Parameters:
      pages - pages to address
      suffixBasePage - the base page used to construct the relative path
      Returns:
      this
    • build

      @NotNull public @NotNull String build()
      Build complete suffix.
      Returns:
      the suffix