Package com.networknt.url
Class QueryString
- java.lang.Object
-
- com.networknt.url.QueryString
-
public class QueryString extends Object
Provides utility methods for getting and setting attributes on a URL query string. This is rewrite from commons-lang to remove extra dependencies.
Since 1.4, query string parameters are stored and returned in the order they were provided.- Author:
- Pascal Essiembre
-
-
Constructor Summary
Constructors Constructor Description QueryString()Constructor.QueryString(String urlWithQueryString)Constructor.QueryString(String urlWithQueryString, String encoding)Constructor.QueryString(URL urlWithQueryString)Default URL character encoding is UTF-8.QueryString(URL urlWithQueryString, String encoding)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddString(String key, String... values)Adds one or multiple string values.StringapplyOnURL(String url)Apply this url QueryString on the given URL.URLapplyOnURL(URL url)Apply this url QueryString on the given URL.StringgetEncoding()Gets the character encoding.booleanisEmpty()StringtoString()Convert thisQueryStringto a URL-encoded string representation that can be appended as is to a URL with no query string.
-
-
-
Constructor Detail
-
QueryString
public QueryString()
Constructor.
-
QueryString
public QueryString(URL urlWithQueryString)
Default URL character encoding is UTF-8.- Parameters:
urlWithQueryString- a URL from which to extract a query string.
-
QueryString
public QueryString(URL urlWithQueryString, String encoding)
Constructor.- Parameters:
urlWithQueryString- a URL from which to extract a query string.encoding- character encoding
-
QueryString
public QueryString(String urlWithQueryString)
Constructor. Default URL character encoding is UTF-8. It is possible to only supply a query string as opposed to an entire URL. Key and values making up a query string are assumed to be URL-encoded. Will throw aRuntimeExceptionif UTF-8 encoding is not supported.- Parameters:
urlWithQueryString- a URL from which to extract a query string.
-
QueryString
public QueryString(String urlWithQueryString, String encoding)
Constructor. It is possible to only supply a query string as opposed to an entire URL. Key and values making up a query string are assumed to be URL-encoded. Will throw aRuntimeExceptionif the supplied encoding is unsupported or invalid.- Parameters:
urlWithQueryString- a URL from which to extract a query string.encoding- character encoding
-
-
Method Detail
-
getEncoding
public String getEncoding()
Gets the character encoding. Default is UTF-8.- Returns:
- character encoding
- Since:
- 1.7.0
-
toString
public String toString()
Convert thisQueryStringto a URL-encoded string representation that can be appended as is to a URL with no query string.
-
applyOnURL
public String applyOnURL(String url)
Apply this url QueryString on the given URL. If a query string already exists, it is replaced by this one.- Parameters:
url- the URL to apply this query string.- Returns:
- url with query string added
-
applyOnURL
public URL applyOnURL(URL url)
Apply this url QueryString on the given URL. If a query string already exists, it is replaced by this one.- Parameters:
url- the URL to apply this query string.- Returns:
- url with query string added
-
addString
public final void addString(String key, String... values)
Adds one or multiple string values. Adding a singlenullvalue has no effect. When adding multiple values,nullvalues are converted to blank strings.- Parameters:
key- the key of the value to setvalues- the values to set
-
isEmpty
public boolean isEmpty()
-
-