The DeviceAtlas DeviceApi documentation
Static Public Member Functions | List of all members
Mobi.Mtld.DA.Api Class Reference

Used to load the recognition tree and perform lookups of all properties, or get individual properties. Typical usage is as follows: More...

Static Public Member Functions

static Hashtable GetTreeFromString (string json)
 Returns a loaded JSON tree from a string of JSON data. This will also initialise the changeable property recognition. More...
 
static Hashtable GetTreeFromString (string json, bool includeChangeableUserAgentProperties)
 Returns a loaded JSON tree from a string of JSON data. More...
 
static Hashtable GetTreeFromFile (string filename)
 Returns a tree from a JSON file, If it has been previously loaded then the version from the static cache will be returned. To reload from file call getTreeFromFile() with reload set to true. More...
 
static Hashtable GetTreeFromFile (string filename, bool reload)
 Returns a tree from a JSON file. The loaded tree is stored in a static cache to avoid multiple reloads if this method is repeatedly called. To reload from the JSON file set reload to true. More...
 
static Hashtable GetTreeFromFile (string filename, bool reload, bool includeChangeableUserAgentProperties)
 Returns a tree from a JSON file. The loaded tree is stored in a static cache to avoid multiple reloads if this method is repeatedly called. To reload from the JSON file set reload to true. More...
 
static string GetTreeGeneration (Hashtable tree)
 Get the generation date for this tree. More...
 
static int GetTreeGenerationAsTimestamp (Hashtable tree)
 Get the generation date for this tree as a UNIX timestamp. More...
 
static int GetApiRevision ()
 Returns the revision number of this API More...
 
static int GetTreeRevision (Hashtable tree)
 Returns the revision number of the tree More...
 
static Hashtable ListProperties (Hashtable tree)
 Returns a HashMap of known property names available for the user agents in this file, with their data type names More...
 
static Hashtable GetProperties (Hashtable tree, string userAgent)
 Returns a HashMap of known properties (as strings) for the user agent More...
 
static Hashtable GetProperties (Hashtable tree, string userAgent, string cookie)
 Returns a HashMap of known properties merged with properties from the client side JavaScript. The client side JavaScript sets a cookie with collected properties. The contents of this cookie must be passed to this method for it to work. The client properties over-ride any properties discovered from the main JSON data file. More...
 
static Hashtable GetPropertiesAsTyped (Hashtable tree, string userAgent)
 Returns a HashMap of known properties (as typed) for the user agent More...
 
static Hashtable GetPropertiesAsTyped (Hashtable tree, string userAgent, string cookie)
 Returns a HashMap of known properties merged with properties from the client side JavaScript. The client side JavaScript sets a cookie with collected properties. The contents of this cookie must be passed to this method for it to work. The client properties over-ride any properties discovered from the main JSON data file. More...
 
static string GetProperty (Hashtable tree, string userAgent, string property)
 Returns a value for the named property for this user agent More...
 
static string GetProperty (Hashtable tree, string userAgent, string cookie, string property)
 Returns a value for the named property for this user agent More...
 
static string GetPropertyAsString (Hashtable tree, string userAgent, string property)
 Strongly typed property accessor. Returns a string property (or throws an exception if the property is actually of another type) More...
 
static string GetPropertyAsString (Hashtable tree, string userAgent, string cookie, string property)
 Strongly typed property accessor. Returns a string property (or throws an exception if the property is actually of another type) More...
 
static bool GetPropertyAsBoolean (Hashtable tree, string userAgent, string property)
 Strongly typed property accessor. Returns a boolean property (or throws an exception if the property is actually of another type) More...
 
static bool GetPropertyAsBoolean (Hashtable tree, string userAgent, string cookie, string property)
 Strongly typed property accessor. Returns a boolean property (or throws an exception if the property is actually of another type) More...
 
static int GetPropertyAsInteger (Hashtable tree, string userAgent, string property)
 Strongly typed property accessor. Returns an integer property (or throws an exception if the property is actually of another type) More...
 
static int GetPropertyAsInteger (Hashtable tree, string userAgent, string cookie, string property)
 Strongly typed property accessor. Returns an integer property (or throws an exception if the property is actually of another type) More...
 
