Package io.wcm.handler.url
Interface UrlHandler
@ProviderType
public interface UrlHandler
Rewrites and builds URLs for links to content pages and resources.
The interface is implemented by a Sling Model. You can adapt from
SlingHttpServletRequest or Resource to get a
context-specific handler instance.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final @NotNull StringSelector that is always added if a Sling-URL contains a suffix (to avoid files and directories with same name in dispatcher cache) -
Method Summary
Modifier and TypeMethodDescriptionapplySiteUrlAutoDetection(@Nullable String siteUrl) Applies auto-detection of Site URL (author or publish instance) for given Site URL that is configured inSiteConfig.@NotNull UrlBuilderget(@NotNull com.day.cq.wcm.api.Page page) Builds and optionally externalizes an URL using a builder pattern.@NotNull UrlBuilderBuilds and optionally externalizes an URL using a builder pattern.@NotNull UrlBuilderget(@NotNull org.apache.sling.api.resource.Resource resource) Builds and optionally externalizes an URL using a builder pattern.booleanisExternalized(@NotNull String url) Checks if the given URL is externalized.@Nullable StringrewritePathToContext(@NotNull org.apache.sling.api.resource.Resource resource) Rewrites given path to current site or context.@Nullable StringrewritePathToContext(@NotNull org.apache.sling.api.resource.Resource resource, @NotNull org.apache.sling.api.resource.Resource contextResource) Rewrites given path to given site or context.
-
Field Details
-
SELECTOR_SUFFIX
Selector that is always added if a Sling-URL contains a suffix (to avoid files and directories with same name in dispatcher cache)- See Also:
-
-
Method Details
-
get
Builds and optionally externalizes an URL using a builder pattern.- Parameters:
path- Path to start URL building with- Returns:
- URL builder which allows to chain further optional parameters before building the URL string.
-
get
Builds and optionally externalizes an URL using a builder pattern.- Parameters:
resource- Resource, URL building is started with its path- Returns:
- URL builder which allows to chain further optional parameters before building the URL string.
-
get
Builds and optionally externalizes an URL using a builder pattern.- Parameters:
page- Page Page, URL building is started with its path- Returns:
- URL builder which allows to chain further optional parameters before building the URL string.
-
rewritePathToContext
@Nullable @Nullable String rewritePathToContext(@NotNull @NotNull org.apache.sling.api.resource.Resource resource) Rewrites given path to current site or context. The site root path is replaced with the one from current site This is useful if a link to an internal page points to a page outside the site (e.g. because the page containing the link was copied from the other site or inherited). When the AEM built-in rewrite logic was not applied the link would be invalid. This methods rewrites the link path to the current site to try to resolve it there.- Parameters:
resource- Resource to rewrite path from- Returns:
- Rewritten path or null if resource invalid
-
rewritePathToContext
@Nullable @Nullable String rewritePathToContext(@NotNull @NotNull org.apache.sling.api.resource.Resource resource, @NotNull @NotNull org.apache.sling.api.resource.Resource contextResource) Rewrites given path to given site or context. The site root path is replaced with the one from current site. This is useful if a link to an internal page points to a page outside the site (e.g. because the page containing the link was copied from the other site or inherited). When the AEM built-in rewrite logic was not applied the link would be invalid. This methods rewrites the link path to the current site to try to resolve it there.- Parameters:
resource- Resource to rewrite path fromcontextResource- Context resource to which the path should be rewritten to- Returns:
- Rewritten path or null if resource or context resource is invalid
-
isExternalized
Checks if the given URL is externalized.An URL is treated as externalized if:
- It starts with a protocol and a colon (e.g. http:, tel:, mailto:, javascript:)
- It starts with // or #
- Parameters:
url- URL- Returns:
- true if the URL is externalized.
-
applySiteUrlAutoDetection
Applies auto-detection of Site URL (author or publish instance) for given Site URL that is configured inSiteConfig.If this Site URL contains an
<auto>placeholder the Site URL detection is enabled and the Site URL is replaced with the current hostname (if possible). Otherwise the remaining part of the Site URL string is returned as fallback.Site URL auto-detection does only work in context of a request - outside request context the placeholders is removed and the remaining string returned as fallback.
- Parameters:
siteUrl- Site URL (author or publish)SiteConfig.- Returns:
- Automatic detected Site URL or fallback
-