Package com.norconex.commons.lang.url
Class QueryString
- java.lang.Object
-
- com.norconex.commons.lang.map.ObservableMap<String,List<String>>
-
- com.norconex.commons.lang.map.Properties
-
- com.norconex.commons.lang.url.QueryString
-
- All Implemented Interfaces:
Serializable
,Map<String,List<String>>
public class QueryString extends Properties
Provides utility methods for getting and setting attributes on a URL query string.
Since 1.4, query string parameters are stored and returned in the order they were provided.- Author:
- Pascal Essiembre
- See Also:
- Serialized Form
-
-
Field Summary
-
Fields inherited from class com.norconex.commons.lang.map.Properties
DEFAULT_JAVA_PROPERTIES_DELIMITER
-
-
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 String
applyOnURL(String url)
Apply this url QueryString on the given URL.URL
applyOnURL(URL url)
Apply this url QueryString on the given URL.String
getEncoding()
Gets the character encoding.String
toString()
Convert thisQueryString
to a URL-encoded string representation that can be appended as is to a URL with no query string.-
Methods inherited from class com.norconex.commons.lang.map.Properties
add, addBigDecimal, addBoolean, addClass, addDate, addDouble, addFile, addFloat, addInt, addList, addLocale, addLong, addString, equals, fromString, get, get, get, getBigDecimal, getBigDecimal, getBigDecimals, getBoolean, getBoolean, getBooleans, getClass, getClass, getClasses, getDate, getDate, getDates, getDouble, getDouble, getDoubles, getFile, getFile, getFiles, getFloat, getFloat, getFloats, getInstant, getInstant, getInstants, getInteger, getInteger, getIntegers, getList, getList, getLocalDateTime, getLocalDateTime, getLocalDateTimes, getLocale, getLocale, getLocales, getLong, getLong, getLongs, getString, getString, getStrings, hashCode, isCaseInsensitiveKeys, load, load, load, load, load, loadFromBean, loadFromJSON, loadFromJSON, loadFromMap, loadFromProperties, loadFromProperties, loadFromProperties, loadFromProperties, loadFromXML, loadFromXML, loadFromXML, loadFromXML, match, match, matchKeys, matchValues, put, putAll, remove, set, setBigDecimal, setBoolean, setClass, setDate, setDouble, setFile, setFloat, setInt, setList, setLocale, setLong, setString, store, store, store, store, store, store, storeToBean, storeToJSON, storeToJSON, storeToProperties, storeToProperties, storeToProperties, storeToProperties, storeToXML, storeToXML, storeToXML, storeToXML, toProperties, valueList
-
Methods inherited from class com.norconex.commons.lang.map.ObservableMap
addMapChangeListener, clear, containsKey, containsValue, entrySet, isEmpty, keySet, removeMapChangeListener, size, values
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
-
-
-
-
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 aURLException
if 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 aURLException
if 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 thisQueryString
to a URL-encoded string representation that can be appended as is to a URL with no query string.- Overrides:
toString
in classProperties
- Returns:
- the properties as 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
-
-