static string GetPropertyAsDate (Hashtable tree, string userAgent, string property)
 
static string GetPropertyAsDate (Hashtable tree, string userAgent, string cookie, string property)
 

Detailed Description

Used to load the recognition tree and perform lookups of all properties, or get individual properties. Typical usage is as follows:

HashTable tree = Api.GetTreeFromFile("datafile.json"); HashTable prps = Api.GetProperties(tree, "Nokia6680..."); Object prop = Api.GetProperty(tree, "Nokia6680...", "displayWidth"); Note that you should normally use the user-agent that was received in the device's HTTP request. In a JSP environment, you would do this as follows: String ua = request.getHeader("User-Agent"); int displayWidth = Api.getPropertyAsInteger(tree, ua, "displayWidth"); (Also note the use of the strongly typed property accessor)

Third-party Browsers

In some contexts, the user-agent you want to recognise may have been provided in a different header. Opera's mobile browser, for example, makes requests via an HTTP proxy, which rewrites the headers. in that case, the original device's user-agent is in the "X-OperaMini-Phone-UA" header, and the following code could be used:

String ua;
String operaHeader = "X-OperaMini-Phone-UA";
if (request.getHeader(operaHeader) != null) {
    ua = request.getHeader(operaHeader);
} else {
    ua = request.getHeader("User-Agent");
}
int displayWidth = Api.getPropertyAsInteger(tree, ua, "displayWidth");


See here for more information: https://deviceatlas.com/resources/side-loaded-browser-handling

Client side properties

Client side properties can be collected and merged into the results by using the DeviceAtlas Javascript detection file. The results from the client side are sent to the server inside a cookie. The contents of this cookie can be passed to the DeviceAtlas getProperty and getProperties methods. The client side properties over-ride any data file properties and also serve as an input into additional logic to determine other properties such as the iPhone models that are otherwise not detectable. The following code shows how this can be done in a JSP:

String userAgent = request.getHeader("User-Agent");
// get the cookie containing the client side properties
String cookieContents = null;
Cookie[] cookies = request.getCookies();
if(cookies != null) {
  for(int i = 0; i < cookies.length; i++) {
    Cookie cookie = cookies[i];
      if(cookie.getName().equals("DAPROPS")) {
        cookieContents = cookie.getValue();
      }
   }
}
HashMap properties = Api.getPropertiesAsTyped(tree, userAgent, cookieContents);

<deprecated>Use "Mobi.Mtld.DA.Device.DeviceApi" instead see

See also
DeviceApi

</deprecated>

Author
DeviceAtlas Limited

Member Function Documentation

◆ GetApiRevision()

static int Mobi.Mtld.DA.Api.GetApiRevision ( )
inlinestatic

Returns the revision number of this API

Returns
integer revision

◆ GetProperties() [1/2]

static Hashtable Mobi.Mtld.DA.Api.GetProperties ( Hashtable  tree,
string  userAgent 
)
inlinestatic

Returns a HashMap of known properties (as strings) for the user agent

Parameters
treepreviously generated HashMap tree
userAgentThe device's User-Agent header string
Returns
HashMap properties

◆ GetProperties() [2/2]

static Hashtable Mobi.Mtld.DA.Api.GetProperties ( Hashtable  tree,
string  userAgent,
string  cookie 
)
inlinestatic

Returns a HashMap of known properties merged with properties from the client side JavaScript. The client side JavaScript sets a cookie with collected properties. The contents of this cookie must be passed to this method for it to work. The client properties over-ride any properties discovered from the main JSON data file.

Parameters
treepreviously generated HashMap tree
userAgentthe device's User-Agent header string
cookiethe contents of the cookie containing the client side properties
Returns
HashMap a map of properties. Property name => Property value
Exceptions
ClientPropertiesExceptionSee
See also
ClientPropertiesException

◆ GetPropertiesAsTyped() [1/2]

static Hashtable Mobi.Mtld.DA.Api.GetPropertiesAsTyped ( Hashtable  tree,
string  userAgent 
)
inlinestatic

Returns a HashMap of known properties (as typed) for the user agent

