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
Resourceparameter, 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 classSlingUrl.UrlTypeCharacterizes the type of the URL.
-
Field Summary
Fields Modifier and Type Field Description protected static PatternABSOLUTE_PATH_PATTERNprotected StringcontextPathprotected Stringextensionprotected static PatternFILE_SCHEMEprotected static PatternFILE_SCHEME_PATTERNprotected static PatternFILE_URL_PATTERNprotected Stringfragmentprotected Stringhostprotected static PatternHTTP_SCHEMEprotected static PatternHTTP_SCHEME_PATTERNprotected static PatternHTTP_URL_PATTERNRegex matching various variants of Sling-URLs.protected LinkMapperlinkMapperprotected StringnameThe filename; if the url could not be parsed (SlingUrl.UrlType.SPECIALorSlingUrl.UrlType.OTHER), this contains the url without the scheme.protected LinkedHashMap<String,List<String>>parametersprotected Stringpasswordprotected StringpathContains the path inclusive leading and trailing / , not the file/resource itself: for /a/b/c it's /a/b/ .protected Integerportprotected static PatternRELATIVE_PATH_PATTERNprotected org.apache.sling.api.SlingHttpServletRequestrequestprotected org.apache.sling.api.resource.Resourceresourceprotected StringresourcePathprotected StringschemeThe scheme of the URL.protected static PatternSCHEME_PATTERNstatic StringSCHEME_PROTOCOL_RELATIVE_URLMarker forgetScheme()for a protocol relative URL, e.g.protected List<String>selectorsprotected static PatternSPECIAL_SCHEMEprotected Stringsuffixprotected SlingUrl.UrlTypetypeprotected Stringusernameprotected static PatternUSERNAMEPASSWORD
-
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 SlingUrladdParameter(String name, String... value)SlingUrladdParameters(String parameterString, boolean decode)Adds parameters parsed from an HTTP query string.SlingUrladdSelector(@Nullable String... value)protected voidassignFromGroups(Matcher matcher, boolean decode, boolean hostAndPort)protected StringbuildUrl()SlingUrlclearParameters()SlingUrlclearSelectors()protected voidclearTransients()Internal reset method for the calculated transient values like the URL, called when anything changes.SlingUrlclone()protected Stringdecode(String value, boolean decode)booleanequals(Object other)Just comparestoString()- that is, the url.SlingUrlextension(@Nullable String extension)@NotNull SlingUrlfragment(@Nullable String fragment)Sets the fragment part of the URL.@NotNull SlingUrlfromPath(@NotNull String resourcePath)Initializes the SlingUrl from a resource path, absolute or relative.SlingUrlfromPathOrUrl(@NotNull String pathOrUrl)Initializes from an url or an absolute resource path.SlingUrlfromPathOrUrl(@NotNull String pathOrUrl, boolean decode)Initializes from an url or an absolute resource path, possibly URL-decoding it when decode = true.@NotNull SlingUrlfromRequest(javax.servlet.http.HttpServletRequest request)Initialzes the SlingUrl from a requests URLSlingUrlfromUri(@NotNull URI uri)Assigns from the given uri, trying to parse extension and suffix from it.@NotNull SlingUrlfromUrl(@NotNull String url)Parses the url.@NotNull SlingUrlfromUrl(@NotNull String url, boolean decode)Parses the url, possibly URL-decoding it when decode = true.@Nullable StringgetContextPath()If an internal path starts with theHttpServletRequest.getContextPath(), this contains the context path, and the context path is removed fromgetPathAndName().@Nullable StringgetExtension()@Nullable StringgetFragment()The fragment part of the URL.@Nullable StringgetHost()The host part of the URL.protected static LinkMappergetLinkMapper(@NotNull org.apache.sling.api.SlingHttpServletRequest request, @Nullable LinkMapper linkMapper)@Nullable StringgetName()The filename; in case of type OTHER this contains the whole URL but the scheme and colon.@Nullable StringgetParameter(@NotNull String name)@NotNull Map<String,List<String>>getParameters()Unmodifiable map of the contained parameters.@Nullable List<String>getParameterValues(@NotNull String name)@Nullable StringgetPassword()The password part of an URL.@NotNull StringgetPathAndName()The path to the file including the filename, but not the extension, selectors etc.@NotNull StringgetPathAndNameExt()The path to the file including the filename and the extension, but no selectors.@Nullable IntegergetPort()The port part of the URL.@NotNull org.apache.sling.api.SlingHttpServletRequestgetRequest()@Nullable org.apache.sling.api.resource.ResourcegetResource()For internal urls: if this is a path to a resource, this returns it (suffix, selectors and parameters ignored, if present).@Nullable StringgetResourcePath()For internal urls the path to the rendered resource.@Nullable StringgetScheme()The scheme part of an URL.@Nullable StringgetSuffix()@NotNull SlingUrl.UrlTypegetType()The type of the URL.StringgetUrl()Builds the URL from its parts saved in the builder.@Nullable StringgetUsername()The username part of an URL.inthashCode()@NotNull SlingUrlhost(@Nullable String host)Sets the host part of the URL.protected booleanisAbsolutePath(String pathOrUrl)booleanisExternal()An external URL: we assume it's external when a scheme is set.@NotNull SlingUrlname(@Nullable String name)Sets the filename; in case of type OTHER this contains the whole URL but the scheme and colon.SlingUrlparameter(String name, String... value)SlingUrlparameters(String parameterString)protected voidparseParameters(@NotNull String parameterString, boolean decode)protected voidparseUrl(@NotNull String url, boolean decode)@NotNull SlingUrlpassword(@Nullable String password)Sets the password part of an URL.@NotNull SlingUrlport(@Nullable Integer port)Sets the port part of the URL.SlingUrlremoveParameter(String name)SlingUrlremoveSelector(String... value)voidreset()SlingUrlresourcePath(@Nullable String resourcePath)Sets the resource path encoded in the URL to the given path.@NotNull SlingUrlscheme(@Nullable String scheme)Sets the scheme part of an URL.SlingUrlselector(@Nullable String... value)SlingUrlselectors(@Nullable String selectors)SlingUrlsetExtension(@Nullable String extension)@NotNull SlingUrlsetFragment(@Nullable String fragment)Sets the fragment.@NotNull SlingUrlsetHost(@Nullable String host)Sets the host part of the URL.@NotNull SlingUrlsetName(@Nullable String name)Sets the name.SlingUrlsetParameter(String name, String... value)SlingUrlsetParameters(String parameterString, boolean decode)@NotNull SlingUrlsetPassword(@Nullable String password)Sets the password.SlingUrlsetPathAndName(@Nullable String fullpath)Sets the path and name from the given e.g.SlingUrlsetPathAndNameExt(@Nullable String fullpath)Sets the path, name and extension from the given e.g.@NotNull SlingUrlsetPort(@Nullable Integer port)Sets the port.SlingUrlsetResourcePath(@Nullable String resourcePath)Sets the resource path encoded in the URL to the given path.@NotNull SlingUrlsetScheme(@Nullable String scheme)Sets the scheme.SlingUrlsetSelector(String... value)SlingUrlsetSelectors(@Nullable String selectors)Sets the selectors to the given string - can contain multiple selectors separated with period.SlingUrlsetSuffix(@Nullable String suffix)@NotNull SlingUrlsetType(@NotNull SlingUrl.UrlType type)Sets the type.@NotNull SlingUrlsetUsername(@Nullable String username)Sets the username.SlingUrlsuffix(@Nullable String suffix)SlingUrlsuffix(@Nullable org.apache.sling.api.resource.Resource resource)SlingUrlsuffix(@Nullable org.apache.sling.api.resource.Resource resource, @Nullable String extension)StringtoDebugString()Lists the internal parse results - mainly for debugging purposes.StringtoString()Same asgetUrl().@NotNull SlingUrltype(@NotNull SlingUrl.UrlType type)Sets the type of the URL.@NotNull SlingUrlusername(@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.SPECIALorSlingUrl.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);
nullif 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.
-
-