Packagecom.ericfeminella.application
Classpublic class QueryString
ImplementsIQueryString

Provides an API which allows for detailed inspection and / or modification of an application QueryString.

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



Public Properties
 PropertyDefined by
  isProvided : Boolean
[read-only] Determines if parameters have been provided to the application
QueryString
Protected Properties
 PropertyDefined 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
Public Methods
 MethodDefined 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
  
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
Protected Methods
 MethodDefined by
  
build(url:String = null, decode:Boolean = true):void
Builds the QueryString Object and members from the specified URL or Application URL
QueryString
  
Parses the querystring into an Array of Objects.
QueryString
  
update():void
Updates the querystring to reflect changes made via setValue(), addParameter() and removeParameter()
QueryString
Property detail
isProvidedproperty
isProvided:Boolean  [read-only]

Determines if parameters have been provided to the application

Implementation
    public function get isProvided():Boolean

Example
         
         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
         
         

parametersproperty 
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

querystringproperty 
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

uriproperty 
protected var uri:String

Uniform Resource Identifier (URI) to which the querystring has been provided

Constructor detail
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.

Parameters
url: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


Example
      
      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
      
      

Method detail
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

Parameters
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

Example
         
         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

Parameters
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

Returns
String — the specified url with the querystring appended

Example
         
         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

Parameters
url: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

Parameters
name:String — the paramter to determine

Returns
Boolean — true if supplied, false if not

Example
         
         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

Parameters
value:* — the value in which to determine

Returns
Boolean — true if the value has been provided, false if not

Example
         
         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

Parameters
value:String — the value of the parameter which is to be located

Returns
String — parameter name to which the specified value has been assigned

Example
         
         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

Returns
Array — each query string parameter name

Example
         
         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

Returns
IMap — IMap containing key / values as specified in the querystring

Example
         
         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

Parameters
decode:Boolean (default = true) — specifies if the querystring is to be URL decoded /encoded

Returns
String — the raw query string which has been supplied

Example
         
         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

Parameters
name:String — the name of the parameter

Returns
String — the value of the specified paramter name

Example
         
         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

Returns
Array — each query string parameter value

Example
         
         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

Returns
int — the length of the query string

Example
         
         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

Parameters
name:String — the name of the parameter which is to be removed

Example
         
         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

Parameters
name:String — the name of the parameter
 
value:* — the value to assigned to the specified parameter name

Example
         
         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