Parameters
treepreviously generated HashMap tree
userAgentthe device's User-Agent header string
Returns
HashMap a map of properties. Property name => Property value

◆ GetPropertiesAsTyped() [2/2]

static Hashtable Mobi.Mtld.DA.Api.GetPropertiesAsTyped ( Hashtable  tree,
string  userAgent,
string  cookie 
)
inlinestatic

Returns a HashMap of known properties merged with properties from the client side JavaScript. The client side JavaScript sets a cookie with collected properties. The contents of this cookie must be passed to this method for it to work. The client properties over-ride any properties discovered from the main JSON data file.

Parameters
treepreviously generated HashMap tree
userAgentthe device's User-Agent header string
cookiethe contents of the cookie containing the client side properties
Returns
HashMap a map of properties. Property name => Property value
Exceptions
ClientPropertiesExceptionSee
See also
ClientPropertiesException

◆ GetProperty() [1/2]

static string Mobi.Mtld.DA.Api.GetProperty ( Hashtable  tree,
string  userAgent,
string  property 
)
inlinestatic

Returns a value for the named property for this user agent

Parameters
treepreviously generated HashMap tree
userAgentthe device's User-Agent header string
propertythe name of the property to return
Returns
Object property
Exceptions
InvalidPropertyExceptionSee
See also
InvalidPropertyException
UnknownPropertyExceptionSee
See also
UnknownPropertyException

◆ GetProperty() [2/2]

static string Mobi.Mtld.DA.Api.GetProperty ( Hashtable  tree,
string  userAgent,
string  cookie,
string  property 
)
inlinestatic

Returns a value for the named property for this user agent

Parameters
treepreviously generated HashMap tree
userAgentthe device's User-Agent header string
cookiethe contents of the cookie containing the client side properties
propertythe name of the property to return
Returns
Object property
Exceptions
InvalidPropertyExceptionSee
See also
InvalidPropertyException
UnknownPropertyExceptionSee
See also
UnknownPropertyException

◆ GetPropertyAsBoolean() [1/2]

static bool Mobi.Mtld.DA.Api.GetPropertyAsBoolean ( Hashtable  tree,
string  userAgent,
string  property 
)
inlinestatic

Strongly typed property accessor. Returns a boolean property (or throws an exception if the property is actually of another type)

<seealso cref= #getProperty(HashMap,String,String)

Parameters
treepreviously generated HashMap tree
userAgentthe device's User-Agent header string
propertythe name of the property to return
Returns
boolean property
Exceptions
IncorrectPropertyTypeExceptionSee
See also
IncorrectPropertyTypeException
InvalidPropertyExceptionSee
See also
InvalidPropertyException
UnknownPropertyExceptionSee
See also
UnknownPropertyException
ClientPropertiesExceptionSee
See also
ClientPropertiesException

◆ GetPropertyAsBoolean() [2/2]

static bool Mobi.Mtld.DA.Api.GetPropertyAsBoolean ( Hashtable  tree,
string  userAgent,
string  cookie,
string  property 
)
inlinestatic

Strongly typed property accessor. Returns a boolean property (or throws an exception if the property is actually of another type)

<seealso cref= #getProperty(HashMap,String,String)

Parameters
treepreviously generated HashMap tree
userAgentthe device's User-Agent header string
cookiethe contents of the cookie containing the client side properties
propertythe name of the property to return
Returns
boolean property
Exceptions
IncorrectPropertyTypeExceptionSee
See also
IncorrectPropertyTypeException
InvalidPropertyExceptionSee
See also
InvalidPropertyException
UnknownPropertyExceptionSee
See also
UnknownPropertyException
ClientPropertiesExceptionSee
See also
ClientPropertiesException

◆ GetPropertyAsInteger() [1/2]

static int Mobi.Mtld.DA.Api.GetPropertyAsInteger ( Hashtable  tree,
string  userAgent,
string  property 
)
inlinestatic

Strongly typed property accessor. Returns an integer property (or throws an exception if the property is actually of another type)

<seealso cref= #getProperty(HashMap,String,String)

