DeviceApi
public class Api
extends java.lang.Object
HashMap tree = Api.getTreeFromFile("data_file/sample.json");
HashMap prps = Api.getProperties(tree, "Nokia6680...");
Object prop = Api.getProperty(tree, "Nokia6680...", "displayWidth");
String ua = request.getHeader("User-Agent");
int displayWidth = Api.getPropertyAsInteger(tree, ua, "displayWidth");
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");
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);
Constructor and Description |
---|
Api()
Deprecated.
|
Modifier and Type | Method and Description |
---|---|
static int |
getApiRevision()
Deprecated.
Returns the revision number of this API
|
static java.util.HashMap |
getProperties(java.util.HashMap tree,
java.lang.String userAgent)
Deprecated.
Returns a HashMap of known properties (as strings) for the user agent
|
static java.util.HashMap |
getProperties(java.util.HashMap tree,
java.lang.String userAgent,
java.lang.String cookie)
Deprecated.
Returns a HashMap of known properties merged with properties from the client
side JavaScript.
|
static java.util.HashMap |
getPropertiesAsTyped(java.util.HashMap tree,
java.lang.String userAgent)
Deprecated.
Returns a HashMap of known properties (as typed) for the user agent
|
static java.util.HashMap |
getPropertiesAsTyped(java.util.HashMap tree,
java.lang.String userAgent,
java.lang.String cookie)
Deprecated.
Returns a HashMap of known properties merged with properties from the client
side JavaScript.
|
static java.lang.String |
getProperty(java.util.HashMap tree,
java.lang.String userAgent,
java.lang.String property)
Deprecated.
Returns a value for the named property for this user agent
|
static java.lang.String |
getProperty(java.util.HashMap tree,
java.lang.String userAgent,
java.lang.String cookie,
java.lang.String property)
Deprecated.
Returns a value for the named property for this user agent
|
static boolean |
getPropertyAsBoolean(java.util.HashMap tree,
java.lang.String userAgent,
java.lang.String property)
Deprecated.
Strongly typed property accessor.
|
static boolean |
getPropertyAsBoolean(java.util.HashMap tree,
java.lang.String userAgent,
java.lang.String cookie,
java.lang.String property)
Deprecated.
Strongly typed property accessor.
|
static java.lang.String |
getPropertyAsDate(java.util.HashMap tree,
java.lang.String userAgent,
java.lang.String property)
Deprecated.
|
static java.lang.String |
getPropertyAsDate(java.util.HashMap tree,
java.lang.String userAgent,
java.lang.String cookie,
java.lang.String property)
Deprecated.
|
static int |
getPropertyAsInteger(java.util.HashMap tree,
java.lang.String userAgent,
java.lang.String property)
Deprecated.
Strongly typed property accessor.
|
static int |
getPropertyAsInteger(java.util.HashMap tree,
java.lang.String userAgent,
java.lang.String cookie,
java.lang.String property)
Deprecated.
Strongly typed property accessor.
|
static java.lang.String |
getPropertyAsString(java.util.HashMap tree,
java.lang.String userAgent,
java.lang.String property)
Deprecated.
Strongly typed property accessor.
|
static java.lang.String |
getPropertyAsString(java.util.HashMap tree,
java.lang.String userAgent,
java.lang.String cookie,
java.lang.String property)
Deprecated.
Strongly typed property accessor.
|
static java.util.HashMap |
getTreeFromFile(java.lang.String filename)
Deprecated.
Returns a tree from a JSON file, If it has been previously loaded then the
version from the static cache will be returned.
|
static java.util.HashMap |
getTreeFromFile(java.lang.String filename,
boolean reload)
Deprecated.
Returns a tree from a JSON file.
|
static java.util.HashMap |
getTreeFromFile(java.lang.String filename,
boolean reload,
boolean includeChangeableUserAgentProperties)
Deprecated.
Returns a tree from a JSON file.
|
static java.util.HashMap |
getTreeFromString(java.lang.String json)
Deprecated.
Returns a loaded JSON tree from a string of JSON data.
|
static java.util.HashMap |
getTreeFromString(java.lang.String json,
boolean includeChangeableUserAgentProperties)
Deprecated.
Returns a loaded JSON tree from a string of JSON data.
|
static java.lang.String |
getTreeGeneration(java.util.HashMap tree)
Deprecated.
Get the generation date for this tree.
|
static int |
getTreeGenerationAsTimestamp(java.util.HashMap tree)
Deprecated.
Get the generation date for this tree as a UNIX timestamp.
|
static int |
getTreeRevision(java.util.HashMap tree)
Deprecated.
Returns the revision number of the tree
|
static java.util.HashMap |
listProperties(java.util.HashMap tree)
Deprecated.
Returns a HashMap of known property names available for the user agents
in this file, with their data type names
|
public static java.util.HashMap getTreeFromString(java.lang.String json) throws JsonException
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.
json
- The JSON HashMap objectJsonException
public static java.util.HashMap getTreeFromString(java.lang.String json, boolean includeChangeableUserAgentProperties) throws JsonException
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.
json
- The string of json data.includeChangeableUserAgentProperties
- Also detect changeable user-agent propertiesJsonException
- JsonException
public static java.util.HashMap getTreeFromFile(java.lang.String filename) throws JsonException, java.io.IOException
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.
filename
- the 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.JsonException
- JsonException
java.io.IOException
- There was an unknown error reading the JSON filepublic static java.util.HashMap getTreeFromFile(java.lang.String filename, boolean reload) throws JsonException, java.io.IOException
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.
filename
- the 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.reload
- set true to reload regardless of static cacheJsonException
- JsonException
java.io.IOException
- There was an unknown error reading the JSON filepublic static java.util.HashMap getTreeFromFile(java.lang.String filename, boolean reload, boolean includeChangeableUserAgentProperties) throws JsonException, java.io.IOException
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.
filename
- the 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.reload
- set true to reload regardless of static cacheincludeChangeableUserAgentProperties
- Also detect changeable user-agent propertiesJsonException
- JsonException
java.io.IOException
- There was an unknown error reading the JSON filepublic static java.lang.String getTreeGeneration(java.util.HashMap tree)
tree
- public static int getTreeGenerationAsTimestamp(java.util.HashMap tree)
tree
- public static int getApiRevision()
public static int getTreeRevision(java.util.HashMap tree)
tree
- previously generated HashMap treepublic static java.util.HashMap listProperties(java.util.HashMap tree)
tree
- previously generated HashMap treepublic static java.util.HashMap getProperties(java.util.HashMap tree, java.lang.String userAgent)
tree
- previously generated HashMap treeuserAgent
- The device's User-Agent header stringpublic static java.util.HashMap getProperties(java.util.HashMap tree, java.lang.String userAgent, java.lang.String cookie) throws ClientPropertiesException
tree
- previously generated HashMap treeuserAgent
- the device's User-Agent header stringcookie
- the contents of the cookie containing the client side propertiesClientPropertiesException
- See ClientPropertiesException
public static java.util.HashMap getPropertiesAsTyped(java.util.HashMap tree, java.lang.String userAgent)
tree
- previously generated HashMap treeuserAgent
- the device's User-Agent header stringpublic static java.util.HashMap getPropertiesAsTyped(java.util.HashMap tree, java.lang.String userAgent, java.lang.String cookie) throws ClientPropertiesException
tree
- previously generated HashMap treeuserAgent
- the device's User-Agent header stringcookie
- the contents of the cookie containing the client side propertiesClientPropertiesException
- See ClientPropertiesException
public static java.lang.String getProperty(java.util.HashMap tree, java.lang.String userAgent, java.lang.String property) throws InvalidPropertyException, UnknownPropertyException
tree
- previously generated HashMap treeuserAgent
- the device's User-Agent header stringproperty
- the name of the property to returnInvalidPropertyException
- See InvalidPropertyException
UnknownPropertyException
- See UnknownPropertyException
public static java.lang.String getProperty(java.util.HashMap tree, java.lang.String userAgent, java.lang.String cookie, java.lang.String property) throws InvalidPropertyException, UnknownPropertyException, ClientPropertiesException
tree
- previously generated HashMap treeuserAgent
- the device's User-Agent header stringcookie
- the contents of the cookie containing the client side propertiesproperty
- the name of the property to returnInvalidPropertyException
- See InvalidPropertyException
UnknownPropertyException
- See UnknownPropertyException
ClientPropertiesException
public static java.lang.String getPropertyAsString(java.util.HashMap tree, java.lang.String userAgent, java.lang.String property) throws IncorrectPropertyTypeException, InvalidPropertyException, UnknownPropertyException
tree
- previously generated HashMap treeuserAgent
- the device's User-Agent header stringproperty
- the name of the property to returnIncorrectPropertyTypeException
- See IncorrectPropertyTypeException
InvalidPropertyException
- See InvalidPropertyException
UnknownPropertyException
- See UnknownPropertyException
ClientPropertiesException
- See ClientPropertiesException
getProperty(HashMap,String,String)
public static java.lang.String getPropertyAsString(java.util.HashMap tree, java.lang.String userAgent, java.lang.String cookie, java.lang.String property) throws IncorrectPropertyTypeException, InvalidPropertyException, UnknownPropertyException, ClientPropertiesException
tree
- previously generated HashMap treeuserAgent
- the device's User-Agent header stringcookie
- the contents of the cookie containing the client side propertiesproperty
- the name of the property to returnIncorrectPropertyTypeException
- See IncorrectPropertyTypeException
InvalidPropertyException
- See InvalidPropertyException
UnknownPropertyException
- See UnknownPropertyException
ClientPropertiesException
- See ClientPropertiesException
getProperty(HashMap,String,String)
public static boolean getPropertyAsBoolean(java.util.HashMap tree, java.lang.String userAgent, java.lang.String property) throws IncorrectPropertyTypeException, InvalidPropertyException, UnknownPropertyException
tree
- previously generated HashMap treeuserAgent
- the device's User-Agent header stringproperty
- the name of the property to returnIncorrectPropertyTypeException
- See IncorrectPropertyTypeException
InvalidPropertyException
- See InvalidPropertyException
UnknownPropertyException
- See UnknownPropertyException
ClientPropertiesException
- See ClientPropertiesException
getProperty(HashMap,String,String)
public static boolean getPropertyAsBoolean(java.util.HashMap tree, java.lang.String userAgent, java.lang.String cookie, java.lang.String property) throws IncorrectPropertyTypeException, InvalidPropertyException, UnknownPropertyException, ClientPropertiesException
tree
- previously generated HashMap treeuserAgent
- the device's User-Agent header stringcookie
- the contents of the cookie containing the client side propertiesproperty
- the name of the property to returnIncorrectPropertyTypeException
- See IncorrectPropertyTypeException
InvalidPropertyException
- See InvalidPropertyException
UnknownPropertyException
- See UnknownPropertyException
ClientPropertiesException
- See ClientPropertiesException
getProperty(HashMap,String,String)
public static int getPropertyAsInteger(java.util.HashMap tree, java.lang.String userAgent, java.lang.String property) throws IncorrectPropertyTypeException, InvalidPropertyException, UnknownPropertyException
tree
- previously generated HashMap treeuserAgent
- the device's User-Agent header stringproperty
- the name of the property to returnIncorrectPropertyTypeException
- See IncorrectPropertyTypeException
InvalidPropertyException
- See InvalidPropertyException
UnknownPropertyException
- See UnknownPropertyException
ClientPropertiesException
- See ClientPropertiesException
getProperty(HashMap,String,String)
public static int getPropertyAsInteger(java.util.HashMap tree, java.lang.String userAgent, java.lang.String cookie, java.lang.String property) throws IncorrectPropertyTypeException, InvalidPropertyException, UnknownPropertyException, ClientPropertiesException
tree
- previously generated HashMap treeuserAgent
- the device's User-Agent header stringcookie
- the contents of the cookie containing the client side propertiesproperty
- the name of the property to returnIncorrectPropertyTypeException
- See IncorrectPropertyTypeException
InvalidPropertyException
- See InvalidPropertyException
UnknownPropertyException
- See UnknownPropertyException
ClientPropertiesException
- See ClientPropertiesException
getProperty(HashMap,String,String)
public static java.lang.String getPropertyAsDate(java.util.HashMap tree, java.lang.String userAgent, java.lang.String property) throws IncorrectPropertyTypeException, InvalidPropertyException, UnknownPropertyException
public static java.lang.String getPropertyAsDate(java.util.HashMap tree, java.lang.String userAgent, java.lang.String cookie, java.lang.String property) throws IncorrectPropertyTypeException, InvalidPropertyException, UnknownPropertyException, ClientPropertiesException