Package io.wcm.handler.url.suffix
Class SuffixBuilder
- java.lang.Object
-
- io.wcm.handler.url.suffix.SuffixBuilder
-
@ProviderType public final class SuffixBuilder extends java.lang.Object
Builds suffixes to be used in Sling URLs and that can be parsed withSuffixParser
.
-
-
Constructor Summary
Constructors Constructor Description SuffixBuilder()
Create aSuffixBuilder
which discards all existing suffix state when constructing a new suffix.SuffixBuilder(@NotNull org.apache.sling.api.SlingHttpServletRequest request, @NotNull SuffixStateKeepingStrategy stateStrategy)
Create aSuffixBuilder
with a customSuffixStateKeepingStrategy
(see convenience methods likethatKeepsResourceParts(SlingHttpServletRequest)
for often-used strategies)SuffixBuilder(@NotNull org.apache.sling.api.SlingHttpServletRequest request, @NotNull java.util.function.Predicate<java.lang.String> suffixPartFilter)
Create aSuffixBuilder
that keeps only the suffix parts matched by the given filter when constructing a new suffix
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description @NotNull java.lang.String
build()
Build complete suffix.@NotNull SuffixBuilder
page(@NotNull com.day.cq.wcm.api.Page page, @NotNull com.day.cq.wcm.api.Page suffixBasePage)
Puts a relative path of a page into the suffix.@NotNull SuffixBuilder
pages(@NotNull java.util.List<com.day.cq.wcm.api.Page> pages, @NotNull com.day.cq.wcm.api.Page suffixBasePage)
Constructs a suffix that contains multiple key-value pairs and address pages.@NotNull SuffixBuilder
put(@NotNull java.lang.String key, @NotNull java.lang.Object value)
Puts a key-value pair into the suffix.@NotNull SuffixBuilder
putAll(@NotNull java.util.Map<java.lang.String,java.lang.Object> map)
Puts a map of key-value pairs into the suffix.@NotNull SuffixBuilder
resource(@NotNull org.apache.sling.api.resource.Resource resource, @NotNull org.apache.sling.api.resource.Resource suffixBaseResource)
Puts a relative path of a resource into the suffix.@NotNull SuffixBuilder
resources(@NotNull java.util.List<org.apache.sling.api.resource.Resource> resources, @NotNull org.apache.sling.api.resource.Resource baseResource)
Constructs a suffix that contains multiple key-value pairs and address resources.static @NotNull SuffixBuilder
thatDiscardsAllSuffixState()
static @NotNull SuffixBuilder
thatDiscardsNamedParts(@NotNull org.apache.sling.api.SlingHttpServletRequest request, @NotNull java.lang.String @NotNull ... keysToDiscard)
static @NotNull SuffixBuilder
thatDiscardsResourceAndNamedParts(@NotNull org.apache.sling.api.SlingHttpServletRequest request, @NotNull java.lang.String @NotNull ... keysToDiscard)
static @NotNull SuffixBuilder
thatDiscardsResourceParts(@NotNull org.apache.sling.api.SlingHttpServletRequest request)
static @NotNull SuffixBuilder
thatDiscardsSpecificResourceAndNamedParts(@NotNull org.apache.sling.api.SlingHttpServletRequest request, @NotNull java.lang.String resourcePathToDiscard, @NotNull java.lang.String @NotNull ... keysToDiscard)
static @NotNull SuffixBuilder
thatKeepsAllParts(@NotNull org.apache.sling.api.SlingHttpServletRequest request)
static @NotNull SuffixBuilder
thatKeepsNamedParts(@NotNull org.apache.sling.api.SlingHttpServletRequest request, @NotNull java.lang.String @NotNull ... keysToKeep)
static @NotNull SuffixBuilder
thatKeepsNamedPartsAndResources(@NotNull org.apache.sling.api.SlingHttpServletRequest request, @NotNull java.lang.String @NotNull ... keysToKeep)
static @NotNull SuffixBuilder
thatKeepsResourceParts(@NotNull org.apache.sling.api.SlingHttpServletRequest request)
-
-
-
Constructor Detail
-
SuffixBuilder
public SuffixBuilder()
Create aSuffixBuilder
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 aSuffixBuilder
with a customSuffixStateKeepingStrategy
(see convenience methods likethatKeepsResourceParts(SlingHttpServletRequest)
for often-used strategies)- Parameters:
request
- Sling requeststateStrategy
- 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 java.util.function.Predicate<java.lang.String> suffixPartFilter)
Create aSuffixBuilder
that keeps only the suffix parts matched by the given filter when constructing a new suffix- Parameters:
request
- Sling requestsuffixPartFilter
- the filter that is called for each suffix part
-
-
Method Detail
-
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 java.lang.String @NotNull ... keysToKeep)
- Parameters:
request
- Sling requestkeysToKeep
- 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 java.lang.String @NotNull ... keysToKeep)
- Parameters:
request
- Sling requestkeysToKeep
- 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 java.lang.String @NotNull ... keysToDiscard)
- Parameters:
request
- Sling requestkeysToDiscard
- 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 java.lang.String @NotNull ... keysToDiscard)
- Parameters:
request
- Sling requestkeysToDiscard
- 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 java.lang.String resourcePathToDiscard, @NotNull @NotNull java.lang.String @NotNull ... keysToDiscard)
- Parameters:
request
- Sling requestresourcePathToDiscard
- relative path of the resource to discardkeysToDiscard
- 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 java.lang.String key, @NotNull @NotNull java.lang.Object value)
Puts a key-value pair into the suffix.- Parameters:
key
- the keyvalue
- the value- Returns:
- this
-
putAll
@NotNull public @NotNull SuffixBuilder putAll(@NotNull @NotNull java.util.Map<java.lang.String,java.lang.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 resourcesuffixBaseResource
- the base resource used to construct the relative path- Returns:
- this
-
resources
@NotNull public @NotNull SuffixBuilder resources(@NotNull @NotNull java.util.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 theSuffixStateKeepingStrategy
, the suffix contains further parts from the current request that should be kept when constructing new links.- Parameters:
resources
- resources to addressbaseResource
- 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 pagesuffixBasePage
- the base page used to construct the relative path- Returns:
- this
-
pages
@NotNull public @NotNull SuffixBuilder pages(@NotNull @NotNull java.util.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 theSuffixStateKeepingStrategy
, the suffix contains further parts from the current request that should be kept when constructing new links.- Parameters:
pages
- pages to addresssuffixBasePage
- the base page used to construct the relative path- Returns:
- this
-
build
@NotNull public @NotNull java.lang.String build()
Build complete suffix.- Returns:
- the suffix
-
-