Class SlingUrl
- java.lang.Object
-
- com.composum.sling.core.util.SlingUrl
-
- All Implemented Interfaces:
Cloneable
public class SlingUrl extends Object implements Cloneable
A Sling URL parser / builder class supporting the Sling URL decomposition (and composition / modification by using the builder methods) and provides builder methods to change e.g. selectors and extension, but can also represent other URL types. It is meant to represent every user input without failing - if it's not a known URL scheme and thus cannot be parsed it'll just return the input unchanged, and the modification methods fail silently.Major usecases
Building URLs for resources
With the constructors with a
Resource
parameter, e.g.SlingUrl(SlingHttpServletRequest, Resource)
, it's possible to generate an URL and give it someselectors(String)
,extension(String)
or andsuffix(Resource)
andparameter(String, String...)
. If only the path of the resource is known, that'd start withSlingUrl(SlingHttpServletRequest)
and initalized withfromPath(String)
.Modifying userspecified URLs
The class is meant to represent all types of URL (including invalid ones), and parse them in a do-what-I-mean fashion, so that they can be modified according to Sling rules, as far as possible. There are direct constructors from a Resource, and various ways to initialize it mit a method starting with from (e.g.fromPathOrUrl(String)
) after creating a basic builder withSlingUrl(SlingHttpServletRequest)
orSlingUrl(SlingHttpServletRequest, LinkMapper)
.Caution: this does not consider the resource tree to parse URLs from String form, so there will be cases where this differs from
ResourceResolver.resolve(HttpServletRequest, String)
: e.g. we consider in /foo/a.b/bar/c.d the /bar/c.d as suffix, while this might be different in reality!- See Also:
- "https://sling.apache.org/documentation/the-sling-engine/url-decomposition.html", "https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/net/URI.html"
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
SlingUrl.UrlType
Characterizes the type of the URL.
-
Field Summary
Fields Modifier and Type Field Description protected static Pattern
ABSOLUTE_PATH_PATTERN
protected String
contextPath
protected String
extension
protected static Pattern
FILE_SCHEME
protected static Pattern
FILE_SCHEME_PATTERN
protected static Pattern
FILE_URL_PATTERN
protected String
fragment
protected String
host
protected static Pattern
HTTP_SCHEME
protected static Pattern
HTTP_SCHEME_PATTERN
protected static Pattern
HTTP_URL_PATTERN
Regex matching various variants of Sling-URLs.protected LinkMapper
linkMapper
protected String
name
The filename; if the url could not be parsed (SlingUrl.UrlType.SPECIAL
orSlingUrl.UrlType.OTHER
), this contains the url without the scheme.protected LinkedHashMap<String,List<String>>
parameters
protected String
password
protected String
path
Contains the path inclusive leading and trailing / , not the file/resource itself: for /a/b/c it's /a/b/ .protected Integer
port
protected static Pattern
RELATIVE_PATH_PATTERN
protected org.apache.sling.api.SlingHttpServletRequest
request
protected org.apache.sling.api.resource.Resource
resource
protected String
resourcePath
protected String
scheme
The scheme of the URL.protected static Pattern
SCHEME_PATTERN
static String
SCHEME_PROTOCOL_RELATIVE_URL
Marker forgetScheme()
for a protocol relative URL, e.g.protected List<String>
selectors
protected static Pattern
SPECIAL_SCHEME
protected String
suffix
protected SlingUrl.UrlType
type
protected String
username
protected static Pattern
USERNAMEPASSWORD
-
Constructor Summary
Constructors Constructor Description SlingUrl(@NotNull org.apache.sling.api.SlingHttpServletRequest request)
Constructs a yet invalid SlingUrl that has to be initialized with one of the from* methods.SlingUrl(@NotNull org.apache.sling.api.SlingHttpServletRequest request, @NotNull org.apache.sling.api.resource.Resource resource)
SlingUrl(@NotNull org.apache.sling.api.SlingHttpServletRequest request, @NotNull org.apache.sling.api.resource.Resource resource, @Nullable String extension)
SlingUrl(@NotNull org.apache.sling.api.SlingHttpServletRequest request, @NotNull org.apache.sling.api.resource.Resource resource, @Nullable String selectors, @Nullable String extension)
SlingUrl(@NotNull org.apache.sling.api.SlingHttpServletRequest request, @NotNull org.apache.sling.api.resource.Resource resource, @Nullable String selectors, @Nullable String extension, @Nullable String suffix)
SlingUrl(@NotNull org.apache.sling.api.SlingHttpServletRequest request, @NotNull org.apache.sling.api.resource.Resource resource, @Nullable String selectors, @Nullable String extension, @Nullable String suffix, @Nullable String parameterString)
SlingUrl(@NotNull org.apache.sling.api.SlingHttpServletRequest request, @NotNull org.apache.sling.api.resource.Resource resource, @Nullable String selectors, @Nullable String extension, @Nullable String suffix, @Nullable String parameterString, boolean decodeParameters, @Nullable LinkMapper linkMapper)
SlingUrl(@NotNull org.apache.sling.api.SlingHttpServletRequest request, @Nullable LinkMapper linkMapper)
Constructs a yet invalid SlingUrl that has to be initialized with one of the from* methods.SlingUrl(@NotNull org.apache.sling.api.SlingHttpServletRequest request, String url)
Deprecated.use new SlingUrl(request).fromUrl(url)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description SlingUrl
addParameter(String name, String... value)
SlingUrl
addParameters(String parameterString, boolean decode)
Adds parameters parsed from an HTTP query string.SlingUrl
addSelector(@Nullable String... value)
protected void
assignFromGroups(Matcher matcher, boolean decode, boolean hostAndPort)
protected String
buildUrl()
SlingUrl
clearParameters()
SlingUrl
clearSelectors()
protected void
clearTransients()
Internal reset method for the calculated transient values like the URL, called when anything changes.SlingUrl
clone()
protected String
decode(String value, boolean decode)
boolean
equals(Object other)
Just comparestoString()
- that is, the url.SlingUrl
extension(@Nullable String extension)
@NotNull SlingUrl
fragment(@Nullable String fragment)
Sets the fragment part of the URL.@NotNull SlingUrl
fromPath(@NotNull String resourcePath)
Initializes the SlingUrl from a resource path, absolute or relative.SlingUrl
fromPathOrUrl(@NotNull String pathOrUrl)
Initializes from an url or an absolute resource path.SlingUrl
fromPathOrUrl(@NotNull String pathOrUrl, boolean decode)
Initializes from an url or an absolute resource path, possibly URL-decoding it when decode = true.@NotNull SlingUrl
fromRequest(javax.servlet.http.HttpServletRequest request)
Initialzes the SlingUrl from a requests URLSlingUrl
fromUri(@NotNull URI uri)
Assigns from the given uri, trying to parse extension and suffix from it.@NotNull SlingUrl
fromUrl(@NotNull String url)
Parses the url.@NotNull SlingUrl
fromUrl(@NotNull String url, boolean decode)
Parses the url, possibly URL-decoding it when decode = true.@Nullable String
getContextPath()
If an internal path starts with theHttpServletRequest.getContextPath()
, this contains the context path, and the context path is removed fromgetPathAndName()
.@Nullable String
getExtension()
@Nullable String
getFragment()
The fragment part of the URL.@Nullable String
getHost()
The host part of the URL.protected static LinkMapper
getLinkMapper(@NotNull org.apache.sling.api.SlingHttpServletRequest request, @Nullable LinkMapper linkMapper)
@Nullable String
getName()
The filename; in case of type OTHER this contains the whole URL but the scheme and colon.@Nullable String
getParameter(@NotNull String name)
@NotNull Map<String,List<String>>
getParameters()
Unmodifiable map of the contained parameters.@Nullable List<String>
getParameterValues(@NotNull String name)
@Nullable String
getPassword()
The password part of an URL.@NotNull String
getPathAndName()
The path to the file including the filename, but not the extension, selectors etc.@NotNull String
getPathAndNameExt()
The path to the file including the filename and the extension, but no selectors.@Nullable Integer
getPort()
The port part of the URL.@NotNull org.apache.sling.api.SlingHttpServletRequest
getRequest()
@Nullable org.apache.sling.api.resource.Resource
getResource()
For internal urls: if this is a path to a resource, this returns it (suffix, selectors and parameters ignored, if present).@Nullable String
getResourcePath()
For internal urls the path to the rendered resource.@Nullable String
getScheme()
The scheme part of an URL.@Nullable String
getSuffix()
@NotNull SlingUrl.UrlType
getType()
The type of the URL.String
getUrl()
Builds the URL from its parts saved in the builder.@Nullable String
getUsername()
The username part of an URL.int
hashCode()
@NotNull SlingUrl
host(@Nullable String host)
Sets the host part of the URL.protected boolean
isAbsolutePath(String pathOrUrl)
boolean
isExternal()
An external URL: we assume it's external when a scheme is set.@NotNull SlingUrl
name(@Nullable String name)
Sets the filename; in case of type OTHER this contains the whole URL but the scheme and colon.SlingUrl
parameter(String name, String... value)
SlingUrl
parameters(String parameterString)
protected void
parseParameters(@NotNull String parameterString, boolean decode)
protected void
parseUrl(@NotNull String url, boolean decode)
@NotNull SlingUrl
password(@Nullable String password)
Sets the password part of an URL.@NotNull SlingUrl
port(@Nullable Integer port)
Sets the port part of the URL.SlingUrl
removeParameter(String name)
SlingUrl
removeSelector(String... value)
void
reset()
SlingUrl
resourcePath(@Nullable String resourcePath)
Sets the resource path encoded in the URL to the given path.@NotNull SlingUrl
scheme(@Nullable String scheme)
Sets the scheme part of an URL.SlingUrl
selector(@Nullable String... value)
SlingUrl
selectors(@Nullable String selectors)
SlingUrl
setExtension(@Nullable String extension)
@NotNull SlingUrl
setFragment(@Nullable String fragment)
Sets the fragment.@NotNull SlingUrl
setHost(@Nullable String host)
Sets the host part of the URL.@NotNull SlingUrl
setName(@Nullable String name)
Sets the name.SlingUrl
setParameter(String name, String... value)
SlingUrl
setParameters(String parameterString, boolean decode)
@NotNull SlingUrl
setPassword(@Nullable String password)
Sets the password.SlingUrl
setPathAndName(@Nullable String fullpath)
Sets the path and name from the given e.g.SlingUrl
setPathAndNameExt(@Nullable String fullpath)
Sets the path, name and extension from the given e.g.@NotNull SlingUrl
setPort(@Nullable Integer port)
Sets the port.SlingUrl
setResourcePath(@Nullable String resourcePath)
Sets the resource path encoded in the URL to the given path.@NotNull SlingUrl
setScheme(@Nullable String scheme)
Sets the scheme.SlingUrl
setSelector(String... value)
SlingUrl
setSelectors(@Nullable String selectors)
Sets the selectors to the given string - can contain multiple selectors separated with period.SlingUrl
setSuffix(@Nullable String suffix)
@NotNull SlingUrl
setType(@NotNull SlingUrl.UrlType type)
Sets the type.@NotNull SlingUrl
setUsername(@Nullable String username)
Sets the username.SlingUrl
suffix(@Nullable String suffix)
SlingUrl
suffix(@Nullable org.apache.sling.api.resource.Resource resource)
SlingUrl
suffix(@Nullable org.apache.sling.api.resource.Resource resource, @Nullable String extension)
String
toDebugString()
Lists the internal parse results - mainly for debugging purposes.String
toString()
Same asgetUrl()
.@NotNull SlingUrl
type(@NotNull SlingUrl.UrlType type)
Sets the type of the URL.@NotNull SlingUrl
username(@Nullable String username)
Sets the username part of an URL.
-
-
-
Field Detail
-
SCHEME_PROTOCOL_RELATIVE_URL
public static final String SCHEME_PROTOCOL_RELATIVE_URL
Marker forgetScheme()
for a protocol relative URL, e.g. //www/something.css - just the empty string, as opposed to null for no scheme as inSlingUrl.UrlType.RELATIVE
.- See Also:
- Constant Field Values
-
SCHEME_PATTERN
protected static final Pattern SCHEME_PATTERN
-
HTTP_SCHEME_PATTERN
protected static final Pattern HTTP_SCHEME_PATTERN
-
FILE_SCHEME_PATTERN
protected static final Pattern FILE_SCHEME_PATTERN
-
USERNAMEPASSWORD
protected static final Pattern USERNAMEPASSWORD
-
HTTP_URL_PATTERN
protected static final Pattern HTTP_URL_PATTERN
Regex matching various variants of Sling-URLs.Debug regex e.g. with http://www.softlion.com/webtools/regexptest/ .
-
FILE_URL_PATTERN
protected static final Pattern FILE_URL_PATTERN
-
ABSOLUTE_PATH_PATTERN
protected static final Pattern ABSOLUTE_PATH_PATTERN
-
RELATIVE_PATH_PATTERN
protected static final Pattern RELATIVE_PATH_PATTERN
-
HTTP_SCHEME
protected static final Pattern HTTP_SCHEME
-
FILE_SCHEME
protected static final Pattern FILE_SCHEME
-
SPECIAL_SCHEME
protected static final Pattern SPECIAL_SCHEME
-
type
protected SlingUrl.UrlType type
-
scheme
protected String scheme
The scheme of the URL. To be able to represent protocol-relative URL, we distinguish here null and the empty string: null is no scheme, empty string is a protocol-relative URL (e.g. //www/something.css).
-
username
protected String username
-
password
protected String password
-
host
protected String host
-
port
protected Integer port
-
contextPath
protected String contextPath
-
path
protected String path
Contains the path inclusive leading and trailing / , not the file/resource itself: for /a/b/c it's /a/b/ . Emptly for relative paths / unparseable stuff.
-
name
protected String name
The filename; if the url could not be parsed (SlingUrl.UrlType.SPECIAL
orSlingUrl.UrlType.OTHER
), this contains the url without the scheme.
-
extension
protected String extension
-
suffix
protected String suffix
-
parameters
protected final LinkedHashMap<String,List<String>> parameters
-
fragment
protected String fragment
-
resourcePath
protected transient String resourcePath
-
resource
protected transient org.apache.sling.api.resource.Resource resource
-
request
protected final org.apache.sling.api.SlingHttpServletRequest request
-
linkMapper
protected final LinkMapper linkMapper
-
-
Constructor Detail
-
SlingUrl
public SlingUrl(@NotNull @NotNull org.apache.sling.api.SlingHttpServletRequest request, @NotNull @NotNull org.apache.sling.api.resource.Resource resource)
-
SlingUrl
public SlingUrl(@NotNull @NotNull org.apache.sling.api.SlingHttpServletRequest request, @NotNull @NotNull org.apache.sling.api.resource.Resource resource, @Nullable @Nullable String extension)
-
SlingUrl
public SlingUrl(@NotNull @NotNull org.apache.sling.api.SlingHttpServletRequest request, @NotNull @NotNull org.apache.sling.api.resource.Resource resource, @Nullable @Nullable String selectors, @Nullable @Nullable String extension)
-
SlingUrl
public SlingUrl(@NotNull @NotNull org.apache.sling.api.SlingHttpServletRequest request, @NotNull @NotNull org.apache.sling.api.resource.Resource resource, @Nullable @Nullable String selectors, @Nullable @Nullable String extension, @Nullable @Nullable String suffix)
-
SlingUrl
public SlingUrl(@NotNull @NotNull org.apache.sling.api.SlingHttpServletRequest request, @NotNull @NotNull org.apache.sling.api.resource.Resource resource, @Nullable @Nullable String selectors, @Nullable @Nullable String extension, @Nullable @Nullable String suffix, @Nullable @Nullable String parameterString)
-
SlingUrl
public SlingUrl(@NotNull @NotNull org.apache.sling.api.SlingHttpServletRequest request, @NotNull @NotNull org.apache.sling.api.resource.Resource resource, @Nullable @Nullable String selectors, @Nullable @Nullable String extension, @Nullable @Nullable String suffix, @Nullable @Nullable String parameterString, boolean decodeParameters, @Nullable @Nullable LinkMapper linkMapper)
-
SlingUrl
public SlingUrl(@NotNull @NotNull org.apache.sling.api.SlingHttpServletRequest request, @Nullable @Nullable LinkMapper linkMapper)
Constructs a yet invalid SlingUrl that has to be initialized with one of the from* methods. A linkmapper can be given if the url is a path.
-
SlingUrl
public SlingUrl(@NotNull @NotNull org.apache.sling.api.SlingHttpServletRequest request)
Constructs a yet invalid SlingUrl that has to be initialized with one of the from* methods.
-
SlingUrl
@Deprecated public SlingUrl(@NotNull @NotNull org.apache.sling.api.SlingHttpServletRequest request, String url)
Deprecated.use new SlingUrl(request).fromUrl(url)
-
-
Method Detail
-
fromUrl
@NotNull public @NotNull SlingUrl fromUrl(@NotNull @NotNull String url)
Parses the url. Caution: if the url contains several periods like e.g. http://host/a.b/c.d/suffix , this might parse it wrong, since we'd have to consult the resource tree to determine whether the resource path is /a or /a.b/c . Caution 2: This applies URL-decoding that replaces percent encoded characters (%[0-9a-fA-F][0-9a-fA-F]) by their decoded counterparts before saving the URL (except if it'll be of typeSlingUrl.UrlType.OTHER
, where we don't touch anything). If there are characters outside the URL range (say, the user types an url http://www/päth) these are left untouched for now. When the URL is reconstructed ingetUrl()
, such characters are encoded (to http://www/p%C3A4th). This might however lead to some rare trouble when there is something in there that looks like a percent encoded character but isn't meant as such, e.g. '%effect', but that won't work right in a browser, too.- Returns:
- this for builder style chaining
-
fromUrl
@NotNull public @NotNull SlingUrl fromUrl(@NotNull @NotNull String url, boolean decode)
Parses the url, possibly URL-decoding it when decode = true. Caution: if the url contains several periods like e.g. http://host/a.b/c.d/suffix , this might parse it wrong, since we'd have to consult the resource tree to determine whether the resource path is /a or /a.b/c .
-
fromUri
public SlingUrl fromUri(@NotNull @NotNull URI uri)
Assigns from the given uri, trying to parse extension and suffix from it. This avoids any issues with character encoding and broken URLs. Caution: if the url contains several periods like e.g. http://host/a.b/c.d/suffix , this * might parse it wrong, since we'd have to consult the resource tree to determine whether the resource path * is /a or /a.b/c .
-
fromPathOrUrl
public SlingUrl fromPathOrUrl(@NotNull @NotNull String pathOrUrl, boolean decode)
Initializes from an url or an absolute resource path, possibly URL-decoding it when decode = true. If pathOrUrl starts with a single slash, this is the same asfromPath(String)
, otherwise the same asfromUrl(String, boolean)
.- Returns:
- this for builder style chaining
-
fromPathOrUrl
public SlingUrl fromPathOrUrl(@NotNull @NotNull String pathOrUrl)
Initializes from an url or an absolute resource path. If pathOrUrl starts with a single slash, this is the same asfromPath(String)
, otherwise the same asfromUrl(String)
.- Returns:
- this for builder style chaining
-
isAbsolutePath
protected boolean isAbsolutePath(String pathOrUrl)
-
fromPath
@NotNull public @NotNull SlingUrl fromPath(@NotNull @NotNull String resourcePath)
Initializes the SlingUrl from a resource path, absolute or relative.- Parameters:
resourcePath
- an absolute or relative path- Returns:
- this for builder style chaining
-
fromRequest
@NotNull public @NotNull SlingUrl fromRequest(javax.servlet.http.HttpServletRequest request)
Initialzes the SlingUrl from a requests URL- Parameters:
request
- the HTTP request to use- Returns:
- this for builder style chaining
-
getRequest
@NotNull public @NotNull org.apache.sling.api.SlingHttpServletRequest getRequest()
-
isExternal
public boolean isExternal()
An external URL: we assume it's external when a scheme is set.
-
getResourcePath
@Nullable public @Nullable String getResourcePath()
For internal urls the path to the rendered resource. The path togetResource()
if that exists.
-
getResource
@Nullable public @Nullable org.apache.sling.api.resource.Resource getResource()
For internal urls: if this is a path to a resource, this returns it (suffix, selectors and parameters ignored, if present).
-
getContextPath
@Nullable public @Nullable String getContextPath()
If an internal path starts with theHttpServletRequest.getContextPath()
, this contains the context path, and the context path is removed fromgetPathAndName()
.
-
getPathAndName
@NotNull public @NotNull String getPathAndName()
The path to the file including the filename, but not the extension, selectors etc.
-
getPathAndNameExt
@NotNull public @NotNull String getPathAndNameExt()
The path to the file including the filename and the extension, but no selectors.
-
setPathAndNameExt
public SlingUrl setPathAndNameExt(@Nullable @Nullable String fullpath)
Sets the path, name and extension from the given e.g. resource path. Caution: if the fullpath contains several periods, the result can be different than you expect and broken.- Returns:
- this for builder style chaining
-
setPathAndName
public SlingUrl setPathAndName(@Nullable @Nullable String fullpath)
Sets the path and name from the given e.g. resource path, but does not touch thegetExtension()
. Alias forsetResourcePath(String)
- Parameters:
fullpath
- the path and filename to be set. We do not check for periods in there.- Returns:
- this for builder style chaining
-
setResourcePath
public SlingUrl setResourcePath(@Nullable @Nullable String resourcePath)
Sets the resource path encoded in the URL to the given path. This touches path andgetName()
, but not selectors and extension, works also when the resource path contains periods.- Parameters:
resourcePath
- an absolute or possibly relative path. We do not check for periods in there.- Returns:
- this for builder style chaining
-
resourcePath
public SlingUrl resourcePath(@Nullable @Nullable String resourcePath)
Sets the resource path encoded in the URL to the given path. This touches path andgetName()
, but not selectors and extension, works also when the resource path contains periods. Alias forsetResourcePath(String)
.- Parameters:
resourcePath
- an absolute or possibly relative path. We do not check for periods in there.- Returns:
- this for builder style chaining
-
setSelectors
public SlingUrl setSelectors(@Nullable @Nullable String selectors)
Sets the selectors to the given string - can contain multiple selectors separated with period.
-
clearSelectors
public SlingUrl clearSelectors()
-
getExtension
@Nullable public @Nullable String getExtension()
-
getSuffix
@Nullable public @Nullable String getSuffix()
-
suffix
public SlingUrl suffix(@Nullable @Nullable org.apache.sling.api.resource.Resource resource)
-
suffix
public SlingUrl suffix(@Nullable @Nullable org.apache.sling.api.resource.Resource resource, @Nullable @Nullable String extension)
-
getParameter
@Nullable public @Nullable String getParameter(@NotNull @NotNull String name)
- Returns:
- the first value of the parameter values if values are present;
an empty string if the value list is empty (parameter present but without a value);
null
if the parameter is not present
-
getParameterValues
@Nullable public @Nullable List<String> getParameterValues(@NotNull @NotNull String name)
- Returns:
- an unmodifiable List of the parameter values if present
-
getParameters
@NotNull public @NotNull Map<String,List<String>> getParameters()
Unmodifiable map of the contained parameters.This is unmodifiable since otherwise we would have to trust the user to call
clearTransients()
on every change.
-
addParameters
public SlingUrl addParameters(String parameterString, boolean decode)
Adds parameters parsed from an HTTP query string.
-
clearParameters
public SlingUrl clearParameters()
-
getFragment
@Nullable public @Nullable String getFragment()
The fragment part of the URL. Caution: this isn't available on all types.
-
setFragment
@NotNull public @NotNull SlingUrl setFragment(@Nullable @Nullable String fragment)
Sets the fragment. Caution: this isn't available on all types. Same asfragment(String)
.- Returns:
- this for builder style chaining
-
fragment
@NotNull public @NotNull SlingUrl fragment(@Nullable @Nullable String fragment)
Sets the fragment part of the URL. Caution: this isn't available on all types. Same assetFragment(String)
.- Returns:
- this for builder style chaining
-
equals
public boolean equals(Object other)
Just comparestoString()
- that is, the url.
-
getUrl
public String getUrl()
Builds the URL from its parts saved in the builder.
-
clearTransients
protected void clearTransients()
Internal reset method for the calculated transient values like the URL, called when anything changes.
-
getScheme
@Nullable public @Nullable String getScheme()
The scheme part of an URL. Caution: this isn't available on all types. To be able to represent protocol-relative URL, we distinguish here null and the empty string: null is no scheme applicable, as inSlingUrl.UrlType.RELATIVE
, empty string is a protocol-relative URL (e.g. //www/something.css).
-
setScheme
@NotNull public @NotNull SlingUrl setScheme(@Nullable @Nullable String scheme)
Sets the scheme. Caution: this isn't available on all types. To be able to represent protocol-relative URL, we distinguish here null and the empty string: null is no scheme, empty string is a protocol-relative URL (e.g. //www/something.css). Same asscheme(String)
.- Returns:
- this for builder style chaining
-
scheme
@NotNull public @NotNull SlingUrl scheme(@Nullable @Nullable String scheme)
Sets the scheme part of an URL. Caution: this isn't available on all types. Same assetScheme(String)
.- Returns:
- this for builder style chaining
-
getUsername
@Nullable public @Nullable String getUsername()
The username part of an URL. Caution: this isn't available on all types.
-
setUsername
@NotNull public @NotNull SlingUrl setUsername(@Nullable @Nullable String username)
Sets the username. Caution: this isn't available on all types. Same asusername(String)
.- Returns:
- this for builder style chaining
-
username
@NotNull public @NotNull SlingUrl username(@Nullable @Nullable String username)
Sets the username part of an URL. Caution: this isn't available on all types. Same assetUsername(String)
.- Returns:
- this for builder style chaining
-
getPassword
@Nullable public @Nullable String getPassword()
The password part of an URL. Caution: this isn't available on all types.
-
setPassword
@NotNull public @NotNull SlingUrl setPassword(@Nullable @Nullable String password)
Sets the password. Caution: this isn't available on all types. Same aspassword(String)
.- Returns:
- this for builder style chaining
-
password
@NotNull public @NotNull SlingUrl password(@Nullable @Nullable String password)
Sets the password part of an URL. Caution: this isn't available on all types. Same assetPassword(String)
.- Returns:
- this for builder style chaining
-
getHost
@Nullable public @Nullable String getHost()
The host part of the URL. Caution: this isn't available on all types.
-
setHost
@NotNull public @NotNull SlingUrl setHost(@Nullable @Nullable String host)
Sets the host part of the URL. Caution: this isn't available on all types. Same ashost(String)
.- Returns:
- this for builder style chaining
-
host
@NotNull public @NotNull SlingUrl host(@Nullable @Nullable String host)
Sets the host part of the URL. Caution: this isn't available on all types. Same assetHost(String)
.- Returns:
- this for builder style chaining
-
getPort
@Nullable public @Nullable Integer getPort()
The port part of the URL. Caution: this isn't available on all types.
-
setPort
@NotNull public @NotNull SlingUrl setPort(@Nullable @Nullable Integer port)
Sets the port. Caution: this isn't available on all types. Same asport(Integer)
.- Returns:
- this for builder style chaining
-
port
@NotNull public @NotNull SlingUrl port(@Nullable @Nullable Integer port)
Sets the port part of the URL. Caution: this isn't available on all types. Same assetPort(Integer)
.- Returns:
- this for builder style chaining
-
getType
@NotNull public @NotNull SlingUrl.UrlType getType()
The type of the URL. Caution: this isn't available on all types.
-
setType
@NotNull public @NotNull SlingUrl setType(@NotNull @NotNull SlingUrl.UrlType type)
Sets the type. Caution: this isn't available on all types. Same astype(UrlType)
.- Returns:
- this for builder style chaining
-
type
@NotNull public @NotNull SlingUrl type(@NotNull @NotNull SlingUrl.UrlType type)
Sets the type of the URL. Caution: this isn't available on all types. Same assetType(UrlType)
.- Returns:
- this for builder style chaining
-
getName
@Nullable public @Nullable String getName()
The filename; in case of type OTHER this contains the whole URL but the scheme and colon. Caution: this isn't available on all types.
-
setName
@NotNull public @NotNull SlingUrl setName(@Nullable @Nullable String name)
Sets the name. Caution: this isn't available on all types. Same asname(String)
.- Returns:
- this for builder style chaining
-
name
@NotNull public @NotNull SlingUrl name(@Nullable @Nullable String name)
Sets the filename; in case of type OTHER this contains the whole URL but the scheme and colon. Caution: this isn't available on all types. Same assetName(String)
.- Returns:
- this for builder style chaining
-
reset
public void reset()
-
buildUrl
protected String buildUrl()
-
parseUrl
protected void parseUrl(@NotNull @NotNull String url, boolean decode) throws IllegalArgumentException
- Throws:
IllegalArgumentException
-
assignFromGroups
protected void assignFromGroups(Matcher matcher, boolean decode, boolean hostAndPort)
-
parseParameters
protected void parseParameters(@NotNull @NotNull String parameterString, boolean decode)
-
getLinkMapper
protected static LinkMapper getLinkMapper(@NotNull @NotNull org.apache.sling.api.SlingHttpServletRequest request, @Nullable @Nullable LinkMapper linkMapper)
-
toDebugString
public String toDebugString()
Lists the internal parse results - mainly for debugging purposes.
-
-