|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectmobi.mtld.da.Api
public class Api
Used to load the recognition tree and perform lookups of all properties, or get
individual properties. Typical usage is as follows:
HashMap tree = Api.getTreeFromFile("sample/DeviceAtlas.json");
HashMap 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)
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");
| Constructor Summary | |
|---|---|
Api()
|
|
| Method Summary | |
|---|---|
static int |
getApiRevision()
Returns the revision number of this API |
static java.util.HashMap |
getProperties(java.util.HashMap tree,
java.lang.String userAgent)
Returns a HashMap of known properties (as strings) for the user agent |
static java.util.HashMap |
getPropertiesAsTyped(java.util.HashMap tree,
java.lang.String userAgent)
Returns a HashMap of known properties (as typed) for the user agent |
static java.lang.String |
getProperty(java.util.HashMap tree,
java.lang.String userAgent,
java.lang.String property)
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)
Strongly typed property accessor. |
static java.lang.String |
getPropertyAsDate(java.util.HashMap tree,
java.lang.String userAgent,
java.lang.String property)
Strongly typed property accessor. |
static int |
getPropertyAsInteger(java.util.HashMap tree,
java.lang.String userAgent,
java.lang.String property)
Strongly typed property accessor. |
static java.lang.String |
getPropertyAsString(java.util.HashMap tree,
java.lang.String userAgent,
java.lang.String property)
Strongly typed property accessor. |
static java.util.HashMap |
getTreeFromFile(java.lang.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. |
static java.util.HashMap |
getTreeFromFile(java.lang.String filename,
boolean reload)
Returns a tree from a JSON file. |
static java.util.HashMap |
getTreeFromFile(java.lang.String filename,
boolean reload,
boolean includeChangeableUserAgentProperties)
Returns a tree from a JSON file. |
static java.util.HashMap |
getTreeFromString(java.lang.String json)
Returns a loaded JSON tree from a string of JSON data. |
static java.util.HashMap |
getTreeFromString(java.lang.String json,
boolean includeChangeableUserAgentProperties)
Returns a loaded JSON tree from a string of JSON data. |
static java.lang.String |
getTreeGeneration(java.util.HashMap tree)
Get the generation date for this tree. |
static int |
getTreeGenerationAsTimestamp(java.util.HashMap tree)
Get the generation date for this tree as a UNIX timestamp. |
static int |
getTreeRevision(java.util.HashMap tree)
Returns the revision number of the tree |
static java.util.HashMap |
listProperties(java.util.HashMap tree)
Returns a HashMap of known property names available for the user agents in this file, with their data type names |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public Api()
| Method Detail |
|---|
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 object
JsonException
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 properties
JsonException - 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 file
public 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 cache
JsonException - JsonException
java.io.IOException - There was an unknown error reading the JSON file
public 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 properties
JsonException - 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 tree
public static java.util.HashMap listProperties(java.util.HashMap tree)
tree - previously generated HashMap tree
public static java.util.HashMap getProperties(java.util.HashMap tree,
java.lang.String userAgent)
tree - previously generated HashMap treeuserAgent - string from the device's User-Agent header
public static java.util.HashMap getPropertiesAsTyped(java.util.HashMap tree,
java.lang.String userAgent)
tree - previously generated HashMap treeuserAgent - string from the device's User-Agent header
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 - string from the device's User-Agent headerproperty - the name of the property to return
InvalidPropertyException - See InvalidPropertyException
UnknownPropertyException - See UnknownPropertyException
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 - string from the device's User-Agent headerproperty - the name of the property to return
IncorrectPropertyTypeException - See IncorrectPropertyTypeException
InvalidPropertyException - See InvalidPropertyException
UnknownPropertyException - See UnknownPropertyExceptiongetProperty(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 - string from the device's User-Agent headerproperty - the name of the property to return
IncorrectPropertyTypeException - See IncorrectPropertyTypeException
InvalidPropertyException - See InvalidPropertyException
UnknownPropertyException - See UnknownPropertyExceptiongetProperty(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 - string from the device's User-Agent headerproperty - the name of the property to return
IncorrectPropertyTypeException - See IncorrectPropertyTypeException
InvalidPropertyException - See InvalidPropertyException
UnknownPropertyException - See UnknownPropertyExceptiongetProperty(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
tree - previously generated HashMap treeuserAgent - string from the device's User-Agent headerproperty - the name of the property to return
IncorrectPropertyTypeException - See IncorrectPropertyTypeException
InvalidPropertyException - See InvalidPropertyException
UnknownPropertyException - See UnknownPropertyExceptiongetProperty(HashMap,String,String)
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||