Parameters
treepreviously generated HashMap tree
userAgentthe device's User-Agent header string
propertythe name of the property to return
Returns
int property
Exceptions
IncorrectPropertyTypeExceptionSee
See also
IncorrectPropertyTypeException
InvalidPropertyExceptionSee
See also
InvalidPropertyException
UnknownPropertyExceptionSee
See also
UnknownPropertyException
ClientPropertiesExceptionSee
See also
ClientPropertiesException

◆ GetPropertyAsInteger() [2/2]

static int Mobi.Mtld.DA.Api.GetPropertyAsInteger ( Hashtable  tree,
string  userAgent,
string  cookie,
string  property 
)
inlinestatic

Strongly typed property accessor. Returns an integer property (or throws an exception if the property is actually of another type)

<seealso cref= #getProperty(HashMap,String,String)

Parameters
treepreviously generated HashMap tree
userAgentthe device's User-Agent header string
cookiethe contents of the cookie containing the client side properties
propertythe name of the property to return
Returns
int property
Exceptions
IncorrectPropertyTypeExceptionSee
See also
IncorrectPropertyTypeException
InvalidPropertyExceptionSee
See also
InvalidPropertyException
UnknownPropertyExceptionSee
See also
UnknownPropertyException
ClientPropertiesExceptionSee
See also
ClientPropertiesException

◆ GetPropertyAsString() [1/2]

static string Mobi.Mtld.DA.Api.GetPropertyAsString ( Hashtable  tree,
string  userAgent,
string  property 
)
inlinestatic

Strongly typed property accessor. Returns a string property (or throws an exception if the property is actually of another type)

<seealso cref= #getProperty(HashMap,String,String)

Parameters
treepreviously generated HashMap tree
userAgentthe device's User-Agent header string
propertythe name of the property to return
Returns
String property
Exceptions
IncorrectPropertyTypeExceptionSee
See also
IncorrectPropertyTypeException
InvalidPropertyExceptionSee
See also
InvalidPropertyException
UnknownPropertyExceptionSee
See also
UnknownPropertyException
ClientPropertiesExceptionSee
See also
ClientPropertiesException

◆ GetPropertyAsString() [2/2]

static string Mobi.Mtld.DA.Api.GetPropertyAsString ( Hashtable  tree,
string  userAgent,
string  cookie,
string  property 
)
inlinestatic

Strongly typed property accessor. Returns a string property (or throws an exception if the property is actually of another type)

<seealso cref= #getProperty(HashMap,String,String)

Parameters
treepreviously generated HashMap tree
userAgentthe device's User-Agent header string
cookiethe contents of the cookie containing the client side properties
propertythe name of the property to return
Returns
String property
Exceptions
IncorrectPropertyTypeExceptionSee
See also
IncorrectPropertyTypeException
InvalidPropertyExceptionSee
See also
InvalidPropertyException
UnknownPropertyExceptionSee
See also
UnknownPropertyException
ClientPropertiesExceptionSee
See also
ClientPropertiesException

◆ GetTreeFromFile() [1/3]

static Hashtable Mobi.Mtld.DA.Api.GetTreeFromFile ( string  filename)
inlinestatic

Returns a tree from a JSON file, If it has been previously loaded then the version from the static cache will be returned. To reload from file call getTreeFromFile() with reload set to true.

Some properties cannot be known before runtime and can change from user-agent to user-agent. The most common of these are the OS Version and the Browser Version. This API is able to dynamically detect these changing properties but introduces a small overhead to do so. To disable returning these extra properties set includeChangeableUserAgentProperties to false.

Returns
HashMap The loaded JSON tree
Parameters
filenamethe location of the file to read in. Use an absolute path name to be sure of success if the current working directory is not clear.
Exceptions
JsonException
See also
JsonException
IOExceptionThere was an unknown error reading the JSON file

◆ GetTreeFromFile() [2/3]

static Hashtable Mobi.Mtld.DA.Api.GetTreeFromFile ( string  filename,
bool  reload 
)
inlinestatic

Returns a tree from a JSON file. The loaded tree is stored in a static cache to avoid multiple reloads if this method is repeatedly called. To reload from the JSON file set reload to true.

