Package org.faceless.publisher.type
Class URL2
java.lang.Object
org.faceless.publisher.type.URL2
- All Implemented Interfaces:
Serializable
A replacement for the
URI
class that always try to parse the URI
and not throw a URISyntaxException, ever. It will correctly resolve
relative paths for "jar" URLs, and function based on the spec at
https://tools.ietf.org/html/rfc3986 and
Two URLs are considered equal if they have the same string values.
This explicitly excludes link-parameters from the comparison- See Also:
-
Constructor Summary
ConstructorDescriptionURL2
(String scheme, String userInfo, String host, int port, String path, String query, String fragment) Create a URL from the specified parameters All parameters are supplied unescaped.Create an opaque URL from the specified parameters All parameters are supplied unescaped.Create a new URL2 that is a clone of the supplied URICreate a new URL2 that is a clone of the supplied URLCreate a new URL2 that is a clone of the supplied value -
Method Summary
Modifier and TypeMethodDescriptionboolean
Returns the decoded authority component of this URL.Returns the decoded fragment in this URL, or null if there is no fragment.Return a Map of the "fragment parameters" for this URL.getHost()
Returns the host in this URL, or null if there is no host.Get a value previously set by#setParameter
getPath()
Returns the decoded path of this URL, or null if there is no path.int
getPort()
Returns the port in this URL, or -1 if there is no port.getQuery()
Returns the decoded query in this URL, or null if there is no query.Return a Map of the query parameters for this URL, or an empty Map if there are noneReturns the raw scheme-specific part of this URL, before it has been escape-decodedReturns the scheme of this URL.Returns the scheme-specific part of this URL.Returns the decoded userinfo in this URL, or null if there is no userinfo.int
hashCode()
boolean
Tells whether or not this URL is absolute.boolean
Return true if this URL is a fragment onlyboolean
isOpaque()
Tells whether or not this URL is opaque.boolean
isSameDocument
(URL2 uri) Return true if this URL is, or is a fragment of the base URL.boolean
Return whether the URL scheme is a file scheme - not local and not network.boolean
Return whether the URL scheme is "local", which is defined in https://fetch.spec.whatwg.org/#local-schem as "about", "blob" or "data".boolean
Return whether the URL scheme is a network scheme (currently http, https, ftp) and therefore subject to CORSboolean
Return whether the URL scheme is secured by TLS.Return a new URL which is the normalized equivalent of this URLstatic URL2
Create a URL from the specified String, or return null if it is so invalid it's beyond salvagerelativize
(URL2 uri, boolean safe) Relativize the supplied URL aginst the current one.Constructs a new URL by parsing the given string and then resolving it against this URL.setFragment
(String fragment) Set the fragment on this URLsetFragmentParameters
(Map<String, List<String>> params) Set the Fragment to be the supplied set of fragment parametersSet the query on this URLsetUserInfo
(String userInfo) Set the userInfo on this URLReturn the "origin" version of this URL; just the scheme, host and port.Return the same value astoString()
, but with any password value in the userinfo string replaced with asteriskstoString()
toURI()
Convert this URL2 to aURI
, or return null if it is not possible.toURL()
Convert this URL2 to aURL
.
-
Constructor Details
-
URL2
public URL2(String scheme, String userInfo, String host, int port, String path, String query, String fragment) Create a URL from the specified parameters All parameters are supplied unescaped.- Parameters:
scheme
- the scheme, or nulluserInfo
- the user-info for authentcation, or nullhost
- the host, or nullport
- the port, or -1 to leave this unspecifiedpath
- the path, or nullquery
- the query string excluding the question-mark, or nullfragment
- the fragment excluding the hash, or null
-
URL2
Create an opaque URL from the specified parameters All parameters are supplied unescaped.- Parameters:
scheme
- the scheme, or nullssp
- the scheme-specific part, or nullquery
- the query string excluding the question0mark, or nullfragment
- the fragment excluding the hash, or null
-
URL2
Create a new URL2 that is a clone of the supplied value -
URL2
Create a new URL2 that is a clone of the supplied URI- Parameters:
uri
- the uri
-
URL2
Create a new URL2 that is a clone of the supplied URL- Parameters:
url
- the url
-
-
Method Details
-
parse
Create a URL from the specified String, or return null if it is so invalid it's beyond salvage -
toURI
Convert this URL2 to aURI
, or return null if it is not possible. -
toURL
Convert this URL2 to aURL
.- Throws:
IllegalArgumentException
- If this URL is not absoluteMalformedURLException
- If a protocol handler for the URL could not be found, or if some other error occurred while constructing the URL
-
getScheme
Returns the scheme of this URL. -
getAuthority
Returns the decoded authority component of this URL. -
getUserInfo
Returns the decoded userinfo in this URL, or null if there is no userinfo. -
getHost
Returns the host in this URL, or null if there is no host. -
getPort
public int getPort()Returns the port in this URL, or -1 if there is no port. -
getPath
Returns the decoded path of this URL, or null if there is no path. -
getSchemeSpecificPart
Returns the scheme-specific part of this URL. -
getRawSchemeSpecificPart
Returns the raw scheme-specific part of this URL, before it has been escape-decoded -
getQuery
Returns the decoded query in this URL, or null if there is no query. The returned string does not include the leading query character. -
getQueryParameters
Return a Map of the query parameters for this URL, or an empty Map if there are none -
getFragmentParameters
Return a Map of the "fragment parameters" for this URL. These are identical to Query parameters but defined on the Fragment - for example, "path.svg#xwwh=0,0,20,50&t=40,50" -
setFragmentParameters
Set the Fragment to be the supplied set of fragment parameters -
getFragment
Returns the decoded fragment in this URL, or null if there is no fragment. The returned string does not include the leading hash character. -
isAbsolute
public boolean isAbsolute()Tells whether or not this URL is absolute. -
isFragmentOnly
public boolean isFragmentOnly()Return true if this URL is a fragment only -
isOpaque
public boolean isOpaque()Tells whether or not this URL is opaque. -
isSameDocument
Return true if this URL is, or is a fragment of the base URL. The base URL may be null, in which case the URL must be a fragment only- Parameters:
uri
- if not null, the URL which this URL is being tested against
-
resolve
Constructs a new URL by parsing the given string and then resolving it against this URL. The value "#" is a quick way of removing the fragment from the supplied URL. -
normalize
Return a new URL which is the normalized equivalent of this URL -
relativize
Relativize the supplied URL aginst the current one.
Where we have
http://a.com/b/c
and relativizehttp://a.com/a/d
, it's unclear if "c" is a folder (in which case the path is "../d" or "c" is a file (in which case the path is "d"). This is the safe flag:- safe - don't risk it. The case above gives "/a/d". This matches
URI
, and always gives correct results, but the path will begin with a slash. - short - if the path ends in a slash it's a folder, otherwise its a file. The result will be shorter, but possibly incorrect.
If this is is a file URL and the file exists, we can resolve this automatically, but otherwise the "safe" flag will be used to determine which strategy to use.
Opaque URLs are never relativized. If the destination is already relative, it's returned.
- Parameters:
uri
- the URL to relativize against this URLsafe
- whether to use the "safe" strategy- Returns:
- the relative URL, or "uri" if it can't be determined
- safe - don't risk it. The case above gives "/a/d". This matches
-
setFragment
Set the fragment on this URL- Returns:
- this
-
setQuery
Set the query on this URL- Returns:
- this
-
setUserInfo
Set the userInfo on this URL- Returns:
- this
-
getLinkParameters
Get a value previously set by#setParameter
-
toPublicString
Return the same value astoString()
, but with any password value in the userinfo string replaced with asterisks -
toString
-
toOriginString
Return the "origin" version of this URL; just the scheme, host and port. If this URL is not a network-resolving URL, return null -
isSchemeSecure
public boolean isSchemeSecure()Return whether the URL scheme is secured by TLS. Returns true for "https", false otherwise. Used byEgressFilter
to make decisions. -
isSchemeLocal
public boolean isSchemeLocal()Return whether the URL scheme is "local", which is defined in https://fetch.spec.whatwg.org/#local-schem as "about", "blob" or "data". Used byEgressFilter
to make decisions. -
isSchemeFileBased
public boolean isSchemeFileBased()Return whether the URL scheme is a file scheme - not local and not network. -
isSchemeNetwork
public boolean isSchemeNetwork()Return whether the URL scheme is a network scheme (currently http, https, ftp) and therefore subject to CORS -
hashCode
public int hashCode() -
equals
-