Package io.wcm.handler.url.suffix
Class SuffixParser
- java.lang.Object
-
- io.wcm.handler.url.suffix.SuffixParser
-
@ProviderType public final class SuffixParser extends Object
Parses suffixes from Sling URLs build withSuffixBuilder.
-
-
Constructor Summary
Constructors Constructor Description SuffixParser(@NotNull org.apache.sling.api.SlingHttpServletRequest request)Create aSuffixParserwith the defaultSuffixStateKeepingStrategy(which discards all existing suffix state when constructing a new suffix)SuffixParser(@NotNull org.apache.sling.api.SlingHttpServletRequest request, @NotNull Predicate<String> suffixPartFilter)Create aSuffixParserthat keeps only the suffix parts matched by the given filter when constructing a new suffix
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <T> Tget(@NotNull String key, @NotNull Class<T> clazz)Extract the value of a named suffix part from this request's suffix<T> Tget(@NotNull String key, T defaultValue)Extract the value of a named suffix part from this request's suffix@Nullable com.day.cq.wcm.api.PagegetPage()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.PagegetPage(@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.PagegetPage(@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.PagegetPage(@Nullable Predicate<com.day.cq.wcm.api.Page> filter, @Nullable com.day.cq.wcm.api.Page basePage)Get the first item returned bygetPages(Predicate, Page)or null if list is empty@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.@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.ResourcegetResource()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.ResourcegetResource(@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.ResourcegetResource(@NotNull org.apache.sling.api.resource.Resource baseResource)Parse the suffix as resource paths and return the first resource that exists@Nullable org.apache.sling.api.resource.ResourcegetResource(@Nullable Predicate<org.apache.sling.api.resource.Resource> filter, @Nullable org.apache.sling.api.resource.Resource baseResource)Get the first item returned bygetResources(Predicate, Resource)or null if list is empty@NotNull List<org.apache.sling.api.resource.Resource>getResources()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(@NotNull 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(@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
-
-
-
Constructor Detail
-
SuffixParser
public SuffixParser(@NotNull @NotNull org.apache.sling.api.SlingHttpServletRequest request)Create aSuffixParserwith the defaultSuffixStateKeepingStrategy(which discards all existing suffix state when constructing a new suffix)- Parameters:
request- Sling request
-
SuffixParser
public SuffixParser(@NotNull @NotNull org.apache.sling.api.SlingHttpServletRequest request, @NotNull @NotNull Predicate<String> suffixPartFilter)Create aSuffixParserthat 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
-
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 partclazz- 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 partdefaultValue- 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 bygetResources(Predicate, Resource)or null if list is empty- Parameters:
filter- the resource filterbaseResource- the suffix path is relative to this resource path (null for current page's jcr:content node)- Returns:
- the first
Resourceor 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 resourcesbaseResource- 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 bygetPages(Predicate, Page)or null if list is empty- Parameters:
filter- the resource filterbasePage- the suffix path is relative to this page path (null for current page)- Returns:
- the first
Pageor 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 pagesbasePage- the suffix path is relative to this page path (null for current page)- Returns:
- a list containing the Pages
-
-