Some properties cannot be known before runtime and can change from user-agent to user-agent. The most common of these are the OS Version and the Browser Version. This API is able to dynamically detect these changing properties but introduces a small overhead to do so. To disable returning these extra properties call getTreeFromFile() with includeChangeableUserAgentProperties set to false.

Parameters
filenamethe location of the file to read in. Use an absolute path name to be sure of success if the current working directory is not clear.
reloadset true to reload regardless of static cache
Returns
HashMap The loaded JSON tree
Exceptions
JsonException
See also
JsonException
IOExceptionThere was an unknown error reading the JSON file

◆ GetTreeFromFile() [3/3]

static Hashtable Mobi.Mtld.DA.Api.GetTreeFromFile ( string  filename,
bool  reload,
bool  includeChangeableUserAgentProperties 
)
inlinestatic

Returns a tree from a JSON file. The loaded tree is stored in a static cache to avoid multiple reloads if this method is repeatedly called. To reload from the JSON file set reload to true.

Some properties cannot be known before runtime and can change from user-agent to user-agent. The most common of these are the OS Version and the Browser Version. This API is able to dynamically detect these changing properties but introduces a small overhead to do so. To disable returning these extra properties set includeChangeableUserAgentProperties to false.

Parameters
filenamethe location of the file to read in. Use an absolute path name to be sure of success if the current working directory is not clear.
reloadset true to reload regardless of static cache
includeChangeableUserAgentPropertiesAlso detect changeable user-agent properties
Returns
HashMap tree
Exceptions
JsonException
See also
JsonException
IOExceptionThere was an unknown error reading the JSON file

◆ GetTreeFromString() [1/2]

static Hashtable Mobi.Mtld.DA.Api.GetTreeFromString ( string  json)
inlinestatic

Returns a loaded JSON tree from a string of JSON data. This will also initialise the changeable property recognition.

Some properties cannot be known before runtime and can change from user-agent to user-agent. The most common of these are the OS Version and the Browser Version. This API is able to dynamically detect these changing properties but introduces a small overhead to do so. To disable returning these extra properties call getTreeFromString() with includeChangeableUserAgentProperties set to false.


This method does not use the built in static cache.

Parameters
jsonThe JSON HashMap object
Returns
The loaded JSON tree
Exceptions
JsonException

◆ GetTreeFromString() [2/2]

static Hashtable Mobi.Mtld.DA.Api.GetTreeFromString ( string  json,
bool  includeChangeableUserAgentProperties 
)
inlinestatic

Returns a loaded JSON tree from a string of JSON data.

Some properties cannot be known before runtime and can change from user-agent to user-agent. The most common of these are the OS Version and the Browser Version. This API is able to dynamically detect these changing properties but introduces a small overhead to do so. To disable returning these extra properties set includeChangeableUserAgentProperties to false.


This method does not use the built in static cache.

Parameters
jsonThe string of json data.
includeChangeableUserAgentPropertiesAlso detect changeable user-agent properties
Returns
The loaded JSON tree
Exceptions
JsonException
See also
JsonException

◆ GetTreeGeneration()

static string Mobi.Mtld.DA.Api.GetTreeGeneration ( Hashtable  tree)
inlinestatic

Get the generation date for this tree.

Parameters
tree
Returns
The time/date the tree was generated.

◆ GetTreeGenerationAsTimestamp()

static int Mobi.Mtld.DA.Api.GetTreeGenerationAsTimestamp ( Hashtable  tree)
inlinestatic

Get the generation date for this tree as a UNIX timestamp.

Parameters
tree
Returns
The time/date the tree was generated.

◆ GetTreeRevision()

static int Mobi.Mtld.DA.Api.GetTreeRevision ( Hashtable  tree)
inlinestatic

Returns the revision number of the tree

Parameters
treepreviously generated HashMap tree
Returns
integer revision

◆ ListProperties()

static Hashtable Mobi.Mtld.DA.Api.ListProperties ( Hashtable  tree)
inlinestatic

Returns a HashMap of known property names available for the user agents in this file, with their data type names

Parameters
treepreviously generated HashMap tree
Returns
HashMap properties

The documentation for this class was generated from the following file: