Class URLBuilder
- java.lang.Object
-
- net.shibboleth.utilities.java.support.net.URLBuilder
-
public class URLBuilder extends Object
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
Fields Modifier and Type Field Description private StringfragmentURL fragment.private StringhostHost for the URL.private StringpasswordPassword in the URL.private StringpathURL path.private IntegerportURL port number.private List<Pair<String,String>>queryParamsParameters in the query string.private StringschemeURL schema (http, https, etc).private StringusernameUser name in the URL.
-
Constructor Summary
Constructors Constructor Description URLBuilder()Constructor.URLBuilder(String baseURL)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description StringbuildQueryString()Builds the query string for the URL.StringbuildURL()Builds a URL from the given data.StringgetFragment()Gets the URL fragment in its decoded form.StringgetHost()Gets the host component of the URL.StringgetPassword()Gets the user's password in the URL.StringgetPath()Gets the path component of the URL.IntegergetPort()Gets the port component of the URL.List<Pair<String,String>>getQueryParams()Gets the query string parameters for the URL.StringgetScheme()Gets the URL scheme (http, https, etc).StringgetUsername()Gets the user name component of the URL.voidsetFragment(String newFragment)Sets the URL fragment in its decoded form.voidsetHost(String newHost)Sets the host component of the URL.voidsetPassword(String newPassword)Sets the user's password in the URL.voidsetPath(String newPath)Sets the path component of the URL.voidsetPort(Integer newPort)Sets the port component of the URL.voidsetScheme(String newScheme)Sets the URL scheme (http, https, etc).voidsetUsername(String newUsername)Sets the user name component of the URL.
-
-
-
Field Detail
-
scheme
@Nullable private String scheme
URL schema (http, https, etc).
-
username
@Nullable private String username
User name in the URL.
-
password
@Nullable private String password
Password in the URL.
-
host
@Nullable private String host
Host for the URL.
-
port
@Nullable private Integer port
URL port number.
-
path
@Nullable private String path
URL path.
-
fragment
private String fragment
URL fragment.
-
-
Constructor Detail
-
URLBuilder
public URLBuilder()
Constructor.
-
URLBuilder
public URLBuilder(@Nonnull @NotEmpty String baseURL) throws MalformedURLException
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 Detail
-
getFragment
@Nullable public String getFragment()
Gets the URL fragment in its decoded form.- Returns:
- URL fragment in its decoded form
-
setFragment
public void setFragment(@Nullable String newFragment)Sets the URL fragment in its decoded form.- Parameters:
newFragment- URL fragment in its decoded form
-
getHost
@Nullable public String getHost()
Gets the host component of the URL.- Returns:
- host component of the URL
-
setHost
public void setHost(@Nullable String newHost)Sets the host component of the URL.- Parameters:
newHost- host component of the URL
-
getPassword
@Nullable public String getPassword()
Gets the user's password in the URL.- Returns:
- user's password in the URL
-
setPassword
public void setPassword(@Nullable String newPassword)Sets the user's password in the URL.- Parameters:
newPassword- user's password in the URL
-
getPath
@Nullable public String getPath()
Gets the path component of the URL.- Returns:
- path component of the URL
-
setPath
public void setPath(@Nullable String newPath)Sets the path component of the URL.- Parameters:
newPath- path component of the URL
-
getPort
@Nullable public Integer getPort()
Gets the port component of the URL.- Returns:
- port component of the URL
-
setPort
public void setPort(@Nullable Integer newPort)Sets the port component of the URL.- Parameters:
newPort- port component of the URL
-
getQueryParams
@Nonnull public List<Pair<String,String>> 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
@Nullable public String getScheme()
Gets the URL scheme (http, https, etc).- Returns:
- URL scheme (http, https, etc)
-
setScheme
public void setScheme(@Nullable String newScheme)Sets the URL scheme (http, https, etc).- Parameters:
newScheme- URL scheme (http, https, etc)
-
getUsername
@Nullable public String getUsername()
Gets the user name component of the URL.- Returns:
- user name component of the URL
-
setUsername
public void setUsername(@Nullable String newUsername)Sets the user name component of the URL.- Parameters:
newUsername- user name component of the URL
-
buildURL
@Nullable public String 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
@Nullable public String buildQueryString()
Builds the query string for the URL.- Returns:
- query string for the URL or null if there are now query parameters
-
-