Package | com.ericfeminella.application |
Class | public class QueryString |
Implements | IQueryString |
QueryString supports parsing of a QueryString which has been provided to the application via a user agent. Additionally, support for specific QueryStrings is provided which allows for detailed inspection of arbitrary query strings via the constructor
Property | Defined by | ||
---|---|---|---|
isProvided : Boolean [read-only]
Determines if parameters have been provided to the application
| QueryString |
Property | Defined by | ||
---|---|---|---|
parameters : IMap
Defines the name / value pairs which have been supplied
to the querystring, any modification to the querystring
are reflected in this HashMap
| QueryString | ||
querystring : String
The querystring which has been provided via the application
URL or specified in the constructor, any modification to the
querystring are reflected in this String
| QueryString | ||
uri : String
Uniform Resource Identifier (URI) to which the querystring
has been provided
| QueryString |
Method | Defined by | ||
---|---|---|---|
QueryString(url:String = null, decode:Boolean = true)
By default the QueryString constructor will use the applications
querystring and decode it unless specified otherwise
Additionally, support for specific QueryStrings is provided which allows for detailed inspection of arbitrary query strings via the constructor The QueryString constructor takes a single url as an argument. | QueryString | ||
addParameter(name:String, value:*):void
Adds a new parameter ( name / value ) pair to the querystring
If the parameter name which has been specified currently exists in the querystring then it is simply ignored. | QueryString | ||
appendToURL(url:String, decode:Boolean = true):String
Appends the current state of the
querystring
to a URL
| QueryString | ||
containsParameter(name:String):Boolean
Determines if the specified parameter has been provided to
the query string
| QueryString | ||
containsValue(value:*):Boolean
Determines if the specified value has been provided to the
query string
| QueryString | ||
getName(value:String):String
Retrieves a specific parameter name based on the parameters
value
| QueryString | ||
getNames():Array
Retrieves the parameter names provided to the application
| QueryString | ||
getParameters():IMap
Retrieves all name / value pair provided to the application and
returns an Array of Objects which contain each parameter name
and value.
| QueryString | ||
getQueryString(decode:Boolean = true):String
Retrieves the raw query string provided to the application
| QueryString | ||
getValue(name:String):String
Retrieves the value of the specified parameter name.
| QueryString | ||
getValues():Array
Retrieves the parameter values provided to the application
| QueryString | ||
length():int
Determines the length of the query string based on the amount
of name value pairs which have been supplied to the QueryString
| QueryString | ||
removeParameter(name:String):void
Removes an existing parameter from the querystring
| QueryString | ||
setValue(name:String, value:*):void
Assigns a new value to the specified querystring parameter
| QueryString |
Method | Defined by | ||
---|---|---|---|
build(url:String = null, decode:Boolean = true):void
Builds the QueryString Object and members from the specified
URL or Application URL
| QueryString | ||
createParameters():void
Parses the
querystring into an Array of Objects. | QueryString | ||
update():void
Updates the querystring to reflect changes made via
setValue() , addParameter()
and removeParameter()
| QueryString |
isProvided | property |
isProvided:Boolean
[read-only]Determines if parameters have been provided to the application
Implementation public function get isProvided():Boolean
var uri:String = "http://127.0.0.1/test.html?name=Adobe Flex&version=3.0"; var querystring:IQueryString = new QueryString( uri ); trace( querystring.isProvided ); //true
parameters | property |
protected var parameters:IMap
Defines the name / value pairs which have been supplied to the querystring, any modification to the querystring are reflected in this HashMap
querystring | property |
protected var querystring:String
The querystring which has been provided via the application URL or specified in the constructor, any modification to the querystring are reflected in this String
uri | property |
protected var uri:String
Uniform Resource Identifier (URI) to which the querystring has been provided
QueryString | () | constructor |
public function QueryString(url:String = null, decode:Boolean = true)
By default the QueryString constructor will use the applications querystring and decode it unless specified otherwise
Additionally, support for specific QueryStrings is provided which allows for detailed inspection of arbitrary query strings via the constructor
The QueryString constructor takes a single url as an argument. This argument is optional, and, if specified instructs the QueryString object to use the specified url for all subsequent operations. If the url is not specified the QueryString object will assume the aplication query string is to be used for all operations.
Unfortunately, ActionScript 3 does not support constructor / method overloading so the url parameter is used to achive the correct functionality based on context.
Parametersurl:String (default = null ) — optional url from which the query string is to be based
|
|
decode:Boolean (default = true ) — if the query string is to be URL decoded
|
See also
var querystring:IQueryString = new QueryString(); //defaults to application querystring trace ( querystring.getQueryString() ); //outputs application querystring
Optionally, you can opt to use a specific QueryString by passing it to the constructor:
var url:String = "http://127.0.0.1/test.html?name=Adobe Flex&version=3"; var querystring:IQueryString = new QueryString(); //defaults to: name=Adobe Flex&version=3 trace ( querystring.getQueryString() ); //name=Adobe Flex&version=3
addParameter | () | method |
public function addParameter(name:String, value:*):void
Adds a new parameter ( name / value ) pair to the querystring
If the parameter name which has been specified currently exists in the querystring then it is simply ignored.
If you need to overwrite an existing parameter or modify the value
of an existing parameter use setValue
instead
name:String — the name of the parameter which is to be added to the QueryString
|
|
value:* — the value to assigned to the specified parameter name
|
var uri:String = "http://127.0.0.1/test.html?name=Adobe Flex&version=3.0"; var querystring:IQueryString = new QueryString( uri ); trace( querystring.getQueryString(true) ); //name=Adobe Flex&version=3.0 //add an additional parameter to the querystring querystring.addParameter("year", 2007); trace( querystring.getQueryString( true ) ); //name=Adobe Flex&version=3.0&year=2007
appendToURL | () | method |
public function appendToURL(url:String, decode:Boolean = true):String
Appends the current state of the querystring
to a URL
url:String — the url to which the querystring is to be appended
|
|
decode:Boolean (default = true ) — specifies if the querystring is to be URL decoded /encoded
|
String — the specified url with the querystring appended
|
var uri:String = "http://127.0.0.1/test.html?name=Adobe Flex&version=3.0"; var querystring:IQueryString = new QueryString( uri, true ); var url:String = "http://127.0.0.1/apps/test.html"; url = querystring.appendToURL( url ); trace( url ); //http://127.0.0.1/apps/test.html?name=Adobe Flex&version=3.0;
build | () | method |
protected function build(url:String = null, decode:Boolean = true):void
Builds the QueryString Object and members from the specified URL or Application URL
Parametersurl:String (default = null ) — optional url from which the query string is to be based
|
|
decode:Boolean (default = true ) — if the query string is to be URL decoded
|
See also
containsParameter | () | method |
public function containsParameter(name:String):Boolean
Determines if the specified parameter has been provided to the query string
Parametersname:String — the paramter to determine
|
Boolean — true if supplied, false if not
|
var uri:String = "http://127.0.0.1/test.html?name=Adobe Flex&version=3.0"; var querystring:IQueryString = new QueryString( uri ); trace( querystring.containsParameter("name") ); //true
containsValue | () | method |
public function containsValue(value:*):Boolean
Determines if the specified value has been provided to the query string
Parametersvalue:* — the value in which to determine
|
Boolean — true if the value has been provided, false if not
|
var uri:String = "http://127.0.0.1/test.html?name=Adobe Flex&version=3.0"; var querystring:IQueryString = new QueryString( uri ); trace( querystring.containsValue(3.0) ); //true
createParameters | () | method |
protected function createParameters():void
Parses the querystring
into an Array of Objects.
Each containing a specific name property and a value property which contains the values of each name / value pair in provided in the querystring
getName | () | method |
public function getName(value:String):String
Retrieves a specific parameter name based on the parameters value
Parametersvalue:String — the value of the parameter which is to be located
|
String — parameter name to which the specified value has been assigned
|
var uri:String = "http://127.0.0.1/test.html?name=Adobe Flex&version=3.0"; var querystring:IQueryString = new QueryString( uri ); trace( querystring.getName(3.0) ); //version
getNames | () | method |
public function getNames():Array
Retrieves the parameter names provided to the application
ReturnsArray — each query string parameter name
|
var uri:String = "http://127.0.0.1/test.html?name=Adobe Flex&version=3.0"; var querystring:IQueryString = new QueryString( uri ); trace( querystring.getNames() ); //name, version
getParameters | () | method |
public function getParameters():IMap
Retrieves all name / value pair provided to the application and returns an Array of Objects which contain each parameter name and value.
QueryString.getParameters()
returns a new HashMap
which contains all key / value pairs. A reference to the internal
HashMap instance is not returned
IMap — IMap containing key / values as specified in the querystring
|
var uri:String = "http://127.0.0.1/test.html?name=Adobe Flex&version=3.0"; var querystring:IQueryString = new QueryString( uri ); trace( querystring.parameters ); //[object Dictionary]
getQueryString | () | method |
public function getQueryString(decode:Boolean = true):String
Retrieves the raw query string provided to the application
Parametersdecode:Boolean (default = true ) — specifies if the querystring is to be URL decoded /encoded
|
String — the raw query string which has been supplied
|
var url:String = "http://127.0.0.1/test.html?name=Adobe Flex&version=3.0"; var querystring:IQueryString = new QueryString( url ); trace( querystring.getQueryString() ); //name=Adobe%20Flex&version=3.0 //QueryString Object with decode set to true trace( querystring.getQueryString(true) ); //name=Adobe Flex&version=3.0
getValue | () | method |
public function getValue(name:String):String
Retrieves the value of the specified parameter name. If the parameter does not exist a null value is returned. If the name has not been provided in the querystring then a null value is returned
Parametersname:String — the name of the parameter
|
String — the value of the specified paramter name
|
var uri:String = "http://127.0.0.1/test.html?name=Adobe Flex&version=3.0"; var querystring:IQueryString = new QueryString( uri, true ); trace( querystring.getValue("version") ); //3.0
getValues | () | method |
public function getValues():Array
Retrieves the parameter values provided to the application
ReturnsArray — each query string parameter value
|
var uri:String = "http://127.0.0.1/test.html?name=Adobe Flex&version=3.0"; var querystring:IQueryString = new QueryString( uri, true ); trace( querystring.getValues() ); //Adobe Flex, 3.0
length | () | method |
public function length():int
Determines the length of the query string based on the amount of name value pairs which have been supplied to the QueryString
Returnsint — the length of the query string
|
var uri:String = "http://127.0.0.1/test.html?name=Adobe Flex&version=3.0"; var querystring:IQueryString = new QueryString( uri ); trace( querystring.length() ); // 2
removeParameter | () | method |
public function removeParameter(name:String):void
Removes an existing parameter from the querystring
Parametersname:String — the name of the parameter which is to be removed
|
var uri:String = "http://127.0.0.1/test.html?name=Adobe Flex&version=3.0"; var querystring:IQueryString = new QueryString( uri ); trace( querystring.getQueryString(true) ); //name=Adobe Flex&version=3.0 //remove a parameter from the querystring querystring.removeParameter("version"); trace( querystring.getQueryString( true ) ); //name=Adobe Flex
setValue | () | method |
public function setValue(name:String, value:*):void
Assigns a new value to the specified querystring parameter
Parametersname:String — the name of the parameter
|
|
value:* — the value to assigned to the specified parameter name
|
var uri:String = "http://127.0.0.1/test.html?name=Adobe Flex&version=3.0"; var querystring:IQueryString = new QueryString( uri, true ); trace( querystring.getValue("version") ); //3.0 querystring.setValue("version", 2.1) trace( querystring.getValue("version") ); //2.1
update | () | method |
protected final function update():void
Updates the querystring to reflect changes made via
setValue()
, addParameter()
and removeParameter()
See also