Package net.shibboleth.shared.net
Class URLBuilder
java.lang.Object
net.shibboleth.shared.net.URLBuilder
Utility class for building URLs. May also be used to parse a URL into its individual components.
All components will be converted UTF-8 encoding and then application/x-www-form-urlencoded when built.
This class is not thread-safe.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate StringURL fragment.private StringHost for the URL.private StringPassword in the URL.private StringURL path.private IntegerURL port number.Parameters in the query string.private StringURL schema (http, https, etc).private StringUser name in the URL. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionBuilds the query string for the URL.buildURL()Builds a URL from the given data.Gets the URL fragment in its decoded form.getHost()Gets the host component of the URL.Gets the user's password in the URL.getPath()Gets the path component of the URL.getPort()Gets the port component of the URL.Gets the query string parameters for the URL.Gets the URL scheme (http, https, etc).Gets the user name component of the URL.voidsetFragment(String newFragment) Sets the URL fragment in its decoded form.voidSets the host component of the URL.voidsetPassword(String newPassword) Sets the user's password in the URL.voidSets the path component of the URL.voidSets the port component of the URL.voidSets the URL scheme (http, https, etc).voidsetUsername(String newUsername) Sets the user name component of the URL.
-
Field Details
-
scheme
URL schema (http, https, etc). -
username
User name in the URL. -
password
Password in the URL. -
host
Host for the URL. -
port
URL port number. -
path
URL path. -
queryParams
Parameters in the query string. -
fragment
URL fragment.
-
-
Constructor Details
-
URLBuilder
public URLBuilder()Constructor. -
URLBuilder
Constructor.- Parameters:
baseURL- URL to parse and use as basis for creating other URLs- Throws:
MalformedURLException- thrown if the given base URL is not well formed
-
-
Method Details
-
getFragment
Gets the URL fragment in its decoded form.- Returns:
- URL fragment in its decoded form
-
setFragment
Sets the URL fragment in its decoded form.- Parameters:
newFragment- URL fragment in its decoded form
-
getHost
Gets the host component of the URL.- Returns:
- host component of the URL
-
setHost
Sets the host component of the URL.- Parameters:
newHost- host component of the URL
-
getPassword
Gets the user's password in the URL.- Returns:
- user's password in the URL
-
setPassword
Sets the user's password in the URL.- Parameters:
newPassword- user's password in the URL
-
getPath
Gets the path component of the URL.- Returns:
- path component of the URL
-
setPath
Sets the path component of the URL.- Parameters:
newPath- path component of the URL
-
getPort
Gets the port component of the URL.- Returns:
- port component of the URL
-
setPort
Sets the port component of the URL.- Parameters:
newPort- port component of the URL
-
getQueryParams
Gets the query string parameters for the URL. Params may be added and removed through theListinterface.A note on the use of nulls in the
Pair:- A null
Pair.getFirst()is generated from a URL segment such as?=foo. Such pairs are ignored bybuildURL(). - A null
Pair.getSecond()is generated from a URL segment such as?foo=&bar=fredand will be rendered asfoo&bar=fredbybuildURL().
- Returns:
- query string parameters for the URL
- A null
-
getScheme
Gets the URL scheme (http, https, etc).- Returns:
- URL scheme (http, https, etc)
-
setScheme
Sets the URL scheme (http, https, etc).- Parameters:
newScheme- URL scheme (http, https, etc)
-
getUsername
Gets the user name component of the URL.- Returns:
- user name component of the URL
-
setUsername
Sets the user name component of the URL.- Parameters:
newUsername- user name component of the URL
-
buildURL
Builds a URL from the given data. The constructed URL may not be valid if sufficient information is not provided. The returned URL will be appropriately encoded using application/x-www-form-urlencoded with appropriate encoding of UTF-8 characters.- Returns:
- URL built from the given data
-
buildQueryString
Builds the query string for the URL.- Returns:
- query string for the URL or null if there are now query parameters
-