DeviceApi
public class Api extends 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 HashMap |
getProperties(HashMap tree,
String userAgent)
Deprecated.
Returns a HashMap of known properties (as strings) for the user agent
|
static HashMap |
getProperties(HashMap tree,
String userAgent,
String cookie)
Deprecated.
Returns a HashMap of known properties merged with properties from the client
side JavaScript.
|
static HashMap |
getPropertiesAsTyped(HashMap tree,
String userAgent)
Deprecated.
Returns a HashMap of known properties (as typed) for the user agent
|
static HashMap |
getPropertiesAsTyped(HashMap tree,
String userAgent,
String cookie)
Deprecated.
Returns a HashMap of known properties merged with properties from the client
side JavaScript.
|
static String |
getProperty(HashMap tree,
String userAgent,
String property)
Deprecated.
Returns a value for the named property for this user agent
|
static String |
getProperty(HashMap tree,
String userAgent,
String cookie,
String property)
Deprecated.
Returns a value for the named property for this user agent
|
static boolean |
getPropertyAsBoolean(HashMap tree,
String userAgent,
String property)
Deprecated.
Strongly typed property accessor.
|
static boolean |
getPropertyAsBoolean(HashMap tree,
String userAgent,
String cookie,
String property)
Deprecated.
Strongly typed property accessor.
|
static String |
getPropertyAsDate(HashMap tree,
String userAgent,
String property)
Deprecated.
|
static String |
getPropertyAsDate(HashMap tree,
String userAgent,
String cookie,
String property)
Deprecated.
|
static int |
getPropertyAsInteger(HashMap tree,
String userAgent,
String property)
Deprecated.
Strongly typed property accessor.
|
static int |
getPropertyAsInteger(HashMap tree,
String userAgent,
String cookie,
String property)
Deprecated.
Strongly typed property accessor.
|
static String |
getPropertyAsString(HashMap tree,
String userAgent,
String property)
Deprecated.
Strongly typed property accessor.
|
static String |
getPropertyAsString(HashMap tree,
String userAgent,
String cookie,
String property)
Deprecated.
Strongly typed property accessor.
|
static HashMap |
getTreeFromFile(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 HashMap |
getTreeFromFile(String filename,
boolean reload)
Deprecated.
Returns a tree from a JSON file.
|
static HashMap |
getTreeFromFile(String filename,
boolean reload,
boolean includeChangeableUserAgentProperties)
Deprecated.
Returns a tree from a JSON file.
|
static HashMap |
getTreeFromString(String json)
Deprecated.
Returns a loaded JSON tree from a string of JSON data.
|
static HashMap |
getTreeFromString(String json,
boolean includeChangeableUserAgentProperties)
Deprecated.
Returns a loaded JSON tree from a string of JSON data.
|
static String |
getTreeGeneration(HashMap tree)
Deprecated.
Get the generation date for this tree.
|
static int |
getTreeGenerationAsTimestamp(HashMap tree)
Deprecated.
Get the generation date for this tree as a UNIX timestamp.
|
static int |
getTreeRevision(HashMap tree)
Deprecated.
Returns the revision number of the tree
|
static HashMap |
listProperties(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 HashMap getTreeFromString(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 HashMap getTreeFromString(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 HashMap getTreeFromFile(String filename) throws JsonException, 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
IOException
- There was an unknown error reading the JSON filepublic static HashMap getTreeFromFile(String filename, boolean reload) throws JsonException, 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
IOException
- There was an unknown error reading the JSON filepublic static HashMap getTreeFromFile(String filename, boolean reload, boolean includeChangeableUserAgentProperties) throws JsonException, 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
IOException
- There was an unknown error reading the JSON filepublic static String getTreeGeneration(HashMap tree)
tree
- public static int getTreeGenerationAsTimestamp(HashMap tree)
tree
- public static int getApiRevision()
public static int getTreeRevision(HashMap tree)
tree
- previously generated HashMap treepublic static HashMap listProperties(HashMap tree)
tree
- previously generated HashMap treepublic static HashMap getProperties(HashMap tree, String userAgent)
tree
- previously generated HashMap treeuserAgent
- The device's User-Agent header stringpublic static HashMap getProperties(HashMap tree, String userAgent, 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 HashMap getPropertiesAsTyped(HashMap tree, String userAgent)
tree
- previously generated HashMap treeuserAgent
- the device's User-Agent header stringpublic static HashMap getPropertiesAsTyped(HashMap tree, String userAgent, 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 String getProperty(HashMap tree, String userAgent, 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 String getProperty(HashMap tree, String userAgent, String cookie, 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 String getPropertyAsString(HashMap tree, String userAgent, 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 String getPropertyAsString(HashMap tree, String userAgent, String cookie, 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(HashMap tree, String userAgent, 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(HashMap tree, String userAgent, String cookie, 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(HashMap tree, String userAgent, 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(HashMap tree, String userAgent, String cookie, 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 String getPropertyAsDate(HashMap tree, String userAgent, String property) throws IncorrectPropertyTypeException, InvalidPropertyException, UnknownPropertyException
public static String getPropertyAsDate(HashMap tree, String userAgent, String cookie, String property) throws IncorrectPropertyTypeException, InvalidPropertyException, UnknownPropertyException, ClientPropertiesException
Copyright © 2021 DeviceAtlas Limited. All rights reserved.