- java.lang.Object
-
- org.refcodes.web.Url
-
- All Implemented Interfaces:
org.refcodes.mixin.CredentialsAccessor
,org.refcodes.mixin.Dumpable
,org.refcodes.mixin.IdentityAccessor
,org.refcodes.mixin.PathAccessor
,org.refcodes.mixin.PortAccessor
,org.refcodes.mixin.SecretAccessor
,org.refcodes.net.IpAddressAccessor
,FragmentAccessor
,HostAccessor
,QueryFieldsAccessor
,SchemeAccessor
- Direct Known Subclasses:
UrlBuilder
public class Url extends Object implements org.refcodes.mixin.Dumpable, SchemeAccessor, HostAccessor, org.refcodes.net.IpAddressAccessor, org.refcodes.mixin.PortAccessor, org.refcodes.mixin.PathAccessor, QueryFieldsAccessor, FragmentAccessor, org.refcodes.mixin.CredentialsAccessor
TheUrl
class represents an immutable URL: An URL looks something like this: "scheme://[identity[:secret]@]host[:port][/path][?query][#fragment] In contrast to thejava.net
URL
, this URL also supports "relative" locators with neither a scheme nor a host declaration. If the relative locator starts with a "/" slash, then we assume not having a host being provided: "/path?query#fragment" When it does *not* start with a "/" slash, then we assume that the first element being the host: "[identity[:secret]@]host[:port]/path[?query][#fragment]"
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.refcodes.mixin.CredentialsAccessor
org.refcodes.mixin.CredentialsAccessor.CredentialsBuilder<B extends org.refcodes.mixin.CredentialsAccessor.CredentialsBuilder<B>>, org.refcodes.mixin.CredentialsAccessor.CredentialsMutator, org.refcodes.mixin.CredentialsAccessor.CredentialsProperty
-
Nested classes/interfaces inherited from interface org.refcodes.web.FragmentAccessor
FragmentAccessor.FragmentBuilder<B extends FragmentAccessor.FragmentBuilder<?>>, FragmentAccessor.FragmentMutator, FragmentAccessor.FragmentProperty
-
Nested classes/interfaces inherited from interface org.refcodes.web.HostAccessor
HostAccessor.HostBuilder<B extends HostAccessor.HostBuilder<?>>, HostAccessor.HostMutator, HostAccessor.HostProperty
-
Nested classes/interfaces inherited from interface org.refcodes.mixin.IdentityAccessor
org.refcodes.mixin.IdentityAccessor.IdentityBuilder<B extends org.refcodes.mixin.IdentityAccessor.IdentityBuilder<B>>, org.refcodes.mixin.IdentityAccessor.IdentityMutator, org.refcodes.mixin.IdentityAccessor.IdentityProperty
-
Nested classes/interfaces inherited from interface org.refcodes.net.IpAddressAccessor
org.refcodes.net.IpAddressAccessor.IpAddressBuilder<B extends org.refcodes.net.IpAddressAccessor.IpAddressBuilder<B>>, org.refcodes.net.IpAddressAccessor.IpAddressMutator, org.refcodes.net.IpAddressAccessor.IpAddressProperty
-
Nested classes/interfaces inherited from interface org.refcodes.mixin.PathAccessor
org.refcodes.mixin.PathAccessor.PathBuilder<B extends org.refcodes.mixin.PathAccessor.PathBuilder<?>>, org.refcodes.mixin.PathAccessor.PathMutator, org.refcodes.mixin.PathAccessor.PathProperty
-
Nested classes/interfaces inherited from interface org.refcodes.mixin.PortAccessor
org.refcodes.mixin.PortAccessor.PortBuilder<B extends org.refcodes.mixin.PortAccessor.PortBuilder<B>>, org.refcodes.mixin.PortAccessor.PortMutator, org.refcodes.mixin.PortAccessor.PortProperty
-
Nested classes/interfaces inherited from interface org.refcodes.web.QueryFieldsAccessor
QueryFieldsAccessor.QueryFieldsBuilder<B extends QueryFieldsAccessor.QueryFieldsBuilder<?>>, QueryFieldsAccessor.QueryFieldsMutator, QueryFieldsAccessor.QueryFieldsProperty
-
Nested classes/interfaces inherited from interface org.refcodes.web.SchemeAccessor
SchemeAccessor.SchemeBuilder<B extends SchemeAccessor.SchemeBuilder<B>>, SchemeAccessor.SchemeMutator, SchemeAccessor.SchemeProperty
-
-
Field Summary
Fields Modifier and Type Field Description protected String
_fragment
protected String
_host
protected String
_identity
protected int[]
_ipAddress
protected String
_path
protected int
_port
protected String
_protocol
protected FormFields
_queryFields
protected org.refcodes.data.Scheme
_scheme
protected String
_secret
-
Constructor Summary
Constructors Modifier Constructor Description protected
Url()
Default constructor.Url(String aUrl)
Url(String aProtocol, String aHost)
Constructs anUrl
with the common attributes.Url(String aProtocol, String aHost, int aPort)
Constructs anUrl
with the common attributes.Url(String aProtocol, String aHost, int aPort, String aPath)
Constructs anUrl
with the common attributes.Url(String aProtocol, String aHost, int aPort, String aPath, FormFields aQueryFields)
Constructs anUrl
with the common attributes.Url(String aProtocol, String aHost, int aPort, String aPath, FormFields aQueryFields, String aFragment)
Constructs anUrl
with the common attributes.Url(String aProtocol, String aHost, String aPath)
Constructs anUrl
with the common attributes.Url(String aProtocol, String aHost, String aPath, FormFields aQueryFields)
Constructs anUrl
with the common attributes.Url(String aProtocol, String aHost, String aPath, FormFields aQueryFields, String aFragment)
Constructs anUrl
with the common attributes.Url(String aUrl, FormFields aQueryFields)
Url(String aUrl, FormFields aQueryFields, String aFragment)
Url(URL aURL)
Url(org.refcodes.data.Scheme aScheme, String aHost)
Constructs anUrl
with the common attributes.Url(org.refcodes.data.Scheme aScheme, String aHost, int aPort)
Constructs anUrl
with the common attributes.Url(org.refcodes.data.Scheme aScheme, String aHost, int aPort, String aPath)
Constructs anUrl
with the common attributes.Url(org.refcodes.data.Scheme aScheme, String aHost, int aPort, String aPath, FormFields aQueryFields)
Constructs anUrl
with the common attributes.Url(org.refcodes.data.Scheme aScheme, String aHost, int aPort, String aPath, FormFields aQueryFields, String aFragment)
Constructs anUrl
with the common attributes.Url(org.refcodes.data.Scheme aScheme, String aHost, String aPath)
Constructs anUrl
with the common attributes.Url(org.refcodes.data.Scheme aScheme, String aHost, String aPath, FormFields aQueryFields)
Constructs anUrl
with the common attributes.Url(org.refcodes.data.Scheme aScheme, String aHost, String aPath, FormFields aQueryFields, String aFragment)
Constructs anUrl
with the common attributes.Url(Url aUrl)
Url(Url aUrl, String... aPaths)
Url(Url aUrl, Url aOtherUrl)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
fromUrl(String aUrl)
protected void
fromURL(URL aUrl)
String
getFragment()
Retrieves the fragment from the fragment property.String
getHost()
Retrieves the host from the host property.String
getIdentity()
int[]
getIpAddress()
String
getPath()
int
getPort()
FormFields
getQueryFields()
Retrieves the request Query-Fields from the request Query-Fields property.org.refcodes.data.Scheme
getScheme()
Retrieves the UrlScheme from the URL scheme.String
getSecret()
protected void
setHost(String aHost)
protected void
setIpAddress(int[] aIpAddress)
protected void
setPath(String aPath)
protected void
setPort(int aPort)
protected void
setProtocol(String aProtocol)
protected void
setScheme(org.refcodes.data.Scheme aScheme)
String
toHost()
Returns the "host" depending on whether an IP-Address has been provided or a host name.String
toHttpUrl()
String
toLocator()
Creates the locator part from theUrl
instance's state, excluding the fragment or the query fields.String
toProtocol()
Retrieves the protocol representation from theScheme
.String
toString()
protected static String
toTruncatePath(String aPath)
Removes any leading and trailing path delimiters (as ofDelimiter.PATH
).protected static String
toTruncatePathPrefix(String aPath)
Removes any leading path delimiters (as ofDelimiter.PATH
).protected static String
toTruncatePathSuffix(String aPath)
Removes any trailing path delimiters (as ofDelimiter.PATH
).URL
toURL()
-
-
-
Field Detail
-
_scheme
protected org.refcodes.data.Scheme _scheme
-
_protocol
protected String _protocol
-
_host
protected String _host
-
_ipAddress
protected int[] _ipAddress
-
_path
protected String _path
-
_port
protected int _port
-
_queryFields
protected FormFields _queryFields
-
_identity
protected String _identity
-
_secret
protected String _secret
-
_fragment
protected String _fragment
-
-
Constructor Detail
-
Url
protected Url()
Default constructor. Make sure to set required attributes for a valid URL.
-
Url
public Url(String aUrl) throws MalformedURLException
- Parameters:
aUrl
- The URLString
to be parsed. The URL consists of the scheme (protocol), the identify and the secret (optional), the host as well as an optional port and the (optional) path.- Throws:
MalformedURLException
- in case the provided URL is considered being malformed.
-
Url
public Url(String aUrl, FormFields aQueryFields) throws MalformedURLException
- Parameters:
aUrl
- The URLString
to be parsed. The URL consists of the scheme (protocol), the identify and the secret (optional), the host as well as an optional port and the (optional) path.aQueryFields
- The Query-Fields to be used for the HTTP Query-String.- Throws:
MalformedURLException
- in case the provided URL is considered being malformed.
-
Url
public Url(String aUrl, FormFields aQueryFields, String aFragment) throws MalformedURLException
- Parameters:
aUrl
- The URLString
to be parsed. The URL consists of the scheme (protocol), the identify and the secret (optional), the host as well as an optional port and the (optional) path.aQueryFields
- The Query-Fields to be used for the HTTP Query-String.aFragment
- The fragment to be set.- Throws:
MalformedURLException
- in case the provided URL is considered being malformed.
-
Url
public Url(org.refcodes.data.Scheme aScheme, String aHost)
Constructs anUrl
with the common attributes.- Parameters:
aScheme
- TheScheme
(e.g. HTTP or HTTPS) to be used for the destination URL.aHost
- The host to which the destination URL is to point to.
-
Url
public Url(org.refcodes.data.Scheme aScheme, String aHost, int aPort)
Constructs anUrl
with the common attributes.- Parameters:
aScheme
- TheScheme
(e.g. HTTP or HTTPS) to be used for the destination URL.aHost
- The host to which the destination URL is to point to.aPort
- The port to be used when connecting to the host.
-
Url
public Url(org.refcodes.data.Scheme aScheme, String aHost, int aPort, String aPath)
Constructs anUrl
with the common attributes.- Parameters:
aScheme
- TheScheme
(e.g. HTTP or HTTPS) to be used for the destination URL.aHost
- The host to which the destination URL is to point to.aPort
- The port to be used when connecting to the host.aPath
- The path on the host to which the base destination URL is to point to.
-
Url
public Url(org.refcodes.data.Scheme aScheme, String aHost, int aPort, String aPath, FormFields aQueryFields)
Constructs anUrl
with the common attributes.- Parameters:
aScheme
- TheScheme
(e.g. HTTP or HTTPS) to be used for the destination URL.aHost
- The host to which the destination URL is to point to.aPort
- The port to be used when connecting to the host.aPath
- The path on the host to which the base destination URL is to point to.aQueryFields
- The Query-Fields to be used for the HTTP Query-String.
-
Url
public Url(org.refcodes.data.Scheme aScheme, String aHost, int aPort, String aPath, FormFields aQueryFields, String aFragment)
Constructs anUrl
with the common attributes.- Parameters:
aScheme
- TheScheme
(e.g. HTTP or HTTPS) to be used for the destination URL.aHost
- The host to which the destination URL is to point to.aPort
- The port to be used when connecting to the host.aPath
- The path on the host to which the base destination URL is to point to.aFragment
- The fragment to be set.aQueryFields
- The Query-Fields to be used for the HTTP Query-String.
-
Url
public Url(String aProtocol, String aHost)
Constructs anUrl
with the common attributes.- Parameters:
aProtocol
- The protocolString
(e.g. "http://" or "https://") to be used for the destination URL.aHost
- The host to which the destination URL is to point to.
-
Url
public Url(String aProtocol, String aHost, int aPort)
Constructs anUrl
with the common attributes.- Parameters:
aProtocol
- The protocolString
(e.g. "http://" or "https://") to be used for the destination URL.aHost
- The host to which the destination URL is to point to.aPort
- The port to be used when connecting to the host.
-
Url
public Url(String aProtocol, String aHost, int aPort, String aPath)
Constructs anUrl
with the common attributes.- Parameters:
aProtocol
- The protocolString
(e.g. "http://" or "https://") to be used for the destination URL.aHost
- The host to which the destination URL is to point to.aPort
- The port to be used when connecting to the host.aPath
- The path on the host to which the base destination URL is to point to.
-
Url
public Url(String aProtocol, String aHost, int aPort, String aPath, FormFields aQueryFields)
Constructs anUrl
with the common attributes.- Parameters:
aProtocol
- The protocolString
(e.g. "http://" or "https://") to be used for the destination URL.aHost
- The host to which the destination URL is to point to.aPort
- The port to be used when connecting to the host.aPath
- The path on the host to which the base destination URL is to point to.aQueryFields
- The Query-Fields to be used for the HTTP Query-String.
-
Url
public Url(String aProtocol, String aHost, int aPort, String aPath, FormFields aQueryFields, String aFragment)
Constructs anUrl
with the common attributes.- Parameters:
aProtocol
- The protocolString
(e.g. "http://" or "https://") to be used for the destination URL.aHost
- The host to which the destination URL is to point to.aPort
- The port to be used when connecting to the host.aPath
- The path on the host to which the base destination URL is to point to.aFragment
- The fragment to be set.aQueryFields
- The Query-Fields to be used for the HTTP Query-String.
-
Url
public Url(org.refcodes.data.Scheme aScheme, String aHost, String aPath)
Constructs anUrl
with the common attributes.- Parameters:
aScheme
- TheScheme
(e.g. HTTP or HTTPS) to be used for the destination URL.aHost
- The host to which the destination URL is to point to.aPath
- The path on the host to which the base destination URL is to point to.
-
Url
public Url(org.refcodes.data.Scheme aScheme, String aHost, String aPath, FormFields aQueryFields)
Constructs anUrl
with the common attributes.- Parameters:
aScheme
- TheScheme
(e.g. HTTP or HTTPS) to be used for the destination URL.aHost
- The host to which the destination URL is to point to.aPath
- The path on the host to which the base destination URL is to point to.aQueryFields
- The Query-Fields to be used for the HTTP Query-String.
-
Url
public Url(org.refcodes.data.Scheme aScheme, String aHost, String aPath, FormFields aQueryFields, String aFragment)
Constructs anUrl
with the common attributes.- Parameters:
aScheme
- TheScheme
(e.g. HTTP or HTTPS) to be used for the destination URL.aHost
- The host to which the destination URL is to point to.aPath
- The path on the host to which the base destination URL is to point to.aQueryFields
- The Query-Fields to be used for the HTTP Query-String.aFragment
- The fragment to be set.
-
Url
public Url(String aProtocol, String aHost, String aPath)
Constructs anUrl
with the common attributes.- Parameters:
aProtocol
- The protocolString
(e.g. "http://" or "https://") to be used for the destination URL.aHost
- The host to which the destination URL is to point to.aPath
- The path on the host to which the base destination URL is to point to.
-
Url
public Url(String aProtocol, String aHost, String aPath, FormFields aQueryFields)
Constructs anUrl
with the common attributes.- Parameters:
aProtocol
- The protocolString
(e.g. "http://" or "https://") to be used for the destination URL.aHost
- The host to which the destination URL is to point to.aPath
- The path on the host to which the base destination URL is to point to.aQueryFields
- The Query-Fields to be used for the HTTP Query-String.
-
Url
public Url(String aProtocol, String aHost, String aPath, FormFields aQueryFields, String aFragment)
Constructs anUrl
with the common attributes.- Parameters:
aProtocol
- The protocolString
(e.g. "http://" or "https://") to be used for the destination URL.aHost
- The host to which the destination URL is to point to.aPath
- The path on the host to which the base destination URL is to point to.aQueryFields
- The Query-Fields to be used for the HTTP Query-String.aFragment
- The fragment to be set.
-
-
Method Detail
-
getFragment
public String getFragment()
Retrieves the fragment from the fragment property.- Specified by:
getFragment
in interfaceFragmentAccessor
- Returns:
- The fragment stored by the fragment property.
-
getHost
public String getHost()
Retrieves the host from the host property.- Specified by:
getHost
in interfaceHostAccessor
- Returns:
- The host stored by the host property.
-
getIdentity
public String getIdentity()
- Specified by:
getIdentity
in interfaceorg.refcodes.mixin.IdentityAccessor
-
getIpAddress
public int[] getIpAddress()
- Specified by:
getIpAddress
in interfaceorg.refcodes.net.IpAddressAccessor
-
getPath
public String getPath()
- Specified by:
getPath
in interfaceorg.refcodes.mixin.PathAccessor
-
getPort
public int getPort()
- Specified by:
getPort
in interfaceorg.refcodes.mixin.PortAccessor
-
getQueryFields
public FormFields getQueryFields()
Retrieves the request Query-Fields from the request Query-Fields property.- Specified by:
getQueryFields
in interfaceQueryFieldsAccessor
- Returns:
- The request Query-Fields stored by the request Query-Fields property.
-
getScheme
public org.refcodes.data.Scheme getScheme()
Retrieves the UrlScheme from the URL scheme.- Specified by:
getScheme
in interfaceSchemeAccessor
- Returns:
- The UrlScheme stored by the URL scheme.
-
getSecret
public String getSecret()
- Specified by:
getSecret
in interfaceorg.refcodes.mixin.SecretAccessor
-
toProtocol
public String toProtocol()
Retrieves the protocol representation from theScheme
. In case of a scheme unknown by theScheme
enumeration, thenSchemeAccessor.getScheme()
might return null whilstSchemeAccessor.toProtocol()
still retrieves the unknown scheme's protocol representation (as ofSchemeAccessor.SchemeMutator.setProtocol(String)
).- Specified by:
toProtocol
in interfaceSchemeAccessor
- Returns:
- The protocol representation for the URL.
-
toHost
public String toHost()
Returns the "host" depending on whether an IP-Address has been provided or a host name.- Returns:
- The determined host.
-
toLocator
public String toLocator()
Creates the locator part from theUrl
instance's state, excluding the fragment or the query fields.- Returns:
- The locator for the given
Url
.
-
toURL
public URL toURL() throws MalformedURLException
- Returns:
- The according
URL
instance. - Throws:
MalformedURLException
- thrown in case the state of yourUrl
instance cannot be used to construct a validURL
, you may be missing some properties.
-
fromUrl
protected void fromUrl(String aUrl) throws MalformedURLException
- Parameters:
aUrl
- The URL from which to determine the state.- Throws:
MalformedURLException
- in case the provided URL is considered being malformed.
-
fromURL
protected void fromURL(URL aUrl)
-
setScheme
protected void setScheme(org.refcodes.data.Scheme aScheme)
-
setProtocol
protected void setProtocol(String aProtocol)
-
setHost
protected void setHost(String aHost)
-
setIpAddress
protected void setIpAddress(int[] aIpAddress)
-
setPort
protected void setPort(int aPort)
-
setPath
protected void setPath(String aPath)
-
toTruncatePathPrefix
protected static String toTruncatePathPrefix(String aPath)
Removes any leading path delimiters (as ofDelimiter.PATH
).- Parameters:
aPath
- The path to be processed.- Returns:
- The path without any leading path delimiters.
-
toTruncatePathSuffix
protected static String toTruncatePathSuffix(String aPath)
Removes any trailing path delimiters (as ofDelimiter.PATH
).- Parameters:
aPath
- The path to be processed.- Returns:
- The path without any trailing path delimiters.
-
-