Interface SlingUri

All Superinterfaces:
RequestPathInfo

@ProviderType public interface SlingUri extends RequestPathInfo

Represents an immutable URI in the same way as java.net.URI but is extended with Sling-specific URI parts (e.g. selectors). A SlingUri usually points to a resource but alternatively, can also contain an opaque URI like mailto: or javascript:. Use adjust(Consumer) or SlingUriBuilder to create new or modified Sling URIs.

Opposed to URI, the regular getters of SlingUri will not return decoded values, rather the values for user info, path, query and fragment are returned exactly as set before.

Since:
1.0.0 (Sling API Bundle 2.23.0)
  • Method Summary

    Modifier and Type
    Method
    Description
    default @NotNull SlingUri
    adjust(@NotNull Consumer<SlingUriBuilder> builderConsumer)
    Shortcut to adjust Sling URIs, e.g.
    @Nullable String
    Returns the extension.
    @Nullable String
    Returns the fragment.
    @Nullable String
    Returns the host.
    @Nullable String
    Returns the joint path of resource path, selectors, extension and suffix.
    @NotNull Map<String,String>
    Returns the path parameters.
    int
    Returns the port.
    @Nullable String
    Returns the query.
    @Nullable String
    Returns the resource path.
    @Nullable String
    Returns the scheme.
    @Nullable String
    Returns the scheme-specific part of the URI, compare with Javadoc of URI.
    @NotNull String[]
    Returns the selectors array.
    @Nullable String
    Returns the selector string.
    @Nullable String
    Returns the suffix part of the URI
    @Nullable Resource
    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 String
    Returns the user info.
    boolean
    Returns true the URI is an absolute URI.
    boolean
    Returns true if the URI has an absolute path starting with a slash ('/').
    boolean
    Returns true for opaque URIs like e.g. mailto:jon@example.com.
    boolean
    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
    Returns true if the URI is a relative path (no scheme and path does not start with '/').
    @NotNull String
    Returns the URI as String.
    @NotNull URI
    Returns the URI.
  • Method Details

    • toUri

      @NotNull @NotNull URI toUri()
      Returns the URI.
      Returns:
      the URI
    • toString

      @NotNull @NotNull String toString()
      Returns the URI as String.
      Overrides:
      toString in class Object
      Returns:
      the URI string
    • getScheme

      @Nullable @Nullable String getScheme()
      Returns the scheme.
      Returns:
      the scheme or null if not set
    • getUserInfo

      @Nullable @Nullable String getUserInfo()
      Returns the user info.
      Returns:
      the user info of the SlingUri or null if not set
    • getHost

      @Nullable @Nullable String getHost()
      Returns the host.
      Returns:
      returns the host of the SlingUri or null if not set
    • getPort

      int getPort()
      Returns the port.
      Returns:
      returns the port of the SlingUri or -1 if not set
    • getResourcePath

      @Nullable @Nullable String getResourcePath()
      Returns the resource path.
      Specified by:
      getResourcePath in interface RequestPathInfo
      Returns:
      returns the resource path or null if the URI does not contain a path.
    • getSelectorString

      @Nullable @Nullable String getSelectorString()
      Returns the selector string.
      Specified by:
      getSelectorString in interface RequestPathInfo
      Returns:
      returns the selector string or null if the URI does not contain selector(s) (in line with RequestPathInfo)
      See Also:
    • getSelectors

      @NotNull @NotNull String[] getSelectors()
      Returns the selectors array.
      Specified by:
      getSelectors in interface RequestPathInfo
      Returns:
      the selectors array (empty if the URI does not contain selector(s), never null)
      See Also:
    • getExtension

      @Nullable @Nullable String getExtension()
      Returns the extension.
      Specified by:
      getExtension in interface RequestPathInfo
      Returns:
      the extension or null if the URI does not contain an extension
    • getPathParameters

      @NotNull @NotNull Map<String,String> getPathParameters()
      Returns the path parameters.
      Returns:
      the path parameters or an empty Map if the URI does not contain any
    • getSuffix

      @Nullable @Nullable String getSuffix()
      Returns the suffix part of the URI
      Specified by:
      getSuffix in interface RequestPathInfo
      Returns:
      the suffix string or null if the URI does not contain a suffix
    • getPath

      @Nullable @Nullable String getPath()
      Returns the joint path of resource path, selectors, extension and suffix.
      Returns:
      the path or null if no path is set
    • getQuery

      @Nullable @Nullable String getQuery()
      Returns the query.
      Returns:
      the query part of the URI or null if the URI does not contain a query
    • getFragment

      @Nullable @Nullable String getFragment()
      Returns the fragment.
      Returns:
      the fragment or null if the URI does not contain a fragment
    • getSchemeSpecificPart

      @Nullable @Nullable String getSchemeSpecificPart()
      Returns the scheme-specific part of the URI, compare with Javadoc of URI.
      Returns:
      scheme specific part of the URI
    • getSuffixResource

      @Nullable @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
      Specified by:
      getSuffixResource in interface RequestPathInfo
      Returns:
      the suffix resource if available or null
    • isPath

      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)
      Returns:
      returns true for path URIs
    • isAbsolutePath

      boolean isAbsolutePath()
      Returns true if the URI has an absolute path starting with a slash ('/').
      Returns:
      true if the URI is an absolute path
    • isRelativePath

      boolean isRelativePath()
      Returns true if the URI is a relative path (no scheme and path does not start with '/').
      Returns:
      true if URI is a relative path
    • isAbsolute

      boolean isAbsolute()
      Returns true the URI is an absolute URI.
      Returns:
      true if the URI is an absolute URI containing a scheme.
    • isOpaque

      boolean isOpaque()
      Returns true for opaque URIs like e.g. mailto:jon@example.com.
      Returns:
      true if the URI is an opaque URI
    • adjust

      @NotNull default @NotNull SlingUri adjust(@NotNull @NotNull Consumer<SlingUriBuilder> builderConsumer)
      Shortcut to adjust Sling URIs, e.g. slingUri = slingUri.adjust(b -> b.setExtension("html")); .
      Parameters:
      builderConsumer - the consumer (e.g. b -> b.setExtension("html"))
      Returns:
      the adjusted SlingUri (new instance)