Package com.facilita.fc.web
Class QueryData
- java.lang.Object
-
- com.facilita.fc.web.QueryData
-
public class QueryData extends java.lang.Object
Represents the query string of aUrl
as a sequence of name/value pairs.The syntax of a URL is:
Often, the query string consists of a list of name/value pairs, separated by an ampersand.scheme://domain:port/path?query_string#fragment_id
e.g.
key1=value1&key2=value2&key3=value2
It is convenient to use the
QueryData
class to define your query string as a series of name/value pairs.e.g.
// Construct the url "http://localhost/?key1=value1&key2=value2&key3=value3 Url url = new Url("http://localhost/"); QueryData queryData = new QueryData(); queryData.add("key1", "value1"); queryData.add("key2", "value2"); queryData.add("key3", "value3"); url = url.withQuery(queryData);
-
-
Constructor Summary
Constructors Constructor Description QueryData()
Creates aQueryData
object with no name/value pairs.QueryData(long cPtr, boolean cMemoryOwn)
For internal use only.QueryData(java.lang.String urlEncoded)
Initialises a new instance of the QueryData class by parsing a URL encoded string.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(java.lang.String name, QueryData queryData)
Adds a name/value pair to the end of the list, using a value extracted from anotherQueryData
object.void
add(java.lang.String name, java.lang.String value)
Adds a name/value pair to the end of the list.void
clear()
Removes all of the name/value pairs from the list.void
delete()
NameValuePair
get(int index)
Gets theNameValuePair
at the specifiedindex
in the list.int
getCount()
Gets the number of name/value pairs in the list.static long
getCPtr(QueryData obj)
For internal use only.int
getNameCount(java.lang.String name)
Gets the number of name/value pairs in the list that have the specifiedname
.java.lang.String
getValue(java.lang.String name)
Gets the value of the first name/value pair in the list that has the specifiedname
.java.lang.String
getValue(java.lang.String name, int index)
Gets the value of the nth name/value pair in the list that has the specifiedname
.void
insert(java.lang.String name, QueryData queryData, int index)
Inserts a name/value pair into the list at the specifiedindex
, using a value extracted from anotherQueryData
object.void
insert(java.lang.String name, java.lang.String value, int index)
Inserts a name/value pair into the list at the specifiedindex
.void
remove(java.lang.String name)
Removes the first item in the list with the specifiedname
.void
remove(java.lang.String name, int remove)
Removes the nth item in the list with the specifiedname
.void
remove(java.lang.String name, java.lang.String value)
Removes the first item in the list with the specifiedname
andvalue
.void
remove(java.lang.String name, java.lang.String value, int remove)
Removes the nth item in the list with the specifiedname
andvalue
.boolean
setValue(java.lang.String name, java.lang.String value)
Sets the value of the first name/value pair in the list that has the specifiedname
.boolean
setValue(java.lang.String name, java.lang.String value, int index)
Sets the value of the nth name/value pair in the list that has the specifiedname
.
-
-
-
Constructor Detail
-
QueryData
public QueryData(long cPtr, boolean cMemoryOwn)
For internal use only. Of no interest to the user.- Parameters:
cPtr
- pointer to the CPP wrapped objectcMemoryOwn
- indicates if this object is responsible for memory management of the CPP object
-
QueryData
public QueryData()
Creates aQueryData
object with no name/value pairs.
-
QueryData
public QueryData(java.lang.String urlEncoded)
Initialises a new instance of the QueryData class by parsing a URL encoded string.- Parameters:
urlEncoded
- the query section of a url, i.e. the part after the ?
-
-
Method Detail
-
getCPtr
public static long getCPtr(QueryData obj)
For internal use only. Of no interest to the user.- Parameters:
obj
- a reference to an object of this class- Returns:
- a long containing the address of the CPP wrapped object
-
delete
public void delete()
-
add
public void add(java.lang.String name, java.lang.String value)
Adds a name/value pair to the end of the list.- Parameters:
name
- the name to addvalue
- the value to add
-
add
public void add(java.lang.String name, QueryData queryData)
Adds a name/value pair to the end of the list, using a value extracted from anotherQueryData
object. The name used to find the name/value pair in the other object is the same as thename
parameter passed.This is equivalent to
add(name, queryData.getValue(name))
.- Parameters:
name
- the name to addqueryData
- theQueryData
object from which to extract the value to add
-
insert
public void insert(java.lang.String name, QueryData queryData, int index)
Inserts a name/value pair into the list at the specifiedindex
, using a value extracted from anotherQueryData
object. The name used to find the name/value pair in the other object is the same as thename
parameter passed.This is equivalent to
insert(name, queryData.getValue(name), index)
.- Parameters:
name
- the name to insertqueryData
- theQueryData
object from which to extract the value to addindex
- the zero-based position at which to insert the name/value pair in the list
-
insert
public void insert(java.lang.String name, java.lang.String value, int index)
Inserts a name/value pair into the list at the specifiedindex
.- Parameters:
name
- the name to insertvalue
- the value to insertindex
- the zero-based position at which to insert the name/value pair in the list
-
getCount
public int getCount()
Gets the number of name/value pairs in the list.- Returns:
- the number of name/value pairs in the list
-
getNameCount
public int getNameCount(java.lang.String name)
Gets the number of name/value pairs in the list that have the specifiedname
.- Parameters:
name
- the name to look for- Returns:
- the number of name/value pairs in the list that have the specified
name
-
getValue
public java.lang.String getValue(java.lang.String name)
Gets the value of the first name/value pair in the list that has the specifiedname
.- Parameters:
name
- the name to look for- Returns:
- the first value in the list that has the specified
name
- See Also:
getValue(String, int)
,getNameCount(String)
-
getValue
public java.lang.String getValue(java.lang.String name, int index)
Gets the value of the nth name/value pair in the list that has the specifiedname
.e.g.
// Find all the values with the name "r" for (int i = 0; i < queryData.getNameCount("r"); i++) { String name = queryData.getValue("r", i); }
- Parameters:
name
- the name to look forindex
- the zero-based index of the value to return- Returns:
- the nth value in the list that has the specified
name
- See Also:
getValue(String)
,getNameCount(String)
-
setValue
public boolean setValue(java.lang.String name, java.lang.String value, int index)
Sets the value of the nth name/value pair in the list that has the specifiedname
.If the list contains fewer than n items with the specified
name
, then a new name/value pair is added to the end of the list.- Parameters:
name
- the name to look forvalue
- the value to setindex
- the zero-based index of the item to change- Returns:
true
if the nth item with the specifiedname
was set successfully, orfalse
if a new name/value pair was added- See Also:
setValue(String, String)
,getValue(String)
-
setValue
public boolean setValue(java.lang.String name, java.lang.String value)
Sets the value of the first name/value pair in the list that has the specifiedname
.If the list does not contain an item with the specified
name
, then a new name/value pair is added to the end of the list.- Parameters:
name
- the name to look forvalue
- the value to set- Returns:
true
if the first item with the specifiedname
was set successfully, orfalse
if a new name/value pair was added- See Also:
setValue(String, String, int)
,getValue(String, int)
-
remove
public void remove(java.lang.String name, int remove)
Removes the nth item in the list with the specifiedname
.- Parameters:
name
- the name to look forremove
- the zero-based index of the item to remove- See Also:
remove(String)
,add(String, String)
-
remove
public void remove(java.lang.String name)
Removes the first item in the list with the specifiedname
.- Parameters:
name
- the name to look for- See Also:
remove(String, int)
,remove(String, String)
,add(String, String)
-
remove
public void remove(java.lang.String name, java.lang.String value, int remove)
Removes the nth item in the list with the specifiedname
andvalue
.- Parameters:
name
- the name to look forvalue
- the value to look forremove
- the zero-based index of the item to remove- See Also:
remove(String)
,remove(String, int)
,remove(String, String)
,add(String, String)
-
remove
public void remove(java.lang.String name, java.lang.String value)
Removes the first item in the list with the specifiedname
andvalue
.- Parameters:
name
- the name to look forvalue
- the value to look for
-
get
public NameValuePair get(int index)
Gets theNameValuePair
at the specifiedindex
in the list.e.g.
// List all the name/value pairs in queryData for (int i = 0; i < queryData.getCount(); i++) { NameValuePair pair = queryData.get(i); writeMessage(String.format("%s=%s", pair.getName(), pair.getValue())); }
- Parameters:
index
- the zero-based index of the name/value pair to get- Returns:
- the
NameValuePair
at the specifiedindex
in the list
-
clear
public void clear()
Removes all of the name/value pairs from the list.
-
-