Class URLWrapper
- java.lang.Object
-
- net.lenni0451.commons.httpclient.utils.URLWrapper
-
public class URLWrapper extends java.lang.Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classURLWrapper.ParameterclassURLWrapper.QueryParametersWrapperclassURLWrapper.QueryWrapperDeprecated.
-
Constructor Summary
Constructors Constructor Description URLWrapper()URLWrapper(java.lang.String url)Deprecated.URLWrapper(java.net.URI uri)URLWrapper(java.net.URL url)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static URLWrapperempty()Create a new empty URLWrapper.java.lang.StringgetFragment()java.lang.StringgetFragmentOr(java.lang.String defaultFragment)java.lang.StringgetHost()java.lang.StringgetHostOr(java.lang.String defaultHost)java.lang.StringgetPath()java.lang.StringgetPathOr(java.lang.String defaultPath)intgetPort()intgetPortOr(int defaultPort)java.lang.StringgetProtocol()java.lang.StringgetProtocolOr(java.lang.String defaultProtocol)java.lang.StringgetQuery()java.lang.StringgetQueryOr(java.lang.String defaultQuery)java.lang.StringgetReference()Deprecated.java.lang.StringgetUserInfo()java.lang.StringgetUserInfoOr(java.lang.String defaultUserInfo)booleanhasFragment()booleanhasHost()booleanhasPath()booleanhasPort()booleanhasProtocol()booleanhasQuery()booleanhasUserInfo()static URLWrapperof(java.lang.String url)Deprecated.static URLWrapperof(java.net.URI uri)Create a new URLWrapper from anURI.static URLWrapperof(java.net.URL url)Create a new URLWrapper from anURL.static URLWrapperofURI(java.lang.String uri)Create a new URLWrapper from a URI string.static URLWrapperofURL(java.lang.String url)Create a new URLWrapper from a URL string.URLWrappersetFragment(java.lang.String fragment)Set the fragment of the URL (e.g.URLWrappersetHost(java.lang.String host)Set the host of the URL (e.g.URLWrappersetPath(java.lang.String path)Set the path of the URL (e.g.URLWrappersetPort(int port)Set the port of the URL (e.g.URLWrappersetProtocol(java.lang.String protocol)Set the protocol of the URL (e.g.URLWrappersetQuery(java.lang.String query)Set the query of the URL (e.g.URLWrappersetReference(java.lang.String reference)Deprecated.URLWrappersetUserInfo(java.lang.String userInfo)Set the user info of the URL (e.g.java.lang.StringtoString()java.net.URItoURI()java.net.URLtoURL()URLWrapper.QueryWrapperwrapQuery()Deprecated.URLWrapper.QueryParametersWrapperwrapQueryParameters()Get a wrapper for the query parameters.
-
-
-
Constructor Detail
-
URLWrapper
public URLWrapper()
-
URLWrapper
@Deprecated @ScheduledForRemoval public URLWrapper(java.lang.String url) throws java.net.MalformedURLExceptionDeprecated.- Throws:
java.net.MalformedURLException
-
URLWrapper
public URLWrapper(java.net.URL url)
-
URLWrapper
public URLWrapper(java.net.URI uri)
-
-
Method Detail
-
empty
public static URLWrapper empty()
Create a new empty URLWrapper.- Returns:
- The URLWrapper
-
of
@Deprecated @ScheduledForRemoval public static URLWrapper of(java.lang.String url) throws java.net.MalformedURLException
Deprecated.- Throws:
java.net.MalformedURLException
-
ofURL
public static URLWrapper ofURL(java.lang.String url) throws java.net.MalformedURLException
Create a new URLWrapper from a URL string.- Parameters:
url- The URL to wrap- Returns:
- The URLWrapper
- Throws:
java.net.MalformedURLException- If the URL is invalid
-
ofURI
public static URLWrapper ofURI(java.lang.String uri) throws java.lang.IllegalArgumentException
Create a new URLWrapper from a URI string.- Parameters:
uri- The URI to wrap- Returns:
- The URLWrapper
- Throws:
java.lang.IllegalArgumentException- If the URI is invalid
-
of
public static URLWrapper of(java.net.URL url)
Create a new URLWrapper from anURL.- Parameters:
url- The URL to wrap- Returns:
- The URLWrapper
-
of
public static URLWrapper of(java.net.URI uri)
Create a new URLWrapper from anURI.- Parameters:
uri- The URI to wrap- Returns:
- The URLWrapper
-
hasProtocol
public boolean hasProtocol()
- Returns:
- If the protocol is set
-
getProtocol
public java.lang.String getProtocol()
- Returns:
- The protocol of the URL (e.g.
https)
-
getProtocolOr
public java.lang.String getProtocolOr(java.lang.String defaultProtocol)
- Parameters:
defaultProtocol- The default protocol to return if none is set- Returns:
- The protocol of the URL (e.g.
https)
-
setProtocol
public URLWrapper setProtocol(java.lang.String protocol)
Set the protocol of the URL (e.g.https).- Parameters:
protocol- The new protocol- Returns:
- The URLWrapper
-
hasHost
public boolean hasHost()
- Returns:
- If the host is set
-
getHost
public java.lang.String getHost()
- Returns:
- The host of the URL (e.g.
www.example.com)
-
getHostOr
public java.lang.String getHostOr(java.lang.String defaultHost)
- Parameters:
defaultHost- The default host to return if none is set- Returns:
- The host of the URL (e.g.
www.example.com)
-
setHost
public URLWrapper setHost(java.lang.String host)
Set the host of the URL (e.g.www.example.com).- Parameters:
host- The new host- Returns:
- The URLWrapper
-
hasPort
public boolean hasPort()
- Returns:
- If the port is set
-
getPort
public int getPort()
- Returns:
- The port of the URL (e.g.
443)
-
getPortOr
public int getPortOr(int defaultPort)
- Parameters:
defaultPort- The default port to return if none is set- Returns:
- The port of the URL (e.g.
443)
-
setPort
public URLWrapper setPort(int port)
Set the port of the URL (e.g.443).- Parameters:
port- The new port- Returns:
- The URLWrapper
-
hasPath
public boolean hasPath()
- Returns:
- If the path is set
-
getPath
public java.lang.String getPath()
- Returns:
- The path of the URL (e.g.
/search)
-
getPathOr
public java.lang.String getPathOr(java.lang.String defaultPath)
- Parameters:
defaultPath- The default path to return if none is set- Returns:
- The path of the URL (e.g.
/search)
-
setPath
public URLWrapper setPath(java.lang.String path)
Set the path of the URL (e.g./search).- Parameters:
path- The new path- Returns:
- The URLWrapper
-
hasQuery
public boolean hasQuery()
- Returns:
- If the query is set
-
getQuery
public java.lang.String getQuery()
- Returns:
- The query of the URL (e.g.
q=hello)
-
getQueryOr
public java.lang.String getQueryOr(java.lang.String defaultQuery)
- Parameters:
defaultQuery- The default query to return if none is set- Returns:
- The query of the URL (e.g.
q=hello)
-
setQuery
public URLWrapper setQuery(java.lang.String query)
Set the query of the URL (e.g.q=hello).- Parameters:
query- The new query- Returns:
- The URLWrapper
-
wrapQuery
@Deprecated @ScheduledForRemoval public URLWrapper.QueryWrapper wrapQuery()
Deprecated.Get a wrapper for the query parameters.- Returns:
- The query wrapper
-
wrapQueryParameters
public URLWrapper.QueryParametersWrapper wrapQueryParameters()
Get a wrapper for the query parameters.- Returns:
- The query parameters wrapper
-
hasUserInfo
public boolean hasUserInfo()
- Returns:
- If the user info is set
-
getUserInfo
public java.lang.String getUserInfo()
- Returns:
- The user info of the URL (e.g.
user:password)
-
getUserInfoOr
public java.lang.String getUserInfoOr(java.lang.String defaultUserInfo)
- Parameters:
defaultUserInfo- The default user info to return if none is set- Returns:
- The user info of the URL (e.g.
user:password)
-
setUserInfo
public URLWrapper setUserInfo(java.lang.String userInfo)
Set the user info of the URL (e.g.user:password).- Parameters:
userInfo- The new user info- Returns:
- The URLWrapper
-
hasFragment
public boolean hasFragment()
- Returns:
- If the fragment is set
-
getFragment
public java.lang.String getFragment()
- Returns:
- The fragment of the URL (e.g.
fragment)
-
getFragmentOr
public java.lang.String getFragmentOr(java.lang.String defaultFragment)
- Parameters:
defaultFragment- The default fragment to return if none is set- Returns:
- The fragment of the URL (e.g.
fragment)
-
setFragment
public URLWrapper setFragment(java.lang.String fragment)
Set the fragment of the URL (e.g.fragment).- Parameters:
fragment- The new fragment- Returns:
- The URLWrapper
-
getReference
@Deprecated @ScheduledForRemoval public java.lang.String getReference()
Deprecated.Deprecated, usegetFragment()instead.
-
setReference
@Deprecated @ScheduledForRemoval public URLWrapper setReference(java.lang.String reference)
Deprecated.Deprecated, usesetFragment(String)instead.
-
toURL
public java.net.URL toURL() throws java.net.MalformedURLException- Returns:
- The wrapped URL
- Throws:
java.net.MalformedURLException- If the URL is invalid
-
toURI
public java.net.URI toURI()
- Returns:
- The wrapped URI
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-