@ProviderType
public class SlingUriBuilder
extends java.lang.Object
SlingUri
.
Example:
SlingUri testUri = SlingUriBuilder.create() .setResourcePath("/test/to/path") .setSelectors(new String[] { "sel1", "sel2" }) .setExtension("html") .setSuffix("/suffix/path") .setQuery("par1=val1&par2=val2") .build();
Modifier and Type | Method and Description |
---|---|
@NotNull SlingUriBuilder |
addQueryParameter(@NotNull java.lang.String parameterName,
@NotNull java.lang.String value)
Add a query parameter to the query of the URI.
|
@NotNull SlingUriBuilder |
addSelector(@NotNull java.lang.String selector)
Add a selector to the URI.
|
@NotNull SlingUri |
build()
Builds the immutable SlingUri from this builder.
|
static @NotNull SlingUriBuilder |
create()
Creates a builder without any URI parameters set.
|
static @NotNull SlingUriBuilder |
createFrom(@NotNull RequestPathInfo requestPathInfo)
Creates a builder from a RequestPathInfo instance .
|
static @NotNull SlingUriBuilder |
createFrom(@NotNull Resource resource)
Creates a builder from a resource (only taking the resource path into account).
|
static @NotNull SlingUriBuilder |
createFrom(@NotNull SlingHttpServletRequest request)
Creates a builder from a request.
|
static @NotNull SlingUriBuilder |
createFrom(@NotNull SlingUri slingUri)
Creates a builder from another SlingUri (clone and modify use case).
|
static @NotNull SlingUriBuilder |
createFrom(@NotNull java.net.URI uri,
@Nullable ResourceResolver resourceResolver)
Creates a builder from an arbitrary URI.
|
@Nullable java.lang.String |
getExtension()
Returns the extension.
|
@Nullable java.lang.String |
getFragment()
Returns the fragment.
|
@Nullable java.lang.String |
getHost()
Returns the host.
|
@Nullable java.lang.String |
getPath()
Returns the joint path of resource path, selectors, extension and suffix.
|
@Nullable java.util.Map<java.lang.String,java.lang.String> |
getPathParameters()
Returns the path parameters.
|
int |
getPort()
Returns the port.
|
@Nullable java.lang.String |
getQuery()
Returns the query.
|
@Nullable java.lang.String |
getResourcePath()
Returns the resource path.
|
@Nullable java.lang.String |
getScheme()
Returns the scheme.
|
@Nullable java.lang.String |
getSchemeSpecificPart()
Returns the scheme-specific part of the URI, compare with Javadoc of
URI . |
@NotNull java.lang.String[] |
getSelectors()
Returns the selectors array.
|
@Nullable java.lang.String |
getSelectorString()
Returns the selector string
|
@Nullable java.lang.String |
getSuffix()
Returns the suffix part of the URI
|
@Nullable Resource |
getSuffixResource()
Returns the corresponding suffix resource or null if
no resource resolver is available (depends on the create method used in SlingUriBuilder)
the URI does not contain a suffix
if the suffix resource could not be found
|
@Nullable java.lang.String |
getUserInfo()
Returns the user info.
|
boolean |
isAbsolute()
Returns true the URI is an absolute URI.
|
boolean |
isAbsolutePath()
Returns true if the URI has an absolute path starting with a slash ('/').
|
boolean |
isOpaque()
Returns true for opaque URIs like e.g.
|
boolean |
isPath()
Returns true the URI is either a relative or absolute path (this is the case if scheme and host is empty and the URI path is set)
|
boolean |
isRelativePath()
Returns true if the URI is a relative path (no scheme and path does not start with '/').
|
static @NotNull SlingUriBuilder |
parse(@NotNull java.lang.String uriStr,
@Nullable ResourceResolver resourceResolver)
Creates a builder from an arbitrary URI string.
|
@NotNull SlingUriBuilder |
rebaseResourcePath()
Will rebase the uri based on the underlying resource structure.
|
@NotNull SlingUriBuilder |
removeSchemeAndAuthority()
Will remove scheme and authority (that is user info, host and port).
|
@NotNull SlingUriBuilder |
setExtension(@Nullable java.lang.String extension)
Set the extension of the URI.
|
@NotNull SlingUriBuilder |
setFragment(@Nullable java.lang.String fragment)
Set the fragment of the URI.
|
@NotNull SlingUriBuilder |
setHost(@Nullable java.lang.String host)
Set the host of the URI.
|
@NotNull SlingUriBuilder |
setPath(@Nullable java.lang.String path)
Set the path of the URI that contains a resource path and optionally path parameters, selectors, an extension and a suffix.
|
@NotNull SlingUriBuilder |
setPathParameter(@NotNull java.lang.String key,
@NotNull java.lang.String value)
Set a path parameter to the URI.
|
@NotNull SlingUriBuilder |
setPathParameters(@NotNull java.util.Map<java.lang.String,java.lang.String> pathParameters)
Replaces all path parameters in the URI.
|
@NotNull SlingUriBuilder |
setPort(int port)
Set the port of the URI.
|
@NotNull SlingUriBuilder |
setQuery(@Nullable java.lang.String query)
Set the query of the URI.
|
@NotNull SlingUriBuilder |
setQueryParameters(@NotNull java.util.Map<java.lang.String,java.lang.String> queryParameters)
Replace all query parameters of the URL.
|
@NotNull SlingUriBuilder |
setResourcePath(@Nullable java.lang.String resourcePath)
Set the resource path of the URI.
|
@NotNull SlingUriBuilder |
setResourceResolver(ResourceResolver resourceResolver)
Sets the resource resolver (required for
RequestPathInfo.getSuffixResource() ). |
@NotNull SlingUriBuilder |
setScheme(@Nullable java.lang.String scheme)
Set the scheme of the URI.
|
@NotNull SlingUriBuilder |
setSchemeSpecificPart(@Nullable java.lang.String schemeSpecificPart)
Set the scheme specific part of the URI.
|
@NotNull SlingUriBuilder |
setSelectors(@Nullable java.lang.String[] selectors)
Set the selectors of the URI.
|
@NotNull SlingUriBuilder |
setSuffix(@Nullable java.lang.String suffix)
Set the suffix of the URI.
|
@NotNull SlingUriBuilder |
setUserInfo(@Nullable java.lang.String userInfo)
Set the user info of the URI.
|
java.lang.String |
toString()
Builds the corresponding string URI for this builder.
|
@NotNull SlingUriBuilder |
useSchemeAndAuthority(@NotNull SlingUri slingUri)
Will take over scheme and authority (user info, host and port) from provided slingUri.
|
@NotNull SlingUriBuilder |
useSchemeAndAuthority(@NotNull java.net.URI uri)
Will take over scheme and authority (user info, host and port) from provided URI.
|
@NotNull public static @NotNull SlingUriBuilder create()
@NotNull public static @NotNull SlingUriBuilder createFrom(@NotNull @NotNull SlingUri slingUri)
slingUri
- the Sling URI to clone@NotNull public static @NotNull SlingUriBuilder createFrom(@NotNull @NotNull Resource resource)
resource
- the resource to take the resource path from@NotNull public static @NotNull SlingUriBuilder createFrom(@NotNull @NotNull RequestPathInfo requestPathInfo)
requestPathInfo
- the request path info to take resource path, selectors, extension and suffix from.@NotNull public static @NotNull SlingUriBuilder createFrom(@NotNull @NotNull SlingHttpServletRequest request)
request
- request to take the URI information from@NotNull public static @NotNull SlingUriBuilder createFrom(@NotNull @NotNull java.net.URI uri, @Nullable @Nullable ResourceResolver resourceResolver)
uri
- the uri to transform to a SlingUriresourceResolver
- a resource resolver is needed to decide up to what part the path is the resource path (that decision is only
possible by checking against the underlying repository). If null is passed in, the shortest viable resource path is used.@NotNull public static @NotNull SlingUriBuilder parse(@NotNull @NotNull java.lang.String uriStr, @Nullable @Nullable ResourceResolver resourceResolver)
uriStr
- to uri string to parseresourceResolver
- a resource resolver is needed to decide up to what part the path is the resource path (that decision is only
possible by checking against the underlying repository). If null is passed in, the shortest viable resource path is used.@NotNull public @NotNull SlingUriBuilder setUserInfo(@Nullable @Nullable java.lang.String userInfo)
userInfo
- the user info@NotNull public @NotNull SlingUriBuilder setHost(@Nullable @Nullable java.lang.String host)
host
- the host@NotNull public @NotNull SlingUriBuilder setPort(int port)
port
- the port@NotNull public @NotNull SlingUriBuilder setPath(@Nullable @Nullable java.lang.String path)
null
.path
- the path@NotNull public @NotNull SlingUriBuilder rebaseResourcePath()
java.lang.IllegalStateException
- if no resource resolver is available@NotNull public @NotNull SlingUriBuilder setResourcePath(@Nullable @Nullable java.lang.String resourcePath)
resourcePath
- the resource path@NotNull public @NotNull SlingUriBuilder setSelectors(@Nullable @Nullable java.lang.String[] selectors)
null
has the same effect as passing in an empty array.selectors
- the selectors@NotNull public @NotNull SlingUriBuilder addSelector(@NotNull @NotNull java.lang.String selector)
selector
- the selector to add@NotNull public @NotNull SlingUriBuilder setExtension(@Nullable @Nullable java.lang.String extension)
extension
- the extension@NotNull public @NotNull SlingUriBuilder setPathParameter(@NotNull @NotNull java.lang.String key, @NotNull @NotNull java.lang.String value)
key
- the path parameter keyvalue
- the path parameter value@NotNull public @NotNull SlingUriBuilder setPathParameters(@NotNull @NotNull java.util.Map<java.lang.String,java.lang.String> pathParameters)
pathParameters
- the path parameters@NotNull public @NotNull SlingUriBuilder setSuffix(@Nullable @Nullable java.lang.String suffix)
suffix
- the suffix@NotNull public @NotNull SlingUriBuilder setQuery(@Nullable @Nullable java.lang.String query)
query
- the query@NotNull public @NotNull SlingUriBuilder addQueryParameter(@NotNull @NotNull java.lang.String parameterName, @NotNull @NotNull java.lang.String value)
parameterName
- the parameter namevalue
- the parameter value@NotNull public @NotNull SlingUriBuilder setQueryParameters(@NotNull @NotNull java.util.Map<java.lang.String,java.lang.String> queryParameters)
Replace all query parameters of the URL. Both keys and values are URL-encoded before adding them to the query string.
For adding multiple query parameters with the same name prefer to use addQueryParameter(String, String)
.
queryParameters
- the map with the query parameters@NotNull public @NotNull SlingUriBuilder setFragment(@Nullable @Nullable java.lang.String fragment)
fragment
- the fragment@NotNull public @NotNull SlingUriBuilder setScheme(@Nullable @Nullable java.lang.String scheme)
scheme
- the scheme@NotNull public @NotNull SlingUriBuilder setSchemeSpecificPart(@Nullable @Nullable java.lang.String schemeSpecificPart)
schemeSpecificPart
- the scheme specific part@NotNull public @NotNull SlingUriBuilder removeSchemeAndAuthority()
@NotNull public @NotNull SlingUriBuilder useSchemeAndAuthority(@NotNull @NotNull SlingUri slingUri)
slingUri
- the Sling URI@Nullable public @Nullable java.lang.String getResourcePath()
@Nullable public @Nullable java.lang.String getSelectorString()
RequestPathInfo
)@NotNull public @NotNull java.lang.String[] getSelectors()
@Nullable public @Nullable java.lang.String getExtension()
@Nullable public @Nullable java.util.Map<java.lang.String,java.lang.String> getPathParameters()
@Nullable public @Nullable java.lang.String getSuffix()
@Nullable public @Nullable Resource getSuffixResource()
@Nullable public @Nullable java.lang.String getPath()
@Nullable public @Nullable java.lang.String getSchemeSpecificPart()
URI
.@Nullable public @Nullable java.lang.String getQuery()
@Nullable public @Nullable java.lang.String getFragment()
@Nullable public @Nullable java.lang.String getScheme()
@Nullable public @Nullable java.lang.String getHost()
public int getPort()
@Nullable public @Nullable java.lang.String getUserInfo()
@NotNull public @NotNull SlingUriBuilder useSchemeAndAuthority(@NotNull @NotNull java.net.URI uri)
uri
- the URI@NotNull public @NotNull SlingUriBuilder setResourceResolver(ResourceResolver resourceResolver)
RequestPathInfo.getSuffixResource()
).resourceResolver
- the resource resolver@NotNull public @NotNull SlingUri build()
public java.lang.String toString()
toString
in class java.lang.Object
public boolean isPath()
public boolean isAbsolutePath()
public boolean isRelativePath()
public boolean isAbsolute()
public boolean isOpaque()
Copyright © 2022 The Apache Software Foundation. All rights reserved.